Skip to content
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

[16.0][MIG] pricelist_brand #187

Open
wants to merge 6 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions pricelist_brand/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
===============
Pricelist Brand
===============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1da3e6535ebeeecede9d443275f9f2f0e2e2dcfd6309f236f3e961bfe38522f7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/16.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-16-0/brand-16-0-pricelist_brand
: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/brand&target_branch=16.0
:alt: Try me on Runboat

|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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/brand/issues/new?body=module:%20pricelist_brand%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
~~~~~~~

* 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/16.0/pricelist_brand>`_ 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 pricelist_brand/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions pricelist_brand/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/brand",
"depends": ["product_brand"],
"data": ["views/product_pricelist.xml"],
}
59 changes: 59 additions & 0 deletions pricelist_brand/i18n/pricelist_brand.pot
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 13.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 ""
1 change: 1 addition & 0 deletions pricelist_brand/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_pricelist
119 changes: 119 additions & 0 deletions pricelist_brand/models/product_pricelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# 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
from odoo.osv import expression


class ProductPricelist(models.Model):

_inherit = "product.pricelist"

def _get_applicable_rules_domain(self, products, date, **kwargs):
res = super()._get_applicable_rules_domain(products, date)
if products._name == "product.template":
brand_domain = ("product_brand_id", "in", products.product_brand_id.ids)

Check warning on line 16 in pricelist_brand/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

pricelist_brand/models/product_pricelist.py#L16

Added line #L16 was not covered by tests
else:
brand_domain = (
"product_brand_id",
"in",
products.product_tmpl_id.product_brand_id.ids,
)
res = expression.AND(
[
res,
[
("|"),
("product_brand_id", "=", False),
(brand_domain),
],
]
)
return res


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": "set default"}
)

@api.constrains("product_id", "product_tmpl_id", "categ_id", "product_brand_id")
def _check_product_consistency(self):
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")
)
return super()._check_product_consistency()

@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):
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)
return super()._get_pricelist_item_name_price()

Check warning on line 77 in pricelist_brand/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

pricelist_brand/models/product_pricelist.py#L76-L77

Added lines #L76 - L77 were not covered by tests

@api.onchange("product_id", "product_tmpl_id", "categ_id", "product_brand_id")
def _onchange_rule_content(self):
return super()._onchange_rule_content()

Check warning on line 81 in pricelist_brand/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

pricelist_brand/models/product_pricelist.py#L81

Added line #L81 was not covered by tests

@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))

Check warning on line 94 in pricelist_brand/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

pricelist_brand/models/product_pricelist.py#L94

Added line #L94 was not covered by tests
elif applied_on == "2_product_category":
values.update(dict(product_brand_id=None))

Check warning on line 96 in pricelist_brand/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

pricelist_brand/models/product_pricelist.py#L96

Added line #L96 was not covered by tests
elif applied_on == "1_product":
values.update(dict(product_brand_id=None))

Check warning on line 98 in pricelist_brand/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

pricelist_brand/models/product_pricelist.py#L98

Added line #L98 was not covered by tests
elif applied_on == "0_product_variant":
values.update(dict(product_brand_id=None))

Check warning on line 100 in pricelist_brand/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

pricelist_brand/models/product_pricelist.py#L100

Added line #L100 was not covered by tests
return super().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().write(values)
1 change: 1 addition & 0 deletions pricelist_brand/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Quentin Groulard <[email protected]>
1 change: 1 addition & 0 deletions pricelist_brand/readme/DESCRIPTION.rst
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.
8 changes: 8 additions & 0 deletions pricelist_brand/readme/USAGE.rst
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.
Binary file added pricelist_brand/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading