diff options
| author | Katherine Zaoral <kz@adhoc.com.ar> | 2020-06-09 19:06:01 +0000 |
|---|---|---|
| committer | Katherine Zaoral <kz@adhoc.com.ar> | 2020-06-12 10:43:58 +0000 |
| commit | b7421e5860822652a3dbe0d3307b11534c076ad1 (patch) | |
| tree | b765fb72a93fb544facb3175e7425ff3794c3bfb /addons/l10n_ar/models | |
| parent | d2bd958765734108065e7f5a46021ba34cadfdc6 (diff) | |
[FIX] l10n_ar: support multiple records inside constraint method
Before this change the constraint that check afip configurations has an ensure_one() that was throwing an error when we try to change journals in batch. Now the constraint support mutilple records at once and return the ValidationError message show information of the journal's which constraint aplies.
Also, we remove the print of the list of the invoices in the ValidationError message because this ones could be a really long list and it is not necessary, only knowing the journal is enough.
closes odoo/odoo#52914
X-original-commit: 710bb9f161da4718024c4454ce14a7dbc2d24c93
Signed-off-by: Josse Colpaert <jco@openerp.com>
Diffstat (limited to 'addons/l10n_ar/models')
| -rw-r--r-- | addons/l10n_ar/models/account_journal.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/addons/l10n_ar/models/account_journal.py b/addons/l10n_ar/models/account_journal.py index ba901e591fc..8a537f57b4d 100644 --- a/addons/l10n_ar/models/account_journal.py +++ b/addons/l10n_ar/models/account_journal.py @@ -107,16 +107,13 @@ class AccountJournal(models.Model): 'l10n_latam_use_documents') def _check_afip_configurations(self): """ Do not let to update journal if already have confirmed invoices """ - self.ensure_one() - if self.company_id.country_id != self.env.ref('base.ar'): - return True - if self.type != 'sale' and self._origin.type != 'sale': - return True - invoices = self.env['account.move'].search([('journal_id', '=', self.id), ('state', '!=', 'draft')]) + arg_sale_journals = self.filtered(lambda x: x.company_id.country_id == self.env.ref('base.ar') and + x.type == 'sale' and x._origin.type == 'sale') + invoices = self.env['account.move'].search([('journal_id', 'in', arg_sale_journals.ids), ('state', '!=', 'draft')]) if invoices: - raise ValidationError(_( - 'You can not change the journal configuration for a journal that already have validate invoices') + - ':<br/><br/> - %s' % ('<br/>- '.join(invoices.mapped('display_name')))) + raise ValidationError( + _("You can not change the journal's configuration if journal already have validated invoices") + ' (' + + ', '.join(invoices.mapped('journal_id').mapped('name')) + ')') @api.constrains('l10n_ar_afip_pos_number') def _check_afip_pos_number(self): |
