From 661a204edae79a96ce9ba8f57aaeabd76d6f84f7 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 29 Sep 2014 11:13:44 +0200 Subject: [PATCH] [IMP] Better demo data + property comment + recheck [IMP] Recheck should be type object and procure_method read only when not in draft [FIX] Inversion of moves in the correct way and assigning production_id As the moves are split the other way, the original move needs to be done. Also the production_id for linking the new to be produced moves and the production order must be written on those. [IMP] Clean --- addons/mrp/mrp.py | 11 +++++------ addons/mrp/mrp_demo.xml | 2 +- addons/mrp/stock.py | 15 ++++++--------- addons/stock/stock_view.xml | 4 ++-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index f302ff8f03c..26528d34b1a 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -220,11 +220,13 @@ class mrp_bom(osv.osv): domain = domain + [ '|', ('date_start', '=', False), ('date_start', '<=', time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)), '|', ('date_stop', '=', False), ('date_stop', '>=', time.strftime(DEFAULT_SERVER_DATETIME_FORMAT))] # order to prioritize bom with product_id over the one without - ids = self.search(cr, uid, domain, order='product_id') + ids = self.search(cr, uid, domain, order='product_id', context=context) + # Search a BoM which has all properties specified, or if you can not find one, you could + # pass a BoM without any properties bom_empty_prop = False - for bom in self.pool.get('mrp.bom').browse(cr, uid, ids): + for bom in self.pool.get('mrp.bom').browse(cr, uid, ids, context=context): if not set(map(int, bom.property_ids or [])) - set(properties or []): - if not bom.property_ids: + if properties and not bom.property_ids: bom_empty_prop = bom.id else: return bom.id @@ -827,7 +829,6 @@ class mrp_production(osv.osv): scheduled_qty[scheduled.product_id.id] = qty dicts = {} # Find product qty to be consumed and consume it - quants_taken = [] for product_id in scheduled_qty.keys(): consumed_qty = consumed_data.get(product_id, 0.0) @@ -909,9 +910,7 @@ class mrp_production(osv.osv): produced_products[produced_product.product_id.id] += produced_product.product_qty for produce_product in production.move_created_ids: - produced_qty = produced_products.get(produce_product.product_id.id, 0) subproduct_factor = self._get_subproduct_factor(cr, uid, production.id, produce_product.id, context=context) - rest_qty = (subproduct_factor * production.product_qty) - produced_qty lot_id = False if wiz: lot_id = wiz.lot_id.id diff --git a/addons/mrp/mrp_demo.xml b/addons/mrp/mrp_demo.xml index 863f19e9bd3..3af8d7d9c0e 100644 --- a/addons/mrp/mrp_demo.xml +++ b/addons/mrp/mrp_demo.xml @@ -451,7 +451,7 @@ 5 - phantom + normal diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 721a4d48233..39850990fa8 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -157,13 +157,12 @@ class StockMove(osv.osv): @param restrict_lot_id: optionnal parameter that allows to restrict the choice of quants on this specific lot @param restrict_partner_id: optionnal parameter that allows to restrict the choice of quants to this specific partner @param consumed_for: optionnal parameter given to this function to make the link between raw material consumed and produced product, for a better traceability - @return: Consumed lines + @return: New lines created if not everything was consumed for this line """ if context is None: context = {} res = [] production_obj = self.pool.get('mrp.production') - uom_obj = self.pool.get('product.uom') if product_qty <= 0: raise osv.except_osv(_('Warning!'), _('Please provide proper quantity.')) @@ -175,7 +174,6 @@ class StockMove(osv.osv): else: ids2.append(move.id) - toassign_move_ids = [] prod_orders = set() for move in self.browse(cr, uid, ids2, context=context): prod_orders.add(move.raw_material_production_id.id or move.production_id.id) @@ -185,18 +183,17 @@ class StockMove(osv.osv): quantity_rest = move_qty - product_qty if quantity_rest > 0: new_mov = self.split(cr, uid, move, quantity_rest, context=context) - if move.location_id.usage == 'internal': - toassign_move_ids.append(new_mov) - res.append(move.id) + res.append(new_mov) vals = {'restrict_lot_id': restrict_lot_id, 'restrict_partner_id': restrict_partner_id, 'consumed_for': consumed_for} if location_id: vals.update({'location_id': location_id}) self.write(cr, uid, [move.id], vals, context=context) - self.action_done(cr, uid, res, context=context) - if toassign_move_ids: - self.action_assign(cr, uid, toassign_move_ids, context=context) + # Original moves will be the quantities consumed, so they need to be done + self.action_done(cr, uid, ids2, context=context) + if res: + self.action_assign(cr, uid, res, context=context) if prod_orders: production_obj.signal_workflow(cr, uid, list(prod_orders), 'button_produce') return res diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 675a5bcb883..7e45cb20a8d 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -646,7 +646,7 @@