Avoid duplicated total amount on SII invoices with multiple taxes per line
This commit is contained in:
@@ -632,6 +632,17 @@ class InvoiceSII(ModelSQL, ModelView):
|
|||||||
tax_amount = Decimal(0)
|
tax_amount = Decimal(0)
|
||||||
for tax_key, tax_lines in groupby(
|
for tax_key, tax_lines in groupby(
|
||||||
tax_lines, key=self.tax_grouping_key):
|
tax_lines, key=self.tax_grouping_key):
|
||||||
|
tax_lines = list(tax_lines)
|
||||||
|
if tax_key and not dict(tax_key).get('excluded'):
|
||||||
|
base_lines = set()
|
||||||
|
for tax_line in tax_lines:
|
||||||
|
# Do not duplicate base for lines with multiple taxes
|
||||||
|
if (tax_line.type == 'base'
|
||||||
|
and tax_line.move_line.id not in base_lines):
|
||||||
|
total_amount += tax_line.amount
|
||||||
|
base_lines.add(tax_line.move_line.id)
|
||||||
|
if tax_line.type == 'tax':
|
||||||
|
total_amount += tax_line.amount
|
||||||
tax_lines = sorted(tax_lines, key=self.tax_detail_grouping_key)
|
tax_lines = sorted(tax_lines, key=self.tax_detail_grouping_key)
|
||||||
for detail_key, tax_lines in groupby(
|
for detail_key, tax_lines in groupby(
|
||||||
tax_lines, key=self.tax_detail_grouping_key):
|
tax_lines, key=self.tax_detail_grouping_key):
|
||||||
@@ -641,11 +652,6 @@ class InvoiceSII(ModelSQL, ModelView):
|
|||||||
continue
|
continue
|
||||||
operation_keys.add(key['operation_key'])
|
operation_keys.add(key['operation_key'])
|
||||||
tax_amount += values["Cuota%s" % key['cuota_suffix']]
|
tax_amount += values["Cuota%s" % key['cuota_suffix']]
|
||||||
total_amount += (
|
|
||||||
values['BaseImponible']
|
|
||||||
+ values["Cuota%s" % key['cuota_suffix']])
|
|
||||||
if 'CuotaRecargoEquivalencia' in values:
|
|
||||||
total_amount += values['CuotaRecargoEquivalencia']
|
|
||||||
tax_values[tax_key].append(values)
|
tax_values[tax_key].append(values)
|
||||||
return self.get_invoice_detail(
|
return self.get_invoice_detail(
|
||||||
tax_values, operation_keys, total_amount, tax_amount)
|
tax_values, operation_keys, total_amount, tax_amount)
|
||||||
|
|||||||
@@ -399,6 +399,8 @@ class AccountEsSiiTestCase(ModuleTestCase):
|
|||||||
['PeriodoLiquidacion', 'IDFactura', 'FacturaExpedida'])
|
['PeriodoLiquidacion', 'IDFactura', 'FacturaExpedida'])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
payload['FacturaExpedida']['TipoFactura'], 'F1')
|
payload['FacturaExpedida']['TipoFactura'], 'F1')
|
||||||
|
self.assertEqual(
|
||||||
|
payload['FacturaExpedida']['ImporteTotal'], '65.50')
|
||||||
tax_detail = {
|
tax_detail = {
|
||||||
'DetalleIVA': [{
|
'DetalleIVA': [{
|
||||||
'BaseImponible': Decimal('50.00'),
|
'BaseImponible': Decimal('50.00'),
|
||||||
|
|||||||
Reference in New Issue
Block a user