Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
773 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,2 @@ | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
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,27 @@ | ||
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) | ||
# Copyright (C) 2019 Open Source Integrators | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
{ | ||
"name": "Operating Unit in Products", | ||
"summary": "Adds the concept of operating unit (OU) in products", | ||
"version": "12.0.1.0.0", | ||
"author": "brain-tec AG, " | ||
"Open Source Integrators, " | ||
"Serpent Consulting Services Pvt. Ltd.," | ||
"Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/operating-unit", | ||
"category": "Product", | ||
"depends": [ | ||
"product", | ||
"stock" | ||
], | ||
"license": "LGPL-3", | ||
"data": [ | ||
"security/product_template_security.xml", | ||
"views/product_template_view.xml", | ||
"views/product_category_view.xml", | ||
], | ||
"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,3 @@ | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from . import product_template | ||
from . import product_category |
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 @@ | ||
# Copyright (C) 2019 Open Source Integrators | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from odoo import api, fields, models | ||
|
||
|
||
class ProductCategory(models.Model): | ||
_inherit = 'product.category' | ||
|
||
operating_unit_ids = fields.Many2many( | ||
'operating.unit', | ||
'product_category_operating_unit_rel', | ||
string='Operating Units') | ||
|
||
@api.multi | ||
def write(self, vals): | ||
res = super(ProductCategory, self).write(vals) | ||
product_template_obj = self.env['product.template'] | ||
if vals.get('operating_unit_ids'): | ||
for rec in self: | ||
products = product_template_obj.search([ | ||
('categ_id', 'child_of', rec.id)]) | ||
for product in products: | ||
ou_ids = product.operating_unit_ids.ids | ||
ou_ids.extend(vals.get('operating_unit_ids')[0][2]) | ||
product.operating_unit_ids = [(6, 0, ou_ids)] | ||
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,42 @@ | ||
# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) | ||
# Copyright (C) 2019 Open Source Integrators | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = 'product.template' | ||
|
||
@api.model | ||
def _default_operating_unit_ids(self): | ||
if self.categ_id and self.categ_id.operating_unit_ids: | ||
return [(6, 0, self.categ_id.operating_unit_ids.ids)] | ||
return [(6, 0, | ||
[self.env['res.users'].operating_unit_default_get( | ||
self.env.uid).id])] | ||
|
||
operating_unit_ids = fields.Many2many( | ||
'operating.unit', | ||
'product_operating_unit_rel', | ||
string='Operating Units', | ||
default=_default_operating_unit_ids) | ||
|
||
@api.multi | ||
@api.constrains('operating_unit_ids', 'categ_id') | ||
def _check_operating_unit(self): | ||
for record in self: | ||
if record.categ_id.operating_unit_ids and \ | ||
not all(ou in record.operating_unit_ids.ids for | ||
ou in record.categ_id.operating_unit_ids.ids): | ||
raise ValidationError(_( | ||
"The operating units of the product must include the " | ||
"ones from the category.")) | ||
|
||
@api.multi | ||
@api.onchange('categ_id') | ||
def onchange_operating_unit_ids(self): | ||
for record in self: | ||
record.operating_unit_ids = \ | ||
[(6, 0, record.categ_id.operating_unit_ids.ids)] |
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 @@ | ||
* Raul Martin Felez <raul.martin@braintec-group.com> | ||
* Nikul Chaudhary <nikul.chaudhary.serpentcs@gmail.com> | ||
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com> |
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 @@ | ||
This module introduces the following features: | ||
|
||
- It introduces the operating unit to the product template. | ||
- The operating unit from the user is assigned by default when creating a new | ||
product template. | ||
- In case of multi-company, no operating unit from another company to that | ||
assigned to the product can be set for it | ||
- It implements user's security rules. |
Empty file.
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,6 @@ | ||
#. Create a Product: the Default Operating Unit of the user is assigned to it. | ||
If you want, you can change to another Operating Unit. | ||
#. Assignment of an operating unit of another company to the one set in the | ||
product raises an error for a multi-company setting. | ||
#. Access rules allow to just show those products having the same operating | ||
units as the user |
33 changes: 33 additions & 0 deletions
33
product_operating_unit/security/product_template_security.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,33 @@ | ||
<!-- | ||
Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) | ||
Copyright (C) 2019 Open Source Integrators | ||
Copyright (C) 2019 Serpent Consulting Services | ||
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
--> | ||
<odoo> | ||
|
||
<!-- <record id="ir_rule_product_template_allowed_operating_units" model="ir.rule"> | ||
<field name="model_id" ref="product.model_product_template"/> | ||
<field name="domain_force">['|',('operating_unit_ids','=',False), | ||
('operating_unit_ids','in', user.operating_unit_ids.ids)]</field> | ||
<field name="name">Product Templates from allowed operating units</field> | ||
<field name="global" eval="True"/> | ||
<field eval="0" name="perm_unlink"/> | ||
<field eval="0" name="perm_write"/> | ||
<field eval="1" name="perm_read"/> | ||
<field eval="0" name="perm_create"/> | ||
</record> --> | ||
|
||
<record id="ir_rule_product_category_allowed_operating_units" model="ir.rule"> | ||
<field name="model_id" ref="product.model_product_category"/> | ||
<field name="domain_force">['|',('operating_unit_ids','=',False), | ||
('operating_unit_ids','in', user.operating_unit_ids.ids)]</field> | ||
<field name="name">Product Category from allowed operating units</field> | ||
<field name="global" eval="True"/> | ||
<field eval="0" name="perm_unlink"/> | ||
<field eval="0" name="perm_write"/> | ||
<field eval="1" name="perm_read"/> | ||
<field eval="0" name="perm_create"/> | ||
</record> | ||
|
||
</odoo> |
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.