Search code examples
odoo

Create an stock.picking through xmlrpc in odoo with lots


Hello i am trying to create a stock.picking in Odoo, using Python and XMLRPC, the issue comes when I try to validate the product that give me this message:

You cannot validate a transfer if no quantities are reserved nor done.

The code that I used is this:

picking_data = {
            'picking_type_id': 1,  # replace with your picking type ID
            'location_dest_id': 8,  # replace with your destination location ID
            'location_id': 4,  # replace with your source location ID
            'move_ids': [
                (0, 0, {
                    "name":"Movida1",
                    'location_id': 4,
                    'location_dest_id': 8,
                    'product_id': 376,  # replace with your product ID
                    'product_uom_qty': 10,
                    'product_uom': 1,  # replace with your UOM ID
                    'move_line_ids': [
                        (0, 0, {
                            'product_id': 376,  # replace with your product ID
                            'lot_id':12,
                            'qty_done':5,
                            'lot_name':'LOT001'
                        }
                        ),
                        (0, 0, 
                        {
                            'product_id': 376,  # replace with your product ID
                            'lot_id':14,
                            'qty_done':5,
                            'lot_name':'LOT003'
                        }
                        ),
                    ],
                }),
            ],
        }
    
    picking = self.env['stock.picking'].create(picking_data)
    picking.action_confirm()
    
    picking.action_assign()
    picking.button_validate()

The code is inside odoo, I just need to create the stock.picking when the system execute a method.


Solution

  • I had this issue and solved it by using product_uom_qty instead of qty done and going through the full process of what you would do to create a record on the front end i.e using 'action_set_quantities_to_reservation' (in Odoo 16) after action_assign. P.S If this is for historical orders, it is important to note that the button_validate will apply the current timestamp as the date_done.