Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
1280 Lượt xem

I want to prevent the import of duplicate internal product codes. I hope someone who has dealt with it before can help

Ảnh đại diện
Huỷ bỏ

I am facing this same issue. Have you found solution for it?

Câu trả lời hay nhất

In addition to using _sql_constraints you can try to combine the following solutions:

Step 1: Declare the attribute compute = False for the default_code field of the product.template model (The default Odoo declaration is compute='_compute_default_code').

Step 2: Using _sql_constraints for default_code field of both model product.template and product.product.

Ảnh đại diện
Huỷ bỏ

Thank you. This is a great way.

Câu trả lời hay nhất

Hi, you can follow https://youtu.be/SgFmOD9Q2S4?si=46y7nPM_rumGs9NU

I hope it helps, thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Define columns' needed fields and data types to guarantee that critical information is captured and presented correctly. Invalid character and string checking - Examine the information to find any errors, anomalies, or irrelevant details that can be discarded. Limit the maximum length of text strings, the permissible range of numeric values, etc., to prevent inaccuracies. Put in place data validation and drop-down menus - Limit input fields to pre-defined choices rather than free text.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi  TTN SOLUTION,

Adding a constraint for the field will help you in this case. During the test import, if there's a record with the same internal product code, the constraint will trigger an error indicating that a record with the same code already exists. This prevents the creation of duplicate entries with the same internal product code and maintains the uniqueness.

_sql_constraints = [('default_code_uniq', 'unique (default_code)', "Internal Reference already exists !")]

Hope it helps,
Kiran K




Ảnh đại diện
Huỷ bỏ
Tác giả

you're welcome for the solution. However, I've tried it, and it only works when I create it manually. For imports, it doesn't function.