From e44cd81ef2198eb5dd7d0bd02d081518a1feec37 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Fri, 14 Jul 2023 10:16:56 +0200 Subject: [PATCH 1/2] [IMP] product_packaging_dimension: Don't use max_weight anymore As max_weight is defined now on stock.package.type, rely on that one. Migrate data that was filled in to weight field. --- product_packaging_dimension/__manifest__.py | 2 +- .../migrations/16.0.1.1.0/post-migrate.py | 22 +++++++++++++++++++ .../models/product_packaging.py | 7 +++--- .../views/product_packaging.xml | 7 ------ 4 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 product_packaging_dimension/migrations/16.0.1.1.0/post-migrate.py diff --git a/product_packaging_dimension/__manifest__.py b/product_packaging_dimension/__manifest__.py index 9b1c06fb879..f7451123f1c 100644 --- a/product_packaging_dimension/__manifest__.py +++ b/product_packaging_dimension/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Product Packaging Dimension", "summary": "Manage packaging dimensions and weight", - "version": "16.0.1.0.2", + "version": "16.0.1.1.0", "category": "Product", "author": "Camptocamp, Akretion, Odoo Community Association (OCA)", "license": "AGPL-3", diff --git a/product_packaging_dimension/migrations/16.0.1.1.0/post-migrate.py b/product_packaging_dimension/migrations/16.0.1.1.0/post-migrate.py new file mode 100644 index 00000000000..cb18cc1a59f --- /dev/null +++ b/product_packaging_dimension/migrations/16.0.1.1.0/post-migrate.py @@ -0,0 +1,22 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +def _move_max_weight(env): + """ + Move max_weight value to weight if not defined + """ + query = """ + UPDATE product_packaging + SET weight = max_weight + WHERE weight IS NULL OR weight = 0.0 + AND max_weight IS NOT NULL + AND product_id IS NOT NULL + """ + openupgrade.logged_query(env.cr, query) + + +@openupgrade.migrate() +def migrate(env, version): + _move_max_weight(env) diff --git a/product_packaging_dimension/models/product_packaging.py b/product_packaging_dimension/models/product_packaging.py index e248f1173b1..e790f6e0b79 100644 --- a/product_packaging_dimension/models/product_packaging.py +++ b/product_packaging_dimension/models/product_packaging.py @@ -14,9 +14,9 @@ class ProductPackaging(models.Model): ("positive_width", "CHECK(width>=0)", "Width must be positive"), ("positive_length", "CHECK(packaging_length>=0)", "Length must be positive"), ( - "positive_max_weight", - "CHECK(max_weight>=0)", - "Max Weight must be positive", + "positive_weight", + "CHECK(weight>=0)", + "Weight must be positive", ), ] height = fields.Integer() @@ -41,7 +41,6 @@ class ProductPackaging(models.Model): ) weight = fields.Float() - max_weight = fields.Float("Maximum Weight") weight_uom_id = fields.Many2one( "uom.uom", string="Weight Units of Measure", diff --git a/product_packaging_dimension/views/product_packaging.xml b/product_packaging_dimension/views/product_packaging.xml index 9ba820036fd..417093c4025 100644 --- a/product_packaging_dimension/views/product_packaging.xml +++ b/product_packaging_dimension/views/product_packaging.xml @@ -37,13 +37,6 @@ - -