From f07b8beb1a528dd3fb58800afe02126a4c89302d Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 27 Jan 2023 15:56:31 +0000 Subject: [PATCH] [IMP] l10n_latam_invoice_document: avoid changing back document number as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous commit solved the issues for the Belgian, ... case, but not for l10n_latam_invoice_document. We saw two extra problems we solved: - As the name is readonly you can not even store the new name easily, so we needed a force_save on that field. - As the _compute_name is inherited in this module as well, there is a logic that recomputes the name when the document type is changed and the invoice is in draft to recompute that initial value. However, when you confirm and the date gets set, that logic is also triggered, while we do not want to recompute but keep our old document number. closes odoo/odoo#111294 X-original-commit: 7edee80545daf29b3a46947838a23e1f4458f12d Related: odoo/enterprise#36434 Signed-off-by: William André (wan) --- .../models/account_move.py | 12 ++++++++---- .../views/account_move_view.xml | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/l10n_latam_invoice_document/models/account_move.py b/addons/l10n_latam_invoice_document/models/account_move.py index fdeadd2f54a..f7fcd06da78 100644 --- a/addons/l10n_latam_invoice_document/models/account_move.py +++ b/addons/l10n_latam_invoice_document/models/account_move.py @@ -65,10 +65,6 @@ class AccountMove(models.Model): without_doc_type = self.filtered(lambda x: x.journal_id.l10n_latam_use_documents and not x.l10n_latam_document_type_id) manual_documents = self.filtered(lambda x: x.journal_id.l10n_latam_use_documents and x.l10n_latam_manual_document_number) (without_doc_type + manual_documents.filtered(lambda x: not x.name or x.name and x.state == 'draft' and not x.posted_before)).name = '/' - # if we change document or journal and we are in draft and not posted, we clean number so that is recomputed in super - self.filtered( - lambda x: x.journal_id.l10n_latam_use_documents and x.l10n_latam_document_type_id - and not x.l10n_latam_manual_document_number and x.state == 'draft' and not x.posted_before).name = '/' # we need to group moves by document type as _compute_name will apply the same name prefix of the first record to the others group_by_document_type = defaultdict(self.env['account.move'].browse) for move in (self - without_doc_type - manual_documents): @@ -111,6 +107,14 @@ class AccountMove(models.Model): rec.l10n_latam_document_number = l10n_latam_document_number rec.name = "%s %s" % (rec.l10n_latam_document_type_id.doc_code_prefix, l10n_latam_document_number) + @api.onchange('l10n_latam_document_type_id') + def _onchange_l10n_latam_document_type_id(self): + # if we change document or journal and we are in draft and not posted, we clean number so that is recomputed + if (self.journal_id.l10n_latam_use_documents and self.l10n_latam_document_type_id + and not self.l10n_latam_manual_document_number and self.state == 'draft' and not self.posted_before): + self.name = '/' + self._compute_name() + @api.depends('journal_id', 'l10n_latam_document_type_id') def _compute_highest_name(self): manual_records = self.filtered('l10n_latam_manual_document_number') diff --git a/addons/l10n_latam_invoice_document/views/account_move_view.xml b/addons/l10n_latam_invoice_document/views/account_move_view.xml index a2e040339da..b92abe2adcf 100644 --- a/addons/l10n_latam_invoice_document/views/account_move_view.xml +++ b/addons/l10n_latam_invoice_document/views/account_move_view.xml @@ -54,6 +54,7 @@ {'invisible':[('name', '=', '/'), ('posted_before', '=', False), ('quick_edit_mode', '=', False)], 'readonly': ['|', ('state', '!=', 'draft'), ('l10n_latam_use_documents', '=', True)]} + 1