# -*- coding: utf-8 -*- ################################################################################ # # Cybrosys Technologies Pvt. Ltd. # # Copyright (C) 2023-TODAY Cybrosys Technologies(). # Author: Sruthi Renjith (odoo@cybrosys.com) # # You can modify it under the terms of the GNU AFFERO # GENERAL PUBLIC LICENSE (AGPL v3), Version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. # # You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE # (AGPL v3) along with this program. # If not, see . # ################################################################################ from odoo import fields, models class ProductTemplate(models.Model): """ Class to inherit product.template to add costing method """ _inherit = 'product.template' property_cost_method = fields.Selection([ ('standard', 'Standard Price'), ('last', 'Last Purchase Price'), ('fifo', 'First In First Out (FIFO)'), ('average', 'Average Cost (AVCO)')], string='Costing Method', company_dependent=True, copy=True, help="""Standard Price: The products are valued at their standard cost defined on the product. Average Cost (AVCO): The products are valued at weighted average cost. First In First Out (FIFO): The products are valued supposing those that enter the company first will also leave it first. Last Purchase Price: The products are valued same as 'Standard Price' Method, But standard price defined on the product will be updated automatically with last purchase price.""") def _set_cost_method(self): """ When going from FIFO to AVCO or to standard, we update the standard price with the average value in stock """ if (self.property_cost_method == 'fifo' and self.cost_method in ['average', 'standard', 'last']): # Cannot use the `stock_value` computed field as it's already # invalidated when entering this method. valuation = sum([variant._sum_remaining_values()[0] for variant in self.product_variant_ids]) qty_available = self.with_context(company_owned=True).qty_available if qty_available: self.standard_price = valuation / qty_available return self.write({'property_cost_method': self.cost_method})