51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models
|
|
|
|
class ProductTemplate(models.Model):
|
|
_inherit = 'product.template'
|
|
|
|
@api.depends_context('company')
|
|
@api.depends('categ_id.property_cost_method')
|
|
def _compute_cost_method(self):
|
|
for product_template in self:
|
|
product_template.cost_method = (
|
|
product_template.categ_id.sudo().with_company(
|
|
product_template.company_id
|
|
).property_cost_method
|
|
or (product_template.company_id or self.env.company).cost_method
|
|
)
|
|
|
|
@api.depends_context('company')
|
|
@api.depends('categ_id.property_valuation')
|
|
def _compute_valuation(self):
|
|
for product_template in self:
|
|
product_template.valuation = (
|
|
product_template.categ_id.sudo().with_company(
|
|
product_template.company_id
|
|
).property_valuation
|
|
or self.env.company.inventory_valuation
|
|
)
|
|
|
|
def action_archive(self):
|
|
# Use sudo() to bypass multi-company checks during archival cascade
|
|
return super(ProductTemplate, self.sudo()).action_archive()
|
|
|
|
def write(self, vals):
|
|
# Use sudo() during archival write to bypass multi-company checks
|
|
if 'active' in vals and not vals['active']:
|
|
return super(ProductTemplate, self.sudo()).write(vals)
|
|
return super().write(vals)
|
|
|
|
class ProductProduct(models.Model):
|
|
_inherit = 'product.product'
|
|
|
|
def action_archive(self):
|
|
# Use sudo() to bypass multi-company checks during archival cascade
|
|
return super(ProductProduct, self.sudo()).action_archive()
|
|
|
|
def write(self, vals):
|
|
# Use sudo() during archival write to bypass multi-company checks
|
|
if 'active' in vals and not vals['active']:
|
|
return super(ProductProduct, self.sudo()).write(vals)
|
|
return super().write(vals)
|