From a2af0ea898ab76d4a3057d6f921d23b89cb6ec25 Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Thu, 23 Jan 2020 21:02:35 +0000 Subject: [PATCH] [IMP] l10n_ar: extend constraint on pos number to ensure max 5 digits Before this change we were letting the user to create a journal with a AFIP POS Number they like, and where they try to post an invoice in that jounrals they receive an error message telling that the document has not valid POS Number. In order to avoid this we add as part of the constraint where we check the validity of the AFIP POS Number which is: should be greater that 0, and should be 5 digits max. closes odoo/odoo#44433 X-original-commit: 3e991fb4ceb02eeb41ed6579ac409f9595663c41 Signed-off-by: Josse Colpaert --- addons/l10n_ar/models/account_journal.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/l10n_ar/models/account_journal.py b/addons/l10n_ar/models/account_journal.py index d8f501e5db6..25ffcae5c45 100644 --- a/addons/l10n_ar/models/account_journal.py +++ b/addons/l10n_ar/models/account_journal.py @@ -167,11 +167,15 @@ class AccountJournal(models.Model): @api.constrains('l10n_ar_afip_pos_number') def _check_afip_pos_number(self): - missing_pos_number = self.filtered( - lambda x: x.type == 'sale' and x.l10n_latam_use_documents and x.company_id.country_id == self.env.ref('base.ar') - and x.l10n_ar_afip_pos_number == 0) - if missing_pos_number: - raise ValidationError(_('Please define a valid AFIP POS number')) + to_review = self.filtered( + lambda x: x.type == 'sale' and x.l10n_latam_use_documents and + x.company_id.country_id == self.env.ref('base.ar')) + + if to_review.filtered(lambda x: x.l10n_ar_afip_pos_number == 0): + raise ValidationError(_('Please define an AFIP POS number')) + + if to_review.filtered(lambda x: x.l10n_ar_afip_pos_number > 99999): + raise ValidationError(_('Please define a valid AFIP POS number (5 digits max)')) @api.onchange('l10n_ar_afip_pos_system') def _onchange_l10n_ar_afip_pos_system(self):