Skip to Content
Menu
This question has been flagged
2441 Views

I'm trying to create a product and its variant. Afterwards I want to add some quantity to stock (including price_unit), but it doesn't work like that. Seems like "env['stock.move'].create" doesn't take any effect.

What am I doing wrong?


Thanks!


Code example:

product_template = self.env["product.template"].create({'name': title,
"default_code": permalink,
"price": price,
"type": "product",
"weight": weight})

product_template.write({
'attribute_line_ids': [(0, 0, {
'attribute_id': 2,
'value_ids': [(6, 0, [156])],
})]
})

product_product = product_template.product_variant_id
product_product.write({
'name': title,
"default_code": sku,
"price": price,
"type": "product",
"weight": weight
})
move = self.env['stock.move'].create({
'name': 'test_move',
'product_id': product_product.id,
'product_uom': 1,
'product_uom_qty': quantity,
'price_unit': cost_price,
'location_id': 14,
'location_dest_id': 8,
})

move._action_confirm()
move._action_assign()
move.move_line_ids.write({'qty_done': quantity, 'product_uom_qty': 0})
move._action_done()


Avatar
Discard

do it with sudo it may be hep to create record

Author

I need to do it in my odoo module, so that I'm using python to do this

Related Posts Replies Views Activity
2
Jul 24
505
0
Jan 21
1644
1
Nov 24
1483
1
Nov 24
1188
0
Oct 24
108