From 49265e2f8c7b9462d05bc6e010c0e3d08a1a87a4 Mon Sep 17 00:00:00 2001 From: mara1 Date: Thu, 28 Mar 2019 16:46:39 +0100 Subject: [PATCH 01/25] New module product_operating_unit to introduce the operating unit to the product template. --- product_operating_unit/__init__.py | 9 + product_operating_unit/__manifest__.py | 23 + product_operating_unit/models/__init__.py | 10 + .../models/product_template.py | 35 ++ .../readme/CONTRIBUTORS.rst | 1 + product_operating_unit/readme/DESCRIPTION.rst | 8 + product_operating_unit/readme/ROADMAP.rst | 0 product_operating_unit/readme/USAGE.rst | 6 + .../security/product_template_security.xml | 18 + .../static/description/icon.png | Bin 0 -> 9455 bytes .../static/description/index.html | 443 ++++++++++++++++++ product_operating_unit/tests/__init__.py | 8 + .../tests/test_product_operating_unit.py | 94 ++++ .../views/product_template_view.xml | 44 ++ 14 files changed, 699 insertions(+) create mode 100644 product_operating_unit/__init__.py create mode 100644 product_operating_unit/__manifest__.py create mode 100644 product_operating_unit/models/__init__.py create mode 100644 product_operating_unit/models/product_template.py create mode 100644 product_operating_unit/readme/CONTRIBUTORS.rst create mode 100644 product_operating_unit/readme/DESCRIPTION.rst create mode 100644 product_operating_unit/readme/ROADMAP.rst create mode 100644 product_operating_unit/readme/USAGE.rst create mode 100644 product_operating_unit/security/product_template_security.xml create mode 100644 product_operating_unit/static/description/icon.png create mode 100644 product_operating_unit/static/description/index.html create mode 100644 product_operating_unit/tests/__init__.py create mode 100644 product_operating_unit/tests/test_product_operating_unit.py create mode 100644 product_operating_unit/views/product_template_view.xml diff --git a/product_operating_unit/__init__.py b/product_operating_unit/__init__.py new file mode 100644 index 0000000000..02ef4e8dec --- /dev/null +++ b/product_operating_unit/__init__.py @@ -0,0 +1,9 @@ +############################################################################## +# +# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# +############################################################################## + + +from . import models diff --git a/product_operating_unit/__manifest__.py b/product_operating_unit/__manifest__.py new file mode 100644 index 0000000000..da3d200062 --- /dev/null +++ b/product_operating_unit/__manifest__.py @@ -0,0 +1,23 @@ +############################################################################## +# +# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) +# 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, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/operating-unit", + "category": "Purchase Management", + "depends": ["product", "stock"], + "license": "LGPL-3", + "data": [ + "security/product_template_security.xml", + "views/product_template_view.xml", + ], + "installable": True, +} diff --git a/product_operating_unit/models/__init__.py b/product_operating_unit/models/__init__.py new file mode 100644 index 0000000000..e050b2f337 --- /dev/null +++ b/product_operating_unit/models/__init__.py @@ -0,0 +1,10 @@ +############################################################################## +# +# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# +############################################################################## + + +from . import product_template + diff --git a/product_operating_unit/models/product_template.py b/product_operating_unit/models/product_template.py new file mode 100644 index 0000000000..61fbcad0ab --- /dev/null +++ b/product_operating_unit/models/product_template.py @@ -0,0 +1,35 @@ +############################################################################## +# +# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) +# 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' + + def _default_operating_unit_ids(self): + 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 Unit', + default=_default_operating_unit_ids + ) + + @api.constrains('operating_unit_ids', 'company_id') + def _check_company_operating_unit(self): + for record in self: + if record.company_id and record.operating_unit_ids: + for operating_unit in record.operating_unit_ids: + if record.company_id != operating_unit.company_id: + raise ValidationError( + _('Configuration error. The Company in the Product' + ' and in the Operating Unit must be the same.') + ) diff --git a/product_operating_unit/readme/CONTRIBUTORS.rst b/product_operating_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..d2bd725104 --- /dev/null +++ b/product_operating_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Raul Martin Felez diff --git a/product_operating_unit/readme/DESCRIPTION.rst b/product_operating_unit/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..9ad605e577 --- /dev/null +++ b/product_operating_unit/readme/DESCRIPTION.rst @@ -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. diff --git a/product_operating_unit/readme/ROADMAP.rst b/product_operating_unit/readme/ROADMAP.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/product_operating_unit/readme/USAGE.rst b/product_operating_unit/readme/USAGE.rst new file mode 100644 index 0000000000..57282753e2 --- /dev/null +++ b/product_operating_unit/readme/USAGE.rst @@ -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 diff --git a/product_operating_unit/security/product_template_security.xml b/product_operating_unit/security/product_template_security.xml new file mode 100644 index 0000000000..d096ed5312 --- /dev/null +++ b/product_operating_unit/security/product_template_security.xml @@ -0,0 +1,18 @@ + + + + + + ['|',('operating_unit_ids','=',False),('operating_unit_ids','in', user.operating_unit_ids.ids)] + Product Templates from allowed operating units + + + + + + + + diff --git a/product_operating_unit/static/description/icon.png b/product_operating_unit/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)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`_iBe2ot~6%7mLt5t8Vwi^Jy7|jWXqa3amOIoRb zOr}WVFP--DsS`1WpN%~)t3R!arKF^Q$e12KEqU36AWwnCBICpH4XCsfnyrHr>$I$4 z!DpKX$OKLWarN7nv@!uIA+~RNO)l$$w}p(;b>mx8pwYvu;dD_unryX_NhT8*Tj>BTrTTL&!?O+%Rv;b?B??gSzdp?6Uug9{ zd@V08Z$BdI?fpoCS$)t4mg4rT8Q_I}h`0d-vYZ^|dOB*Q^S|xqTV*vIg?@fVFSmMpaw0qtTRbx} z({Pg?#{2`sc9)M5N$*N|4;^t$+QP?#mov zGVC@I*lBVrOU-%2y!7%)fAKjpEFsgQc4{amtiHb95KQEwvf<(3T<9-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/product_operating_unit/static/description/index.html b/product_operating_unit/static/description/index.html new file mode 100644 index 0000000000..372bdce150 --- /dev/null +++ b/product_operating_unit/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Operating Unit in Products + + + +
+

Operating Unit in Products

+ + +

Beta License: LGPL-3 OCA/operating-unit Translate me on Weblate Try me on Runbot

+

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.
  • +
+

Table of contents

+ +
+

Usage

+
    +
  1. Create a Product: the Default Operating Unit of the user is assigned to it. + If you want, you can change to another Operating Unit.
  2. +
  3. Assignment of an operating unit of another company to the one set in the + product raises an error for a multi-company setting.
  4. +
  5. Access rules allow to just show those products having the same operating + units as the user
  6. +
+
+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • brain-tec AG
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/operating-unit project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/product_operating_unit/tests/__init__.py b/product_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..169dc9a0b6 --- /dev/null +++ b/product_operating_unit/tests/__init__.py @@ -0,0 +1,8 @@ +############################################################################## +# +# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# +############################################################################## + +from . import test_product_operating_unit diff --git a/product_operating_unit/tests/test_product_operating_unit.py b/product_operating_unit/tests/test_product_operating_unit.py new file mode 100644 index 0000000000..cb262f8ac6 --- /dev/null +++ b/product_operating_unit/tests/test_product_operating_unit.py @@ -0,0 +1,94 @@ +############################################################################## +# +# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# +############################################################################## + +from odoo.tests import common + + +class TestProductOperatingUnit(common.TransactionCase): + + def setUp(self): + super(TestProductOperatingUnit, self).setUp() + self.ResUsers = self.env['res.users'] + self.ProductTemplate = self.env['product.template'] + # company + self.company1 = self.env.ref('base.main_company') + self.company2 = self.env.ref('stock.res_company_1') + # groups + self.group_stock_user = self.env.ref('stock.group_stock_user') + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # B2B Operating Unit + self.b2b = self.env.ref('operating_unit.b2b_operating_unit') + # Products + self.product1 = self.env.ref( + 'product.product_product_1_product_template') + self.product2 = self.env.ref( + 'product.product_product_9_product_template') + self.product3 = self.env.ref( + 'product.product_product_11_product_template') + # Create users + self.user1_id = self._create_user('user_1', + [self.group_stock_user], + self.company1, + [self.ou1]) + self.user2_id = self._create_user('user_2', + [self.group_stock_user], + self.company2, + [self.b2b]) + self.product1.operating_unit_ids = [(6, 0, [self.ou1.id])] + self.product2.operating_unit_ids = [(6, 0, [self.b2b.id])] + self.product3.operating_unit_ids = [(6, 0, [self.ou1.id, self.b2b.id])] + + def _create_user(self, login, groups, company, operating_units): + """ Create a user.""" + group_ids = [group.id for group in groups] + user =\ + self.ResUsers.with_context({'no_reset_password': True}).\ + create({ + 'name': 'Chicago Purchase User', + 'login': login, + 'password': 'demo', + 'email': 'chicago@yourcompany.com', + 'company_id': company.id, + 'company_ids': [(4, company.id)], + 'operating_unit_ids': [(4, ou.id) for ou in operating_units], + 'groups_id': [(6, 0, group_ids)] + }) + return user.id + + def test_po_ou_security(self): + """Test Security of Product Operating Unit""" + + # User 1 is only assigned to Operating Unit 1, and can see all + # products having Operating Unit 1. + product_ids = \ + self.ProductTemplate.sudo(self.user1_id).search( + [('operating_unit_ids', 'in', self.ou1.id)]).ids + self.assertEqual(set(product_ids), set([self.product1.id, + self.product3.id])) + + # User 2 is only assigned to Operating Unit 2, so cannot see products + # having Operating Unit 1, expect those also having Operating Unit b2b + product_ids = \ + self.ProductTemplate.sudo(self.user2_id).search( + [('operating_unit_ids', 'in', self.ou1.id)]).ids + self.assertEqual(product_ids, [self.product3.id]) + + # User 2 is only assigned to Operating Unit 2, and can see all + # products having Operating Unit b2b. + product_ids = \ + self.ProductTemplate.sudo(self.user2_id).search( + [('operating_unit_ids', 'in', self.b2b.id)]).ids + self.assertEqual(set(product_ids), + set([self.product2.id, self.product3.id])) + + # User 1 is only assigned to Operating Unit 1, so cannot see products + # having Operating Unit b2b, expect those also having Operating Unit 1 + product_ids = \ + self.ProductTemplate.sudo(self.user1_id).search( + [('operating_unit_ids', 'in', self.b2b.id)]).ids + self.assertEqual(product_ids, [self.product3.id]) diff --git a/product_operating_unit/views/product_template_view.xml b/product_operating_unit/views/product_template_view.xml new file mode 100644 index 0000000000..cfa14e3a49 --- /dev/null +++ b/product_operating_unit/views/product_template_view.xml @@ -0,0 +1,44 @@ + + + + + product.template_tree + product.template + + + + + + + + + + product.template_form + product.template + + + + + + + + + + product.template_filter + product.template + + + + + + + + From 88a75dc1bcad43da7b17973d68b1f8a9f2e3ad72 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Mon, 30 Dec 2019 11:53:39 +0530 Subject: [PATCH 02/25] [ADD] Added a product_operating_unit v12 --- product_operating_unit/__init__.py | 9 +- product_operating_unit/__manifest__.py | 20 +++-- product_operating_unit/models/__init__.py | 11 +-- .../models/product_category.py | 27 ++++++ .../models/product_template.py | 47 ++++++----- .../readme/CONTRIBUTORS.rst | 2 + .../security/product_template_security.xml | 19 ++++- product_operating_unit/tests/__init__.py | 8 +- .../tests/test_product_operating_unit.py | 83 +++++++++++-------- .../views/product_category_view.xml | 22 +++++ .../views/product_template_view.xml | 6 +- 11 files changed, 164 insertions(+), 90 deletions(-) create mode 100644 product_operating_unit/models/product_category.py create mode 100644 product_operating_unit/views/product_category_view.xml diff --git a/product_operating_unit/__init__.py b/product_operating_unit/__init__.py index 02ef4e8dec..133f68732d 100644 --- a/product_operating_unit/__init__.py +++ b/product_operating_unit/__init__.py @@ -1,9 +1,2 @@ -############################################################################## -# -# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -# -############################################################################## - - +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models diff --git a/product_operating_unit/__manifest__.py b/product_operating_unit/__manifest__.py index da3d200062..4ea7280b1d 100644 --- a/product_operating_unit/__manifest__.py +++ b/product_operating_unit/__manifest__.py @@ -1,23 +1,27 @@ -############################################################################## -# -# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -# -############################################################################## +# 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": "Purchase Management", - "depends": ["product", "stock"], + "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, } diff --git a/product_operating_unit/models/__init__.py b/product_operating_unit/models/__init__.py index e050b2f337..044da9a2ad 100644 --- a/product_operating_unit/models/__init__.py +++ b/product_operating_unit/models/__init__.py @@ -1,10 +1,3 @@ -############################################################################## -# -# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -# -############################################################################## - - +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import product_template - +from . import product_category diff --git a/product_operating_unit/models/product_category.py b/product_operating_unit/models/product_category.py new file mode 100644 index 0000000000..30c63e8f5a --- /dev/null +++ b/product_operating_unit/models/product_category.py @@ -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 diff --git a/product_operating_unit/models/product_template.py b/product_operating_unit/models/product_template.py index 61fbcad0ab..aaf2550e4a 100644 --- a/product_operating_unit/models/product_template.py +++ b/product_operating_unit/models/product_template.py @@ -1,10 +1,7 @@ -############################################################################## -# -# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -# -############################################################################## - +# 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 @@ -12,24 +9,34 @@ 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 Unit', - default=_default_operating_unit_ids - ) + '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.constrains('operating_unit_ids', 'company_id') - def _check_company_operating_unit(self): + @api.multi + @api.onchange('categ_id') + def onchange_operating_unit_ids(self): for record in self: - if record.company_id and record.operating_unit_ids: - for operating_unit in record.operating_unit_ids: - if record.company_id != operating_unit.company_id: - raise ValidationError( - _('Configuration error. The Company in the Product' - ' and in the Operating Unit must be the same.') - ) + record.operating_unit_ids = \ + [(6, 0, record.categ_id.operating_unit_ids.ids)] diff --git a/product_operating_unit/readme/CONTRIBUTORS.rst b/product_operating_unit/readme/CONTRIBUTORS.rst index d2bd725104..a6ef368af3 100644 --- a/product_operating_unit/readme/CONTRIBUTORS.rst +++ b/product_operating_unit/readme/CONTRIBUTORS.rst @@ -1 +1,3 @@ * Raul Martin Felez +* Nikul Chaudhary +* Maxime Chambreuil diff --git a/product_operating_unit/security/product_template_security.xml b/product_operating_unit/security/product_template_security.xml index d096ed5312..67d6295f74 100644 --- a/product_operating_unit/security/product_template_security.xml +++ b/product_operating_unit/security/product_template_security.xml @@ -1,18 +1,33 @@ - + + + + + ['|',('operating_unit_ids','=',False), + ('operating_unit_ids','in', user.operating_unit_ids.ids)] + Product Category from allowed operating units + + + + + diff --git a/product_operating_unit/tests/__init__.py b/product_operating_unit/tests/__init__.py index 169dc9a0b6..2fcbf95749 100644 --- a/product_operating_unit/tests/__init__.py +++ b/product_operating_unit/tests/__init__.py @@ -1,8 +1,2 @@ -############################################################################## -# -# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -# -############################################################################## - +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_product_operating_unit diff --git a/product_operating_unit/tests/test_product_operating_unit.py b/product_operating_unit/tests/test_product_operating_unit.py index cb262f8ac6..116e6fa573 100644 --- a/product_operating_unit/tests/test_product_operating_unit.py +++ b/product_operating_unit/tests/test_product_operating_unit.py @@ -1,11 +1,9 @@ -############################################################################## -# -# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -# -############################################################################## - +# 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.tests import common +from odoo.exceptions import ValidationError class TestProductOperatingUnit(common.TransactionCase): @@ -14,11 +12,13 @@ def setUp(self): super(TestProductOperatingUnit, self).setUp() self.ResUsers = self.env['res.users'] self.ProductTemplate = self.env['product.template'] + self.ProductCategory = self.env['product.category'] # company - self.company1 = self.env.ref('base.main_company') - self.company2 = self.env.ref('stock.res_company_1') + self.company = self.env.ref('base.main_company') # groups - self.group_stock_user = self.env.ref('stock.group_stock_user') + self.group_stock_manager = self.env.ref('stock.group_stock_manager') + self.grp_acc_user = self.env.ref('account.group_account_invoice') + self.grp_stock_user = self.env.ref('stock.group_stock_user') # Main Operating Unit self.ou1 = self.env.ref('operating_unit.main_operating_unit') # B2B Operating Unit @@ -31,17 +31,20 @@ def setUp(self): self.product3 = self.env.ref( 'product.product_product_11_product_template') # Create users - self.user1_id = self._create_user('user_1', - [self.group_stock_user], - self.company1, - [self.ou1]) - self.user2_id = self._create_user('user_2', - [self.group_stock_user], - self.company2, - [self.b2b]) - self.product1.operating_unit_ids = [(6, 0, [self.ou1.id])] - self.product2.operating_unit_ids = [(6, 0, [self.b2b.id])] - self.product3.operating_unit_ids = [(6, 0, [self.ou1.id, self.b2b.id])] + self.user1_id = self._create_user( + 'user_1', + [self.grp_stock_user, self.grp_acc_user, self.group_stock_manager], + self.company, [self.ou1, self.b2b] + ) + self.user2_id = self._create_user( + 'user_2', + [self.grp_stock_user, self.grp_acc_user, self.group_stock_manager], + self.company, [self.b2b] + ) + self.product1.categ_id.operating_unit_ids = [(6, 0, [self.ou1.id])] + self.product2.categ_id.operating_unit_ids = [(6, 0, [self.b2b.id])] + self.product3.categ_id.operating_unit_ids = \ + [(6, 0, [self.ou1.id, self.b2b.id])] def _create_user(self, login, groups, company, operating_units): """ Create a user.""" @@ -60,35 +63,45 @@ def _create_user(self, login, groups, company, operating_units): }) return user.id + def test_po_ou_onchange(self): + with self.assertRaises(ValidationError): + self.product1.operating_unit_ids = [(6, 0, [self.b2b.id])] + + self.product1.onchange_operating_unit_ids() + def test_po_ou_security(self): """Test Security of Product Operating Unit""" # User 1 is only assigned to Operating Unit 1, and can see all # products having Operating Unit 1. + ou_domain = [('operating_unit_ids', 'in', self.ou1.id)] product_ids = \ - self.ProductTemplate.sudo(self.user1_id).search( - [('operating_unit_ids', 'in', self.ou1.id)]).ids - self.assertEqual(set(product_ids), set([self.product1.id, - self.product3.id])) + self.ProductTemplate.sudo(self.user1_id).search(ou_domain).ids + category_ids = \ + self.ProductCategory.sudo(self.user1_id).search(ou_domain).ids + self.assertIn(category_ids[0], product_ids) # User 2 is only assigned to Operating Unit 2, so cannot see products # having Operating Unit 1, expect those also having Operating Unit b2b product_ids = \ - self.ProductTemplate.sudo(self.user2_id).search( - [('operating_unit_ids', 'in', self.ou1.id)]).ids - self.assertEqual(product_ids, [self.product3.id]) + self.ProductTemplate.sudo(self.user2_id).search(ou_domain).ids + category_ids = \ + self.ProductCategory.sudo(self.user2_id).search(ou_domain).ids + self.assertIn(category_ids[0], product_ids) # User 2 is only assigned to Operating Unit 2, and can see all # products having Operating Unit b2b. + b2b_domain = [('operating_unit_ids', 'in', self.b2b.id)] product_ids = \ - self.ProductTemplate.sudo(self.user2_id).search( - [('operating_unit_ids', 'in', self.b2b.id)]).ids - self.assertEqual(set(product_ids), - set([self.product2.id, self.product3.id])) + self.ProductTemplate.sudo(self.user2_id).search(b2b_domain).ids + category_ids = \ + self.ProductCategory.sudo(self.user2_id).search(b2b_domain).ids + self.assertIn(category_ids[0], product_ids) # User 1 is only assigned to Operating Unit 1, so cannot see products # having Operating Unit b2b, expect those also having Operating Unit 1 product_ids = \ - self.ProductTemplate.sudo(self.user1_id).search( - [('operating_unit_ids', 'in', self.b2b.id)]).ids - self.assertEqual(product_ids, [self.product3.id]) + self.ProductTemplate.sudo(self.user1_id).search(b2b_domain).ids + category_ids = \ + self.ProductCategory.sudo(self.user2_id).search(b2b_domain).ids + self.assertIn(category_ids[0], product_ids) diff --git a/product_operating_unit/views/product_category_view.xml b/product_operating_unit/views/product_category_view.xml new file mode 100644 index 0000000000..a1a1fed844 --- /dev/null +++ b/product_operating_unit/views/product_category_view.xml @@ -0,0 +1,22 @@ + + + + + product.category.form + product.category + + + + + + + + + diff --git a/product_operating_unit/views/product_template_view.xml b/product_operating_unit/views/product_template_view.xml index cfa14e3a49..dc96da0096 100644 --- a/product_operating_unit/views/product_template_view.xml +++ b/product_operating_unit/views/product_template_view.xml @@ -1,5 +1,7 @@ @@ -37,8 +39,10 @@ - + + From 04c879d1abaea2da6fc9cf77dc2ff3f1cb719900 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Mon, 20 Jan 2020 09:48:17 +0530 Subject: [PATCH 03/25] [FIX] Uncomment rule --- product_operating_unit/security/product_template_security.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/product_operating_unit/security/product_template_security.xml b/product_operating_unit/security/product_template_security.xml index 67d6295f74..b065caea96 100644 --- a/product_operating_unit/security/product_template_security.xml +++ b/product_operating_unit/security/product_template_security.xml @@ -6,7 +6,7 @@ --> - + From d36df7788f83ca0558f6da97c965792ae8ec205d Mon Sep 17 00:00:00 2001 From: scampbell Date: Wed, 29 Jan 2020 16:57:23 -0800 Subject: [PATCH 04/25] [FIX] Default Get + Show OU on Small Form --- product_operating_unit/models/product_template.py | 7 ++++--- product_operating_unit/views/product_template_view.xml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/product_operating_unit/models/product_template.py b/product_operating_unit/models/product_template.py index aaf2550e4a..f01dcf64ba 100644 --- a/product_operating_unit/models/product_template.py +++ b/product_operating_unit/models/product_template.py @@ -13,9 +13,10 @@ class ProductTemplate(models.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])] + if self.env.user.default_operating_unit_id: + return [(6, 0, + [self.env['res.users'].operating_unit_default_get( + self.env.uid).id])] operating_unit_ids = fields.Many2many( 'operating.unit', diff --git a/product_operating_unit/views/product_template_view.xml b/product_operating_unit/views/product_template_view.xml index dc96da0096..99aeeb2841 100644 --- a/product_operating_unit/views/product_template_view.xml +++ b/product_operating_unit/views/product_template_view.xml @@ -22,7 +22,7 @@ product.template_form product.template - + Date: Tue, 11 Feb 2020 10:31:16 -0800 Subject: [PATCH 05/25] [IMP] Create Product Access Error --- product_operating_unit/__manifest__.py | 3 +- .../models/product_template.py | 28 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/product_operating_unit/__manifest__.py b/product_operating_unit/__manifest__.py index 4ea7280b1d..02afc48452 100644 --- a/product_operating_unit/__manifest__.py +++ b/product_operating_unit/__manifest__.py @@ -15,7 +15,8 @@ "category": "Product", "depends": [ "product", - "stock" + "stock", + "operating_unit" ], "license": "LGPL-3", "data": [ diff --git a/product_operating_unit/models/product_template.py b/product_operating_unit/models/product_template.py index f01dcf64ba..e7bbda87c2 100644 --- a/product_operating_unit/models/product_template.py +++ b/product_operating_unit/models/product_template.py @@ -3,7 +3,7 @@ # 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 +from odoo.exceptions import ValidationError, AccessError, RedirectWarning class ProductTemplate(models.Model): @@ -41,3 +41,29 @@ def onchange_operating_unit_ids(self): for record in self: record.operating_unit_ids = \ [(6, 0, record.categ_id.operating_unit_ids.ids)] + + def _get_default_category_id(self): + for ou_id in self.env.user.operating_unit_ids: + category = self.env['product.category'].\ + search([], limit=1) + if category: + return category.id + else: + try: + self.env.ref('product.product_category_all', + raise_if_not_found=False).name + except AccessError: + err_msg = _('You must define at least one product \ + category within your Operating Unit in order to be \ + able to create products.') + redir_msg = _('Go to Product Categories') + raise RedirectWarning(err_msg, + self.env.ref('product.\ + product_category_action_form').id, + redir_msg) + return super()._get_default_category_id() + + categ_id = fields.Many2one( + 'product.category', 'Product Category', + change_default=True, default=_get_default_category_id, + required=True, help="Select category for the current product") From d21da807d8b1b92a661f04e7b11a1ae6d14c1c00 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Wed, 25 Mar 2020 11:02:39 +0530 Subject: [PATCH 06/25] Update product_operating_unit/views/product_template_view.xml Co-Authored-By: Patrick Wilson <36892066+patrickrwilson@users.noreply.github.com> --- product_operating_unit/views/product_template_view.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/product_operating_unit/views/product_template_view.xml b/product_operating_unit/views/product_template_view.xml index 99aeeb2841..bcbe4aa98b 100644 --- a/product_operating_unit/views/product_template_view.xml +++ b/product_operating_unit/views/product_template_view.xml @@ -13,6 +13,7 @@ From bc3e96421b78e7d5de43e586c28230bc0a776e89 Mon Sep 17 00:00:00 2001 From: Murtuza Saleh Date: Mon, 20 Apr 2020 16:07:58 +0530 Subject: [PATCH 07/25] [IMP] Improved code --- product_operating_unit/__init__.py | 1 + product_operating_unit/__manifest__.py | 1 + product_operating_unit/hooks.py | 19 +++++++++++++++++++ .../models/product_template.py | 13 +++++++------ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 product_operating_unit/hooks.py diff --git a/product_operating_unit/__init__.py b/product_operating_unit/__init__.py index 133f68732d..d9602600d5 100644 --- a/product_operating_unit/__init__.py +++ b/product_operating_unit/__init__.py @@ -1,2 +1,3 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models +from .hooks import pre_init_hook diff --git a/product_operating_unit/__manifest__.py b/product_operating_unit/__manifest__.py index 02afc48452..a3d3d3f307 100644 --- a/product_operating_unit/__manifest__.py +++ b/product_operating_unit/__manifest__.py @@ -25,4 +25,5 @@ "views/product_category_view.xml", ], "installable": True, + "pre_init_hook": "pre_init_hook", } diff --git a/product_operating_unit/hooks.py b/product_operating_unit/hooks.py new file mode 100644 index 0000000000..1949d6698c --- /dev/null +++ b/product_operating_unit/hooks.py @@ -0,0 +1,19 @@ +# Copyright (C) 2020 Open Source Integrators +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + + +def pre_init_hook(cr): + # Add new table and columns to hold values + cr.execute(""" + CREATE TABLE product_operating_unit_rel ( + product_template_id INTEGER NOT NULL + REFERENCES product_template(id) ON DELETE CASCADE, + operating_unit_id INTEGER NOT NULL + REFERENCES operating_unit(id) ON DELETE CASCADE); + """) + # Add the values + cr.execute(""" + INSERT INTO product_operating_unit_rel + (product_template_id, operating_unit_id) + SELECT id, 1 FROM product_template; + """) diff --git a/product_operating_unit/models/product_template.py b/product_operating_unit/models/product_template.py index e7bbda87c2..3ddcdc1013 100644 --- a/product_operating_unit/models/product_template.py +++ b/product_operating_unit/models/product_template.py @@ -15,8 +15,8 @@ def _default_operating_unit_ids(self): return [(6, 0, self.categ_id.operating_unit_ids.ids)] if self.env.user.default_operating_unit_id: return [(6, 0, - [self.env['res.users'].operating_unit_default_get( - self.env.uid).id])] + [self.env['res.users'].operating_unit_default_get( + self.env.uid).id])] operating_unit_ids = fields.Many2many( 'operating.unit', @@ -57,10 +57,11 @@ def _get_default_category_id(self): category within your Operating Unit in order to be \ able to create products.') redir_msg = _('Go to Product Categories') - raise RedirectWarning(err_msg, - self.env.ref('product.\ - product_category_action_form').id, - redir_msg) + raise RedirectWarning( + err_msg, + self.env.ref( + 'product.product_category_action_form').id, + redir_msg) return super()._get_default_category_id() categ_id = fields.Many2one( From 220914462a5b2a30c0ec552af0d62ab7045c8706 Mon Sep 17 00:00:00 2001 From: mara1 Date: Thu, 28 Mar 2019 16:46:39 +0100 Subject: [PATCH 08/25] New module product_operating_unit to introduce the operating unit to the product template. --- product_operating_unit/__init__.py | 1 - product_operating_unit/__manifest__.py | 6 +----- product_operating_unit/models/__init__.py | 13 +++++++++++++ .../models/product_template.py | 5 +++-- .../security/product_template_security.xml | 9 ++++----- product_operating_unit/tests/__init__.py | 10 ++++++++++ .../tests/test_product_operating_unit.py | 17 ++++------------- .../views/product_template_view.xml | 7 +++---- 8 files changed, 38 insertions(+), 30 deletions(-) diff --git a/product_operating_unit/__init__.py b/product_operating_unit/__init__.py index d9602600d5..133f68732d 100644 --- a/product_operating_unit/__init__.py +++ b/product_operating_unit/__init__.py @@ -1,3 +1,2 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models -from .hooks import pre_init_hook diff --git a/product_operating_unit/__manifest__.py b/product_operating_unit/__manifest__.py index a3d3d3f307..2880ea42c1 100644 --- a/product_operating_unit/__manifest__.py +++ b/product_operating_unit/__manifest__.py @@ -2,11 +2,10 @@ # 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", + "version": "12.0.1.0.1", "author": "brain-tec AG, " "Open Source Integrators, " "Serpent Consulting Services Pvt. Ltd.," @@ -15,7 +14,6 @@ "category": "Product", "depends": [ "product", - "stock", "operating_unit" ], "license": "LGPL-3", @@ -24,6 +22,4 @@ "views/product_template_view.xml", "views/product_category_view.xml", ], - "installable": True, - "pre_init_hook": "pre_init_hook", } diff --git a/product_operating_unit/models/__init__.py b/product_operating_unit/models/__init__.py index 044da9a2ad..2a0f39465c 100644 --- a/product_operating_unit/models/__init__.py +++ b/product_operating_unit/models/__init__.py @@ -1,3 +1,16 @@ +<<<<<<< HEAD # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import product_template from . import product_category +======= +############################################################################## +# +# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# +############################################################################## + + +from . import product_template + +>>>>>>> New module product_operating_unit to introduce the operating unit to the product template. diff --git a/product_operating_unit/models/product_template.py b/product_operating_unit/models/product_template.py index 3ddcdc1013..026c0ec2b3 100644 --- a/product_operating_unit/models/product_template.py +++ b/product_operating_unit/models/product_template.py @@ -39,8 +39,9 @@ def _check_operating_unit(self): @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)] + if record.categ_id.operating_unit_ids: + record.operating_unit_ids = \ + [(6, 0, record.categ_id.operating_unit_ids.ids)] def _get_default_category_id(self): for ou_id in self.env.user.operating_unit_ids: diff --git a/product_operating_unit/security/product_template_security.xml b/product_operating_unit/security/product_template_security.xml index b065caea96..a2e4103140 100644 --- a/product_operating_unit/security/product_template_security.xml +++ b/product_operating_unit/security/product_template_security.xml @@ -8,8 +8,8 @@ - ['|',('operating_unit_ids','=',False), - ('operating_unit_ids','in', user.operating_unit_ids.ids)] + ['|', ('operating_unit_ids', '=', False), + ('operating_unit_ids', 'in', user.operating_unit_ids.ids)] Product Templates from allowed operating units @@ -20,8 +20,8 @@ - ['|',('operating_unit_ids','=',False), - ('operating_unit_ids','in', user.operating_unit_ids.ids)] + ['|', ('operating_unit_ids', '=', False), + ('operating_unit_ids', 'in', user.operating_unit_ids.ids)] Product Category from allowed operating units @@ -29,5 +29,4 @@ - diff --git a/product_operating_unit/tests/__init__.py b/product_operating_unit/tests/__init__.py index 2fcbf95749..eafa09634c 100644 --- a/product_operating_unit/tests/__init__.py +++ b/product_operating_unit/tests/__init__.py @@ -1,2 +1,12 @@ +<<<<<<< HEAD # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +======= +############################################################################## +# +# Copyright (c) 2019 brain-tec AG (http://www.braintec-group.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# +############################################################################## + +>>>>>>> New module product_operating_unit to introduce the operating unit to the product template. from . import test_product_operating_unit diff --git a/product_operating_unit/tests/test_product_operating_unit.py b/product_operating_unit/tests/test_product_operating_unit.py index 116e6fa573..54d514cfb6 100644 --- a/product_operating_unit/tests/test_product_operating_unit.py +++ b/product_operating_unit/tests/test_product_operating_unit.py @@ -15,10 +15,8 @@ def setUp(self): self.ProductCategory = self.env['product.category'] # company self.company = self.env.ref('base.main_company') - # groups - self.group_stock_manager = self.env.ref('stock.group_stock_manager') - self.grp_acc_user = self.env.ref('account.group_account_invoice') - self.grp_stock_user = self.env.ref('stock.group_stock_user') + # group + self.group_user = self.env.ref('base.group_user') # Main Operating Unit self.ou1 = self.env.ref('operating_unit.main_operating_unit') # B2B Operating Unit @@ -32,15 +30,9 @@ def setUp(self): 'product.product_product_11_product_template') # Create users self.user1_id = self._create_user( - 'user_1', - [self.grp_stock_user, self.grp_acc_user, self.group_stock_manager], - self.company, [self.ou1, self.b2b] - ) + 'user_1', [self.group_user], self.company, [self.ou1, self.b2b]) self.user2_id = self._create_user( - 'user_2', - [self.grp_stock_user, self.grp_acc_user, self.group_stock_manager], - self.company, [self.b2b] - ) + 'user_2', [self.group_user], self.company, [self.b2b]) self.product1.categ_id.operating_unit_ids = [(6, 0, [self.ou1.id])] self.product2.categ_id.operating_unit_ids = [(6, 0, [self.b2b.id])] self.product3.categ_id.operating_unit_ids = \ @@ -66,7 +58,6 @@ def _create_user(self, login, groups, company, operating_units): def test_po_ou_onchange(self): with self.assertRaises(ValidationError): self.product1.operating_unit_ids = [(6, 0, [self.b2b.id])] - self.product1.onchange_operating_unit_ids() def test_po_ou_security(self): diff --git a/product_operating_unit/views/product_template_view.xml b/product_operating_unit/views/product_template_view.xml index bcbe4aa98b..00685f7336 100644 --- a/product_operating_unit/views/product_template_view.xml +++ b/product_operating_unit/views/product_template_view.xml @@ -34,16 +34,15 @@ - + product.template_filter product.template - + - + - From 7b6b5aa6d01166c47c89f905644386e5ccfc2b14 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Mon, 30 Dec 2019 11:53:39 +0530 Subject: [PATCH 09/25] [ADD] Added a product_operating_unit v12 --- product_operating_unit/__manifest__.py | 2 +- product_operating_unit/models/__init__.py | 6 +++++ .../models/product_template.py | 11 +++++++++ .../security/product_template_security.xml | 19 ++++++++++++++- product_operating_unit/tests/__init__.py | 4 ++++ .../tests/test_product_operating_unit.py | 23 +++++++++++++++++++ .../views/product_template_view.xml | 3 ++- 7 files changed, 65 insertions(+), 3 deletions(-) diff --git a/product_operating_unit/__manifest__.py b/product_operating_unit/__manifest__.py index 2880ea42c1..5499129e8c 100644 --- a/product_operating_unit/__manifest__.py +++ b/product_operating_unit/__manifest__.py @@ -22,4 +22,4 @@ "views/product_template_view.xml", "views/product_category_view.xml", ], -} +} \ No newline at end of file diff --git a/product_operating_unit/models/__init__.py b/product_operating_unit/models/__init__.py index 2a0f39465c..e1aad69736 100644 --- a/product_operating_unit/models/__init__.py +++ b/product_operating_unit/models/__init__.py @@ -1,4 +1,5 @@ <<<<<<< HEAD +<<<<<<< HEAD # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import product_template from . import product_category @@ -14,3 +15,8 @@ from . import product_template >>>>>>> New module product_operating_unit to introduce the operating unit to the product template. +======= +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import product_template +from . import product_category +>>>>>>> [ADD] Added a product_operating_unit v12 diff --git a/product_operating_unit/models/product_template.py b/product_operating_unit/models/product_template.py index 026c0ec2b3..9ff76a9ec7 100644 --- a/product_operating_unit/models/product_template.py +++ b/product_operating_unit/models/product_template.py @@ -13,10 +13,16 @@ class ProductTemplate(models.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)] +<<<<<<< HEAD if self.env.user.default_operating_unit_id: return [(6, 0, [self.env['res.users'].operating_unit_default_get( self.env.uid).id])] +======= + return [(6, 0, + [self.env['res.users'].operating_unit_default_get( + self.env.uid).id])] +>>>>>>> [ADD] Added a product_operating_unit v12 operating_unit_ids = fields.Many2many( 'operating.unit', @@ -39,6 +45,7 @@ def _check_operating_unit(self): @api.onchange('categ_id') def onchange_operating_unit_ids(self): for record in self: +<<<<<<< HEAD if record.categ_id.operating_unit_ids: record.operating_unit_ids = \ [(6, 0, record.categ_id.operating_unit_ids.ids)] @@ -69,3 +76,7 @@ def _get_default_category_id(self): 'product.category', 'Product Category', change_default=True, default=_get_default_category_id, required=True, help="Select category for the current product") +======= + record.operating_unit_ids = \ + [(6, 0, record.categ_id.operating_unit_ids.ids)] +>>>>>>> [ADD] Added a product_operating_unit v12 diff --git a/product_operating_unit/security/product_template_security.xml b/product_operating_unit/security/product_template_security.xml index a2e4103140..5a091a2fa1 100644 --- a/product_operating_unit/security/product_template_security.xml +++ b/product_operating_unit/security/product_template_security.xml @@ -6,16 +6,33 @@ --> - + + + + + ['|',('operating_unit_ids','=',False), + ('operating_unit_ids','in', user.operating_unit_ids.ids)] + Product Category from allowed operating units + + + + + diff --git a/product_operating_unit/tests/__init__.py b/product_operating_unit/tests/__init__.py index eafa09634c..7b7ac2f500 100644 --- a/product_operating_unit/tests/__init__.py +++ b/product_operating_unit/tests/__init__.py @@ -1,4 +1,5 @@ <<<<<<< HEAD +<<<<<<< HEAD # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). ======= ############################################################################## @@ -9,4 +10,7 @@ ############################################################################## >>>>>>> New module product_operating_unit to introduce the operating unit to the product template. +======= +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +>>>>>>> [ADD] Added a product_operating_unit v12 from . import test_product_operating_unit diff --git a/product_operating_unit/tests/test_product_operating_unit.py b/product_operating_unit/tests/test_product_operating_unit.py index 54d514cfb6..b0e9d4ae01 100644 --- a/product_operating_unit/tests/test_product_operating_unit.py +++ b/product_operating_unit/tests/test_product_operating_unit.py @@ -15,8 +15,15 @@ def setUp(self): self.ProductCategory = self.env['product.category'] # company self.company = self.env.ref('base.main_company') +<<<<<<< HEAD # group self.group_user = self.env.ref('base.group_user') +======= + # groups + self.group_stock_manager = self.env.ref('stock.group_stock_manager') + self.grp_acc_user = self.env.ref('account.group_account_invoice') + self.grp_stock_user = self.env.ref('stock.group_stock_user') +>>>>>>> [ADD] Added a product_operating_unit v12 # Main Operating Unit self.ou1 = self.env.ref('operating_unit.main_operating_unit') # B2B Operating Unit @@ -30,9 +37,21 @@ def setUp(self): 'product.product_product_11_product_template') # Create users self.user1_id = self._create_user( +<<<<<<< HEAD 'user_1', [self.group_user], self.company, [self.ou1, self.b2b]) self.user2_id = self._create_user( 'user_2', [self.group_user], self.company, [self.b2b]) +======= + 'user_1', + [self.grp_stock_user, self.grp_acc_user, self.group_stock_manager], + self.company, [self.ou1, self.b2b] + ) + self.user2_id = self._create_user( + 'user_2', + [self.grp_stock_user, self.grp_acc_user, self.group_stock_manager], + self.company, [self.b2b] + ) +>>>>>>> [ADD] Added a product_operating_unit v12 self.product1.categ_id.operating_unit_ids = [(6, 0, [self.ou1.id])] self.product2.categ_id.operating_unit_ids = [(6, 0, [self.b2b.id])] self.product3.categ_id.operating_unit_ids = \ @@ -58,6 +77,10 @@ def _create_user(self, login, groups, company, operating_units): def test_po_ou_onchange(self): with self.assertRaises(ValidationError): self.product1.operating_unit_ids = [(6, 0, [self.b2b.id])] +<<<<<<< HEAD +======= + +>>>>>>> [ADD] Added a product_operating_unit v12 self.product1.onchange_operating_unit_ids() def test_po_ou_security(self): diff --git a/product_operating_unit/views/product_template_view.xml b/product_operating_unit/views/product_template_view.xml index 00685f7336..2144b4c2e2 100644 --- a/product_operating_unit/views/product_template_view.xml +++ b/product_operating_unit/views/product_template_view.xml @@ -45,4 +45,5 @@ - + + \ No newline at end of file From 0acca412bad7bda2c11c9d764df9483ab90b064a Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Mon, 20 Jan 2020 09:48:17 +0530 Subject: [PATCH 10/25] [FIX] Uncomment rule --- product_operating_unit/security/product_template_security.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/product_operating_unit/security/product_template_security.xml b/product_operating_unit/security/product_template_security.xml index 5a091a2fa1..0b00cf7380 100644 --- a/product_operating_unit/security/product_template_security.xml +++ b/product_operating_unit/security/product_template_security.xml @@ -6,7 +6,7 @@ --> - + From 29f7c4637e236d724fba84bace3179fe3ace9c0d Mon Sep 17 00:00:00 2001 From: scampbell Date: Wed, 29 Jan 2020 16:57:23 -0800 Subject: [PATCH 11/25] [FIX] Default Get + Show OU on Small Form --- product_operating_unit/models/product_template.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/product_operating_unit/models/product_template.py b/product_operating_unit/models/product_template.py index 9ff76a9ec7..a82c5a130f 100644 --- a/product_operating_unit/models/product_template.py +++ b/product_operating_unit/models/product_template.py @@ -13,16 +13,10 @@ class ProductTemplate(models.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)] -<<<<<<< HEAD if self.env.user.default_operating_unit_id: return [(6, 0, [self.env['res.users'].operating_unit_default_get( self.env.uid).id])] -======= - return [(6, 0, - [self.env['res.users'].operating_unit_default_get( - self.env.uid).id])] ->>>>>>> [ADD] Added a product_operating_unit v12 operating_unit_ids = fields.Many2many( 'operating.unit', @@ -45,7 +39,6 @@ def _check_operating_unit(self): @api.onchange('categ_id') def onchange_operating_unit_ids(self): for record in self: -<<<<<<< HEAD if record.categ_id.operating_unit_ids: record.operating_unit_ids = \ [(6, 0, record.categ_id.operating_unit_ids.ids)] @@ -75,8 +68,4 @@ def _get_default_category_id(self): categ_id = fields.Many2one( 'product.category', 'Product Category', change_default=True, default=_get_default_category_id, - required=True, help="Select category for the current product") -======= - record.operating_unit_ids = \ - [(6, 0, record.categ_id.operating_unit_ids.ids)] ->>>>>>> [ADD] Added a product_operating_unit v12 + required=True, help="Select category for the current product") \ No newline at end of file From 4fbe281f1dbac7fa666345d1b00a7e1e54e7f133 Mon Sep 17 00:00:00 2001 From: scampbell Date: Tue, 11 Feb 2020 10:31:16 -0800 Subject: [PATCH 12/25] [IMP] Create Product Access Error --- product_operating_unit/__manifest__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/product_operating_unit/__manifest__.py b/product_operating_unit/__manifest__.py index 5499129e8c..d9b12920a5 100644 --- a/product_operating_unit/__manifest__.py +++ b/product_operating_unit/__manifest__.py @@ -14,6 +14,10 @@ "category": "Product", "depends": [ "product", +<<<<<<< HEAD +======= + "stock", +>>>>>>> [IMP] Create Product Access Error "operating_unit" ], "license": "LGPL-3", From 34cc635ac0bdeabe56f16910d53b7cc1f8f8b872 Mon Sep 17 00:00:00 2001 From: Murtuza Saleh Date: Mon, 20 Apr 2020 16:07:58 +0530 Subject: [PATCH 13/25] [IMP] Improved code --- product_operating_unit/__init__.py | 1 + product_operating_unit/__manifest__.py | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/product_operating_unit/__init__.py b/product_operating_unit/__init__.py index 133f68732d..d9602600d5 100644 --- a/product_operating_unit/__init__.py +++ b/product_operating_unit/__init__.py @@ -1,2 +1,3 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models +from .hooks import pre_init_hook diff --git a/product_operating_unit/__manifest__.py b/product_operating_unit/__manifest__.py index d9b12920a5..5499129e8c 100644 --- a/product_operating_unit/__manifest__.py +++ b/product_operating_unit/__manifest__.py @@ -14,10 +14,6 @@ "category": "Product", "depends": [ "product", -<<<<<<< HEAD -======= - "stock", ->>>>>>> [IMP] Create Product Access Error "operating_unit" ], "license": "LGPL-3", From 234d05bf98e427634eddc65068a97e39e058f672 Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Mon, 20 Apr 2020 22:27:05 -0500 Subject: [PATCH 14/25] [IMP] product_operating_unit --- product_operating_unit/__init__.py | 1 - product_operating_unit/hooks.py | 19 -------------- .../security/product_template_security.xml | 20 ++------------- .../tests/test_product_operating_unit.py | 25 +------------------ 4 files changed, 3 insertions(+), 62 deletions(-) delete mode 100644 product_operating_unit/hooks.py diff --git a/product_operating_unit/__init__.py b/product_operating_unit/__init__.py index d9602600d5..133f68732d 100644 --- a/product_operating_unit/__init__.py +++ b/product_operating_unit/__init__.py @@ -1,3 +1,2 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models -from .hooks import pre_init_hook diff --git a/product_operating_unit/hooks.py b/product_operating_unit/hooks.py deleted file mode 100644 index 1949d6698c..0000000000 --- a/product_operating_unit/hooks.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (C) 2020 Open Source Integrators -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). - - -def pre_init_hook(cr): - # Add new table and columns to hold values - cr.execute(""" - CREATE TABLE product_operating_unit_rel ( - product_template_id INTEGER NOT NULL - REFERENCES product_template(id) ON DELETE CASCADE, - operating_unit_id INTEGER NOT NULL - REFERENCES operating_unit(id) ON DELETE CASCADE); - """) - # Add the values - cr.execute(""" - INSERT INTO product_operating_unit_rel - (product_template_id, operating_unit_id) - SELECT id, 1 FROM product_template; - """) diff --git a/product_operating_unit/security/product_template_security.xml b/product_operating_unit/security/product_template_security.xml index 0b00cf7380..8c5d234857 100644 --- a/product_operating_unit/security/product_template_security.xml +++ b/product_operating_unit/security/product_template_security.xml @@ -8,13 +8,8 @@ -<<<<<<< HEAD ['|', ('operating_unit_ids', '=', False), ('operating_unit_ids', 'in', user.operating_unit_ids.ids)] -======= - ['|',('operating_unit_ids','=',False), - ('operating_unit_ids','in', user.operating_unit_ids.ids)] ->>>>>>> [ADD] Added a product_operating_unit v12 Product Templates from allowed operating units @@ -23,18 +18,6 @@ - - - ['|',('operating_unit_ids','=',False), - ('operating_unit_ids','in', user.operating_unit_ids.ids)] - Product Category from allowed operating units - - - - - - - ['|', ('operating_unit_ids', '=', False), @@ -46,4 +29,5 @@ - + + \ No newline at end of file diff --git a/product_operating_unit/tests/test_product_operating_unit.py b/product_operating_unit/tests/test_product_operating_unit.py index b0e9d4ae01..11cc4f5697 100644 --- a/product_operating_unit/tests/test_product_operating_unit.py +++ b/product_operating_unit/tests/test_product_operating_unit.py @@ -15,15 +15,8 @@ def setUp(self): self.ProductCategory = self.env['product.category'] # company self.company = self.env.ref('base.main_company') -<<<<<<< HEAD # group self.group_user = self.env.ref('base.group_user') -======= - # groups - self.group_stock_manager = self.env.ref('stock.group_stock_manager') - self.grp_acc_user = self.env.ref('account.group_account_invoice') - self.grp_stock_user = self.env.ref('stock.group_stock_user') ->>>>>>> [ADD] Added a product_operating_unit v12 # Main Operating Unit self.ou1 = self.env.ref('operating_unit.main_operating_unit') # B2B Operating Unit @@ -37,21 +30,9 @@ def setUp(self): 'product.product_product_11_product_template') # Create users self.user1_id = self._create_user( -<<<<<<< HEAD 'user_1', [self.group_user], self.company, [self.ou1, self.b2b]) self.user2_id = self._create_user( 'user_2', [self.group_user], self.company, [self.b2b]) -======= - 'user_1', - [self.grp_stock_user, self.grp_acc_user, self.group_stock_manager], - self.company, [self.ou1, self.b2b] - ) - self.user2_id = self._create_user( - 'user_2', - [self.grp_stock_user, self.grp_acc_user, self.group_stock_manager], - self.company, [self.b2b] - ) ->>>>>>> [ADD] Added a product_operating_unit v12 self.product1.categ_id.operating_unit_ids = [(6, 0, [self.ou1.id])] self.product2.categ_id.operating_unit_ids = [(6, 0, [self.b2b.id])] self.product3.categ_id.operating_unit_ids = \ @@ -77,10 +58,6 @@ def _create_user(self, login, groups, company, operating_units): def test_po_ou_onchange(self): with self.assertRaises(ValidationError): self.product1.operating_unit_ids = [(6, 0, [self.b2b.id])] -<<<<<<< HEAD -======= - ->>>>>>> [ADD] Added a product_operating_unit v12 self.product1.onchange_operating_unit_ids() def test_po_ou_security(self): @@ -118,4 +95,4 @@ def test_po_ou_security(self): self.ProductTemplate.sudo(self.user1_id).search(b2b_domain).ids category_ids = \ self.ProductCategory.sudo(self.user2_id).search(b2b_domain).ids - self.assertIn(category_ids[0], product_ids) + self.assertIn(category_ids[0], product_ids) \ No newline at end of file From dfb129fb379c8aa34234c9b633694ba6b56e03b6 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Mon, 27 Apr 2020 13:04:28 +0000 Subject: [PATCH 15/25] [UPD] Update product_operating_unit.pot README.rst --- product_operating_unit/README.rst | 94 +++++++++++++++++++ .../i18n/product_operating_unit.pot | 58 ++++++++++++ .../static/description/index.html | 48 +++++----- 3 files changed, 176 insertions(+), 24 deletions(-) create mode 100644 product_operating_unit/README.rst create mode 100644 product_operating_unit/i18n/product_operating_unit.pot diff --git a/product_operating_unit/README.rst b/product_operating_unit/README.rst new file mode 100644 index 0000000000..7ee45aba46 --- /dev/null +++ b/product_operating_unit/README.rst @@ -0,0 +1,94 @@ +========================== +Operating Unit in Products +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github + :target: https://github.com/OCA/operating-unit/tree/12.0/product_operating_unit + :alt: OCA/operating-unit +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/operating-unit-12-0/operating-unit-12-0-product_operating_unit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/213/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. 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 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* brain-tec AG +* Open Source Integrators +* Serpent Consulting Services Pvt. Ltd. + +Contributors +~~~~~~~~~~~~ + +* Raul Martin Felez +* Nikul Chaudhary +* Maxime Chambreuil + +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/operating-unit `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_operating_unit/i18n/product_operating_unit.pot b/product_operating_unit/i18n/product_operating_unit.pot new file mode 100644 index 0000000000..e4fb9a4d4a --- /dev/null +++ b/product_operating_unit/i18n/product_operating_unit.pot @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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: product_operating_unit +#: code:addons/product_operating_unit/models/product_template.py:60 +#, python-format +msgid "Go to Product Categories" +msgstr "" + +#. module: product_operating_unit +#: model:ir.model.fields,field_description:product_operating_unit.field_product_category__operating_unit_ids +#: model:ir.model.fields,field_description:product_operating_unit.field_product_product__operating_unit_ids +#: model:ir.model.fields,field_description:product_operating_unit.field_product_template__operating_unit_ids +msgid "Operating Units" +msgstr "" + +#. module: product_operating_unit +#: model:ir.model,name:product_operating_unit.model_product_category +#: model:ir.model.fields,field_description:product_operating_unit.field_product_product__categ_id +#: model:ir.model.fields,field_description:product_operating_unit.field_product_template__categ_id +msgid "Product Category" +msgstr "" + +#. module: product_operating_unit +#: model:ir.model,name:product_operating_unit.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_operating_unit +#: model:ir.model.fields,help:product_operating_unit.field_product_product__categ_id +#: model:ir.model.fields,help:product_operating_unit.field_product_template__categ_id +msgid "Select category for the current product" +msgstr "" + +#. module: product_operating_unit +#: code:addons/product_operating_unit/models/product_template.py:34 +#, python-format +msgid "The operating units of the product must include the ones from the category." +msgstr "" + +#. module: product_operating_unit +#: code:addons/product_operating_unit/models/product_template.py:57 +#, python-format +msgid "You must define at least one product category within your Operating Unit in order to be able to create products." +msgstr "" + diff --git a/product_operating_unit/static/description/index.html b/product_operating_unit/static/description/index.html index 372bdce150..7209b00a0e 100644 --- a/product_operating_unit/static/description/index.html +++ b/product_operating_unit/static/description/index.html @@ -3,7 +3,7 @@ - + Operating Unit in Products