0

I need to create stock.move.line record with a specific serial number and add it into move_line_nosuggest_ids of stock.move record (or update stock.move.line record).

I have a receipt picking (reserved) that is a return of a faulty device with a specific SN. I would like to create or update stock.move.line record so that it has the same SN I am expecting instead of letting choose Odoo or user.

enter image description here enter image description here

I tried writing into move_line_nosuggest_ids field of stock.move but the record of stock.move.line was created inside move_line_ids field instead of move_line_nosuggest_ids for some reason and the move_line_nosuggest_ids field was empty.

xixo222
  • 157
  • 2
  • 9

1 Answers1

0

You can use the same function over stock.move object that odoo uses to create the stock.move.lines from stock.move:

def update_reserved_quantity(self,  need,
            available_quantity,
            location_id,
            lot_id=lot_id,
            package_id=package_id,
            owner_id=owner_id,
            strict=strict)

In this function you can set the lot, so it creates a stock.move.line with the lot that you choose: So, if you have a variable called lot, with the instance of your selected lot (not the id, the object itself) you cand do something like:

# Get availability for my lot
available_quantity = self.env["stock.quant"]._get_available_quantity(
                    lot.product_id,
                    lot.lot_location_id,
                    lot_id=lot,
                    strict=False,
                )    

# Create stock.move.line eith that lot. 
move._update_reserved_quantity(
                    1,
                    available_quantity,
                    move.location_id,
                    lot_id=lot,
                    strict=False,
                )

The 1, is the reserved quantity, if you use unique serial number it must be one. available_quantity in my example i get the available quantity for that lot.

Then if you want to set quantity_done in the created stock.move.line yo do:

 # Set qty done
 move._set_quantity_done(1)

If you search in code for the _update_reserved_quantitymethod you will see a lot of uses in test files and when yo so the action_assign over stock.move.

Eml0c
  • 1
  • 4
  • Thank you for your detailed answer @Eml0c. I have one more question. Won't `available_quantity` be 0 when I sent the product (with unique SN) to the customer and the receipt picking (for the same product with same SN) is not yet completed so I have 0 pieces of that product with a specific unique SN at the moment? – xixo222 Jan 03 '23 at 13:00
  • Yes, you should control the case where available_quantity = 0. I think you should do a raise UserException or somethig like that cause Odoo is going to fail in the same function of stock.quant object in that case. – Eml0c Jan 03 '23 at 15:36