-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFR] l10n_eu_product_adr: allow different adr goods per variant
- Loading branch information
1 parent
60a4ffb
commit ee881f5
Showing
10 changed files
with
371 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2021 Opener B.V. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
try: | ||
from openupgradelib import openupgrade | ||
except ImportError: | ||
openupgrade = None | ||
|
||
|
||
def migrate(cr, version): | ||
"""Move adr data from product_template to product_product""" | ||
if ( | ||
not openupgrade | ||
or not openupgrade.column_exists(cr, "product_template", "adr_goods_id") | ||
or openupgrade.column_exists(cr, "product_product", "adr_goods_id") | ||
): | ||
return | ||
cr.execute( | ||
""" | ||
ALTER TABLE product_product | ||
ADD COLUMN adr_goods_id INTEGER, | ||
ADD COLUMN is_dangerous BOOLEAN; | ||
UPDATE product_product pp | ||
SET adr_goods_id = pt.adr_goods_id, | ||
is_dangerous = pt.is_dangerous | ||
FROM product_template pt | ||
WHERE pt.id = pp.product_tmpl_id | ||
""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
l10n_eu_product_adr/migrations/14.0.1.1.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2021 Opener B.V. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
try: | ||
from openupgradelib import openupgrade | ||
except ImportError: | ||
openupgrade = None | ||
|
||
|
||
def migrate(cr, version): | ||
"""Move adr data from product_template to product_product""" | ||
if ( | ||
not openupgrade | ||
or not openupgrade.column_exists(cr, "product_template", "adr_goods_id") | ||
or openupgrade.column_exists(cr, "product_product", "adr_goods_id") | ||
): | ||
return | ||
cr.execute( | ||
""" | ||
ALTER TABLE product_product | ||
ADD COLUMN adr_goods_id INTEGER, | ||
ADD COLUMN is_dangerous BOOLEAN; | ||
UPDATE product_product pp | ||
SET adr_goods_id = pt.adr_goods_id, | ||
is_dangerous = pt.is_dangerous | ||
FROM product_template pt | ||
WHERE pt.id = pp.product_tmpl_id | ||
""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright 2019 Iryna Vyshnevska (Camptocamp) | ||
# Copyright 2021 Opener B.V. <stefan@opener.amsterdam> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import api, fields, models | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.product" | ||
|
||
is_dangerous = fields.Boolean(help="This product belongs to a dangerous class") | ||
adr_goods_id = fields.Many2one("adr.goods", "Dangerous Goods") | ||
adr_class_id = fields.Many2one( | ||
"adr.class", related="adr_goods_id.class_id", readonly=True | ||
) | ||
adr_classification_code = fields.Char( | ||
related="adr_goods_id.classification_code", readonly=True | ||
) | ||
adr_label_ids = fields.Many2many( | ||
"adr.label", related="adr_goods_id.label_ids", readonly=True | ||
) | ||
adr_limited_quantity = fields.Float( | ||
related="adr_goods_id.limited_quantity", | ||
readonly=True, | ||
) | ||
adr_limited_quantity_uom_id = fields.Many2one( | ||
related="adr_goods_id.limited_quantity_uom_id", | ||
readonly=True, | ||
) | ||
adr_packing_instruction_ids = fields.Many2many( | ||
"adr.packing.instruction", | ||
related="adr_goods_id.packing_instruction_ids", | ||
readonly=True, | ||
) | ||
adr_transport_category = fields.Selection( | ||
related="adr_goods_id.transport_category", readonly=True | ||
) | ||
adr_tunnel_restriction_code = fields.Selection( | ||
related="adr_goods_id.tunnel_restriction_code", readonly=True | ||
) | ||
|
||
@api.onchange("is_dangerous") | ||
def onchange_is_dangerous(self): | ||
"""Remove the dangerous goods attribute from the product | ||
(when is_dangerous is deselected) | ||
""" | ||
if not self.is_dangerous and self.adr_goods_id: | ||
self.adr_goods_id = False | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
"""Propagate the template's adr settings when creating variants""" | ||
for vals in vals_list: | ||
if ( | ||
"product_tmpl_id" in vals | ||
and "adr_goods_id" not in vals | ||
and "is_dangerous" not in vals | ||
): | ||
template = self.env["product.template"].browse(vals["product_tmpl_id"]) | ||
vals.update( | ||
{ | ||
"adr_goods_id": template.adr_goods_id.id, | ||
"is_dangerous": template.is_dangerous, | ||
} | ||
) | ||
return super().create(vals_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.