diff --git a/l10n_it_fatturapa_out/models/partner.py b/l10n_it_fatturapa_out/models/partner.py index 804b3eedb3c2..797072117243 100644 --- a/l10n_it_fatturapa_out/models/partner.py +++ b/l10n_it_fatturapa_out/models/partner.py @@ -11,7 +11,9 @@ class ResPartner(models.Model): max_invoice_in_xml = fields.Integer( string="Max Invoice # in XML", default=lambda self: self.env.company.max_invoice_in_xml, - help="Maximum number of invoices to group in a single " "XML file. 0=Unlimited", + help="Maximum number of invoices to group in a single XML file." + "0=Unlimited. If this is 0, then the number configured " + "in the account settings is considered.", ) @api.constrains("max_invoice_in_xml") diff --git a/l10n_it_fatturapa_out/tests/fatturapa_common.py b/l10n_it_fatturapa_out/tests/fatturapa_common.py index 0208d5530335..b999c5cc5147 100644 --- a/l10n_it_fatturapa_out/tests/fatturapa_common.py +++ b/l10n_it_fatturapa_out/tests/fatturapa_common.py @@ -182,9 +182,16 @@ def set_sequences( seq_date = inv_seq._create_date_range_seq(dt) seq_date.number_next_actual = invoice_number - def run_wizard(self, invoice_id): + def run_wizard(self, invoice_ids): + """ + Execute the export wizard on the invoices having ID `invoice_ids`. + :param invoice_ids: integer or list of integers + :return: result of export wizard + """ + if not isinstance(invoice_ids, list): + invoice_ids = [invoice_ids] wizard = self.wizard_model.create({}) - return wizard.with_context({"active_ids": [invoice_id]}).exportFatturaPA() + return wizard.with_context({"active_ids": invoice_ids}).exportFatturaPA() def set_e_invoice_file_id(self, e_invoice, file_name): # We need this because file name is random and we can't predict it diff --git a/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py b/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py index 36610d1ab8b9..31411d12db15 100644 --- a/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py +++ b/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py @@ -882,3 +882,53 @@ def test_no_export_bill(self): with self.assertRaises(UserError) as ue: self.run_wizard(invoice.id) self.assertIn(invoice.name, ue.exception.args[0]) + + def test_max_invoice_in_xml(self): + invoice1_form = Form( + self.env["account.move"].with_context({"default_move_type": "out_invoice"}) + ) + invoice1_form.partner_id = self.res_partner_fatturapa_0 + with invoice1_form.line_ids.new() as line_form: + line_form.product_id = self.product_product_10 + line_form.account_id = self.a_sale + line_form.tax_ids.clear() + line_form.tax_ids.add(self.tax_22) + invoice1 = invoice1_form.save() + invoice2 = invoice1.copy() + invoice3 = invoice1.copy() + + invoice1.action_post() + invoice2.action_post() + invoice3.action_post() + invoices = invoice1 | invoice2 | invoice3 + + # partner limited, company limited (expect 3 xml attachments) + self.res_partner_fatturapa_0.max_invoice_in_xml = 1 + self.env.company.max_invoice_in_xml = 2 + res = self.run_wizard(invoices.ids) + attachments = self.attach_model.search(res["domain"]) + self.assertEqual(len(attachments), 3) + attachments.unlink() + + # partner limited, company unlimited (expect 3 xml attachments) + self.res_partner_fatturapa_0.max_invoice_in_xml = 1 + self.env.company.max_invoice_in_xml = 0 + res = self.run_wizard(invoices.ids) + attachments = self.attach_model.search(res["domain"]) + self.assertEqual(len(attachments), 3) + attachments.unlink() + + # partner unlimited, company limited (expect 2 xml attachments) + self.res_partner_fatturapa_0.max_invoice_in_xml = 0 + self.env.company.max_invoice_in_xml = 2 + res = self.run_wizard(invoices.ids) + attachments = self.attach_model.search(res["domain"]) + self.assertEqual(len(attachments), 2) + attachments.unlink() + + # partner unlimited, company unlimited (expect 1 xml attachment) + self.res_partner_fatturapa_0.max_invoice_in_xml = 0 + self.env.company.max_invoice_in_xml = 0 + res = self.run_wizard(invoices.ids) + attachments = self.attach_model.browse(res["res_id"]) + self.assertEqual(len(attachments), 1) diff --git a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py index a2b56ed95395..2f702015e750 100644 --- a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py +++ b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py @@ -102,10 +102,11 @@ def split_list(my_list, size): res[invoice.partner_id] = [] res[invoice.partner_id].append(invoice.id) for partner_id in res.keys(): - if partner_id.max_invoice_in_xml: - res[partner_id] = list( - split_list(res[partner_id], partner_id.max_invoice_in_xml) - ) + max_invoice_in_xml = ( + partner_id.max_invoice_in_xml or self.env.company.max_invoice_in_xml + ) + if max_invoice_in_xml: + res[partner_id] = list(split_list(res[partner_id], max_invoice_in_xml)) else: res[partner_id] = [res[partner_id]] # The returned dictionary contains a plain res.partner object as key