Skip to Content
Menu
This question has been flagged
2 Replies
3795 Views

i get this error everytime i want to add a new line in stock.move.line

'qty_qty': line.qty_qty,
UnboundLocalError: local variable 'line' referenced before assignment

here is my code 

qty_qty = fields.Float('Quantity', compute="_multiplication_qty")

def _multiplication_qty(self): for order in self: qty_qty = 0.0 for line in order.picking_id.move_line_ids_without_package: weight = line.product_id.weight if line.qty_done: line.qty_qty = (line.qty_done * 100) / weight order.update({ 'qty_qty': line.qty_qty,
})




~~~~~~~~~/xml~~~~~~
<record id="view_stock_mov" model="ir.ui.view">
    <field name="name">stock.inherit</field>     
    <field name="model">stock.move.line</field>
    <field name="inherit_id" ref="stock.view_stock_move_line_detailed_operation_tree"/>     <field name="arch" type="xml">
        <xpath expr="//field[@name='lot_id']" position="after">
        <field name="qty_qty" />
        </xpath>
    </field>
</record>

Avatar
Discard
Best Answer

Please use the following code inside the for loop

order.update({
            'qty_qty': line.qty_qty,
})

So you can use:
def _multiplication_qty(self): for order in self: qty_qty = 0.0 for line in order.picking_id.move_line_ids_without_package: weight = line.product_id.weight if line.qty_done: qty_qty = (line.qty_done * 100) / weight order.update({ 'qty_qty': qty_qty, })
Avatar
Discard
Author

thanks, that works (y)

Best Answer

Hi,

Update your function like this,

def _multiplication_qty(self):
for order in self:
qty_qty = 0.0
for line in order.picking_id.move_line_ids_without_package:
weight = line.product_id.weight
if line.qty_done:
qty_qty = (line.qty_done * 100) / weight
order.update({
'qty_qty': qty_qty,
})

Thanks

Avatar
Discard
Author

if you delete line from the update statement it will generate error stock.move.line(<NewId origin=48>,).qty_qty

Related Posts Replies Views Activity
1
May 21
1059
0
Jan 21
1416
1
Jun 23
2836
0
Oct 24
107
4
May 24
10070