[IMP] l10n_latam_invoice_document: avoid changing back document number as well
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) <wan@odoo.com>
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
<field name="name" position="attributes">
|
||||
<attribute name="attrs">{'invisible':[('name', '=', '/'), ('posted_before', '=', False), ('quick_edit_mode', '=', False)],
|
||||
'readonly': ['|', ('state', '!=', 'draft'), ('l10n_latam_use_documents', '=', True)]}</attribute>
|
||||
<attribute name="force_save">1</attribute>
|
||||
</field>
|
||||
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user