From 497a4700fbcb9beb167feacb965d94fdb2b29222 Mon Sep 17 00:00:00 2001 From: "Djamel (otd)" Date: Mon, 7 Jun 2021 12:17:28 +0000 Subject: [PATCH] [FIX] stock_landed_cost: Moving of the fix #71596 from the product module to stock_landed_cost module Link to the original commit: https://github.com/odoo/odoo/pull/71596/commits/fc9d63f541340ebcd485cffcd6e9a3ee6cd57f49 opw-2547663 closes odoo/odoo#71890 X-original-commit: 4139a80ac6c366289be7e328329d4868f7685e3d Signed-off-by: William Henrotin Signed-off-by: Djamel Touati --- .../stock_landed_costs/i18n/stock_landed_costs.pot | 8 ++++++++ addons/stock_landed_costs/models/product.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/addons/stock_landed_costs/i18n/stock_landed_costs.pot b/addons/stock_landed_costs/i18n/stock_landed_costs.pot index 7a3bad085a3..96169c5391b 100644 --- a/addons/stock_landed_costs/i18n/stock_landed_costs.pot +++ b/addons/stock_landed_costs/i18n/stock_landed_costs.pot @@ -756,3 +756,11 @@ msgid "" "applied for products with automated inventory valuation and FIFO or average " "costing method." msgstr "" + +#. module: stock_landed_costs +#: code:addons/stock_landed_costs/models/product.py:0 +#, python-format +msgid "" +"You cannot change the product type or disable landed cost option because the" +" product is used in an account move line." +msgstr "" diff --git a/addons/stock_landed_costs/models/product.py b/addons/stock_landed_costs/models/product.py index 4318955cc71..52cec5828c8 100644 --- a/addons/stock_landed_costs/models/product.py +++ b/addons/stock_landed_costs/models/product.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import fields, models, _ from odoo.addons.stock_landed_costs.models.stock_landed_cost import SPLIT_METHOD +from odoo.exceptions import UserError class ProductTemplate(models.Model): @@ -11,3 +12,12 @@ class ProductTemplate(models.Model): landed_cost_ok = fields.Boolean('Is a Landed Cost', help='Indicates whether the product is a landed cost.') split_method_landed_cost = fields.Selection(SPLIT_METHOD, string="Default Split Method", help="Default Split Method when used for Landed Cost") + + def write(self, vals): + for product in self: + if (('type' in vals and vals['type'] != 'service') or ('landed_cost_ok' in vals and not vals['landed_cost_ok'])) and product.type == 'service' and product.landed_cost_ok: + if self.env['account.move.line'].search_count([('product_id', 'in', product.product_variant_ids.ids), ('is_landed_costs_line', '=', True)]): + raise UserError(_("You cannot change the product type or disable landed cost option because the product is used in an account move line.")) + else: + vals['landed_cost_ok'] = False + super(ProductTemplate, product).write(vals)