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

Dear,

if i want to create two products with same product name, it's been created in odoo 11.0 E, so if i want to make a restriction so no one can create a same product again, is it possible.

many thanks

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

Hi Muhammad,

Yes, this is possible. You can create filters or restrictions in any way that you like to prevent these kind of behaviours. You could for example override the create function and then search in the database for a product with the same name. If it is the same name you can show a warning saying that there is already a product with this name and that it already exists. A raw example:

@api.model def create(self, values): record = super(YourClass, self).create(values) matching_products = self.env['product.product'].search([('name', '=', self.name)]) if len(matching_products) > 1: raise Warning(_('You already have a product with this name. Please don't recreate it'))   return record

Regards,
Yenthe

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

Hi, you can also use the sql_constraints.

eg:
name = fields.Char(string="Name")
_sql_constraints = [('unique_name', 'UNIQUE(name)', 'name must be unique')]

Thank you

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

hi, avinash,

is it possible without any coding

thanks

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 25
221
0
thg 6 24
1629
0
thg 3 24
1703
1
thg 1 24
1912
2
thg 1 24
2106