[IMP] Invoice_state on move and search custom picking type
authorJosse Colpaert <jco@odoo.com>
Mon, 8 Sep 2014 13:20:01 +0000 (15:20 +0200)
committerJosse Colpaert <jco@odoo.com>
Fri, 12 Sep 2014 11:49:42 +0000 (13:49 +0200)
addons/mrp/mrp.py
addons/stock/stock.py
addons/stock_account/stock.py
addons/stock_account/stock_account_view.xml

index c06acff..5f84cda 100644 (file)
@@ -1065,16 +1065,32 @@ class mrp_production(osv.osv):
 
 
 
+
     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)
+        precedes the consumption line (chained).  The picking type depends on the warehouse in which this happens
+        and the type of locations. 
         '''
-        
+        loc_obj = self.pool.get("stock.location")
         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)
+        # Need to search for a picking type
+        src_loc = loc_obj.browse(cr, uid, source_location_id, context=context)
+        dest_loc = loc_obj.browse(cr, uid, dest_location_id, context=context)
+        code = 'internal'
+        check_loc = dest_loc
+        if src_loc.usage == 'internal' and dest_loc.usage != 'internal':
+            code = 'outgoing'
+            check_loc = src_loc
+        if src_loc.usage != 'internal' and dest_loc.usage == 'internal':
+            code = 'incoming'
+        wh = loc_obj.get_warehouse(cr, uid, check_loc, context=context)
+        domain = [('code','=', code)]
+        if wh: 
+            domain += [('warehouse_id', '=', wh)]
+        types = type_obj.search(cr, uid, domain, context=context)
         move = stock_move.copy(cr, uid, move_id, default = {
             'location_id': source_location_id,
             'location_dest_id': dest_location_id,
index f033b4d..9b9d8a5 100644 (file)
@@ -189,6 +189,16 @@ class stock_location(osv.osv):
         return self._default_removal_strategy(cr, uid, context=context)
 
 
+    def get_warehouse(self, cr, uid, location, context=None):
+        """
+            Returns warehouse id of warehouse that contains location
+            :param location: browse record (stock.location)
+        """
+        wh_obj = self.pool.get("stock.warehouse")
+        whs = wh_obj.search(cr, uid, [('view_location_id.parent_left', '<=', location.parent_left), 
+                                ('view_location_id.parent_right', '>=', location.parent_left)], context=context)
+        return whs and whs[0] or False
+
 #----------------------------------------------------------
 # Routes
 #----------------------------------------------------------
@@ -3460,6 +3470,7 @@ class stock_warehouse(osv.osv):
             'limit': 20
         }
 
+
 class stock_location_path(osv.osv):
     _name = "stock.location.path"
     _description = "Pushed Flows"
index 12f6c76..f1a3680 100644 (file)
@@ -97,7 +97,6 @@ class stock_move(osv.osv):
     def _get_master_data(self, cr, uid, move, company, context=None):
         ''' returns a tuple (browse_record(res.partner), ID(res.users), ID(res.currency)'''
         currency = company.currency_id.id
-        import pdb; pdb.set_trace()
         partner = move.picking_id and move.picking_id.partner_id
         if partner:
             if partner.property_product_pricelist and move.location_id.usage == 'internal' and move.location_dest_id.usage != 'internal':
@@ -193,11 +192,6 @@ class stock_picking(osv.osv):
                 res.append(move.picking_id.id)
         return res
 
-    def _set_inv_state(self, cr, uid, picking_id, name, value, arg, context=None):
-        pick = self.browse(cr, uid, picking_id, context=context)
-        moves = [x.id for x in pick.move_lines]
-        move_obj= self.pool.get("stock.move")
-        move_obj.write(cr, uid, moves, {'invoice_state': pick.invoice_state})
 
 
     _columns = {
@@ -206,7 +200,6 @@ class stock_picking(osv.osv):
             ("2binvoiced", "To Be Invoiced"),
             ("none", "Not Applicable")
           ], string="Invoice Control", required=True,
-        #fnct_inv = _set_inv_state,
         store={
             'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['state'], 10),
             'stock.move': (__get_picking_move, ['picking_id', 'invoice_state'], 10),
index dbce1a9..a3dd626 100644 (file)
                 </xpath>
             </field>
         </record>
+        <record model="ir.ui.view" id="view_move_picking_from_stockaccount_inherit">
+            <field name="name">stock.move.form.invoice_state</field>
+            <field name="model">stock.move</field>
+            <field name="inherit_id" ref="stock.view_move_picking_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='date_expected']" position="after">
+                    <field name="invoice_state" groups="account.group_account_invoice"/>
+                </xpath>
+            </field>
+        </record>
     </data>
 </openerp>