From 064b1a3a404eef5c5140c33d405c9ac1ea0066b0 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 1 Sep 2014 15:39:32 +0200 Subject: [PATCH] [IMP] Old hack where uom_id had to be empty in on_change [IMP] Add purchase order origin on picking [WIP] Picking type on move for location on routing [IMP] Provide extra function for custom buttons on picking [IMP] Action assign optim [IMP] Push apply should take invoice_state into account. Propagation of cancel of stock moves should depend on procurement rule --- addons/mrp/mrp.py | 7 +++++++ addons/purchase/purchase.py | 4 +++- addons/sale_stock/sale_stock.py | 2 +- addons/stock/stock.py | 30 ++++++++++++++++++------------ addons/stock_account/stock.py | 5 +++++ 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 9e6afe3cc2c..2c484808064 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -1059,19 +1059,25 @@ class mrp_production(osv.osv): return "make_to_order" return "make_to_stock" + + def _create_previous_move(self, cr, uid, move_id, product, source_location_id, dest_location_id, context=None): ''' When the routing gives a different location than the raw material location of the production order, we should create an extra move from the raw material location to the location of the routing, which precedes the consumption line (chained) ''' + stock_move = self.pool.get('stock.move') + type_obj = self.pool.get('stock.picking.type') + types = type_obj.search(cr, uid, [('code','=','outgoing')], context=context) move = stock_move.copy(cr, uid, move_id, default = { 'location_id': source_location_id, 'location_dest_id': dest_location_id, 'procure_method': self._get_raw_material_procure_method(cr, uid, product, context=context), 'raw_material_production_id': False, 'move_dest_id': move_id, + 'picking_type_id': types and types[0] or False, }, context=context) return move @@ -1109,6 +1115,7 @@ class mrp_production(osv.osv): if prev_move: prev_move = self._create_previous_move(cr, uid, move_id, product, prod_location_id, source_location_id, context=context) + stock_move.action_confirm(cr, uid, [prev_move], context=context) return move_id def _make_production_consume_line(self, cr, uid, line, context=None): diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index fb2a40d2741..2cd492e1b9f 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -741,6 +741,7 @@ class purchase_order(osv.osv): 'group_id': procurement.group_id.id or group_id, #move group is same as group of procurements if it exists, otherwise take another group 'procurement_id': procurement.id, 'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state=='picking' and '2binvoiced') or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale + 'propagate': procurement.rule_id.propagate, }) diff_quantity -= min(procurement_qty, diff_quantity) res.append(tmp) @@ -821,7 +822,8 @@ class purchase_order(osv.osv): picking_vals = { 'picking_type_id': order.picking_type_id.id, 'partner_id': order.dest_address_id.id or order.partner_id.id, - 'date': max([l.date_planned for l in order.order_line]) + 'date': max([l.date_planned for l in order.order_line]), + 'origin': order.name } picking_id = self.pool.get('stock.picking').create(cr, uid, picking_vals, context=context) self._create_stock_moves(cr, uid, order, order.order_line, picking_id, context=context) diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 4371a40a100..7fef11b7472 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -289,7 +289,7 @@ class sale_order_line(osv.osv): product_obj = self.pool.get('product.product') warning = {} res = self.product_id_change(cr, uid, ids, pricelist, product, qty=qty, - uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, + uom=False, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context) if not product: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 47bf0ad29bd..acbc9b672c3 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -3503,6 +3503,22 @@ class stock_location_path(osv.osv): 'active': True, } + def _prepare_push_apply(self, cr, uid, rule, move, context=None): + newdate = (datetime.strptime(move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta.relativedelta(days=rule.delay or 0)).strftime(DEFAULT_SERVER_DATETIME_FORMAT) + return { + 'location_id': move.location_dest_id.id, + 'location_dest_id': rule.location_dest_id.id, + 'date': newdate, + 'company_id': rule.company_id and rule.company_id.id or False, + 'date_expected': newdate, + 'picking_id': False, + 'picking_type_id': rule.picking_type_id and rule.picking_type_id.id or False, + 'propagate': rule.propagate, + 'push_rule_id': rule.id, + 'warehouse_id': rule.warehouse_id and rule.warehouse_id.id or False, + } + + def _apply(self, cr, uid, rule, move, context=None): move_obj = self.pool.get('stock.move') newdate = (datetime.strptime(move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta.relativedelta(days=rule.delay or 0)).strftime(DEFAULT_SERVER_DATETIME_FORMAT) @@ -3519,18 +3535,8 @@ class stock_location_path(osv.osv): #call again push_apply to see if a next step is defined move_obj._push_apply(cr, uid, [move], context=context) else: - move_id = move_obj.copy(cr, uid, move.id, { - 'location_id': move.location_dest_id.id, - 'location_dest_id': rule.location_dest_id.id, - 'date': newdate, - 'company_id': rule.company_id and rule.company_id.id or False, - 'date_expected': newdate, - 'picking_id': False, - 'picking_type_id': rule.picking_type_id and rule.picking_type_id.id or False, - 'propagate': rule.propagate, - 'push_rule_id': rule.id, - 'warehouse_id': rule.warehouse_id and rule.warehouse_id.id or False, - }) + vals = self._prepare_push_apply(cr, uid, rule, move, context=context) + move_id = move_obj.copy(cr, uid, move.id, vals, context=context) move_obj.write(cr, uid, [move.id], { 'move_dest_id': move_id, }) diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py index 644128f2b5f..7a0d5ccca3b 100644 --- a/addons/stock_account/stock.py +++ b/addons/stock_account/stock.py @@ -33,6 +33,11 @@ class stock_location_path(osv.osv): 'invoice_state': '', } + def _prepare_push_apply(self, cr, uid, rule, move, context=None): + res = super(stock_location_path, self)._prepare_push_apply(cr, uid, rule, move, context=context) + res['invoice_state'] = rule.invoice_state or 'none' + return res + #---------------------------------------------------------- # Procurement Rule #----------------------------------------------------------