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

Hello,

i have 2 fields (partner_id, ref_ids(many2many)) i want to make sure that not a single ref_id can be repeated for each customer:

partner "test" ref "ref1" 

partner "test2" ref "ref1" (ok)

partner  "test" ref "ref1" (not accepted)


any help would be appreciated 

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất
@api.constrains('ref_ids', 'partner_id')
def _check_ref(self):
for record in self:
for ref in record.ref_ids.ids:
bill = self.env['account.move'].search(
[('ref_ids', 'in', ref), ('partner_id', '=', self.partner_id.id)])
if len(bill) > 1:
raise ValidationError(_("You can't create 2 bills with the same vendor and reference"))


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
3219
0
thg 9 22
1853
1
thg 7 22
2125
1
thg 8 15
8142
4
thg 3 15
11941