Skip to content

Commit

Permalink
[14.0][FIX] l10n_es_facturae: out_refund invoice file
Browse files Browse the repository at this point in the history
Show negative amounts on facturae refund invoices file generation
  • Loading branch information
almumu authored and docker-odoo committed Jul 26, 2023
1 parent 24ae27d commit 7515f35
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 24 deletions.
60 changes: 60 additions & 0 deletions l10n_es_facturae/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,34 @@ def setUpClass(cls):
"27.98",
"57.090000",
]
self.refund_move = self.env["account.move"].create(
{
"partner_id": self.partner.id,
"journal_id": self.sale_journal.id,
"invoice_date": "2016-03-12",
"payment_mode_id": self.payment_mode_02.id,
"move_type": "out_refund",
"invoice_line_ids": [
(
0,
0,
{
"product_id": self.env.ref(
"product.product_delivery_02"
).id,
"account_id": self.account.id,
"name": "Producto de prueba",
"quantity": 1.0,
"price_unit": 100.0,
"tax_ids": [(6, 0, self.tax.ids)],
},
)
],
}
)
self.refund_move.refresh()
self.refund_check_amount = ["-100.000000", "-100.000000", "-100.00", "-21.00"]
self.refund_check_totals = ["-100.00", "-100.00", "-21.00", "-121.00"]

def test_facturae_generation(self):
self.move.action_post()
Expand Down Expand Up @@ -420,6 +448,14 @@ def test_refund(self):
active_model="account.move",
).create_facturae_file()

def test_refund_amounts_file_generation(self):
self._activate_certificate(self.certificate_password)
self._check_amounts(self.refund_move, *self.refund_check_amount)

def test_refund_totals_file_generation(self):
self._activate_certificate(self.certificate_password)
self._check_totals(self.refund_move, *self.refund_check_totals)

def test_constrains_01(self):
move = self.env["account.move"].create(
{
Expand Down Expand Up @@ -579,6 +615,30 @@ def _check_amounts(self, move, wo_discount, subtotal, base, tax, discount=0):
discount,
)

def _check_totals(self, move, subtotal, base, tax, total):
move.action_post()
move.name = "2999/99999"
self.wizard.with_context(
active_ids=move.ids, active_model="account.move"
).create_facturae_file()
facturae_xml = etree.fromstring(base64.b64decode(self.wizard.facturae))
self.assertEqual(
facturae_xml.xpath("//InvoiceTotals/TotalGrossAmount")[0].text,
subtotal,
)
self.assertEqual(
facturae_xml.xpath("//InvoiceTotals/TotalGrossAmountBeforeTaxes")[0].text,
base,
)
self.assertEqual(
facturae_xml.xpath("//InvoiceTotals/TotalTaxOutputs")[0].text,
tax,
)
self.assertEqual(
facturae_xml.xpath("//InvoiceTotals//InvoiceTotal")[0].text,
total,
)

def test_move_rounding(self):
self._activate_certificate(self.certificate_password)
self.main_company.tax_calculation_rounding_method = "round_globally"
Expand Down
2 changes: 2 additions & 0 deletions l10n_es_facturae/tests/test_l10n_es_facturae_32.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ def setUp(self):
"27.98",
"57.090000",
]
self.refund_check_amount = ["-100.000000", "-100.000000", "-100.00", "-21.00"]
self.refund_check_totals = ["-100.00", "-100.00", "-21.00", "-121.00"]
12 changes: 12 additions & 0 deletions l10n_es_facturae/tests/test_l10n_es_facturae_321.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ def setUp(self):
"133.22000000",
"27.97620000",
]
self.refund_check_amount = [
"-100.00000000",
"-100.00000000",
"-100.00000000",
"-21.00000000",
]
self.refund_check_totals = [
"-100.00000000",
"-100.00000000",
"-21.00000000",
"-121.00000000",
]
12 changes: 12 additions & 0 deletions l10n_es_facturae/tests/test_l10n_es_facturae_322.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ def setUp(self):
"133.22000000",
"27.97620000",
]
self.refund_check_amount = [
"-100.00000000",
"-100.00000000",
"-100.00000000",
"-21.00000000",
]
self.refund_check_totals = [
"-100.00000000",
"-100.00000000",
"-21.00000000",
"-121.00000000",
]
52 changes: 28 additions & 24 deletions l10n_es_facturae/views/report_facturae.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,26 +223,26 @@
<InvoicesCount t-esc="'1'" />
<TotalInvoicesAmount>
<TotalAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total"
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total_signed"
/>
<EquivalentInEuros
t-esc="'%.2f' % (move.amount_total * euro_rate / currency_rate)"
t-esc="'%.2f' % (move.amount_total_signed * euro_rate / currency_rate)"
/>
</TotalInvoicesAmount>
<TotalOutstandingAmount>
<TotalAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total"
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total_signed"
/>
<EquivalentInEuros
t-esc="'%.2f' % (move.amount_total * euro_rate / currency_rate)"
t-esc="'%.2f' % (move.amount_total_signed * euro_rate / currency_rate)"
/>
</TotalOutstandingAmount>
<TotalExecutableAmount>
<TotalAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total"
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total_signed"
/>
<EquivalentInEuros
t-esc="'%.2f' % (move.amount_total * euro_rate / currency_rate)"
t-esc="'%.2f' % (move.amount_total_signed * euro_rate / currency_rate)"
/>
</TotalExecutableAmount>
<InvoiceCurrencyCode t-esc="move.currency_id.name" />
Expand Down Expand Up @@ -432,14 +432,14 @@
</TaxesWithheld>
<InvoiceTotals>
<TotalGrossAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_untaxed"
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_untaxed_signed"
/>
<GeneralDiscounts t-if="False" />
<GeneralSurcharges t-if="False" />
<TotalGeneralDiscounts t-if="False" />
<TotalGeneralSurcharges t-if="False" />
<TotalGrossAmountBeforeTaxes
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_untaxed"
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_untaxed_signed"
/>
<TotalTaxOutputs
t-esc="('%.2f' if version == '3_2' else '%.8f') % (-amount_tax)"
Expand All @@ -448,19 +448,19 @@
t-esc="('%.2f' if version == '3_2' else '%.8f') % (-amount_tax_withheld)"
/>
<InvoiceTotal
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total"
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total_signed"
/>
<Subsidies t-if="False" />
<PaymentsOnAccount t-if="False" />
<ReimbursableExpenses t-if="False" />
<TotalFinancialExpenses t-if="False" />
<TotalOutstandingAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total"
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total_signed"
/>
<TotalPaymentsOnAccount t-if="False" />
<AmountsWithheld t-if="False" />
<TotalExecutableAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total"
t-esc="('%.2f' if version == '3_2' else '%.8f') % move.amount_total_signed"
/>
<TotalReimbursableExpenses t-if="False" />
<t t-if="version not in ('3_2', '3_2_1')">
Expand All @@ -475,6 +475,10 @@
t-foreach="move.line_ids.filtered(lambda r: not r.display_type and not r.exclude_from_invoice_tab)"
t-as="line"
>
<t
t-set="line_sign"
t-value="-1 if move.move_type == 'out_refund' else 1"
/>
<t t-set="withheld" t-value="False" />
<t t-foreach="line.tax_ids" t-as="line_tax">
<t t-if="line_tax.amount &lt; 0">
Expand Down Expand Up @@ -529,7 +533,7 @@
<SequenceNumber t-if="False" />
<DeliveryNotesReferences t-if="False" />
<ItemDescription t-length="2500" t-esc="line.name" />
<Quantity t-esc="line.quantity" />
<Quantity t-esc="line_sign * line.quantity" />
<UnitOfMeasure t-if="False" />
<UnitPriceWithoutTax
t-esc="('%.6f' if version == '3_2' else '%.8f') % line.price_unit"
Expand All @@ -539,7 +543,7 @@
t-value="line._get_price_total_and_subtotal_model(line.price_unit, line.quantity,0,line.move_id.currency_id, line.product_id, line.move_id.partner_id, line.tax_ids, line.move_id.move_type,).get('price_subtotal', 0.0)"
/>
<TotalCost
t-esc="('%.6f' if version == '3_2' else '%.8f') % subtotal_gross"
t-esc="('%.6f' if version == '3_2' else '%.8f') % (line_sign * subtotal_gross)"
/>
<DiscountsAndRebates t-if="line.discount != 0">
<Discount>
Expand All @@ -548,13 +552,13 @@
t-esc="('%.4f' if version == '3_2' else '%.8f') % line.discount"
/>
<DiscountAmount
t-esc="('%.6f' if version == '3_2' else '%.8f') % (subtotal_gross - line.price_subtotal)"
t-esc="('%.6f' if version == '3_2' else '%.8f') % (line_sign * (subtotal_gross - line.price_subtotal))"
/>
</Discount>
</DiscountsAndRebates>
<Charges t-if="False" />
<GrossAmount
t-esc="('%.6f' if version == '3_2' else '%.8f') % line.price_subtotal"
t-esc="('%.6f' if version == '3_2' else '%.8f') % (line_sign * line.price_subtotal)"
/>
<TaxesWithheld t-if="withheld">
<t t-foreach="line.tax_ids" t-as="line_tax">
Expand All @@ -565,18 +569,18 @@
/>
<TaxableBase>
<TotalAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % line.price_subtotal"
t-esc="('%.2f' if version == '3_2' else '%.8f') % (line_sign * line.price_subtotal)"
/>
<EquivalentInEuros
t-esc="'%.2f' % (line.price_subtotal * euro_rate / currency_rate)"
t-esc="'%.2f' % (line_sign * (line.price_subtotal * euro_rate / currency_rate))"
/>
</TaxableBase>
<TaxAmount>
<TotalAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % (line.price_subtotal * (-line_tax.amount))"
t-esc="('%.2f' if version == '3_2' else '%.8f') % (line_sign * (line.price_subtotal * (-line_tax.amount)))"
/>
<EquivalentInEuros
t-esc="'%.2f' % (line.price_subtotal * (-line_tax.amount) * euro_rate / currency_rate)"
t-esc="'%.2f' % (line_sign * (line.price_subtotal * (-line_tax.amount) * euro_rate / currency_rate))"
/>
</TaxAmount>
</Tax>
Expand All @@ -591,18 +595,18 @@
/>
<TaxableBase>
<TotalAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % line.price_subtotal"
t-esc="('%.2f' if version == '3_2' else '%.8f') % (line_sign * line.price_subtotal)"
/>
<EquivalentInEuros
t-esc="'%.2f' % (line.price_subtotal * euro_rate / currency_rate)"
t-esc="'%.2f' % (line_sign * (line.price_subtotal * euro_rate / currency_rate))"
/>
</TaxableBase>
<TaxAmount>
<TotalAmount
t-esc="('%.2f' if version == '3_2' else '%.8f') % (line.price_subtotal * (line_tax.amount) / 100)"
t-esc="('%.2f' if version == '3_2' else '%.8f') % (line_sign * (line.price_subtotal * (line_tax.amount) / 100))"
/>
<EquivalentInEuros
t-esc="'%.2f' % (line.price_subtotal * (line_tax.amount) / 100 * euro_rate / currency_rate)"
t-esc="'%.2f' % (line_sign * (line.price_subtotal * (line_tax.amount) / 100 * euro_rate / currency_rate))"
/>
</TaxAmount>
</Tax>
Expand Down Expand Up @@ -637,7 +641,7 @@
t-esc="move.invoice_date_due or move.invoice_date"
/>
<InstallmentAmount
t-esc="'%.2f' % (move.amount_residual)"
t-esc="'%.2f' % (move.amount_residual_signed)"
/>
<t
t-set="partner_bank"
Expand Down

0 comments on commit 7515f35

Please sign in to comment.