Skip to content

Commit

Permalink
Not create 347 register if the invoice is and auto-invoice, the party is
Browse files Browse the repository at this point in the history
the comapny party.

Ensure if the identifier doesn't exist, not create a 347 register.

Task: #174268
  • Loading branch information
bernatnan committed Feb 12, 2025
1 parent e869e57 commit b884d4e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions aeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_scenario_aeat347.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b884d4e

Please sign in to comment.