-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BKP] account_invoice_show_currency_rate
- Loading branch information
1 parent
e25d560
commit 75ec7d1
Showing
9 changed files
with
113 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import account_move | ||
from . import account_invoice |
53 changes: 53 additions & 0 deletions
53
account_invoice_show_currency_rate/models/account_invoice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2021 Tecnativa - Víctor Martínez | ||
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = "account.invoice" | ||
|
||
currency_rate_amount = fields.Float( | ||
string="Rate amount", compute="_compute_currency_rate_amount", digits=0, | ||
) | ||
show_currency_rate_amount = fields.Boolean( | ||
compute="_compute_show_currency_rate_amount", readonly=True | ||
) | ||
|
||
@api.depends( | ||
"state", | ||
"date", | ||
"amount_total_company_signed", | ||
"amount_total_signed", | ||
"company_id", | ||
"currency_id", | ||
"show_currency_rate_amount", | ||
) | ||
def _compute_currency_rate_amount(self): | ||
""" It's necessary to define value according to some cases: | ||
- Case A: Currency is equal to company currency (Value = 1) | ||
- Case B: Invoice exist previously (confirmed) and get real rate | ||
according to amount | ||
- Case C: Get expected rate (according to date) | ||
to show some value in creation. | ||
""" | ||
for item in self: | ||
item.currency_rate_amount = 1 | ||
if not item.show_currency_rate_amount: | ||
continue | ||
if item.state == 'open': | ||
item.currency_rate_amount = item.currency_id.round( | ||
item.amount_total_signed / item.amount_total_company_signed | ||
) | ||
else: | ||
date = item.date or fields.Date.today() | ||
item.currency_rate_amount = item.currency_id.with_context( | ||
date=date).rate | ||
|
||
@api.depends("currency_id", "currency_id.rate_ids", "company_id") | ||
def _compute_show_currency_rate_amount(self): | ||
for item in self: | ||
item.show_currency_rate_amount = ( | ||
item.currency_id and item.currency_id != item.company_id.currency_id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
account_invoice_show_currency_rate/views/account_invoice_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
--> | ||
<odoo> | ||
<record id="account_invoice_form_inherit" model="ir.ui.view"> | ||
<field name="name">account.invoice.form.inherit</field> | ||
<field name="model">account.invoice</field> | ||
<field name="inherit_id" ref="account.invoice_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//label[@for='currency_id']" position="before"> | ||
<field name="show_currency_rate_amount" invisible="1" /> | ||
<field | ||
name="currency_rate_amount" | ||
groups="base.group_multi_currency" | ||
digits="[12,12]" | ||
attrs="{'invisible':[('show_currency_rate_amount', '=', False)]}" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
setup/account_invoice_show_currency_rate/odoo/addons/account_invoice_show_currency_rate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../account_invoice_show_currency_rate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |