Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
3 Besvarelser
10896 Visninger

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
Kassér
Bedste svar

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
Kassér
Bedste svar

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
Kassér
Forfatter Bedste svar

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
Kassér
Related Posts Besvarelser Visninger Aktivitet
2
maj 20
3380
0
apr. 18
2844
1
jul. 16
3613
0
mar. 15
6017
0
maj 21
2152