From 691ef8e9f7d407000eff71f81ebc8d603910ed8f Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Mon, 27 Jun 2022 15:31:26 +0000 Subject: [PATCH] [FIX] l10n_latam_invoice_document: wrong name on batch post MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Have a Peru company setup Create 2+ draft invoices of mixed type 'Boleta' and 'Factura' In list view select the created moves and do action>"post entries" The posted entries will have the same name prefix, either all 'BOL' or 'FFI', depending on the first computed name, the system will use the same prefix for the remaining move names opw-2860231 closes odoo/odoo#95271 X-original-commit: d7a5b34e46436f49592ab6706ac33bcf7a3fbf80 Signed-off-by: William André (wan) --- .../l10n_latam_invoice_document/models/account_move.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/l10n_latam_invoice_document/models/account_move.py b/addons/l10n_latam_invoice_document/models/account_move.py index 4fc9326095e..fdeadd2f54a 100644 --- a/addons/l10n_latam_invoice_document/models/account_move.py +++ b/addons/l10n_latam_invoice_document/models/account_move.py @@ -1,5 +1,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. +from collections import defaultdict + from odoo import models, fields, api, _ from odoo.exceptions import UserError, ValidationError from odoo.tools.sql import column_exists, create_column @@ -67,7 +69,12 @@ class AccountMove(models.Model): 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 = '/' - super(AccountMove, self - without_doc_type - manual_documents)._compute_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): + group_by_document_type[move.l10n_latam_document_type_id.id] += move + for group in group_by_document_type.values(): + super(AccountMove, group)._compute_name() @api.depends('l10n_latam_document_type_id', 'journal_id') def _compute_l10n_latam_manual_document_number(self):