-
-
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 d0e10c4
Showing
9 changed files
with
127 additions
and
33 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 |
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
# Copyright 2021 Tecnativa - Víctor Martínez | ||
# 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 item.show_currency_rate_amount: | ||
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() | ||
rates = item.currency_id._get_rates(item.company_id, date) | ||
item.currency_rate_amount = rates.get(item.currency_id.id) | ||
|
||
@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, | ||
) |