Hey Jay,
I think there is some trouble in code of weight calculation. It does not take into account the uos coeff because the weight is ofcourse for default UOM and not UOS and therefore UOS coefficient should be used (it is used in weight calculation in sale module). I forgot to remind you about this but now since we r discussing the coefficients (in another thread) so please rectify the code for delivery module as well. Also it is much better to have each stock.move has a weight field that represents weight of the individual move in a picking and then the picking can just sum up the weights of the move. Also Stock picking view can be modified accordingly to show the weight of each move individually.
This is the code that i did in stock.py file of delivery module:
Hey Jay,
I think there is some trouble in code of weight calculation. It does not take into account the uos coeff because the weight is ofcourse for default UOM and not UOS and therefore UOS coefficient should be used (it is used in weight calculation in sale module). I forgot to remind you about this but now since we r discussing the coefficients (in another thread) so please rectify the code for delivery module as well. Also it is much better to have each stock.move has a weight field that represents weight of the individual move in a picking and then the picking can just sum up the weights of the move. Also Stock picking view can be modified accordingly to show the weight of each move individually.
This is the code that i did in stock.py file of delivery module:
class stock_move( osv.osv) :
_name = "stock.move"
_description = "Stock Move"
_inherit = 'stock.move'
def _cal_weight(self, cr, uid, ids, name, args, context=None): uos_qty > 0.00 and move.product_ id.weight > 0.00: id.weight * move.product_ uos_qty / move.product_ id.uos_ coeff)
res = {}
for move in self.browse(cr, uid, ids, context):
weight = 0.00
if move.product_id and move.product_
weight += (move.product_
res[move.id] = weight
return res
_columns = { function( _cal_weight, method=True, type='float', string= 'Weight' ,digits= (16, int(tools. config[ 'price_ accuracy' ])), id','product_ uos_qty' ], 10),
'weight': fields.
store={
'stock.move': (lambda self, cr, uid, ids, c={}: ids, ['product_
}),
}
stock_move()
# Overloaded stock_picking to manage carriers : osv.osv) :
class stock_picking(
_name = "stock.picking"
_description = "Picking list"
_inherit = 'stock.picking'
def _cal_weight(self, cr, uid, ids, name, args, context=None):
data_picking = self.browse(cr, uid, ids, context)
total_ weight = 0.00
total_ weight += move.weight
res[ picking. id] = total_weight
res = {}
for picking in data_picking:
if picking.move_lines:
for move in picking.move_lines:
if move.weight > 0.00:
return res
def _get_picking_ line(self, cr, uid, ids, context=None): get('stock. move'). browse( cr, uid, ids, context=context):
result[ line.picking_ id.id] = True
result = {}
for line in self.pool.
return result.keys()
_columns = {
'carrier_ id':fields. many2one( "delivery. carrier" ,"Carrier" ), float(' Volume' ), function( _cal_weight, method=True, type='float', string= 'Weight' ,digits= (16, int(tools. config[ 'price_ accuracy' ])),
store= {
'stock. picking' : (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 20),
'stock. move': (_get_picking_line, ['weight'], 20),
}),
'volume': fields.
'weight': fields.
}
.
.
.
<more code here>
stock_picking()
I hope this code also makes it to stable version :)