Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
1
account_invoice_show_currency_rate/models/__init__.py
Normal file
1
account_invoice_show_currency_rate/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import account_move
|
||||
67
account_invoice_show_currency_rate/models/account_move.py
Normal file
67
account_invoice_show_currency_rate/models/account_move.py
Normal file
@@ -0,0 +1,67 @@
|
||||
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
@api.depends(
|
||||
"currency_id",
|
||||
"company_currency_id",
|
||||
"company_id",
|
||||
"invoice_date",
|
||||
"state",
|
||||
"line_ids.amount_currency",
|
||||
"line_ids.balance",
|
||||
)
|
||||
def _compute_invoice_currency_rate(self):
|
||||
# If move is posted, get rate based on line amount
|
||||
res = super()._compute_invoice_currency_rate()
|
||||
for move in self:
|
||||
lines = move.line_ids.filtered(lambda x: abs(x.amount_currency) > 0)
|
||||
if move.state != "posted" or not lines or not move.currency_id:
|
||||
continue
|
||||
amount_currency_positive = sum(
|
||||
[abs(amc) for amc in lines.mapped("amount_currency")]
|
||||
)
|
||||
total_balance_positive = sum([abs(b) for b in lines.mapped("balance")])
|
||||
move.invoice_currency_rate = (
|
||||
amount_currency_positive / total_balance_positive
|
||||
)
|
||||
return res
|
||||
|
||||
# Add the 'state', 'line_ids.amount_currency', and 'line_ids.balance'
|
||||
# dependencies to the base dependencies to recalculate the expected exchange rate.
|
||||
#
|
||||
# Without this change, which causes expected_currency_rate and invoice_currency_rate
|
||||
# to be updated simultaneously, invoice_currency_rate is updated with an outdated
|
||||
# expected_currency_rate value in account.move.
|
||||
@api.depends("state", "line_ids.amount_currency", "line_ids.balance")
|
||||
def _compute_expected_currency_rate(self):
|
||||
return super()._compute_expected_currency_rate()
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
@api.depends(
|
||||
"currency_id",
|
||||
"company_id",
|
||||
"move_id.invoice_currency_rate",
|
||||
"move_id.date",
|
||||
"move_id.state",
|
||||
"amount_currency",
|
||||
"balance",
|
||||
)
|
||||
def _compute_currency_rate(self):
|
||||
# If move is posted, get rate based on line amount
|
||||
res = super()._compute_currency_rate()
|
||||
for line in self:
|
||||
if line.move_id.state != "posted" or not line.amount_currency:
|
||||
continue
|
||||
line.currency_rate = (
|
||||
abs(line.amount_currency) / abs(line.balance) if line.balance else 0
|
||||
)
|
||||
return res
|
||||
Reference in New Issue
Block a user