[FIX] l10n_eg_edi_eta: division by zero during computation exchange rate
Steps to reproduce: - Install modules: 'account_accountant', 'l10n_eg', 'l10n_eg_edi_eta'. - Switch company to "EG Company". - Configure "Large Cabinet Accounting" with ETA item code "10001138" and set Customer Taxes to "VAT 14%". - In "Journal Customer Invoices", disable "Factur-X (FR)" under Advanced Settings -> Electronic invoicing. Also, set Branch to "Deco Addict", ETA Activity Code to "Accounting, auditing, bookkeeping and tax advice activities", and ETA Branch ID to 0. - Update "Deco Addict" with Tax ID "204899053" and set building number to 2. - Update "Azure Interior" with Tax ID "204899052" and set building number to 2. - In Accounting -> Configuration -> Thumb Drive, create a new record using "EG Company" with 123 as both the ETA USB Pin and Access Token. - Manually set the certificate in the Thumb Drive record. - Create a new Customer Invoice with Customer set to "Azure Interior", Invoice Date as today, add a line item "Large Cabinet", set the Price to 0, remove "0% taxes" and add "VAT 14%", and set Journal to "Customer invoices in EUR". - Confirm the invoice and attempt to "Sign Invoice". Issue: A traceback occurs with a divide by zero error in the invoice calculation when different currencies are involved. Solution: Refined _l10n_eg_edi_exchange_currency_rate function to calculate the currency exchange rate. Now, it ensures the division by amount_currency only occurs when it's not zero, preventing divide by zero errors during currency conversion in invoices. opw-3580529 closes odoo/odoo#143064 X-original-commit: 14af8243188b86a0d654298feca6dc0980cbebeb Signed-off-by: Florian Gilbert (flg) <flg@odoo.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import json
|
||||
|
||||
from odoo import api, models, fields, _
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
from odoo.tools import float_is_zero
|
||||
from odoo.tools.sql import column_exists, create_column
|
||||
from datetime import datetime
|
||||
|
||||
@@ -121,4 +122,8 @@ class AccountMove(models.Model):
|
||||
self.ensure_one()
|
||||
from_currency = self.currency_id
|
||||
to_currency = self.company_id.currency_id
|
||||
return abs(self.invoice_line_ids[0].balance / self.invoice_line_ids[0].amount_currency) if from_currency != to_currency and self.invoice_line_ids else 1.0
|
||||
if from_currency != to_currency and self.invoice_line_ids:
|
||||
amount_currency = self.invoice_line_ids[0].amount_currency
|
||||
if not float_is_zero(amount_currency, precision_rounding=from_currency.rounding):
|
||||
return abs(self.invoice_line_ids[0].balance / amount_currency)
|
||||
return 1.0
|
||||
|
||||
Reference in New Issue
Block a user