forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] product_attribute_company_favorite
- Loading branch information
1 parent
c0cc348
commit 2d39144
Showing
21 changed files
with
998 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,104 @@ | ||
================================== | ||
Product Attribute Company Favorite | ||
================================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! 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%2Fproduct--attribute-lightgray.png?logo=github | ||
:target: https://github.com/OCA/product-attribute/tree/16.0/product_attribute_company_favorite | ||
: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_attribute_company_favorite | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/135/16.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Set favorite product attributes per company. Only the favorite attributes will be displayed when adding an attribute in a product template form. | ||
This is a flexible way to isolate product attributes per company, allowing a subset of companies to access the same attribute. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
There is a setting to allow to set new attribute as favorites for all companies, instead of the user's current company only. | ||
Go to Settings>Inventory>Products and check "Set new attributes as favorite for all companies" | ||
|
||
Usage | ||
===== | ||
|
||
At installation, all attributes will be set to favorites for all companies. | ||
|
||
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 smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_attribute_company_favorite%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 | ||
~~~~~~~ | ||
|
||
* Coop IT Easy SC | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Coop IT Easy SC <https://coopiteasy.be>`_: | ||
|
||
* Victor Champonnois | ||
* Carmen Bianca Bakker | ||
|
||
* Akretion | ||
|
||
* David Beal | ||
|
||
* Grap | ||
|
||
* Sylvain LE GAL | ||
|
||
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-victor-champonnois| image:: https://github.com/victor-champonnois.png?size=40px | ||
:target: https://github.com/victor-champonnois | ||
:alt: victor-champonnois | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-victor-champonnois| | ||
|
||
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_attribute_company_favorite>`_ 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,5 @@ | ||
# SPDX-FileCopyrightText: 2023 Coop IT Easy SC | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
from . import models | ||
from .post_init_hook import initialize_attribute_is_favorite_field |
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,28 @@ | ||
# SPDX-FileCopyrightText: 2023 Coop IT Easy SC | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
{ | ||
"name": "Product Attribute Company Favorite", | ||
"summary": """ | ||
Possibility to set favorite product attributes per company""", | ||
"version": "16.0.1.0.0", | ||
"category": "Product", | ||
"website": "https://github.com/OCA/product-attribute", | ||
"author": "Coop IT Easy SC, Odoo Community Association (OCA)", | ||
"maintainers": ["victor-champonnois"], | ||
"license": "AGPL-3", | ||
"application": False, | ||
"depends": [ | ||
"product", | ||
"stock", | ||
], | ||
"excludes": [], | ||
"data": [ | ||
"views/product_attribute_views.xml", | ||
"views/res_config_settings_views.xml", | ||
], | ||
"demo": [], | ||
"qweb": [], | ||
"post_init_hook": "initialize_attribute_is_favorite_field", | ||
} |
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,5 @@ | ||
from . import product_attribute_is_favorite_mixin | ||
from . import product_attribute | ||
from . import product_attribute_value | ||
from . import product_template_attribute_line | ||
from . import res_config_settings |
10 changes: 10 additions & 0 deletions
10
product_attribute_company_favorite/models/product_attribute.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,10 @@ | ||
from odoo import models | ||
|
||
|
||
class ProductAttribute(models.Model): | ||
_inherit = ["product.attribute", "product.attribute.favorite.mixin"] | ||
_name = "product.attribute" | ||
|
||
CREATION_ACROSS_COMPANY_CONFIG = ( | ||
"product_attribute_company_favorite.new_attribute_favorite_for_all_companies" | ||
) |
43 changes: 43 additions & 0 deletions
43
product_attribute_company_favorite/models/product_attribute_is_favorite_mixin.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,43 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class ProductAttributeIsFavoriteMixin(models.AbstractModel): | ||
_name = "product.attribute.favorite.mixin" | ||
_description = """Methods used both in product.attribute and | ||
product.attribute.value to implement is_favorite functionalities | ||
""" | ||
|
||
is_favorite = fields.Boolean( | ||
string="Favorite", | ||
company_dependent=True, | ||
default=True, | ||
help="If checked, this record can be linked to a product template.", | ||
) | ||
|
||
def _name_search( | ||
self, name, args=None, operator="ilike", limit=100, name_get_uid=None | ||
): | ||
args = list(args or []) | ||
args += [("is_favorite", "=", True)] | ||
return super()._name_search( | ||
name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid | ||
) | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
new_record_favorite_for_all_companies = ( | ||
self.env["ir.config_parameter"].sudo() | ||
# Class constant stores the configuration boolean | ||
# for its model to distinguish itself from other models. | ||
.get_param(self.CREATION_ACROSS_COMPANY_CONFIG) | ||
) | ||
records = super().create(vals_list) | ||
if new_record_favorite_for_all_companies: | ||
company_ids = ( | ||
self.env["res.company"].with_context(active_test=False).search([]).ids | ||
) | ||
for record in records: | ||
for company_id in company_ids: | ||
contextual_record = record.with_company(company_id) | ||
contextual_record.is_favorite = record.is_favorite | ||
return records |
11 changes: 11 additions & 0 deletions
11
product_attribute_company_favorite/models/product_attribute_value.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,11 @@ | ||
from odoo import models | ||
|
||
|
||
class ProductAttributeValue(models.Model): | ||
_inherit = ["product.attribute.value", "product.attribute.favorite.mixin"] | ||
_name = "product.attribute.value" | ||
|
||
CREATION_ACROSS_COMPANY_CONFIG = ( | ||
"product_attribute_company_favorite." | ||
"new_attribute_value_favorite_for_all_companies" | ||
) |
9 changes: 9 additions & 0 deletions
9
product_attribute_company_favorite/models/product_template_attribute_line.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,9 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ProductTemplateAttributeLine(models.Model): | ||
_inherit = "product.template.attribute.line" | ||
|
||
is_favorite = fields.Boolean( | ||
related="attribute_id.is_favorite", | ||
) |
27 changes: 27 additions & 0 deletions
27
product_attribute_company_favorite/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,27 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
new_attribute_favorite_for_all_companies = fields.Boolean( | ||
config_parameter=( | ||
"product_attribute_company_favorite." | ||
"new_attribute_favorite_for_all_companies" | ||
), | ||
string="Set new attribute as favorite for all companies", | ||
help="""When a new attribute is created, | ||
set it as favorite for all companies. | ||
Otherwise it is only set as favorite for the user's current company""", | ||
) | ||
|
||
new_attribute_value_favorite_for_all_companies = fields.Boolean( | ||
config_parameter=( | ||
"product_attribute_company_favorite." | ||
"new_attribute_value_favorite_for_all_companies" | ||
), | ||
string="Set new attributes value as favorite for all companies", | ||
help="""When a new attribute value is created, | ||
set it as favorite for all companies. | ||
Otherwise it is only set as favorite for the user's current company""", | ||
) |
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,20 @@ | ||
import logging | ||
|
||
from odoo import SUPERUSER_ID, api | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def initialize_attribute_is_favorite_field(cr, registry): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
for company in env["res.company"].with_context(active_test=False).search([]): | ||
_logger.info("Configure is_favorite field for the company %s" % (company.name)) | ||
product_attributes = ( | ||
env["product.attribute"].sudo().with_company(company.id).search([]) | ||
) | ||
product_attributes.write({"is_favorite": True}) | ||
|
||
product_attribute_values = ( | ||
env["product.attribute.value"].sudo().with_company(company.id).search([]) | ||
) | ||
product_attribute_values.write({"is_favorite": True}) |
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,5 @@ | ||
There is two setting to allow to set new attribute and new attribute values as favorites at creation for all companies, instead of the user's current company only. | ||
|
||
Go to Settings>Inventory>Products and check | ||
- "Set new attribute as favorite for all companies" | ||
- "Set new attribute value as favorite for all companies" |
12 changes: 12 additions & 0 deletions
12
product_attribute_company_favorite/readme/CONTRIBUTORS.rst
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,12 @@ | ||
* `Coop IT Easy SC <https://coopiteasy.be>`_: | ||
|
||
* Victor Champonnois | ||
* Carmen Bianca Bakker | ||
|
||
* Akretion | ||
|
||
* David Beal | ||
|
||
* Grap | ||
|
||
* Sylvain LE GAL |
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 @@ | ||
Set favorite product attributes and attribute values per company. Only the favorite attributes and values will be displayed in the dropdown menu in a product template form. |
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 @@ | ||
At installation, all attributes will be set to favorites for all companies. |
Oops, something went wrong.