From 479e1a271028933e9145c479396c8c3c71e2f8e7 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 23 May 2017 10:27:00 +0200 Subject: [PATCH] Handle multi-uom Button to manually update standard from Bom now restricted to MRP manager Improve module description --- mrp_average_cost/__manifest__.py | 5 +++-- mrp_average_cost/mrp.py | 30 +++++++++++++++++++----------- mrp_average_cost/mrp_view.xml | 3 ++- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/mrp_average_cost/__manifest__.py b/mrp_average_cost/__manifest__.py index 19c48cb..ac62be4 100644 --- a/mrp_average_cost/__manifest__.py +++ b/mrp_average_cost/__manifest__.py @@ -14,9 +14,10 @@ MRP Average Cost By default, the official *stock* module updates the *standard_price* of a product that has costing_method = *average* when validating an incoming picking. But the official *mrp* module doesn't do that when you validate a manufactuging order. -With this module, when you validate a manufacturing order of a product that has costing method = *average*, the standard_price of the product will be updated by taking into account the standard_price of each raw material and also the labour cost lines defined on the BOM. +With this module, when you validate a manufacturing order of a product that has costing method = *average*, the standard_price of the product will be updated by taking into account the standard_price of each raw material and also the labour cost lines defined on the BOM. In fact, if you use the costing method *Last Price* (from the module *stock_cost_method_last*), it will work too. -Please contact Alexis de Lattre from Akretion for any help or question about this module. +This module has been written by Alexis de Lattre from Akretion +. """, 'author': 'Akretion', 'website': 'http://www.akretion.com', diff --git a/mrp_average_cost/mrp.py b/mrp_average_cost/mrp.py index 11f4542..ccc8c53 100644 --- a/mrp_average_cost/mrp.py +++ b/mrp_average_cost/mrp.py @@ -2,10 +2,9 @@ # © 2016-2017 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api, _ +from odoo import models, fields, api import odoo.addons.decimal_precision as dp -from odoo.exceptions import UserError -from odoo.tools import float_compare +from odoo.tools import float_compare, float_is_zero import logging logger = logging.getLogger(__name__) @@ -114,7 +113,7 @@ class MrpBom(models.Model): string='Extra Cost', track_visibility='onchange', digits=dp.get_precision('Product Price'), help="Extra cost for the production of the quantity of " - "items of the BOM, in company currency. " + "the BOM in the unit of measure of the BOM, in company currency. " "You can use this field to enter the cost of the consumables " "that are used to produce the product but are not listed in " "the BOM") @@ -125,8 +124,9 @@ class MrpBom(models.Model): total_cost = fields.Float( compute='_compute_total_cost', readonly=True, string='Total Cost', digits=dp.get_precision('Product Price'), - help="Total Cost = Total Components Cost + " - "Total Labour Cost + Extra Cost") + help="Total Cost for the production of the quantity of the BOM " + "in the unit of measure of the BOM in company currency. Total Cost = " + "Total Components Cost + Total Labour Cost + Extra Cost") def manual_update_product_standard_price(self): self.ensure_one() @@ -150,7 +150,6 @@ class MrpBom(models.Model): '''Called by cron''' logger.info( 'Start automatic update of cost price of phantom bom products') - origin = 'Automatic update of Phantom BOMs' boms = self.env['mrp.bom'].search([('type', '=', 'phantom')]) for bom in boms: bom.manual_update_product_standard_price() @@ -185,10 +184,19 @@ class MrpProduction(models.Model): def _generate_finished_moves(self): move = super(MrpProduction, self)._generate_finished_moves() - if self.bom_id: - move.price_unit = self.bom_id.total_cost - # TODO: handle uom conversion - self.unit_cost = self.bom_id.total_cost + prec = self.env['decimal.precision'].precision_get( + 'Product Unit of Measure') + if ( + self.bom_id and + not float_is_zero( + self.bom_id.product_qty, precision_digits=prec)): + unit_cost_bom_uom =\ + self.bom_id.total_cost / self.bom_id.product_qty + unit_cost_mo_uom = self.bom_id.product_uom_id._compute_quantity( + unit_cost_bom_uom, self.product_uom_id) + # MO and finished move are in the same UoM + move.price_unit = unit_cost_mo_uom + self.unit_cost = unit_cost_mo_uom return move # No need to write directly on standard_price of product diff --git a/mrp_average_cost/mrp_view.xml b/mrp_average_cost/mrp_view.xml index 8cbd3af..478a2a9 100644 --- a/mrp_average_cost/mrp_view.xml +++ b/mrp_average_cost/mrp_view.xml @@ -21,7 +21,8 @@ options="{'currency_field': 'company_currency_id'}" class="oe_inline"/>