| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from odoo import fields, models, _ |
| 5 |
from odoo.addons.stock_landed_costs.models.stock_landed_cost import SPLIT_METHOD |
| 6 |
from odoo.exceptions import UserError |
| 7 |
|
| 8 |
|
| 9 |
class ProductTemplate(models.Model): |
| 10 |
_inherit = "product.template" |
| 11 |
|
| 12 |
landed_cost_ok = fields.Boolean('Is a Landed Cost', help='Indicates whether the product is a landed cost: when receiving a vendor bill, you can allocate this cost on preceding receipts.') |
| 13 |
split_method_landed_cost = fields.Selection( |
| 14 |
SPLIT_METHOD, string="Default Split Method", |
| 15 |
help="Default Split Method when used for Landed Cost") |
| 16 |
|
| 17 |
def write(self, vals): |
| 18 |
for product in self: |
| 19 |
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: |
| 20 |
if self.env['account.move.line'].search_count([('product_id', 'in', product.product_variant_ids.ids), ('is_landed_costs_line', '=', True)]): |
| 21 |
raise UserError(_("You cannot change the product type or disable landed cost option because the product is used in an account move line.")) |
| 22 |
vals['landed_cost_ok'] = False |
| 23 |
|
| 24 |
return super().write(vals) |