-
-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] product_pricelist_company_price
- Loading branch information
1 parent
28db8a2
commit 2207a6f
Showing
24 changed files
with
1,024 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,98 @@ | ||
============================ | ||
Price from company pricelist | ||
============================ | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:d87e22e76f34eb418645d0b21645c1c8a3071e03cb21d7a80ffe1253b9af6167 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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_company_price | ||
: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_company_price | ||
: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| | ||
|
||
Manage product prices from a pricelist configured at company level. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
Enable Advanced Pricelists and fill the Products pricelist in General Settings. | ||
|
||
Usage | ||
===== | ||
|
||
In the configured pricelist, define product or variant rules computed with fixed price. | ||
|
||
The chosen products will have their sale price set to the price fixed in the 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_company_price%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 | ||
~~~~~~~ | ||
|
||
* Aion Tech | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Aion Tech <https://aiontech.company/>`_: | ||
|
||
* Simone Rubino <[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-SirAionTech| image:: https://github.com/SirAionTech.png?size=40px | ||
:target: https://github.com/SirAionTech | ||
:alt: SirAionTech | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-SirAionTech| | ||
|
||
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_company_price>`_ 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,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
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,23 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Price from company pricelist", | ||
"summary": "Manage product prices from a pricelist configured at company level.", | ||
"version": "16.0.1.0.0", | ||
"category": "Product", | ||
"website": "https://github.com/OCA/product-attribute" | ||
"/tree/16.0/product_pricelist_company_price", | ||
"author": "Aion Tech, Odoo Community Association (OCA)", | ||
"maintainers": [ | ||
"SirAionTech", | ||
], | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"product", | ||
], | ||
"data": [ | ||
"views/product_template_views.xml", | ||
"views/product_product_views.xml", | ||
"views/res_config_settings_views.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,59 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * product_pricelist_company_price | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-11-23 11:42+0000\n" | ||
"PO-Revision-Date: 2023-11-23 11:42+0000\n" | ||
"Last-Translator: Simone Rubino <[email protected]>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: product_pricelist_company_price | ||
#: model:ir.model,name:product_pricelist_company_price.model_res_company | ||
msgid "Companies" | ||
msgstr "Aziende" | ||
|
||
#. module: product_pricelist_company_price | ||
#: model:ir.model,name:product_pricelist_company_price.model_res_config_settings | ||
msgid "Config Settings" | ||
msgstr "Impostazioni di configurazione" | ||
|
||
#. module: product_pricelist_company_price | ||
#: model:ir.model,name:product_pricelist_company_price.model_product_pricelist_item | ||
msgid "Pricelist Rule" | ||
msgstr "Regola listino prezzi" | ||
|
||
#. module: product_pricelist_company_price | ||
#: model:ir.model.fields,help:product_pricelist_company_price.field_res_company__products_price_pricelist_id | ||
#: model:ir.model.fields,help:product_pricelist_company_price.field_res_config_settings__products_price_pricelist_id | ||
#: model_terms:ir.ui.view,arch_db:product_pricelist_company_price.res_config_settings_view_form | ||
msgid "" | ||
"Prices set for individual products in this pricelist propagate to the sales " | ||
"price of the products it affects." | ||
msgstr "" | ||
"I prezzi impostato per i singoli prodotti in questo listino saranno riportati " | ||
"sui prezzi di vendita dei prodotti interessati." | ||
|
||
#. module: product_pricelist_company_price | ||
#: model:ir.model,name:product_pricelist_company_price.model_product_template | ||
msgid "Product" | ||
msgstr "Prodotto" | ||
|
||
#. module: product_pricelist_company_price | ||
#: model:ir.model,name:product_pricelist_company_price.model_product_product | ||
msgid "Product Variant" | ||
msgstr "Variante prodotto" | ||
|
||
#. module: product_pricelist_company_price | ||
#: model:ir.model.fields,field_description:product_pricelist_company_price.field_res_company__products_price_pricelist_id | ||
#: model:ir.model.fields,field_description:product_pricelist_company_price.field_res_config_settings__products_price_pricelist_id | ||
#: model_terms:ir.ui.view,arch_db:product_pricelist_company_price.res_config_settings_view_form | ||
msgid "Products Pricelist" | ||
msgstr "Listino prodotti" |
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 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import product_pricelist_item | ||
from . import product_product | ||
from . import product_template | ||
from . import res_company | ||
from . import res_config_settings |
44 changes: 44 additions & 0 deletions
44
product_pricelist_company_price/models/product_pricelist_item.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,44 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class ProductPricelistItem(models.Model): | ||
_inherit = "product.pricelist.item" | ||
|
||
def _is_products_pricelist_item(self): | ||
"""This price rule will update product prices when updated.""" | ||
self.ensure_one() | ||
company = self.company_id or self.env.company | ||
company_pricelist = company.products_price_pricelist_id | ||
return ( | ||
self.pricelist_id == company_pricelist | ||
and self.compute_price == "fixed" | ||
and self.applied_on | ||
in [ | ||
"1_product", | ||
"0_product_variant", | ||
] | ||
) | ||
|
||
def _update_products_pricelist_prices(self): | ||
"""If the items are in the company pricelist, update price of matching products.""" | ||
for item in self: | ||
if item._is_products_pricelist_item(): | ||
price = item.fixed_price | ||
if item.applied_on == "1_product": | ||
item.product_tmpl_id.list_price = price | ||
elif item.applied_on == "0_product_variant": | ||
item.product_id.lst_price = price | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
items = super().create(vals_list) | ||
items._update_products_pricelist_prices() | ||
return items | ||
|
||
def write(self, vals): | ||
res = super().write(vals) | ||
self._update_products_pricelist_prices() | ||
return res |
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,35 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.product" | ||
|
||
is_in_products_pricelist = fields.Boolean( | ||
compute="_compute_is_in_products_pricelist", | ||
) | ||
|
||
@api.model | ||
def _is_in_products_pricelist(self, product): | ||
"""Determine if `product` (template or variant) is in the Company pricelist.""" | ||
now = fields.Datetime.now() | ||
company = product.company_id or product.env.company | ||
products_pricelist = company.products_price_pricelist_id | ||
if products_pricelist: | ||
products_pricelist_items = products_pricelist._get_applicable_rules( | ||
product, now | ||
) | ||
products_pricelist_items = products_pricelist_items.filtered( | ||
lambda rule: rule._is_products_pricelist_item() | ||
) | ||
is_in_products_pricelist = bool(products_pricelist_items) | ||
else: | ||
is_in_products_pricelist = False | ||
return is_in_products_pricelist | ||
|
||
def _compute_is_in_products_pricelist(self): | ||
for product in self: | ||
is_in_products_pricelist = self._is_in_products_pricelist(product) | ||
product.is_in_products_pricelist = is_in_products_pricelist |
18 changes: 18 additions & 0 deletions
18
product_pricelist_company_price/models/product_template.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,18 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
is_in_products_pricelist = fields.Boolean( | ||
compute="_compute_is_in_products_pricelist", | ||
) | ||
|
||
def _compute_is_in_products_pricelist(self): | ||
product_model = self.env["product.product"] | ||
for product in self: | ||
is_in_products_pricelist = product_model._is_in_products_pricelist(product) | ||
product.is_in_products_pricelist = is_in_products_pricelist |
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,24 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
products_price_pricelist_id = fields.Many2one( | ||
comodel_name="product.pricelist", | ||
string="Products Pricelist", | ||
help="Prices set for individual products in this pricelist " | ||
"propagate to the sales price of the products it affects.", | ||
) | ||
|
||
def write(self, vals): | ||
res = super().write(vals) | ||
if "products_price_pricelist_id" in vals: | ||
for company in self: | ||
products_pricelist = company.products_price_pricelist_id | ||
if products_pricelist: | ||
products_pricelist.item_ids._update_products_pricelist_prices() | ||
return res |
13 changes: 13 additions & 0 deletions
13
product_pricelist_company_price/models/res_config_settings.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,13 @@ | ||
# Copyright 2023 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
products_price_pricelist_id = fields.Many2one( | ||
related="company_id.products_price_pricelist_id", | ||
readonly=False, | ||
) |
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 @@ | ||
Enable Advanced Pricelists and fill the Products pricelist in General Settings. |
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 @@ | ||
* `Aion Tech <https://aiontech.company/>`_: | ||
|
||
* Simone Rubino <[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 @@ | ||
Manage product prices from a pricelist configured at company level. |
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 @@ | ||
In the configured pricelist, define product or variant rules computed with fixed price. | ||
|
||
The chosen products will have their sale price set to the price fixed in the pricelist. |
Oops, something went wrong.