From 884a8ad4a56009f9e993048954dc7722eb0194c0 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 29 Sep 2014 17:48:38 +0200 Subject: [PATCH] [IMP] UoM corrections + Adapt tables in stock doc [IMP] Float_compare before splitting moves in mrp --- addons/mrp/mrp.py | 7 ++-- addons/mrp/stock.py | 6 ++- addons/mrp/wizard/mrp_product_produce.py | 8 ++-- addons/stock/doc/stock.rst | 50 ++++++++++++------------ 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 26528d34b1a..7bfa74cfa45 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -816,7 +816,8 @@ class mrp_production(osv.osv): #In case no product_qty is given, take the remaining qty to produce for the given production if not product_qty: - product_qty = uom_obj._compute_qty(cr, uid, production.uom_id.id, production.product_qty, production.product_id.uom_id.id) - produced_qty + product_qty = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, production.product_id.uom_id.id) - produced_qty + production_qty = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, production.product_id.uom_id.id) scheduled_qty = {} for scheduled in production.product_lines: @@ -844,8 +845,8 @@ class mrp_production(osv.osv): dicts[product_id] = {} # total qty of consumed product we need after this consumption - if product_qty + produced_qty <= production.product_qty: - total_consume = ((product_qty + produced_qty) * sched_product_qty / production.product_qty) + if product_qty + produced_qty <= production_qty: + total_consume = ((product_qty + produced_qty) * sched_product_qty / production_qty) else: total_consume = sched_product_qty qty = total_consume - consumed_qty diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 39850990fa8..adf20d0bc0f 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -25,7 +25,7 @@ from openerp.osv import fields from openerp.osv import osv from openerp.tools.translate import _ from openerp import SUPERUSER_ID -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, float_compare class StockMove(osv.osv): _inherit = 'stock.move' @@ -181,7 +181,9 @@ class StockMove(osv.osv): if move_qty <= 0: raise osv.except_osv(_('Error!'), _('Cannot consume a move with negative or zero quantity.')) quantity_rest = move_qty - product_qty - if quantity_rest > 0: + # Compare with numbers of move uom as we want to avoid a split with 0 qty + quantity_rest_uom = move.product_uom_qty - self.pool.get("product.uom")._compute_qty_obj(cr, uid, move.product_id.uom_id, product_qty, move.product_uom) + if float_compare(quantity_rest_uom, 0, precision_rounding=move.product_uom.rounding) != 0: new_mov = self.split(cr, uid, move, quantity_rest, context=context) res.append(new_mov) vals = {'restrict_lot_id': restrict_lot_id, diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py index 890ec211b07..f41bcec9c76 100644 --- a/addons/mrp/wizard/mrp_product_produce.py +++ b/addons/mrp/wizard/mrp_product_produce.py @@ -61,11 +61,13 @@ class mrp_product_produce(osv.osv_memory): which the user can still adapt """ prod_obj = self.pool.get("mrp.production") + uom_obj = self.pool.get("product.uom") production = prod_obj.browse(cr, uid, context['active_id'], context=context) consume_lines = [] new_consume_lines = [] if product_qty > 0.0: - consume_lines = prod_obj._calculate_qty(cr, uid, production, product_qty=product_qty, context=context) + product_uom_qty = uom_obj._compute_qty(cr, uid, production.product_uom.id, product_qty, production.product_id.uom_id.id) + consume_lines = prod_obj._calculate_qty(cr, uid, production, product_qty=product_uom_qty, context=context) for consume in consume_lines: new_consume_lines.append([0, False, consume]) @@ -88,8 +90,8 @@ class mrp_product_produce(osv.osv_memory): for move in prod.move_created_ids2: if move.product_id == prod.product_id: if not move.scrapped: - done += move.product_qty - return (prod.product_qty - done) or prod.product_qty + done += move.product_uom_qty # As uom of produced products and production order should correspond + return prod.product_qty - done def _get_product_id(self, cr, uid, context=None): """ To obtain product id diff --git a/addons/stock/doc/stock.rst b/addons/stock/doc/stock.rst index c12427fc19d..0f49cabd285 100644 --- a/addons/stock/doc/stock.rst +++ b/addons/stock/doc/stock.rst @@ -237,38 +237,38 @@ To see a calculation of the lead times, take the example of the cabinet above. S Bill of Materials for 1 SHE100 Unit -+-------------+----------+------------ -| Product Code| Quantity | UoM | -+====================================+ -|SIDEPAN | 2 | PCE | -+-------------+----------+-----------+ -|LIN040 | 1 | M | -+-------------+----------+-----------+ -|WOOD010 | 0.249| M | -+-------------+----------+-----------+ -|METC000 | 12| PCE | -+-------------+----------+-----------+ ++--------------+----------+-----------+ +| Product Code | Quantity | UoM | ++==============+==========+===========+ +| SIDEPAN | 2 | PCE | ++--------------+----------+-----------+ +| LIN040 | 1 | M | ++--------------+----------+-----------+ +| WOOD010 | 0.249 | M | ++--------------+----------+-----------+ +| METC000 | 12 | PCE | ++--------------+----------+-----------+ Bill of Materials for 2 SIDEPAN Units -+-------------+----------+------------ -| Product Code| Quantity | UoM | -+====================================+ -| WOOD002 | 0.17| M | -+-------------+----------+------------ ++--------------+----------+-----------+ +| Product Code | Quantity | UoM | ++==============+==========+===========+ +| WOOD002 | 0.17 | M | ++--------------+----------+-----------+ The SIDEPAN is made from an order using the workflow shown. The WOOD002 is purchased on order and the other products are all found in stock. An order for the product SHE100 will then generate two production orders (SHE100 and SIDEPAN) then produce two purchase orders for the product WOOD002. Product WOOD002 is used in the production of both SHE100 and SIDEPAN. Set the lead times on the product forms to the following: -+-------------+-------------------+------------------------+---------------------+ -|Product Code |Customer Lead Time |Manufacturing Lead Time |Supplier Lead Time | -+================================================================================+ -|SHE100 | 30 days | 5 days | | -+-------------+-------------------+------------------------+---------------------+ -|SIDEPAN | | 10 days | | -+-------------+-------------------+------------------------+---------------------+ -|WOOD002 | | | 5 days | -+-------------+-------------------+------------------------+---------------------+ ++--------------+--------------------+-------------------------+--------------------+ +| Product Code | Customer Lead Time | Manufacturing Lead Time | Supplier Lead Time | ++=============+=====================+=========================+====================+ +| SHE100 | 30 days | 5 days | | ++--------------+--------------------+-------------------------+--------------------+ +| SIDEPAN | | 10 days | | ++--------------+--------------------+-------------------------+--------------------+ +| WOOD002 | | | 5 days | ++--------------+--------------------+-------------------------+--------------------+ A customer order placed on the 1st January will set up the following operations and lead times: