From c7e25784a36c5dda5fbe8d2a527954e8e2622c30 Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Thu, 26 Jan 2023 17:07:02 -0300 Subject: [PATCH] [ADD] l10n_ar_ux: Debit note withou debit origin Necessary when creating a debit note different from view, for example, from python or API, an automated action, or an ir.cron. X-original-commit: ab67d623b84242f4f53296cb40f22c9da8dd0fd0 --- l10n_ar_ux/models/account_move.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/l10n_ar_ux/models/account_move.py b/l10n_ar_ux/models/account_move.py index 7b2c6c082..ef9312c70 100644 --- a/l10n_ar_ux/models/account_move.py +++ b/l10n_ar_ux/models/account_move.py @@ -124,3 +124,15 @@ def _is_manual_document_number(self): if self.country_code == 'AR' and self.journal_id._l10n_ar_journal_issuer_is_supplier(): return not res return res + + @api.depends('l10n_latam_available_document_type_ids', 'debit_origin_id') + def _compute_l10n_latam_document_type(self): + """ Sobre escribimos este metodo porque es necesario para poder auto calcular el tipo de documento por defecto + de una nota de debito cuando no hay un debit_origin_id definido, puede ser porque simplemente no haya un + documento relacionado original o porque hay muchos documentos relacionados pero no puede ser asociados """ + super()._compute_l10n_latam_document_type() + if self.env.context.get('internal_type') == 'debit_note': + for rec in self.filtered(lambda x: x.state == 'draft'): + document_types = rec.l10n_latam_available_document_type_ids._origin + document_types = document_types.filtered(lambda x: x.internal_type == 'debit_note') + rec.l10n_latam_document_type_id = document_types and document_types[0].id