Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] l10n_it_reverse_charge in multi currency: use the supplier invoice date #4462

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l10n_it_reverse_charge/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Copyright 2017 Lorenzo Battistini - Agile Business Group
# Copyright 2017 Marco Calcagni - Dinamiche Aziendali srl

from . import account_fiscal_position, account_move, account_rc_type
from . import account_fiscal_position, account_move, account_rc_type, res_currency
28 changes: 23 additions & 5 deletions l10n_it_reverse_charge/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,25 @@ def generate_self_invoice(self):
for line in rc_invoice.line_ids:
line.remove_move_reconcile()
rc_invoice.invoice_line_ids.unlink()
rc_invoice.write(inv_vals)
rc_invoice.with_context(
force_conversion_date=self.rc_original_purchase_invoice_ids[
0
].invoice_date
if self.rc_original_purchase_invoice_ids
else self.rc_purchase_invoice_id.invoice_date,
).write(inv_vals)
else:
rc_invoice = self.create(inv_vals)
rc_invoice = self.with_context(
force_conversion_date=self.rc_original_purchase_invoice_ids[
0
].invoice_date
if self.rc_original_purchase_invoice_ids
else self.rc_purchase_invoice_id.invoice_date,
).create(inv_vals)
self.rc_self_invoice_id = rc_invoice.id
rc_invoice.action_post()
rc_invoice.with_context(
force_conversion_date=self.invoice_date,
).action_post()

if self.amount_total:
# No need to reconcile invoices with total = 0
Expand Down Expand Up @@ -468,10 +482,14 @@ def generate_supplier_self_invoice(self):
if inv_line.account_id:
line_vals["account_id"] = rc_type.transitory_account_id.id
invoice_line_vals.append((0, 0, line_vals))
supplier_invoice.write({"invoice_line_ids": invoice_line_vals})
supplier_invoice.with_context(
force_conversion_date=self.invoice_date,
).write({"invoice_line_ids": invoice_line_vals})
self.rc_self_purchase_invoice_id = supplier_invoice.id

supplier_invoice.action_post()
supplier_invoice.with_context(
force_conversion_date=self.invoice_date,
).action_post()
supplier_invoice.fiscal_position_id = self.fiscal_position_id.id

def action_post(self):
Expand Down
19 changes: 19 additions & 0 deletions l10n_it_reverse_charge/models/res_currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import models


class ResCurrency(models.BaseModel):
_inherit = "res.currency"

def _convert(self, from_amount, to_currency, company, date, round=True):
if self.env.context.get("force_conversion_date"):
return super(ResCurrency, self)._convert(
from_amount,
to_currency,
company,
date=self.env.context["force_conversion_date"],
round=round,
)

return super(ResCurrency, self)._convert(
from_amount, to_currency, company, date, round
)
Loading