-
-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by kittiu
- Loading branch information
Showing
18 changed files
with
1,027 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
========================= | ||
Account - Manual Currency | ||
========================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:35466de2e1eddf226817cd39139b497344396512b366f5bd4be981453e5b8721 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-invoicing/tree/15.0/account_manual_currency | ||
:alt: OCA/account-invoicing | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account-invoicing-15-0/account-invoicing-15-0-account_manual_currency | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows users to update the currency manually for invoices that are still in the draft stage. | ||
It offers flexibility to companies when calculating currency rates for invoicing. | ||
|
||
For example, if a company makes a deal with a vendor but the actual purchase happens on a different day, | ||
this module lets them choose whether to use the currency rate from the accounting date | ||
or a special rate agreed upon during the deal. | ||
This ensures accurate currency rate calculations for invoices, | ||
even when the purchase date and deal date differ. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, the company must have access rights for multiple currencies. | ||
|
||
Follow these steps to use manual currency: | ||
|
||
#. Go to Invoicing > Create new invoice/bills. | ||
#. If you need to change the currency to one other than the company's default currency, you will see an option for 'Manual Currency'. | ||
#. Check the 'Manual Currency' box to enable manual currency entry. | ||
#. Specify the desired currency rate for the selected currency. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_manual_currency%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Ecosoft | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Saran Lim. <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/15.0/account_manual_currency>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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,4 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
from . import wizard |
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,16 @@ | ||
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Account - Manual Currency", | ||
"version": "15.0.1.0.0", | ||
"category": "Accounting & Finance", | ||
"summary": "Allows to manual currency of Accounting", | ||
"author": "Ecosoft, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/account-invoicing", | ||
"license": "AGPL-3", | ||
"depends": ["account"], | ||
"data": ["data/decimal_data.xml", "views/account_move_view.xml"], | ||
"installable": True, | ||
"maintainer": ["Saran440"], | ||
} |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="decimal_price" model="decimal.precision" forcecreate="True"> | ||
<field name="name">Manual Currency</field> | ||
<field name="digits">12</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import account_move |
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,186 @@ | ||
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from lxml import etree | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
manual_currency = fields.Boolean( | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
) | ||
is_manual = fields.Boolean(compute="_compute_currency") | ||
type_currency = fields.Selection( | ||
selection=lambda self: self._get_label_currency_name(), | ||
default=lambda self: self._get_label_currency_name()[0][0], | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
) | ||
manual_currency_rate = fields.Float( | ||
digits="Manual Currency", | ||
tracking=True, | ||
readonly=True, | ||
states={"draft": [("readonly", False)]}, | ||
help="Set new currency rate to apply on the invoice\n." | ||
"This rate will be taken in order to convert amounts between the " | ||
"currency on the purchase order and last currency", | ||
) | ||
total_company_currency = fields.Monetary( | ||
compute="_compute_total_company_currency", currency_field="company_currency_id" | ||
) | ||
currency_diff = fields.Boolean( | ||
compute="_compute_currency_diff", | ||
store=True, | ||
) | ||
|
||
@api.depends("currency_id") | ||
def _compute_currency_diff(self): | ||
for rec in self: | ||
rec.currency_diff = rec.company_currency_id != rec.currency_id | ||
|
||
@api.depends("line_ids.balance") | ||
def _compute_total_company_currency(self): | ||
"""Convert total currency to company currency""" | ||
for rec in self: | ||
# check manual currency | ||
if rec.manual_currency: | ||
rate = ( | ||
rec.manual_currency_rate | ||
if rec.type_currency == "inverse_company_rate" | ||
else (1.0 / rec.manual_currency_rate) | ||
) | ||
rec.total_company_currency = rec.amount_total * rate | ||
# default rate currency | ||
else: | ||
rec.total_company_currency = rec.currency_id._convert( | ||
rec.amount_total, | ||
rec.company_currency_id, | ||
rec.company_id, | ||
fields.Date.today(), | ||
) | ||
|
||
def _get_label_currency_name(self): | ||
"""Get label related currency""" | ||
names = { | ||
"company_currency_name": ( | ||
self.env["res.company"].browse(self._context.get("company_id")) | ||
or self.env.company | ||
).currency_id.name, | ||
"rate_currency_name": "Currency", | ||
} | ||
return [ | ||
[ | ||
"company_rate", | ||
_("%(rate_currency_name)s per 1 %(company_currency_name)s", **names), | ||
], | ||
[ | ||
"inverse_company_rate", | ||
_("%(company_currency_name)s per 1 %(rate_currency_name)s", **names), | ||
], | ||
] | ||
|
||
@api.onchange("manual_currency", "type_currency", "currency_id", "date") | ||
def _onchange_currency_change_rate(self): | ||
today = fields.Date.today() | ||
company_currency = self.env.company.currency_id | ||
amount_currency = company_currency._get_conversion_rate( | ||
company_currency, | ||
self.currency_id, | ||
self.company_id, | ||
self.date or today, | ||
) | ||
if self.type_currency == "inverse_company_rate": | ||
amount_currency = 1.0 / amount_currency | ||
self.manual_currency_rate = amount_currency | ||
self.line_ids._onchange_amount_currency() | ||
|
||
@api.onchange("manual_currency_rate") | ||
def _onchange_manual_currency_rate(self): | ||
self.line_ids._onchange_amount_currency() | ||
|
||
@api.depends("currency_id") | ||
def _compute_currency(self): | ||
for rec in self: | ||
rec.is_manual = rec.currency_id != rec.company_id.currency_id | ||
|
||
def action_refresh_currency(self): | ||
self.ensure_one() | ||
if self.state != "draft": | ||
raise ValidationError(_("Rate currency can refresh state draft only.")) | ||
self.with_context(check_move_validity=False)._onchange_currency_change_rate() | ||
return True | ||
|
||
@api.model | ||
def _fields_view_get( | ||
self, view_id=None, view_type="form", toolbar=False, submenu=False | ||
): | ||
"""Change string name to company currency""" | ||
result = super()._fields_view_get( | ||
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu | ||
) | ||
if view_type == "form": | ||
company_currency_name = ( | ||
self.env["res.company"].browse(self._context.get("company_id")) | ||
or self.env.company | ||
).currency_id.name | ||
doc = etree.XML(result["arch"]) | ||
# Total company currency | ||
node = doc.xpath("//field[@name='total_company_currency']") | ||
if node: | ||
node[0].set("string", "Total ({})".format(company_currency_name)) | ||
result["arch"] = etree.tostring(doc, encoding="unicode") | ||
return result | ||
|
||
|
||
class AccountMoveLine(models.Model): | ||
_inherit = "account.move.line" | ||
|
||
@api.onchange("amount_currency") | ||
def _onchange_amount_currency(self): | ||
for line in self: | ||
if line.move_id.manual_currency: | ||
rate = ( | ||
line.move_id.manual_currency_rate | ||
if line.move_id.type_currency == "inverse_company_rate" | ||
else (1.0 / line.move_id.manual_currency_rate) | ||
) | ||
balance = line.amount_currency * rate | ||
line.debit = balance if balance > 0.0 else 0.0 | ||
line.credit = -balance if balance < 0.0 else 0.0 | ||
|
||
if not line.move_id.is_invoice(include_receipts=True): | ||
continue | ||
|
||
line.update(line._get_fields_onchange_balance()) | ||
line.update(line._get_price_total_and_subtotal()) | ||
else: | ||
super(AccountMoveLine, line)._onchange_amount_currency() | ||
return | ||
|
||
@api.model | ||
def _get_fields_onchange_subtotal_model( | ||
self, price_subtotal, move_type, currency, company, date | ||
): | ||
if self.move_id.manual_currency: | ||
sign = -1 if move_type in self.move_id.get_inbound_types() else 1 | ||
amount_currency = price_subtotal * sign | ||
rate = ( | ||
self.move_id.manual_currency_rate | ||
if self.move_id.type_currency == "inverse_company_rate" | ||
else (1.0 / self.move_id.manual_currency_rate) | ||
) | ||
balance = price_subtotal * rate | ||
return { | ||
"amount_currency": amount_currency, | ||
"currency_id": currency.id, | ||
"debit": balance > 0.0 and balance or 0.0, | ||
"credit": balance < 0.0 and -balance or 0.0, | ||
} | ||
return super()._get_fields_onchange_subtotal_model( | ||
price_subtotal, move_type, currency, company, date | ||
) |
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 @@ | ||
* Saran Lim. <[email protected]> |
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,8 @@ | ||
This module allows users to update the currency manually for invoices that are still in the draft stage. | ||
It offers flexibility to companies when calculating currency rates for invoicing. | ||
|
||
For example, if a company makes a deal with a vendor but the actual purchase happens on a different day, | ||
this module lets them choose whether to use the currency rate from the accounting date | ||
or a special rate agreed upon during the deal. | ||
This ensures accurate currency rate calculations for invoices, | ||
even when the purchase date and deal date differ. |
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,8 @@ | ||
To use this module, the company must have access rights for multiple currencies. | ||
|
||
Follow these steps to use manual currency: | ||
|
||
#. Go to Invoicing > Create new invoice/bills. | ||
#. If you need to change the currency to one other than the company's default currency, you will see an option for 'Manual Currency'. | ||
#. Check the 'Manual Currency' box to enable manual currency entry. | ||
#. Specify the desired currency rate for the selected currency. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.