diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/stock_landed_costs/models/product.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/stock_landed_costs/models/product.py')
| -rw-r--r-- | addons/stock_landed_costs/models/product.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/addons/stock_landed_costs/models/product.py b/addons/stock_landed_costs/models/product.py new file mode 100644 index 00000000..9b78e7e9 --- /dev/null +++ b/addons/stock_landed_costs/models/product.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models +from odoo.addons.stock_landed_costs.models.stock_landed_cost import SPLIT_METHOD +from odoo.exceptions import UserError +from odoo import _ + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + 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.")) + vals['landed_cost_ok'] = False + + return super().write(vals) |
