[FW][FIX] l10n_ar: AFIP currency rate.
We have a bug when we were computing the invoice rate that is used to report to AFIP. The rate we were setting was an old rate that references the day that the invoice was created and not the rate of the day where the invoice was validated. This was happening because the l10n_ar_currency_rate field that stores this value was computed before posting the invoice. At that time the date field store the value of the date where the invoice was created and had not been updated yet with the accounting date. Moving the l10n_ar_currency_rate field calculation after the invoice post solves the problem and now the l10n_ar_currency_rate has the rate of the accounting date. Part-of: odoo/odoo#84470 Original commit: aac1165655d31ba3bca4b105e0c905534e91df93 closes odoo/odoo#87163 X-original-commit: ac57ac559d973a1c4c2050fa514668d20bd610f0 Signed-off-by: Josse Colpaert <jco@odoo.com>
This commit is contained in:
committed by
Josse Colpaert
parent
b131f57a88
commit
f0b90c9fa8
@@ -130,6 +130,22 @@ class AccountMove(models.Model):
|
||||
if not rec.l10n_ar_afip_service_end:
|
||||
rec.l10n_ar_afip_service_end = rec.invoice_date + relativedelta(day=1, days=-1, months=+1)
|
||||
|
||||
def _set_afip_responsibility(self):
|
||||
""" We save the information about the receptor responsability at the time we validate the invoice, this is
|
||||
necessary because the user can change the responsability after that any time """
|
||||
for rec in self:
|
||||
rec.l10n_ar_afip_responsibility_type_id = rec.commercial_partner_id.l10n_ar_afip_responsibility_type_id.id
|
||||
|
||||
def _set_afip_rate(self):
|
||||
""" We set the l10n_ar_currency_rate value with the accounting date. This should be done
|
||||
after invoice has been posted in order to have the proper accounting date"""
|
||||
for rec in self:
|
||||
if rec.company_id.currency_id == rec.currency_id:
|
||||
rec.l10n_ar_currency_rate = 1.0
|
||||
elif not rec.l10n_ar_currency_rate:
|
||||
rec.l10n_ar_currency_rate = rec.currency_id._convert(
|
||||
1.0, rec.company_id.currency_id, rec.company_id, rec.date, round=False)
|
||||
|
||||
@api.onchange('partner_id')
|
||||
def _onchange_afip_responsibility(self):
|
||||
if self.company_id.account_fiscal_country_id.code == 'AR' and self.l10n_latam_use_documents and self.partner_id \
|
||||
@@ -166,19 +182,15 @@ class AccountMove(models.Model):
|
||||
|
||||
def _post(self, soft=True):
|
||||
ar_invoices = self.filtered(lambda x: x.company_id.account_fiscal_country_id.code == "AR" and x.l10n_latam_use_documents)
|
||||
for rec in ar_invoices:
|
||||
rec.l10n_ar_afip_responsibility_type_id = rec.commercial_partner_id.l10n_ar_afip_responsibility_type_id.id
|
||||
if rec.company_id.currency_id == rec.currency_id:
|
||||
rec.l10n_ar_currency_rate = 1.0
|
||||
elif not rec.l10n_ar_currency_rate:
|
||||
rec.l10n_ar_currency_rate = rec.currency_id._convert(
|
||||
1.0, rec.company_id.currency_id, rec.company_id, rec.date, round=False)
|
||||
|
||||
# We make validations here and not with a constraint because we want validation before sending electronic
|
||||
# data on l10n_ar_edi
|
||||
ar_invoices._check_argentinean_invoice_taxes()
|
||||
posted = super()._post(soft)
|
||||
posted._set_afip_service_dates()
|
||||
posted = super()._post(soft=soft)
|
||||
|
||||
posted_ar_invoices = posted & ar_invoices
|
||||
posted_ar_invoices._set_afip_responsibility()
|
||||
posted_ar_invoices._set_afip_rate()
|
||||
posted_ar_invoices._set_afip_service_dates()
|
||||
return posted
|
||||
|
||||
def _reverse_moves(self, default_values_list=None, cancel=False):
|
||||
|
||||
Reference in New Issue
Block a user