Skip to content

Commit

Permalink
[ADD] product_pricelist_fixed_currency_rate
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisRForgeFlow committed Oct 24, 2023
1 parent 75bacf2 commit 96e78b9
Show file tree
Hide file tree
Showing 16 changed files with 787 additions and 0 deletions.
98 changes: 98 additions & 0 deletions product_pricelist_fixed_currency_rate/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
=====================================
Product Pricelist Fixed Currency Rate
=====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:705f94a56352ec7c69ab3d351588f96a01ef2266e347c800f32094d29d3de741
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_fixed_currency_rate
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_pricelist_fixed_currency_rate
: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/product-attribute&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the product pricelists feature to allow to set a fixed
currency rate to convert from a pricelist with a different currency.

**Table of contents**

.. contents::
:local:

Usage
=====

When using advanced price rules:

#. Go to a pricelist and create a pricelist with a given currency.
#. Create a new pricelist rule with computation formula.
#. Make it based on other pricelist that uses a different currency.
#. *Fixed Currency Rate* will show up, set a value.

This will force the currency conversion to always use the specified
*Fixed Currency Rate* rate when using this pricelist.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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/product-attribute/issues/new?body=module:%20product_pricelist_fixed_currency_rate%0Aversion:%2016.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
~~~~~~~

* ForgeFlow

Contributors
~~~~~~~~~~~~

* Lois Rilo <[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.

.. |maintainer-LoisRForgeFlow| image:: https://github.com/LoisRForgeFlow.png?size=40px
:target: https://github.com/LoisRForgeFlow
:alt: LoisRForgeFlow

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-LoisRForgeFlow|

This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_fixed_currency_rate>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_pricelist_fixed_currency_rate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions product_pricelist_fixed_currency_rate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Product Pricelist Fixed Currency Rate",
"summary": "Set a fixed currency rate between pricelists",
"version": "16.0.1.0.0",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"maintainers": ["LoisRForgeFlow"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["product"],
"data": [
"views/pricelist_views.xml",
],
}
2 changes: 2 additions & 0 deletions product_pricelist_fixed_currency_rate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_pricelist_item
from . import res_currency
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProductPricelist(models.Model):
_inherit = "product.pricelist.item"

fixed_currency_rate = fields.Float(
help="If set (different to 0.0), the currency conversion will "
"ignore the actual currency rate and always use the fixed "
"currency rate."
)
is_fixed_currency_rate_applicable = fields.Boolean(
compute="_compute_is_fixed_currency_rate_applicable"
)
actual_currency_rate = fields.Float(
compute="_compute_is_fixed_currency_rate_applicable"
)

@api.depends("base_pricelist_id", "base_pricelist_id.currency_id")
def _compute_is_fixed_currency_rate_applicable(self):
for rec in self:
applicable = (
rec.base_pricelist_id
and rec.base_pricelist_id.currency_id != rec.pricelist_id.currency_id
)
rec.is_fixed_currency_rate_applicable = applicable
if applicable:
curr_from = rec.base_pricelist_id.currency_id
curr_to = rec.pricelist_id.currency_id
company = rec.company_id or self.env.company
rec.actual_currency_rate = self.env[
"res.currency"
]._get_conversion_rate(
curr_from, curr_to, company, rec.date_end or fields.Date.today()
)
else:
rec.actual_currency_rate = 1.0

def _compute_base_price(self, product, quantity, uom, date, target_currency):
if self.is_fixed_currency_rate_applicable and self.fixed_currency_rate:
return super(
ProductPricelist,
self.with_context(fixed_currency_rate=self.fixed_currency_rate),
)._compute_base_price(product, quantity, uom, date, target_currency)
return super()._compute_base_price(
product, quantity, uom, date, target_currency
)
15 changes: 15 additions & 0 deletions product_pricelist_fixed_currency_rate/models/res_currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class ProductPricelist(models.Model):
_inherit = "res.currency"

@api.model
def _get_conversion_rate(self, from_currency, to_currency, company, date):
fixed_rate = self.env.context.get("fixed_currency_rate")
if fixed_rate:
return fixed_rate
return super()._get_conversion_rate(from_currency, to_currency, company, date)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Lois Rilo <[email protected]>
2 changes: 2 additions & 0 deletions product_pricelist_fixed_currency_rate/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module extends the product pricelists feature to allow to set a fixed
currency rate to convert from a pricelist with a different currency.
9 changes: 9 additions & 0 deletions product_pricelist_fixed_currency_rate/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
When using advanced price rules:

#. Go to a pricelist and create a pricelist with a given currency.
#. Create a new pricelist rule with computation formula.
#. Make it based on other pricelist that uses a different currency.
#. *Fixed Currency Rate* will show up, set a value.

This will force the currency conversion to always use the specified
*Fixed Currency Rate* rate when using this pricelist.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 96e78b9

Please sign in to comment.