From b884d4e846e5b5585f79d0e9fbce5b1156378892 Mon Sep 17 00:00:00 2001 From: Bernat Brunet Date: Wed, 12 Feb 2025 16:05:24 +0100 Subject: [PATCH] Not create 347 register if the invoice is and auto-invoice, the party is the comapny party. Ensure if the identifier doesn't exist, not create a 347 register. Task: #174268 --- aeat.py | 2 ++ invoice.py | 7 +++++-- tests/test_scenario_aeat347.py | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/aeat.py b/aeat.py index 19c3ee1..defc7a0 100644 --- a/aeat.py +++ b/aeat.py @@ -376,6 +376,8 @@ def is_decimal(value): for (tax_identifier_id, opkey, q1, q2, q3, q4, amount, records ) in result: tax_identifier = PartyIdentifier(tax_identifier_id) + if not tax_identifier: + continue party = tax_identifier.party if not party: continue diff --git a/invoice.py b/invoice.py index 2c1729b..f8be34c 100644 --- a/invoice.py +++ b/invoice.py @@ -196,10 +196,11 @@ def check_347_taxes(self): include = True return include - @fields.depends('type', 'aeat347_operation_key') + @fields.depends('type', 'aeat347_operation_key', 'party', 'company') def _on_change_lines_taxes(self): super(Invoice, self)._on_change_lines_taxes() - if self.taxes and not self.check_347_taxes(): + if ((self.taxes and not self.check_347_taxes()) + or (self.company and self.party == self.company.party)): self.aeat347_operation_key = 'empty' elif not self.aeat347_operation_key: self.aeat347_operation_key = self.get_aeat347_operation_key( @@ -221,6 +222,8 @@ def create_aeat347_records(cls, invoices): invoice.aeat347_operation_key = 'empty' to_update.append(invoice) continue + if invoice.party == invoice.company.party: + continue if not invoice.aeat347_operation_key: invoice.aeat347_operation_key = \ invoice.get_aeat347_operation_key(invoice.type) diff --git a/tests/test_scenario_aeat347.py b/tests/test_scenario_aeat347.py index 551576b..12b605e 100644 --- a/tests/test_scenario_aeat347.py +++ b/tests/test_scenario_aeat347.py @@ -173,6 +173,21 @@ def test(self): self.assertEqual(rec1.operation_key, 'B') self.assertEqual(rec1.amount, Decimal('3520.00')) + # Create self out invoice + Record = Model.get('aeat.347.record') + Invoice = Model.get('account.invoice') + invoice = Invoice() + invoice.party = company.party + invoice.payment_term = payment_term + line = invoice.lines.new() + line.product = product + line.unit_price = Decimal(40) + line.quantity = 80 + self.assertEqual(len(line.taxes), 1) + self.assertEqual(line.amount, Decimal('3200.00')) + invoice.click('post') + self.assertEqual(Record.find([('invoice', '=', invoice.id)]), []) + # Create out credit note invoice = Invoice() invoice.type = 'out'