Handle multi-uom
Button to manually update standard from Bom now restricted to MRP manager Improve module description
This commit is contained in:
@@ -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.
|
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 <alexis.delattre@akretion.com> for any help or question about this module.
|
This module has been written by Alexis de Lattre from Akretion
|
||||||
|
<alexis.delattre@akretion.com>.
|
||||||
""",
|
""",
|
||||||
'author': 'Akretion',
|
'author': 'Akretion',
|
||||||
'website': 'http://www.akretion.com',
|
'website': 'http://www.akretion.com',
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
# © 2016-2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
# © 2016-2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# 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
|
import odoo.addons.decimal_precision as dp
|
||||||
from odoo.exceptions import UserError
|
from odoo.tools import float_compare, float_is_zero
|
||||||
from odoo.tools import float_compare
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -114,7 +113,7 @@ class MrpBom(models.Model):
|
|||||||
string='Extra Cost', track_visibility='onchange',
|
string='Extra Cost', track_visibility='onchange',
|
||||||
digits=dp.get_precision('Product Price'),
|
digits=dp.get_precision('Product Price'),
|
||||||
help="Extra cost for the production of the quantity of "
|
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 "
|
"You can use this field to enter the cost of the consumables "
|
||||||
"that are used to produce the product but are not listed in "
|
"that are used to produce the product but are not listed in "
|
||||||
"the BOM")
|
"the BOM")
|
||||||
@@ -125,8 +124,9 @@ class MrpBom(models.Model):
|
|||||||
total_cost = fields.Float(
|
total_cost = fields.Float(
|
||||||
compute='_compute_total_cost', readonly=True, string='Total Cost',
|
compute='_compute_total_cost', readonly=True, string='Total Cost',
|
||||||
digits=dp.get_precision('Product Price'),
|
digits=dp.get_precision('Product Price'),
|
||||||
help="Total Cost = Total Components Cost + "
|
help="Total Cost for the production of the quantity of the BOM "
|
||||||
"Total Labour Cost + Extra Cost")
|
"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):
|
def manual_update_product_standard_price(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
@@ -150,7 +150,6 @@ class MrpBom(models.Model):
|
|||||||
'''Called by cron'''
|
'''Called by cron'''
|
||||||
logger.info(
|
logger.info(
|
||||||
'Start automatic update of cost price of phantom bom products')
|
'Start automatic update of cost price of phantom bom products')
|
||||||
origin = 'Automatic update of Phantom BOMs'
|
|
||||||
boms = self.env['mrp.bom'].search([('type', '=', 'phantom')])
|
boms = self.env['mrp.bom'].search([('type', '=', 'phantom')])
|
||||||
for bom in boms:
|
for bom in boms:
|
||||||
bom.manual_update_product_standard_price()
|
bom.manual_update_product_standard_price()
|
||||||
@@ -185,10 +184,19 @@ class MrpProduction(models.Model):
|
|||||||
|
|
||||||
def _generate_finished_moves(self):
|
def _generate_finished_moves(self):
|
||||||
move = super(MrpProduction, self)._generate_finished_moves()
|
move = super(MrpProduction, self)._generate_finished_moves()
|
||||||
if self.bom_id:
|
prec = self.env['decimal.precision'].precision_get(
|
||||||
move.price_unit = self.bom_id.total_cost
|
'Product Unit of Measure')
|
||||||
# TODO: handle uom conversion
|
if (
|
||||||
self.unit_cost = self.bom_id.total_cost
|
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
|
return move
|
||||||
|
|
||||||
# No need to write directly on standard_price of product
|
# No need to write directly on standard_price of product
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
options="{'currency_field': 'company_currency_id'}"
|
options="{'currency_field': 'company_currency_id'}"
|
||||||
class="oe_inline"/>
|
class="oe_inline"/>
|
||||||
<button type="object" name="manual_update_product_standard_price"
|
<button type="object" name="manual_update_product_standard_price"
|
||||||
string="Update Cost Price of Product" class="oe_link"/>
|
string="Update Cost Price of Product" class="oe_link"
|
||||||
|
groups="mrp.group_mrp_manager"/>
|
||||||
</div>
|
</div>
|
||||||
<field name="company_currency_id" invisible="1"/>
|
<field name="company_currency_id" invisible="1"/>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user