-
-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[16.0][ADD] product_category_usage_group
- Loading branch information
1 parent
4a89704
commit 02e47db
Showing
19 changed files
with
791 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,89 @@ | ||
============================== | ||
Product Category - Usage Group | ||
============================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:a762429d55c734343359352a51fadba2647aa628f18357002045435883b23f46 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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_category_usage_group | ||
: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_category_usage_group | ||
: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 functionality of the product module, to restrict usage | ||
of product categories to users that belong to a given group. | ||
|
||
.. figure:: https://raw.githubusercontent.com/OCA/product-attribute/16.0/product_category_usage_group/static/description/product_template_warning.png | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
* Go to your product category form and set a group to restrict usage | ||
|
||
.. figure:: https://raw.githubusercontent.com/OCA/product-attribute/16.0/product_category_usage_group/static/description/product_category_form.png | ||
|
||
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_category_usage_group%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 | ||
~~~~~~~ | ||
|
||
* GRAP | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Sylvain LE GAL <https://twitter.com/legalsylvain> | ||
* Quentin DUPONT <https://framapiaf.org/@quentind> | ||
|
||
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/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_category_usage_group>`_ 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,21 @@ | ||
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Product Category - Usage Group", | ||
"summary": "Restrict Usage of Product Categories to a given Group", | ||
"version": "16.0.1.0.0", | ||
"category": "Product", | ||
"author": "GRAP, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/product-attribute", | ||
"license": "AGPL-3", | ||
"depends": ["product"], | ||
"data": ["views/view_product_category.xml"], | ||
"demo": ["demo/product_category.xml"], | ||
"images": [ | ||
"static/description/product_template_warning.png", | ||
"static/description/product_category_form.png", | ||
], | ||
"installable": 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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) | ||
@author Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
--> | ||
<odoo> | ||
|
||
<record id="category_usage_group" model="product.category"> | ||
<field name="name">Demo Category (With Usage Group)</field> | ||
<field name="usage_group_id" ref="base.group_multi_company" /> | ||
</record> | ||
|
||
</odoo> |
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,57 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * product_category_usage_group | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-04-19 15:45+0000\n" | ||
"PO-Revision-Date: 2024-04-19 15:45+0000\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: product_category_usage_group | ||
#: model_terms:ir.ui.view,arch_db:product_category_usage_group.view_product_category_form | ||
msgid "Access Rights" | ||
msgstr "Droits d'accès" | ||
|
||
#. module: product_category_usage_group | ||
#: model:ir.model.fields,help:product_category_usage_group.field_product_category__usage_group_id | ||
msgid "" | ||
"If defined, the user should be member to this group, to use this product " | ||
"category when creating or updating products" | ||
msgstr "" | ||
"Si défini·e, l'utilisateur·rice devra être membre de ce groupe pour utiliser" | ||
" cette catégorie de produit lors de la création ou modification d'un article" | ||
|
||
#. module: product_category_usage_group | ||
#: model:ir.model,name:product_category_usage_group.model_product_template | ||
msgid "Product" | ||
msgstr "Produit" | ||
|
||
#. module: product_category_usage_group | ||
#: model:ir.model,name:product_category_usage_group.model_product_category | ||
msgid "Product Category" | ||
msgstr "Catégorie de produit" | ||
|
||
#. module: product_category_usage_group | ||
#: model:ir.model.fields,field_description:product_category_usage_group.field_product_category__usage_group_id | ||
#: model_terms:ir.ui.view,arch_db:product_category_usage_group.view_product_category_search | ||
msgid "Usage Group" | ||
msgstr "Groupe d'utilisation" | ||
|
||
#. module: product_category_usage_group | ||
#. odoo-python | ||
#: code:addons/product_category_usage_group/models/product_template.py:0 | ||
#, python-format | ||
msgid "" | ||
"You can not use the product category \"%(categname)s\" because you are not " | ||
"member of the group \"%(groupname)s)\"categname" | ||
msgstr "" | ||
"Vous ne pouvez pas utiliser la catégorie de produit \"%(categname)s\" car " | ||
"vous n'êtes pas membre du groupe \"%(groupname)s)\"categname" |
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 @@ | ||
from . import product_category | ||
from . import product_template |
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 (C) 2018 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProductCategory(models.Model): | ||
_inherit = "product.category" | ||
|
||
usage_group_id = fields.Many2one( | ||
comodel_name="res.groups", | ||
string="Usage Group", | ||
help="If defined" | ||
", the user should be member to this group, to use this product" | ||
" category when creating or updating products", | ||
) |
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,42 @@ | ||
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
# Overload Section | ||
@api.model_create_multi | ||
def create(self, vals_list): | ||
templates = super(ProductTemplate, self).create(vals_list) | ||
# This is needed to set given values to first variant after creation | ||
for template, vals in zip(templates, vals_list): | ||
if vals.get("categ_id"): | ||
template._check_usage_product_category(vals["categ_id"]) | ||
return templates | ||
|
||
def write(self, vals): | ||
res = super(ProductTemplate, self).write(vals) | ||
if vals.get("categ_id"): | ||
for rec in self: | ||
rec._check_usage_product_category(vals.get("categ_id")) | ||
return res | ||
|
||
# Custom Section | ||
def _check_usage_product_category(self, categ_id): | ||
ProductCategory = self.env["product.category"] | ||
if categ_id: | ||
category = ProductCategory.browse(categ_id) | ||
group = category.usage_group_id | ||
if group and group.id not in self.env.user.groups_id.ids: | ||
raise ValidationError( | ||
_( | ||
'You can not use the product category "%(categname)s"' | ||
' because you are not member of the group "%(groupname)s)"' | ||
% {"categname": category.name, "groupname": group.name} | ||
) | ||
) |
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 @@ | ||
To configure this module, you need to: | ||
|
||
* Go to your product category form and set a group to restrict usage | ||
|
||
.. figure:: ../static/description/product_category_form.png |
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 @@ | ||
* Sylvain LE GAL <https://twitter.com/legalsylvain> | ||
* Quentin DUPONT <https://framapiaf.org/@quentind> |
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,4 @@ | ||
This module extends the functionality of the product module, to restrict usage | ||
of product categories to users that belong to a given group. | ||
|
||
.. figure:: ../static/description/product_template_warning.png |
Oops, something went wrong.