Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3003 Widoki

How can I limit number of invoice created for customers. For the example 1 customers only can have 2 invoices at the same times, it will raise warn if they create the 3rd invoice, any suggestion? thank you so much if anybody can help


Best Regards, Faalih

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

You can inherit the account.move model if you are using odoo 13 and account.invoice model if you are using odoo12 and below and add the following constrains.

from odoo.exceptions import ValidationError


class AccountMove(models.Model):
_inherit = "account.move"

@api.constrains('partner_id')
def check_partner_id(self):
for rec in self:
invoices = self.search([('partner_id', '=', rec.partner_id.id),
('id', '!=', rec.id), ('state', '=', 'draft')])
if invoices and len(invoices) > 2:
raise ValidationError(_("You cannot have more than two draft invoice at a time."))

Then it will show validation error like this. Adjust the search domain if you need to consider only the customer invoice.



Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lis 21
5852
2
lut 25
1342
2
cze 24
1891
1
cze 24
2787
0
lip 23
1381