Added in delivery module new field net weight in stock.move and stock.picking, becaus...
authorRenato Lima <renato@renato-laptop>
Fri, 3 Sep 2010 22:38:14 +0000 (19:38 -0300)
committerRenato Lima <renato@renato-laptop>
Fri, 3 Sep 2010 22:38:14 +0000 (19:38 -0300)
bzr revid: renato@renato-laptop-20100903223814-w22ajtb2dvoazn2p

addons/delivery/delivery_view.xml
addons/delivery/stock.py

index fdef01e..22ed5ef 100644 (file)
                     <field name="carrier_tracking_ref" groups="base.group_extended"/>
                     <field name="number_of_packages" groups="base.group_extended"/>
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </field>
             </field>
         </record>
             <field name="arch" type="xml">
                 <field name="type" position="after">
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </field>
             </field>
         </record>
             <field name="arch" type="xml">
                 <field name="type" position="after">
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </field>
             </field>
         </record>
                     <field name="carrier_tracking_ref" groups="base.group_extended"/>
                     <field name="number_of_packages" groups="base.group_extended"/>
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </field>
             </field>
         </record>
             <field name="arch" type="xml">
                 <xpath expr="/form/notebook/page/field[@name='move_lines']/tree/field[@name='product_uom']" position="after">
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </xpath>
             </field>
         </record>
             <field name="arch" type="xml">
                 <xpath expr="/form/notebook/page/field[@name='move_lines']/tree/field[@name='product_uom']" position="after">
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </xpath>
             </field>
         </record>
             <field name="inherit_id" ref="stock.view_picking_form"/>
             <field name="arch" type="xml">
                 <xpath expr="/form/notebook/page/field[@name='move_lines']/tree/field[@name='product_uom']" position="after">
-                    <field name="weight"/>
+                       <field name="weight"/>
+                    <field name="weight_net"/>
                 </xpath>
             </field>
         </record>
             <field name="arch" type="xml">
                 <xpath expr="/form/notebook/page/field[@name='move_lines']/tree/field[@name='product_uom']" position="after">
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </xpath>
             </field>
         </record>
             <field name="arch" type="xml">
                 <field name="product_uom" position="after">
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </field>
             </field>
         </record>
             <field name="arch" type="xml">
                 <field name="product_uom" position="after">
                     <field name="weight"/>
+                    <field name="weight_net"/>
                 </field>
             </field>
         </record>
index 76897d4..49d0364 100644 (file)
@@ -32,10 +32,19 @@ class stock_picking(osv.osv):
         res = {}
         uom_obj = self.pool.get('product.uom')
         for picking in self.browse(cr, uid, ids, context):
-            total_weight = 0.00
+            total_weight = total_weight_net = 0.00
+            
             for move in picking.move_lines:
                 total_weight += move.weight
-            res[picking.id] = total_weight
+                total_weight_net += move.weight_net
+            
+            res[picking.id] = {
+                              'weight': total_weight,
+                              'weight_net': total_weight_net,
+                               } 
+            
+            total_weight
+            
         return res
 
 
@@ -48,7 +57,12 @@ class stock_picking(osv.osv):
     _columns = {
         'carrier_id':fields.many2one("delivery.carrier","Carrier"),
         'volume': fields.float('Volume'),
-        'weight': fields.function(_cal_weight, method=True, type='float', string='Weight', digits_compute= dp.get_precision('Stock Weight'),
+        'weight': fields.function(_cal_weight, method=True, type='float', string='Weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_weight',
+                  store={
+                 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 20),
+                 'stock.move': (_get_picking_line, ['product_id','product_qty','product_uom','product_uos_qty'], 20),
+                 }),
+        'weight_net': fields.function(_cal_weight, method=True, type='float', string='Net Weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_weight',
                   store={
                  'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 20),
                  'stock.move': (_get_picking_line, ['product_id','product_qty','product_uom','product_uos_qty'], 20),
@@ -128,7 +142,7 @@ class stock_move(osv.osv):
         res = {}
         uom_obj = self.pool.get('product.uom')
         for move in self.browse(cr, uid, ids, context):
-            weight = 0.00
+            weight = weight_net = 0.00
             if move.product_id.weight > 0.00:
                 converted_qty = move.product_qty
                 
@@ -136,14 +150,27 @@ class stock_move(osv.osv):
                     converted_qty = uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, move.product_id.uom_id.id)
 
                 weight = (converted_qty * move.product_id.weight)
-            res[move.id] = weight
+                
+                if move.product_id.weight_net > 0.00:
+                    weight_net = (converted_qty * move.product_id.weight_net)
+                
+            res[move.id] =  {
+                            'weight': weight,
+                            'weight_net': weight_net,
+                            }
+            
         return res
     
     _columns = {
-        'weight': fields.function(_cal_move_weight, method=True, type='float', string='Weight', digits_compute= dp.get_precision('Stock Weight'),
+        'weight': fields.function(_cal_move_weight, method=True, string='Weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_move_weight',
+                  store={
+                 'stock.move': (lambda self, cr, uid, ids, c={}: ids, ['product_id', 'product_qty', 'product_uom'], 10),
+                 }),
+        'weight_net': fields.function(_cal_move_weight, method=True, string='Net weight', digits_compute= dp.get_precision('Stock Weight'), multi='_cal_move_weight',
                   store={
-                 'stock.move': (lambda self, cr, uid, ids, c={}: ids, ['product_id', 'product_qty', 'product_uom'], 20),
+                 'stock.move': (lambda self, cr, uid, ids, c={}: ids, ['product_id', 'product_qty', 'product_uom'], 10),
                  }),
+                 
         }
 
 stock_move()