[IMP] Old hack where uom_id had to be empty in on_change
authorJosse Colpaert <jco@odoo.com>
Mon, 1 Sep 2014 13:39:32 +0000 (15:39 +0200)
committerJosse Colpaert <jco@odoo.com>
Fri, 12 Sep 2014 11:49:41 +0000 (13:49 +0200)
[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
addons/purchase/purchase.py
addons/sale_stock/sale_stock.py
addons/stock/stock.py
addons/stock_account/stock.py

index 9e6afe3..2c48480 100644 (file)
@@ -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):
index fb2a40d..2cd492e 100644 (file)
@@ -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)
index 4371a40..7fef11b 100644 (file)
@@ -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:
index 47bf0ad..acbc9b6 100644 (file)
@@ -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,
             })
index 644128f..7a0d5cc 100644 (file)
@@ -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
 #----------------------------------------------------------