-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[14.0][MIG] - migration pricelist brand to 14.0 #122
Open
cramosh
wants to merge
12
commits into
OCA:14.0
Choose a base branch
from
dm-integrations:14.0-mig-pricelist_brand
base: 14.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bc8c9ef
[ADD] Pricelist brand
qgroulard 89d3149
[UPD] Update pricelist_brand.pot
oca-travis d4bfbf7
[UPD] README.rst
OCA-git-bot 2da4254
[IMP] : black, isort, prettier
cramosh 6e23237
[MIG] pricelist_brand: Migration to 14.0
cramosh 217fff5
[IMP] pricelist_brand: Implemented new TESTS
cramosh 8eecbb3
[IMP] pricelist_brand: Implemented new TESTS
cramosh 74a27ce
[IMP] pricelist_brand: Implemented new TESTS
cramosh 6fa9476
[IMP] pricelist_brand: Implemented new TESTS
cramosh 90268a7
[IMP] pricelist_brand: Implemented new TESTS
cramosh cafdbdb
[IMP] pricelist_brand: Implemented new TESTS
cramosh e81d3ec
[IMP] pricelist_brand: Implemented new TESTS
cramosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,85 @@ | ||
=============== | ||
Pricelist Brand | ||
=============== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |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%2Fbrand-lightgray.png?logo=github | ||
:target: https://github.com/OCA/brand/tree/13.0/pricelist_brand | ||
:alt: OCA/brand | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/brand-13-0/brand-13-0-pricelist_brand | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/284/13.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to configure pricelist items so that they are applied on products of specific brands. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To apply pricelist items on branded products: | ||
|
||
#. See 'product_brand' module to learn how to configure brands on products. | ||
#. Go to *Sales > Pricelists* and open the pricelist of your choice or create a new one. | ||
#. Edit the pricelist and add a new item to it. | ||
#. Select *Brand* in the field *Applied On*. | ||
#. Select the product brand of your choice in the field *Brand*. | ||
#. Configure the rest of the rule the way you want, this rule will apply on any product from the brand you selected. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/brand/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/brand/issues/new?body=module:%20pricelist_brand%0Aversion:%2013.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 | ||
~~~~~~~ | ||
|
||
* ACSONE SA/NV | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Quentin Groulard <[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/brand <https://github.com/OCA/brand/tree/14.0/pricelist_brand>`_ 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 @@ | ||
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,17 @@ | ||
# Copyright 2020 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Pricelist Brand", | ||
"summary": """This module allows to apply pricelist items on brand""", | ||
"version": "14.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/brand", | ||
"depends": [ | ||
"product_brand", | ||
"sale", | ||
"product", | ||
], | ||
"data": ["views/product_pricelist.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: | ||
# * pricelist_brand | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 14.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: \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: pricelist_brand | ||
#: model:ir.model.fields,field_description:pricelist_brand.field_product_pricelist_item__applied_on | ||
msgid "Apply On" | ||
msgstr "" | ||
|
||
#. module: pricelist_brand | ||
#: model:ir.model.fields,field_description:pricelist_brand.field_product_pricelist_item__product_brand_id | ||
#: model:ir.model.fields.selection,name:pricelist_brand.selection__product_pricelist_item__applied_on__25_brand | ||
msgid "Brand" | ||
msgstr "" | ||
|
||
#. module: pricelist_brand | ||
#: code:addons/pricelist_brand/models/product_pricelist.py:0 | ||
#, python-format | ||
msgid "Brand: %s" | ||
msgstr "" | ||
|
||
#. module: pricelist_brand | ||
#: code:addons/pricelist_brand/models/product_pricelist.py:0 | ||
#, python-format | ||
msgid "Please specify the brand for which this rule should be applied" | ||
msgstr "" | ||
|
||
#. module: pricelist_brand | ||
#: model:ir.model,name:pricelist_brand.model_product_pricelist | ||
msgid "Pricelist" | ||
msgstr "" | ||
|
||
#. module: pricelist_brand | ||
#: model:ir.model.fields,help:pricelist_brand.field_product_pricelist_item__applied_on | ||
msgid "Pricelist Item applicable on selected option" | ||
msgstr "" | ||
|
||
#. module: pricelist_brand | ||
#: model:ir.model,name:pricelist_brand.model_product_pricelist_item | ||
msgid "Pricelist Rule" | ||
msgstr "" | ||
|
||
#. module: pricelist_brand | ||
#: model:ir.model.fields,help:pricelist_brand.field_product_pricelist_item__product_brand_id | ||
msgid "" | ||
"Specify a brand if this rule only applies to productsbelonging to this " | ||
"brand. Keep empty otherwise." | ||
msgstr "" |
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 @@ | ||
from . import product_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,126 @@ | ||
# Copyright 2020 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProductPricelist(models.Model): | ||
_inherit = "product.pricelist" | ||
|
||
def _compute_price_rule_get_items( | ||
self, products_qty_partner, date, uom_id, prod_tmpl_ids, prod_ids, categ_ids | ||
): | ||
self.ensure_one() | ||
product_tmpls = self.env["product.template"].browse(prod_tmpl_ids) | ||
brand_ids = product_tmpls.mapped("product_brand_id").ids | ||
# Load all rules | ||
self.env["product.pricelist.item"].flush(["price", "currency_id", "company_id"]) | ||
self.env.cr.execute( | ||
""" | ||
SELECT | ||
item.id | ||
FROM | ||
product_pricelist_item AS item | ||
LEFT JOIN product_category AS categ ON item.categ_id = categ.id | ||
LEFT JOIN product_brand AS brand ON item.product_brand_id = brand.id | ||
WHERE | ||
(item.product_tmpl_id IS NULL OR item.product_tmpl_id = any(%s)) | ||
AND (item.product_id IS NULL OR item.product_id = any(%s)) | ||
AND (item.categ_id IS NULL OR item.categ_id = any(%s)) | ||
AND (item.product_brand_id IS NULL OR item.product_brand_id = any(%s)) | ||
AND (item.pricelist_id = %s) | ||
AND (item.date_start IS NULL OR item.date_start<=%s) | ||
AND (item.date_end IS NULL OR item.date_end>=%s) | ||
ORDER BY | ||
item.applied_on, item.min_quantity desc, | ||
categ.complete_name desc, item.id desc | ||
""", | ||
(prod_tmpl_ids, prod_ids, categ_ids, brand_ids, self.id, date, date), | ||
) | ||
# NOTE: if you change `order by` on that query, make sure it matches | ||
# _order from model to avoid inconstencies and undeterministic issues. | ||
|
||
item_ids = [x[0] for x in self.env.cr.fetchall()] | ||
return self.env["product.pricelist.item"].browse(item_ids) | ||
|
||
|
||
class ProductPricelistItem(models.Model): | ||
_inherit = "product.pricelist.item" | ||
|
||
product_brand_id = fields.Many2one( | ||
comodel_name="product.brand", | ||
string="Brand", | ||
ondelete="cascade", | ||
help="Specify a brand if this rule only applies to products" | ||
"belonging to this brand. Keep empty otherwise.", | ||
) | ||
applied_on = fields.Selection( | ||
selection_add=[("25_brand", "Brand")], ondelete={"25_brand": "cascade"} | ||
) | ||
|
||
@api.constrains("product_id", "product_tmpl_id", "categ_id", "product_brand_id") | ||
def _check_product_consistency(self): | ||
super(ProductPricelistItem, self)._check_product_consistency() | ||
for item in self: | ||
if item.applied_on == "25_brand" and not item.product_brand_id: | ||
raise ValidationError( | ||
_("Please specify the brand for which this rule should be applied") | ||
) | ||
|
||
@api.depends( | ||
"applied_on", | ||
"categ_id", | ||
"product_tmpl_id", | ||
"product_id", | ||
"compute_price", | ||
"fixed_price", | ||
"pricelist_id", | ||
"percent_price", | ||
"price_discount", | ||
"price_surcharge", | ||
"product_brand_id", | ||
) | ||
def _get_pricelist_item_name_price(self): | ||
super(ProductPricelistItem, self)._get_pricelist_item_name_price() | ||
for item in self: | ||
if item.product_brand_id and item.applied_on == "25_brand": | ||
item.name = _("Brand: %s") % (item.product_brand_id.display_name) | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
for values in vals_list: | ||
if values.get("applied_on", False): | ||
# Ensure item consistency for later searches. | ||
applied_on = values["applied_on"] | ||
if applied_on == "25_brand": | ||
values.update( | ||
dict(product_id=None, product_tmpl_id=None, categ_id=None) | ||
) | ||
elif applied_on == "3_global": | ||
values.update(dict(product_brand_id=None)) | ||
elif applied_on == "2_product_category": | ||
values.update(dict(product_brand_id=None)) | ||
elif applied_on == "1_product": | ||
values.update(dict(product_brand_id=None)) | ||
elif applied_on == "0_product_variant": | ||
values.update(dict(product_brand_id=None)) | ||
return super(ProductPricelistItem, self).create(vals_list) | ||
|
||
def write(self, values): | ||
if values.get("applied_on", False): | ||
# Ensure item consistency for later searches. | ||
applied_on = values["applied_on"] | ||
if applied_on == "25_brand": | ||
values.update( | ||
dict(product_id=None, product_tmpl_id=None, categ_id=None) | ||
) | ||
elif applied_on == "3_global": | ||
values.update(dict(product_brand_id=None)) | ||
elif applied_on == "2_product_category": | ||
values.update(dict(product_brand_id=None)) | ||
elif applied_on == "1_product": | ||
values.update(dict(product_brand_id=None)) | ||
elif applied_on == "0_product_variant": | ||
values.update(dict(product_brand_id=None)) | ||
return super(ProductPricelistItem, self).write(values) |
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,2 @@ | ||
* Quentin Groulard <[email protected]> | ||
* Dmintegrations <[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 @@ | ||
This module allows to configure pricelist items so that they are applied on products of specific brands. |
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 apply pricelist items on branded products: | ||
|
||
#. See 'product_brand' module to learn how to configure brands on products. | ||
#. Go to *Sales > Pricelists* and open the pricelist of your choice or create a new one. | ||
#. Edit the pricelist and add a new item to it. | ||
#. Select *Brand* in the field *Applied On*. | ||
#. Select the product brand of your choice in the field *Brand*. | ||
#. Configure the rest of the rule the way you want, this rule will apply on any product from the brand you selected. |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I think a line
AND (item.active = TRUE)
is missing if compared to the original method. Has it been removed for specific reasons?
https://github.com/odoo/odoo/blob/14.0/addons/product/models/product_pricelist.py#L111