This question has been flagged
3 Replies
8133 Views

We are using lots to track our products. After purchasing a product we receive it and put the lot number that the vendor stated into the lot number field that has to be filled in when validating the receipt. As an example we have product xy with lot number 1234 on stock. If we have another delivery of that product with an identical lot number Odoo refuses to validate the receipt. Error: 'The combination of serial number and product must be unique!'
This seems to be done via a sql_constraint in stock_production_lot.py in the modul "stock" class Class ProductionLot :

_sql_constraints = [('name_ref_inique', 'unique(name, product_id)', 'The combination of serial number and product must be unique!'),]

I tried to comment the lines out but this does not help. There is another error

IntegrityError : dublicate key value violates unique constraint "stock_production_lot_name_ref_uniq"

DETAIL: Key(name, product_id)=(1234, 18) already exist.


Is there a way to remove that constraint and keep the rest of the functionality? We do not want to disable lots and serial number tracking.

Background: In our business it is quite normal that a vendor sells parts with a certain lot not only in one delivery but in several after another. The lot is often stamped into the part and changing the lot number in Odoo (adding another identification number like the receipt number) would confuse our processes.


Avatar
Discard
Best Answer

Hi,

you should both comment the line and remove the constraint from Postgre.

Have a look at: https://www.odoo.com/forum/help-1/question/remove-sql-constraints-5431

Alternatively you may redefine this sql contsraint in your Python class:

class stock_production_lot(models.Model):    
    _inherit = "stock.production.lot"
    _sql_constraints = [('name_ref_inique', 'check(1=1)', 'No error'),]
Avatar
Discard
Best Answer

Hi, 
Just remove the contsraint manually from your python file and from the database. 

try this : 
ALTER TABLE Your_table_name DROP CONSTRAINT Your_constraint_name;

Avatar
Discard
Author Best Answer

Thank you for your answers I did not try them because it turned out that we could solve the problem by ticking an option in the settings of the operation "receipt", field "use_existing_lots" in stock.picking.type.

I am glad that I do not have to alter the database by hand.

Avatar
Discard