From 174078f515361e9bccb0f73da646cebd0856ca32 Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Mon, 19 Sep 2016 16:07:32 +0530 Subject: [PATCH 01/18] [ADD] Migrated mrp_ou to v9. --- mrp_operating_unit/__init__.py | 6 ++ mrp_operating_unit/__openerp__.py | 39 +++++++++ mrp_operating_unit/models/__init__.py | 8 ++ mrp_operating_unit/models/mrp.py | 46 +++++++++++ mrp_operating_unit/models/procurement.py | 34 ++++++++ mrp_operating_unit/security/mrp_security.xml | 21 +++++ mrp_operating_unit/tests/__init__.py | 6 ++ mrp_operating_unit/tests/test_procurement.py | 87 ++++++++++++++++++++ mrp_operating_unit/views/mrp_view.xml | 46 +++++++++++ 9 files changed, 293 insertions(+) create mode 100644 mrp_operating_unit/__init__.py create mode 100644 mrp_operating_unit/__openerp__.py create mode 100644 mrp_operating_unit/models/__init__.py create mode 100644 mrp_operating_unit/models/mrp.py create mode 100644 mrp_operating_unit/models/procurement.py create mode 100644 mrp_operating_unit/security/mrp_security.xml create mode 100644 mrp_operating_unit/tests/__init__.py create mode 100644 mrp_operating_unit/tests/test_procurement.py create mode 100644 mrp_operating_unit/views/mrp_view.xml diff --git a/mrp_operating_unit/__init__.py b/mrp_operating_unit/__init__.py new file mode 100644 index 0000000000..747d0698d4 --- /dev/null +++ b/mrp_operating_unit/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import models diff --git a/mrp_operating_unit/__openerp__.py b/mrp_operating_unit/__openerp__.py new file mode 100644 index 0000000000..ed54ab0f2d --- /dev/null +++ b/mrp_operating_unit/__openerp__.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Operating Unit in MRP", + "version": "9.0.1.0.0", + "author": "Eficent Business and IT Consulting Services S.L., " + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "website": "http://www.eficent.com", + "license": "LGPL-3", + "category": "Manufacturing", + "depends": ["mrp", + "procurement_operating_unit"], + "description": """ +Operating Unit in MRP +======================================= +This module implements global security rules on manufacturing orders so that +a user can only read manufacturing orders where the location is linked to an +operating unit that the user has access to. + +Credits +======= + +Contributors +------------ + +* Jordi Ballester + + """, + "data": [ + "security/mrp_security.xml", + "views/mrp_view.xml" + ], + 'installable': True, +} diff --git a/mrp_operating_unit/models/__init__.py b/mrp_operating_unit/models/__init__.py new file mode 100644 index 0000000000..1cf036a277 --- /dev/null +++ b/mrp_operating_unit/models/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import mrp +from . import procurement diff --git a/mrp_operating_unit/models/mrp.py b/mrp_operating_unit/models/mrp.py new file mode 100644 index 0000000000..baef927441 --- /dev/null +++ b/mrp_operating_unit/models/mrp.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import api, fields, models +from openerp.tools.translate import _ +from openerp.exceptions import Warning + + +class MrpProduction(models.Model): + + _inherit = 'mrp.production' + + operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', + default=lambda self: + self.env['res.users']. + operating_unit_default_get(self._uid)) + + @api.constrains('operating_unit_id', 'location_src_id', 'location_dest_id') + def _check_location_operating_unit(self): + for mo in self: + if ( + not mo.operating_unit_id and + (mo.location_src_id.operating_unit_id or + mo.location_dest_id.operating_unit_id) + ): + raise Warning(_('The Operating Unit of the Manufacturing Order\ + must match with that of the Raw Materials and\ + Finished Product Locations.')) + if ( + mo.operating_unit_id and + mo.operating_unit_id != mo.location_src_id.operating_unit_id + ): + raise Warning(_('The Operating Unit of the Manufacturing Order\ + must match with that of the Raw Materials and\ + Finished Product Locations.')) + if ( + mo.operating_unit_id and + mo.operating_unit_id != mo.location_dest_id.operating_unit_id + ): + raise Warning(_('The Operating Unit of the Manufacturing Order\ + must match with that of the Raw Materials and\ + Finished Product Locations.')) + return True diff --git a/mrp_operating_unit/models/procurement.py b/mrp_operating_unit/models/procurement.py new file mode 100644 index 0000000000..413f3006e8 --- /dev/null +++ b/mrp_operating_unit/models/procurement.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp import api, fields, models +from openerp.tools.translate import _ +from openerp.exceptions import Warning + + +class ProcurementOrder(models.Model): + + _inherit = 'procurement.order' + + @api.constrains('location_id', 'production_id') + def _check_mrp_production_operating_unit(self): + for pr in self: + if ( + pr.production_id and + pr.location_id.operating_unit_id and + pr.production_id.operating_unit_id != + pr.location_id.operating_unit_id + ): + raise Warning(_('The Production Order and the Procurement\ + Order must belong to the same Operating Unit.')) + return True + + @api.model + def _prepare_mo_vals(self, procurement): + res = super(ProcurementOrder, self)._prepare_mo_vals(procurement) + if procurement.location_id.operating_unit_id: + res['operating_unit_id'] = \ + procurement.location_id.operating_unit_id.id + return res diff --git a/mrp_operating_unit/security/mrp_security.xml b/mrp_operating_unit/security/mrp_security.xml new file mode 100644 index 0000000000..c2be24036e --- /dev/null +++ b/mrp_operating_unit/security/mrp_security.xml @@ -0,0 +1,21 @@ + + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Manufacturing Orders from allowed operating units + + + + + + + + + diff --git a/mrp_operating_unit/tests/__init__.py b/mrp_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..0d5d78d785 --- /dev/null +++ b/mrp_operating_unit/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import test_procurement diff --git a/mrp_operating_unit/tests/test_procurement.py b/mrp_operating_unit/tests/test_procurement.py new file mode 100644 index 0000000000..823654f763 --- /dev/null +++ b/mrp_operating_unit/tests/test_procurement.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.tests import common + + +class TestProcurement(common.TransactionCase): + + def setUp(self): + super(TestProcurement, self).setUp() + self.res_users_model = self.env['res.users'] + self.procurement_order_model = self.env['procurement.order'] + self.procurement_rule_model = self.env['procurement.rule'] + self.mrp_line_model = self.env['mrp.bom.line'] + self.bom_model = self.env['mrp.bom'] + self.property_model = self.env['mrp.property'] + self.product_model = self.env['product.product'] + self.product_template_model = self.env['product.template'] + self.product_category_model = self.env['product.category'] + self.product_category = self.env.ref('product.product_category_2') + self.warehouse = self.env.ref('stock.warehouse0') + self.product_unit = self.env.ref('product.product_uom_unit') + self.property = self.env.ref('mrp.mrp_property_0') + self.line = self.env.ref('mrp.mrp_property_0') + self.group = self.env.ref('mrp.mrp_property_group_1') + self.company = self.env.ref('base.main_company') + + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # B2C Operating Unit + self.b2c = self.env.ref('operating_unit.b2c_operating_unit') + + # Products + self.product1 = self.env.ref('product.product_product_9') + + self.rule = self._create_procurement_rule() + self.mrp_bom_method = self._create_bom() + self.procurement_order = self._create_procurement_order() + + + def _create_procurement_rule(self): + rule = self.procurement_rule_model.create({ + 'name': 'Procurement rule', + 'action': 'manufacture' + }) + return rule + + def _create_bom(self): + bom = self.bom_model.create({ + 'product_tmpl_id': self.product1.product_tmpl_id.id, + 'product_id': self.product1.id, + 'product_qty': '1', + 'type': 'normal', + 'product_efficiency': '1.00', + }) + return bom + + def _create_procurement_order(self): + # On change for warehouse_id + new_line = self.procurement_order_model.new() + res = new_line.change_warehouse_id(self.warehouse.id) + if res.get('value') and res.get('value').get('location_id'): + location_id = res.get('value').get('location_id') + # On change for product_id + new_line = self.procurement_order_model.new() + res = new_line.onchange_product_id(self.product1.id) + if res.get('value') and res.get('value').get('product_uom'): + product_uom = res.get('value').get('product_uom') + order = self.procurement_order_model.create({ + 'product_id': self.product1.id, + 'product_uom': product_uom, + 'product_qty': '10', + 'name': 'Procurement Order', + 'warehouse_id': self.warehouse.id, + 'bom_id': self.mrp_bom_method.id, + 'rule_id': self.rule.id, + 'location_id': location_id, + }) + return order + + def test_security(self): + self.assertEqual(self.procurement_order.location_id.operating_unit_id, + self.procurement_order.production_id.operating_unit_id, + 'The Operating Unit in Procurement Order Location' + 'does not match to Manufacturing Order OU.') diff --git a/mrp_operating_unit/views/mrp_view.xml b/mrp_operating_unit/views/mrp_view.xml new file mode 100644 index 0000000000..4e122d74d2 --- /dev/null +++ b/mrp_operating_unit/views/mrp_view.xml @@ -0,0 +1,46 @@ + + + + + + + mrp.production.tree + mrp.production + + + + + + + + + + + mrp.production.form + mrp.production + + + + + + + + + + mrp.production.select + mrp.production + + + + + + + + + + From e3aaed78ab5fe63d04c3f7cdc57255865202cd01 Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Thu, 22 Sep 2016 16:12:04 +0530 Subject: [PATCH 02/18] [ADD] Added Readme file. --- mrp_operating_unit/README.rst | 68 +++++++++++++++++++++++++++++++ mrp_operating_unit/__openerp__.py | 16 -------- 2 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 mrp_operating_unit/README.rst diff --git a/mrp_operating_unit/README.rst b/mrp_operating_unit/README.rst new file mode 100644 index 0000000000..f75c5383a3 --- /dev/null +++ b/mrp_operating_unit/README.rst @@ -0,0 +1,68 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +======================== +MRP with Operating Units +======================== + +This module introduces the following features: + +* Adds Operating Unit (OU) to the Manufacturing Order created from the procurement. + +* This module implements global security rules on manufacturing orders so that a user can only read manufacturing orders where the location is linked to an + operating unit that the user has access to. + +Installation +============ + +No specific installation requirements. + +Configuration +============= + +No configuration is required. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Eficent Business and IT Consulting Services S.L. +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/mrp_operating_unit/__openerp__.py b/mrp_operating_unit/__openerp__.py index ed54ab0f2d..6fcd51c6df 100644 --- a/mrp_operating_unit/__openerp__.py +++ b/mrp_operating_unit/__openerp__.py @@ -15,22 +15,6 @@ "category": "Manufacturing", "depends": ["mrp", "procurement_operating_unit"], - "description": """ -Operating Unit in MRP -======================================= -This module implements global security rules on manufacturing orders so that -a user can only read manufacturing orders where the location is linked to an -operating unit that the user has access to. - -Credits -======= - -Contributors ------------- - -* Jordi Ballester - - """, "data": [ "security/mrp_security.xml", "views/mrp_view.xml" From 876cc7ea3e0a7e7387e5496dc9c957f67f585190 Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Fri, 23 Sep 2016 18:59:24 +0530 Subject: [PATCH 03/18] [IMP] Added test cases for mrp. --- mrp_operating_unit/__init__.py | 1 + mrp_operating_unit/tests/__init__.py | 1 + .../tests/test_mrp_operating_unit.py | 92 +++++++++++++++++++ mrp_operating_unit/tests/test_procurement.py | 11 --- 4 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 mrp_operating_unit/tests/test_mrp_operating_unit.py diff --git a/mrp_operating_unit/__init__.py b/mrp_operating_unit/__init__.py index 747d0698d4..ef6733f80d 100644 --- a/mrp_operating_unit/__init__.py +++ b/mrp_operating_unit/__init__.py @@ -4,3 +4,4 @@ # © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models +from . import tests diff --git a/mrp_operating_unit/tests/__init__.py b/mrp_operating_unit/tests/__init__.py index 0d5d78d785..0e9d0b8e19 100644 --- a/mrp_operating_unit/tests/__init__.py +++ b/mrp_operating_unit/tests/__init__.py @@ -4,3 +4,4 @@ # © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_procurement +from . import test_mrp_operating_unit diff --git a/mrp_operating_unit/tests/test_mrp_operating_unit.py b/mrp_operating_unit/tests/test_mrp_operating_unit.py new file mode 100644 index 0000000000..57be049137 --- /dev/null +++ b/mrp_operating_unit/tests/test_mrp_operating_unit.py @@ -0,0 +1,92 @@ +from openerp.tests import common + + +class TestMrpOperatingUnit(common.TransactionCase): + + def setUp(self): + super(TestMrpOperatingUnit, self).setUp() + self.res_users_model = self.env['res.users'] + self.mrp_production_model = self.env['mrp.production'] + self.company = self.env.ref('base.main_company') + + # Products + self.product1 = self.env.ref('product.product_product_4c') + # Stock Location + self.stock_location = self.env.ref('stock.stock_location_shop0') + + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # Chicago Operating Unit + self.chicago = self.env.ref('stock_operating_unit.operating_unit_shop0') + + # Groups + self.grp_mrp_saleman = self.env.ref('base.group_sale_salesman') + + # Users + self.user1 = self._create_user('user_1', + [self.grp_mrp_saleman], + self.company, + [self.ou1, self.chicago]) + self.user2 = self._create_user('user_2', + [self.grp_mrp_saleman], + self.company, + [self.chicago]) + + # Manufacturing Orders + self.mrp_record1 = self._create_mrp('Manufacturing Order 1', self.ou1) + self.mrp_record2 = self._create_mrp('Manufacturing Order 2', + self.chicago, self.stock_location) + + + def _create_user(self, login, groups, company, operating_units, + context=None): + """Create a user.""" + group_ids = [group.id for group in groups] + user = self.res_users_model.create({ + 'name': 'Test HR Contrac User', + 'login': login, + 'password': 'demo', + 'email': 'example@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 + + def _create_mrp(self, name, operating_unit, stock_location=False): + new_line = self.mrp_production_model.new() + res = new_line.product_id_change(product_id=self.product1.id) + if res.get('value') and res.get('value').get('bom_id'): + bom_id = res.get('value').get('bom_id') + if res.get('value') and res.get('value').get('product_uom'): + product_uom = res.get('value').get('product_uom') + if operating_unit is self.ou1: + mrp = self.mrp_production_model.create({ + 'name': name, + 'product_id': self.product1.id, + 'bom_id': bom_id, + 'product_qty': '10.0', + 'product_uom': product_uom, + 'operating_unit_id': operating_unit.id, + }) + else: + mrp = self.mrp_production_model.create({ + 'name': name, + 'product_id': self.product1.id, + 'bom_id': bom_id, + 'product_qty': '10.0', + 'product_uom': product_uom, + 'operating_unit_id': operating_unit.id, + 'location_src_id': stock_location.id, + 'location_dest_id': stock_location.id + }) + return mrp + + def test_mrp_ou(self): + record = self.mrp_production_model.sudo(self.user2.id).search( + [('id', '=', self.mrp_record1.id), + ('operating_unit_id', '=', + self.ou1.id)]) + self.assertEqual(record.ids, [], 'User 2 should not have access to ' + 'OU : %s' % self.ou1.name) diff --git a/mrp_operating_unit/tests/test_procurement.py b/mrp_operating_unit/tests/test_procurement.py index 823654f763..e8e3bef123 100644 --- a/mrp_operating_unit/tests/test_procurement.py +++ b/mrp_operating_unit/tests/test_procurement.py @@ -13,19 +13,8 @@ def setUp(self): self.res_users_model = self.env['res.users'] self.procurement_order_model = self.env['procurement.order'] self.procurement_rule_model = self.env['procurement.rule'] - self.mrp_line_model = self.env['mrp.bom.line'] self.bom_model = self.env['mrp.bom'] - self.property_model = self.env['mrp.property'] - self.product_model = self.env['product.product'] - self.product_template_model = self.env['product.template'] - self.product_category_model = self.env['product.category'] - self.product_category = self.env.ref('product.product_category_2') self.warehouse = self.env.ref('stock.warehouse0') - self.product_unit = self.env.ref('product.product_uom_unit') - self.property = self.env.ref('mrp.mrp_property_0') - self.line = self.env.ref('mrp.mrp_property_0') - self.group = self.env.ref('mrp.mrp_property_group_1') - self.company = self.env.ref('base.main_company') # Main Operating Unit self.ou1 = self.env.ref('operating_unit.main_operating_unit') From 59f1ae67c17bc7a1f8045df74339eb0760bf9b7e Mon Sep 17 00:00:00 2001 From: darshan-serpent Date: Wed, 1 Feb 2017 17:15:32 +0530 Subject: [PATCH 04/18] [FIX] flake8 --- mrp_operating_unit/models/procurement.py | 2 +- .../tests/test_mrp_operating_unit.py | 13 +++---- mrp_operating_unit/tests/test_procurement.py | 37 +++++++++---------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/mrp_operating_unit/models/procurement.py b/mrp_operating_unit/models/procurement.py index 413f3006e8..56d55a146e 100644 --- a/mrp_operating_unit/models/procurement.py +++ b/mrp_operating_unit/models/procurement.py @@ -3,7 +3,7 @@ # Jordi Ballester Alomar # © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp import api, fields, models +from openerp import api, models from openerp.tools.translate import _ from openerp.exceptions import Warning diff --git a/mrp_operating_unit/tests/test_mrp_operating_unit.py b/mrp_operating_unit/tests/test_mrp_operating_unit.py index 57be049137..86bb8c9c1f 100644 --- a/mrp_operating_unit/tests/test_mrp_operating_unit.py +++ b/mrp_operating_unit/tests/test_mrp_operating_unit.py @@ -17,7 +17,8 @@ def setUp(self): # Main Operating Unit self.ou1 = self.env.ref('operating_unit.main_operating_unit') # Chicago Operating Unit - self.chicago = self.env.ref('stock_operating_unit.operating_unit_shop0') + self.chicago = self.env.ref('stock_operating_unit.' + 'operating_unit_shop0') # Groups self.grp_mrp_saleman = self.env.ref('base.group_sale_salesman') @@ -37,7 +38,6 @@ def setUp(self): self.mrp_record2 = self._create_mrp('Manufacturing Order 2', self.chicago, self.stock_location) - def _create_user(self, login, groups, company, operating_units, context=None): """Create a user.""" @@ -84,9 +84,8 @@ def _create_mrp(self, name, operating_unit, stock_location=False): return mrp def test_mrp_ou(self): - record = self.mrp_production_model.sudo(self.user2.id).search( - [('id', '=', self.mrp_record1.id), - ('operating_unit_id', '=', - self.ou1.id)]) + record = self.mrp_production_model.sudo(self.user2.id).\ + search([('id', '=', self.mrp_record1.id), + ('operating_unit_id', '=', self.ou1.id)]) self.assertEqual(record.ids, [], 'User 2 should not have access to ' - 'OU : %s' % self.ou1.name) + 'OU : %s' % self.ou1.name) diff --git a/mrp_operating_unit/tests/test_procurement.py b/mrp_operating_unit/tests/test_procurement.py index e8e3bef123..f5cfe52961 100644 --- a/mrp_operating_unit/tests/test_procurement.py +++ b/mrp_operating_unit/tests/test_procurement.py @@ -28,7 +28,6 @@ def setUp(self): self.mrp_bom_method = self._create_bom() self.procurement_order = self._create_procurement_order() - def _create_procurement_rule(self): rule = self.procurement_rule_model.create({ 'name': 'Procurement rule', @@ -37,13 +36,12 @@ def _create_procurement_rule(self): return rule def _create_bom(self): - bom = self.bom_model.create({ - 'product_tmpl_id': self.product1.product_tmpl_id.id, - 'product_id': self.product1.id, - 'product_qty': '1', - 'type': 'normal', - 'product_efficiency': '1.00', - }) + bom = self.bom_model.\ + create({'product_tmpl_id': self.product1.product_tmpl_id.id, + 'product_id': self.product1.id, + 'product_qty': '1', + 'type': 'normal', + 'product_efficiency': '1.00'}) return bom def _create_procurement_order(self): @@ -57,20 +55,21 @@ def _create_procurement_order(self): res = new_line.onchange_product_id(self.product1.id) if res.get('value') and res.get('value').get('product_uom'): product_uom = res.get('value').get('product_uom') - order = self.procurement_order_model.create({ - 'product_id': self.product1.id, - 'product_uom': product_uom, - 'product_qty': '10', - 'name': 'Procurement Order', - 'warehouse_id': self.warehouse.id, - 'bom_id': self.mrp_bom_method.id, - 'rule_id': self.rule.id, - 'location_id': location_id, - }) + order = self.procurement_order_model.\ + create({'product_id': self.product1.id, + 'product_uom': product_uom, + 'product_qty': '10', + 'name': 'Procurement Order', + 'warehouse_id': self.warehouse.id, + 'bom_id': self.mrp_bom_method.id, + 'rule_id': self.rule.id, + 'location_id': location_id + }) return order def test_security(self): self.assertEqual(self.procurement_order.location_id.operating_unit_id, - self.procurement_order.production_id.operating_unit_id, + self.procurement_order.production_id.\ + operating_unit_id, 'The Operating Unit in Procurement Order Location' 'does not match to Manufacturing Order OU.') From 374b6b6c3839bc637bac79b2672472a21affa2db Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Thu, 1 Sep 2016 11:27:31 +0530 Subject: [PATCH 05/18] [ADD] Migrated purchase_requisition_ou module to v9 --- .../README.rst | 75 +++++++++++++++ .../__init__.py | 7 ++ .../__openerp__.py | 83 +++++++++++++++++ .../model/__init__.py | 7 ++ .../model/purchase_requisition.py | 91 +++++++++++++++++++ .../security/purchase_security.xml | 30 ++++++ .../tests/__init__.py | 6 ++ ...est_purchase_requisition_operating_unit.py | 82 +++++++++++++++++ .../view/purchase_requisition.xml | 46 ++++++++++ 9 files changed, 427 insertions(+) create mode 100644 purchase_requisition_operating_unit/README.rst create mode 100644 purchase_requisition_operating_unit/__init__.py create mode 100644 purchase_requisition_operating_unit/__openerp__.py create mode 100644 purchase_requisition_operating_unit/model/__init__.py create mode 100644 purchase_requisition_operating_unit/model/purchase_requisition.py create mode 100644 purchase_requisition_operating_unit/security/purchase_security.xml create mode 100644 purchase_requisition_operating_unit/tests/__init__.py create mode 100644 purchase_requisition_operating_unit/tests/test_purchase_requisition_operating_unit.py create mode 100644 purchase_requisition_operating_unit/view/purchase_requisition.xml diff --git a/purchase_requisition_operating_unit/README.rst b/purchase_requisition_operating_unit/README.rst new file mode 100644 index 0000000000..d888b5bc2d --- /dev/null +++ b/purchase_requisition_operating_unit/README.rst @@ -0,0 +1,75 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +========================================= +Purchase Requisition with Operating Units +========================================= + +This module introduces the following features: + +* Adds Operating Unit (OU) to the account moves and its lines created by the payslip, based on the Operating Unit (OU) defined in the Employee's Contract. + +* Security rules are defined to ensure that users can only see the Purchase Requisition of that Operating Units in which they are allowed access to. + +When the user creates a purchase order (PO) from the purchase requisition the +operating unit is copied to the PO. + +Will set by default the Picking type which haves Operating Unit in Warehouse that of the User. + +Warehouse of picking type + + +Installation +============ + +No specific installation requirements. + +Configuration +============= + +No configuration is required. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Eficent Business and IT Consulting Services S.L. +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/purchase_requisition_operating_unit/__init__.py b/purchase_requisition_operating_unit/__init__.py new file mode 100644 index 0000000000..114a2637ca --- /dev/null +++ b/purchase_requisition_operating_unit/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import model diff --git a/purchase_requisition_operating_unit/__openerp__.py b/purchase_requisition_operating_unit/__openerp__.py new file mode 100644 index 0000000000..7241b10721 --- /dev/null +++ b/purchase_requisition_operating_unit/__openerp__.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Operating Unit in Purchase Requisitions", + "version": "9.0.1.0.0", + "author": "Eficent", + "website": "http://www.eficent.com", + "category": "Purchase Management", + "depends": ["purchase_requisition", + "purchase_operating_unit"], + "description": """ +Operating Unit in Purchase Requisitions +======================================= +This module was written to extend the Purchase Requsition capabilities of Odoo. + +This module introduces the operating unit to the purchase requisition. + +Security rules are defined to ensure that users can only display the +Purchase Requisitions in which they are allowed access to. + +Installation +============ + +No additional installation instructions are required. + + +Configuration +============= + +This module does not require any additional configuration. + +Usage +===== + +At the time when a user creates a new purchase requisition the system +proposes the user's default operating unit. + +The operating unit is a required field. + +When the user creates a purchase order (PO) from the purchase requisition the +operating unit is copied to the PO. + + +Known issues / Roadmap +====================== + +No issue has been identified. + +Credits +======= + +Contributors +------------ + +* Jordi Ballester + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit http://odoo-community.org. + + + """, + "data": [ + "view/purchase_requisition.xml", + "security/purchase_security.xml", + ], + 'installable': True, +} diff --git a/purchase_requisition_operating_unit/model/__init__.py b/purchase_requisition_operating_unit/model/__init__.py new file mode 100644 index 0000000000..415a558b4e --- /dev/null +++ b/purchase_requisition_operating_unit/model/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import purchase_requisition diff --git a/purchase_requisition_operating_unit/model/purchase_requisition.py b/purchase_requisition_operating_unit/model/purchase_requisition.py new file mode 100644 index 0000000000..b751fdf877 --- /dev/null +++ b/purchase_requisition_operating_unit/model/purchase_requisition.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp import fields, models, api +from openerp.tools.translate import _ +from openerp.exceptions import Warning + + +class PurchaseRequisition(models.Model): + + _inherit = 'purchase.requisition' + + @api.model + def _get_picking_in(self): + res = super(PurchaseRequisition, self)._get_picking_in() + type_obj = self.env['stock.picking.type'] + operating_unit = self.env['res.users'].operating_unit_default_get( + self._uid) + types = type_obj.search([('code', '=', 'incoming'), + ('warehouse_id.operating_unit_id', '=', + operating_unit.id)]) + if types: + res = types[:1].id + return res + + operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', + readonly=True, + states={'draft': [('readonly', + False)]}, + default=lambda self: + self.env['res.users']. + operating_unit_default_get(self._uid)) + + picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', + domain=[('code', '=', 'incoming')], + required=True, + default=_get_picking_in) + + @api.one + @api.constrains('operating_unit_id', 'company_id') + def _check_company_operating_unit(self): + if self.company_id and self.operating_unit_id and \ + self.company_id != self.operating_unit_id.company_id: + raise Warning(_('The Company in the Purchase Requisition and in ' + 'the Operating Unit must be the same.')) + + @api.one + @api.constrains('operating_unit_id', 'picking_type_id') + def _check_warehouse_operating_unit(self): + picking_type = self.picking_type_id + if picking_type: + if picking_type.warehouse_id and\ + picking_type.warehouse_id.operating_unit_id\ + and self.operating_unit_id and\ + picking_type.warehouse_id.operating_unit_id !=\ + self.operating_unit_id: + raise Warning(_('Configuration error!\nThe Operating Unit in\ + Purchase Requisition and the Warehouse of picking type\ + must belong to the same Operating Unit.')) + + @api.onchange('operating_unit_id') + def _onchange_operating_unit_id(self): + type_obj = self.env['stock.picking.type'] + if self.operating_unit_id: + types = type_obj.search([('code', '=', 'incoming'), + ('warehouse_id.operating_unit_id', '=', + self.operating_unit_id.id)]) + if types: + self.picking_type_id = types[:1] + else: + raise Warning(_("No Warehouse found with the " + "Operating Unit indicated in the " + "Purchase Requisition!")) + + @api.model + def _prepare_purchase_order(self, requisition, supplier): + res = super(PurchaseRequisition, self).\ + _prepare_purchase_order(requisition, supplier) + res.update({'operating_unit_id': requisition.operating_unit_id.id}) + return res + + +class PurchaseRequisitionLine(models.Model): + _inherit = 'purchase.requisition.line' + + operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', + related='requisition_id.' + 'operating_unit_id', + readonly=True, store=True) diff --git a/purchase_requisition_operating_unit/security/purchase_security.xml b/purchase_requisition_operating_unit/security/purchase_security.xml new file mode 100644 index 0000000000..d32292aa4b --- /dev/null +++ b/purchase_requisition_operating_unit/security/purchase_security.xml @@ -0,0 +1,30 @@ + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + PR's from allowed operating units + + + + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + PR lines from allowed operating units + + + + + + + + + diff --git a/purchase_requisition_operating_unit/tests/__init__.py b/purchase_requisition_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..a9e4af8606 --- /dev/null +++ b/purchase_requisition_operating_unit/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).. +from . import test_purchase_requisition_operating_unit diff --git a/purchase_requisition_operating_unit/tests/test_purchase_requisition_operating_unit.py b/purchase_requisition_operating_unit/tests/test_purchase_requisition_operating_unit.py new file mode 100644 index 0000000000..1fd7b83dab --- /dev/null +++ b/purchase_requisition_operating_unit/tests/test_purchase_requisition_operating_unit.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.tests import common +from openerp.exceptions import ValidationError + + +class TestPurchaseRequisitionOperatingUnit(common.TransactionCase): + + # Test Cases: + # - Create Purchase Requisition + # - Change operating_unit_id will change picking_type_id correctly + # - User can't use picking_type_id not belong to same operating_unit_id + # - When create PO, the OU and picking_type_id will be pass correctly + + def setUp(self): + super(TestPurchaseRequisitionOperatingUnit, self).setUp() + self.pr_model = self.env['purchase.requisition'] + self.pr_line_model = self.env['purchase.requisition.line'] + self.po_model = self.env['purchase.order'] + # company + self.company = self.env.ref('base.main_company') + self.grp_acc_manager = self.env.ref('account.group_account_manager') + # 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') + # B2C Operating Unit + self.b2c = self.env.ref('operating_unit.b2c_operating_unit') + # Partner + self.partner1 = self.env.ref('base.res_partner_1') + # Products + self.product1 = self.env.ref('product.product_product_7') + self.product2 = self.env.ref('product.product_product_9') + + def _create_pr(self): + line_products = [(self.product1, 1000), + (self.product2, 500), ] + lines = [] + for product, qty in line_products: + line_values = { + 'product_id': product.id, + 'product_qty': qty, + } + lines.append((0, 0, line_values)) + pr_vals = { + 'exclusive': 'exclusive', + 'operating_unit_id': self.ou1.id, + 'line_ids': lines, + } + # Create PR + self.pr = self.pr_model.sudo().create(pr_vals) + + def test_create_purchase_requisition(self): + self._create_pr() + # Change OU, result in warning + with self.assertRaises(ValidationError): + self.pr.operating_unit_id = self.b2c + # on_change OU + pr_mock = self.pr_model.new() + pr_mock.operating_unit_id = self.b2c + pr_mock._onchange_operating_unit_id() + picktype = pr_mock.picking_type_id # on change result + self.assertEqual(self.b2c, picktype.warehouse_id.operating_unit_id, + 'Purchase Requisition and the Warehouse of picking ' + 'type does not belong to same Operating Unit.') + # Now OU and Picking Type should be in line as b2c + self.pr.picking_type_id = picktype + # Confirm Call + self.pr.sudo().signal_workflow('sent_suppliers') + self.assertEqual(self.pr.state, 'in_progress', + 'State not changed to Confirmed') + # Create PO + pr_po = self.pr.make_purchase_order(self.partner1.id) + po_id = pr_po.get(self.pr.id) + self.po = self.po_model.browse(po_id) + self.assertEqual(self.po.operating_unit_id, self.pr.operating_unit_id, + 'Operating Unit is not correctly passed to PO') + self.assertEqual(self.po.picking_type_id, self.pr.picking_type_id, + 'Picking Type is not correctly passed to PO') diff --git a/purchase_requisition_operating_unit/view/purchase_requisition.xml b/purchase_requisition_operating_unit/view/purchase_requisition.xml new file mode 100644 index 0000000000..772df88f6e --- /dev/null +++ b/purchase_requisition_operating_unit/view/purchase_requisition.xml @@ -0,0 +1,46 @@ + + + + + + purchase.requisition.tree + purchase.requisition + + + + + + + + + + purchase.requisition.form + purchase.requisition + + + + + + + + {'operating_unit_id': operating_unit_id} + + + + + + purchase.requisition.list.select + purchase.requisition + + + + + + + + + + + + + From bbbc08f19aedcc1ebf114be2e6276c93f59ecfa4 Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Thu, 1 Sep 2016 11:57:45 +0530 Subject: [PATCH 06/18] [IMP] Modified Readme file. --- .../README.rst | 9 +-- .../__openerp__.py | 68 ++----------------- 2 files changed, 7 insertions(+), 70 deletions(-) diff --git a/purchase_requisition_operating_unit/README.rst b/purchase_requisition_operating_unit/README.rst index d888b5bc2d..a801315c8e 100644 --- a/purchase_requisition_operating_unit/README.rst +++ b/purchase_requisition_operating_unit/README.rst @@ -8,16 +8,13 @@ Purchase Requisition with Operating Units This module introduces the following features: -* Adds Operating Unit (OU) to the account moves and its lines created by the payslip, based on the Operating Unit (OU) defined in the Employee's Contract. - * Security rules are defined to ensure that users can only see the Purchase Requisition of that Operating Units in which they are allowed access to. -When the user creates a purchase order (PO) from the purchase requisition the -operating unit is copied to the PO. +* Ensures that Operating Unit in Purchase Requisition and the Warehouse of picking type belongs to the same Operating Unit. -Will set by default the Picking type which haves Operating Unit in Warehouse that of the User. +* When the user creates a Purchase Order (PO) from the purchase requisition the operating unit is copied to that PO. -Warehouse of picking type +* Sets default Picking type having Operating Unit (OU) in Warehouse that of the User. Installation diff --git a/purchase_requisition_operating_unit/__openerp__.py b/purchase_requisition_operating_unit/__openerp__.py index 7241b10721..24cdc58b0b 100644 --- a/purchase_requisition_operating_unit/__openerp__.py +++ b/purchase_requisition_operating_unit/__openerp__.py @@ -7,74 +7,14 @@ { "name": "Operating Unit in Purchase Requisitions", "version": "9.0.1.0.0", - "author": "Eficent", + "author": "Eficent Business and IT Consulting Services S.L., " + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "license": "LGPL-3", "website": "http://www.eficent.com", "category": "Purchase Management", "depends": ["purchase_requisition", "purchase_operating_unit"], - "description": """ -Operating Unit in Purchase Requisitions -======================================= -This module was written to extend the Purchase Requsition capabilities of Odoo. - -This module introduces the operating unit to the purchase requisition. - -Security rules are defined to ensure that users can only display the -Purchase Requisitions in which they are allowed access to. - -Installation -============ - -No additional installation instructions are required. - - -Configuration -============= - -This module does not require any additional configuration. - -Usage -===== - -At the time when a user creates a new purchase requisition the system -proposes the user's default operating unit. - -The operating unit is a required field. - -When the user creates a purchase order (PO) from the purchase requisition the -operating unit is copied to the PO. - - -Known issues / Roadmap -====================== - -No issue has been identified. - -Credits -======= - -Contributors ------------- - -* Jordi Ballester - -Maintainer ----------- - -.. image:: http://odoo-community.org/logo.png - :alt: Odoo Community Association - :target: http://odoo-community.org - -This module is maintained by the OCA. - -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. - -To contribute to this module, please visit http://odoo-community.org. - - - """, "data": [ "view/purchase_requisition.xml", "security/purchase_security.xml", From 0f8945648d90a3e0890926b9318321f3372af21e Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Fri, 16 Sep 2016 18:12:09 +0530 Subject: [PATCH 07/18] [IMP] Added Copyrights in xml files and made minor changes. --- .../security/purchase_security.xml | 3 +++ .../view/purchase_requisition.xml | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/purchase_requisition_operating_unit/security/purchase_security.xml b/purchase_requisition_operating_unit/security/purchase_security.xml index d32292aa4b..49c8468d29 100644 --- a/purchase_requisition_operating_unit/security/purchase_security.xml +++ b/purchase_requisition_operating_unit/security/purchase_security.xml @@ -1,4 +1,7 @@ + diff --git a/purchase_requisition_operating_unit/view/purchase_requisition.xml b/purchase_requisition_operating_unit/view/purchase_requisition.xml index 772df88f6e..aa0b6d4a1b 100644 --- a/purchase_requisition_operating_unit/view/purchase_requisition.xml +++ b/purchase_requisition_operating_unit/view/purchase_requisition.xml @@ -1,4 +1,7 @@ + @@ -19,7 +22,7 @@ - + From fe3224a993265f5b2860a9ed95dcec856ca03e8e Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Fri, 30 Sep 2016 16:42:41 +0530 Subject: [PATCH 08/18] [IMP] changed readme file --- purchase_requisition_operating_unit/README.rst | 6 +++--- purchase_requisition_operating_unit/__init__.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/purchase_requisition_operating_unit/README.rst b/purchase_requisition_operating_unit/README.rst index a801315c8e..3ac8eedf12 100644 --- a/purchase_requisition_operating_unit/README.rst +++ b/purchase_requisition_operating_unit/README.rst @@ -10,11 +10,11 @@ This module introduces the following features: * Security rules are defined to ensure that users can only see the Purchase Requisition of that Operating Units in which they are allowed access to. -* Ensures that Operating Unit in Purchase Requisition and the Warehouse of picking type belongs to the same Operating Unit. +* Ensures that Purchase Requisition and the Warehouse in picking type belongs to the same Operating Unit (OU) . -* When the user creates a Purchase Order (PO) from the purchase requisition the operating unit is copied to that PO. +* When the user creates a Purchase Order (PO) from the purchase requisition the operating unit is passed to that PO. -* Sets default Picking type having Operating Unit (OU) in Warehouse that of the User. +* Sets default Picking type whoes Operating Unit (OU) in Warehouse matches to that of the User. Installation diff --git a/purchase_requisition_operating_unit/__init__.py b/purchase_requisition_operating_unit/__init__.py index 114a2637ca..e022c7f39e 100644 --- a/purchase_requisition_operating_unit/__init__.py +++ b/purchase_requisition_operating_unit/__init__.py @@ -5,3 +5,4 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import model +from . import tests From f0d82598f4897d6c0cba7037d4da9d735643a8a8 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Thu, 24 Nov 2016 17:48:56 +0100 Subject: [PATCH 09/18] [IMP] minor changes --- .../__init__.py | 6 +-- .../__openerp__.py | 5 +-- .../model/__init__.py | 6 +-- .../model/purchase_requisition.py | 39 ++++++++++--------- .../tests/__init__.py | 7 ++-- ...est_purchase_requisition_operating_unit.py | 5 +-- 6 files changed, 31 insertions(+), 37 deletions(-) diff --git a/purchase_requisition_operating_unit/__init__.py b/purchase_requisition_operating_unit/__init__.py index e022c7f39e..fda70fc516 100644 --- a/purchase_requisition_operating_unit/__init__.py +++ b/purchase_requisition_operating_unit/__init__.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). - from . import model from . import tests diff --git a/purchase_requisition_operating_unit/__openerp__.py b/purchase_requisition_operating_unit/__openerp__.py index 24cdc58b0b..91e69ea5b3 100644 --- a/purchase_requisition_operating_unit/__openerp__.py +++ b/purchase_requisition_operating_unit/__openerp__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { diff --git a/purchase_requisition_operating_unit/model/__init__.py b/purchase_requisition_operating_unit/model/__init__.py index 415a558b4e..fbf5f5f563 100644 --- a/purchase_requisition_operating_unit/model/__init__.py +++ b/purchase_requisition_operating_unit/model/__init__.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). - from . import purchase_requisition diff --git a/purchase_requisition_operating_unit/model/purchase_requisition.py b/purchase_requisition_operating_unit/model/purchase_requisition.py index b751fdf877..0340050511 100644 --- a/purchase_requisition_operating_unit/model/purchase_requisition.py +++ b/purchase_requisition_operating_unit/model/purchase_requisition.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from openerp import fields, models, api from openerp.tools.translate import _ @@ -38,27 +37,29 @@ def _get_picking_in(self): required=True, default=_get_picking_in) - @api.one + @api.multi @api.constrains('operating_unit_id', 'company_id') def _check_company_operating_unit(self): - if self.company_id and self.operating_unit_id and \ - self.company_id != self.operating_unit_id.company_id: - raise Warning(_('The Company in the Purchase Requisition and in ' - 'the Operating Unit must be the same.')) + for rec in self: + if rec.company_id and rec.operating_unit_id and \ + rec.company_id != rec.operating_unit_id.company_id: + raise Warning(_('The Company in the Purchase Requisition and ' + 'in the Operating Unit must be the same.')) - @api.one + @api.multi @api.constrains('operating_unit_id', 'picking_type_id') def _check_warehouse_operating_unit(self): - picking_type = self.picking_type_id - if picking_type: - if picking_type.warehouse_id and\ - picking_type.warehouse_id.operating_unit_id\ - and self.operating_unit_id and\ - picking_type.warehouse_id.operating_unit_id !=\ - self.operating_unit_id: - raise Warning(_('Configuration error!\nThe Operating Unit in\ - Purchase Requisition and the Warehouse of picking type\ - must belong to the same Operating Unit.')) + for rec in self: + picking_type = rec.picking_type_id + if picking_type: + if picking_type.warehouse_id and\ + picking_type.warehouse_id.operating_unit_id\ + and rec.operating_unit_id and\ + picking_type.warehouse_id.operating_unit_id != \ + rec.operating_unit_id: + raise Warning(_('Configuration error!\nThe Operating Unit in\ + Purchase Requisition and the Warehouse of picking type\ + must belong to the same Operating Unit.')) @api.onchange('operating_unit_id') def _onchange_operating_unit_id(self): diff --git a/purchase_requisition_operating_unit/tests/__init__.py b/purchase_requisition_operating_unit/tests/__init__.py index a9e4af8606..5353f75ed1 100644 --- a/purchase_requisition_operating_unit/tests/__init__.py +++ b/purchase_requisition_operating_unit/tests/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).. +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_purchase_requisition_operating_unit diff --git a/purchase_requisition_operating_unit/tests/test_purchase_requisition_operating_unit.py b/purchase_requisition_operating_unit/tests/test_purchase_requisition_operating_unit.py index 1fd7b83dab..68b574a41b 100644 --- a/purchase_requisition_operating_unit/tests/test_purchase_requisition_operating_unit.py +++ b/purchase_requisition_operating_unit/tests/test_purchase_requisition_operating_unit.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from openerp.tests import common from openerp.exceptions import ValidationError From e98d7a1e3bfd14b7245ae0757c90be5b676907af Mon Sep 17 00:00:00 2001 From: Darshan Patel Date: Thu, 27 Apr 2017 19:16:42 +0530 Subject: [PATCH 10/18] [FIX] travis --- .../README.rst | 10 ------ .../model/purchase_requisition.py | 32 +++++++++---------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/purchase_requisition_operating_unit/README.rst b/purchase_requisition_operating_unit/README.rst index 3ac8eedf12..5ab40a347c 100644 --- a/purchase_requisition_operating_unit/README.rst +++ b/purchase_requisition_operating_unit/README.rst @@ -17,16 +17,6 @@ This module introduces the following features: * Sets default Picking type whoes Operating Unit (OU) in Warehouse matches to that of the User. -Installation -============ - -No specific installation requirements. - -Configuration -============= - -No configuration is required. - Usage ===== diff --git a/purchase_requisition_operating_unit/model/purchase_requisition.py b/purchase_requisition_operating_unit/model/purchase_requisition.py index 0340050511..840b2dc0df 100644 --- a/purchase_requisition_operating_unit/model/purchase_requisition.py +++ b/purchase_requisition_operating_unit/model/purchase_requisition.py @@ -4,7 +4,7 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from openerp import fields, models, api from openerp.tools.translate import _ -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError class PurchaseRequisition(models.Model): @@ -15,8 +15,8 @@ class PurchaseRequisition(models.Model): def _get_picking_in(self): res = super(PurchaseRequisition, self)._get_picking_in() type_obj = self.env['stock.picking.type'] - operating_unit = self.env['res.users'].operating_unit_default_get( - self._uid) + operating_unit = self.env['res.users'].\ + operating_unit_default_get(self._uid) types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.operating_unit_id', '=', operating_unit.id)]) @@ -42,9 +42,9 @@ def _get_picking_in(self): def _check_company_operating_unit(self): for rec in self: if rec.company_id and rec.operating_unit_id and \ - rec.company_id != rec.operating_unit_id.company_id: - raise Warning(_('The Company in the Purchase Requisition and ' - 'in the Operating Unit must be the same.')) + rec.company_id != rec.operating_unit_id.company_id: + raise UserError(_('The Company in the Purchase Requisition and' + ' in the Operating Unit must be the same.')) @api.multi @api.constrains('operating_unit_id', 'picking_type_id') @@ -53,13 +53,13 @@ def _check_warehouse_operating_unit(self): picking_type = rec.picking_type_id if picking_type: if picking_type.warehouse_id and\ - picking_type.warehouse_id.operating_unit_id\ - and rec.operating_unit_id and\ - picking_type.warehouse_id.operating_unit_id != \ - rec.operating_unit_id: - raise Warning(_('Configuration error!\nThe Operating Unit in\ - Purchase Requisition and the Warehouse of picking type\ - must belong to the same Operating Unit.')) + picking_type.warehouse_id.operating_unit_id\ + and rec.operating_unit_id and\ + picking_type.warehouse_id.operating_unit_id !=\ + rec.operating_unit_id: + raise UserError(_('Configuration error!\nThe Operating \ + Unit in Purchase Requisition and the Warehouse of picking \ + type must belong to the same Operating Unit.')) @api.onchange('operating_unit_id') def _onchange_operating_unit_id(self): @@ -71,9 +71,9 @@ def _onchange_operating_unit_id(self): if types: self.picking_type_id = types[:1] else: - raise Warning(_("No Warehouse found with the " - "Operating Unit indicated in the " - "Purchase Requisition!")) + raise UserError(_("No Warehouse found with the " + "Operating Unit indicated in the " + "Purchase Requisition!")) @api.model def _prepare_purchase_order(self, requisition, supplier): From 01990395ba73fff1f9f3411a980eaccc43713ff7 Mon Sep 17 00:00:00 2001 From: OCA Git Bot Date: Thu, 1 Jun 2017 02:37:30 +0200 Subject: [PATCH 11/18] [UPD] addons table in README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 205bc5da28..c852bb6b72 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ addon | version | summary [operating_unit](operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company [procurement_operating_unit](procurement_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company [purchase_operating_unit](purchase_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company +[purchase_requisition_operating_unit](purchase_requisition_operating_unit/) | 9.0.1.0.0 | Operating Unit in Purchase Requisitions [sale_operating_unit](sale_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company [sale_stock_operating_unit](sale_stock_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company [sales_team_operating_unit](sales_team_operating_unit/) | 9.0.1.0.0 | Sales Team Operating Unit From 0273ba2b484f29ad7e5bd8ed5213a003c44ff6fb Mon Sep 17 00:00:00 2001 From: OCA Git Bot Date: Thu, 1 Jun 2017 04:42:14 +0200 Subject: [PATCH 12/18] [ADD] setup.py --- .../odoo_addons/__init__.py | 1 + .../odoo_addons/purchase_requisition_operating_unit | 1 + setup/purchase_requisition_operating_unit/setup.py | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 setup/purchase_requisition_operating_unit/odoo_addons/__init__.py create mode 120000 setup/purchase_requisition_operating_unit/odoo_addons/purchase_requisition_operating_unit create mode 100644 setup/purchase_requisition_operating_unit/setup.py diff --git a/setup/purchase_requisition_operating_unit/odoo_addons/__init__.py b/setup/purchase_requisition_operating_unit/odoo_addons/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/setup/purchase_requisition_operating_unit/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/purchase_requisition_operating_unit/odoo_addons/purchase_requisition_operating_unit b/setup/purchase_requisition_operating_unit/odoo_addons/purchase_requisition_operating_unit new file mode 120000 index 0000000000..fc90e2c391 --- /dev/null +++ b/setup/purchase_requisition_operating_unit/odoo_addons/purchase_requisition_operating_unit @@ -0,0 +1 @@ +../../../purchase_requisition_operating_unit \ No newline at end of file diff --git a/setup/purchase_requisition_operating_unit/setup.py b/setup/purchase_requisition_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_requisition_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 84e1df2e47c46ac726050eb0f2322f016079e06e Mon Sep 17 00:00:00 2001 From: jbeficent Date: Wed, 17 Feb 2016 15:49:35 +0100 Subject: [PATCH 13/18] [ADD] purchase request operating unit [FIX] remove reference to warehouse [ENH] purchase_request_operating_unit, purchase_rquest_procurement_operating_unit 9.0 purchase request operating unit - fixed travis (#81) * [FIX] travis --- oca_dependencies.txt | 1 + purchase_request_operating_unit/README.rst | 58 ++++++++++++ purchase_request_operating_unit/__init__.py | 7 ++ .../__openerp__.py | 22 +++++ .../model/__init__.py | 6 ++ .../model/purchase_request.py | 53 +++++++++++ .../security/purchase_security.xml | 30 ++++++ .../tests/__init__.py | 6 ++ .../test_purchase_request_operating_unit.py | 92 +++++++++++++++++++ .../view/purchase_request_view.xml | 87 ++++++++++++++++++ .../README.rst | 57 ++++++++++++ .../__init__.py | 4 + .../__openerp__.py | 19 ++++ .../model/__init__.py | 5 + .../model/procurement.py | 41 +++++++++ .../tests/__init__.py | 5 + ...hase_request_procurement_operating_unit.py | 70 ++++++++++++++ .../README.rst | 56 +++++++++++ .../__init__.py | 6 ++ .../__openerp__.py | 19 ++++ .../tests/__init__.py | 6 ++ ...e_request_to_requisition_operating_unit.py | 53 +++++++++++ .../wizard/__init__.py | 5 + ..._request_line_make_purchase_requisition.py | 46 ++++++++++ .../README.rst | 56 +++++++++++ .../__init__.py | 6 ++ .../__openerp__.py | 19 ++++ .../tests/__init__.py | 5 + ..._purchase_request_to_rfq_operating_unit.py | 52 +++++++++++ .../wizard/__init__.py | 7 ++ ...rchase_request_line_make_purchase_order.py | 50 ++++++++++ ..._request_line_make_purchase_order_view.xml | 22 +++++ 32 files changed, 971 insertions(+) create mode 100644 oca_dependencies.txt create mode 100644 purchase_request_operating_unit/README.rst create mode 100644 purchase_request_operating_unit/__init__.py create mode 100644 purchase_request_operating_unit/__openerp__.py create mode 100644 purchase_request_operating_unit/model/__init__.py create mode 100644 purchase_request_operating_unit/model/purchase_request.py create mode 100644 purchase_request_operating_unit/security/purchase_security.xml create mode 100644 purchase_request_operating_unit/tests/__init__.py create mode 100644 purchase_request_operating_unit/tests/test_purchase_request_operating_unit.py create mode 100644 purchase_request_operating_unit/view/purchase_request_view.xml create mode 100644 purchase_request_procurement_operating_unit/README.rst create mode 100644 purchase_request_procurement_operating_unit/__init__.py create mode 100644 purchase_request_procurement_operating_unit/__openerp__.py create mode 100644 purchase_request_procurement_operating_unit/model/__init__.py create mode 100644 purchase_request_procurement_operating_unit/model/procurement.py create mode 100644 purchase_request_procurement_operating_unit/tests/__init__.py create mode 100644 purchase_request_procurement_operating_unit/tests/test_purchase_request_procurement_operating_unit.py create mode 100644 purchase_request_to_requisition_operating_unit/README.rst create mode 100644 purchase_request_to_requisition_operating_unit/__init__.py create mode 100644 purchase_request_to_requisition_operating_unit/__openerp__.py create mode 100644 purchase_request_to_requisition_operating_unit/tests/__init__.py create mode 100644 purchase_request_to_requisition_operating_unit/tests/test_purchase_request_to_requisition_operating_unit.py create mode 100644 purchase_request_to_requisition_operating_unit/wizard/__init__.py create mode 100644 purchase_request_to_requisition_operating_unit/wizard/purchase_request_line_make_purchase_requisition.py create mode 100644 purchase_request_to_rfq_operating_unit/README.rst create mode 100644 purchase_request_to_rfq_operating_unit/__init__.py create mode 100644 purchase_request_to_rfq_operating_unit/__openerp__.py create mode 100644 purchase_request_to_rfq_operating_unit/tests/__init__.py create mode 100644 purchase_request_to_rfq_operating_unit/tests/test_purchase_request_to_rfq_operating_unit.py create mode 100644 purchase_request_to_rfq_operating_unit/wizard/__init__.py create mode 100644 purchase_request_to_rfq_operating_unit/wizard/purchase_request_line_make_purchase_order.py create mode 100644 purchase_request_to_rfq_operating_unit/wizard/purchase_request_line_make_purchase_order_view.xml diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 0000000000..b46a770d50 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1 @@ +purchase-workflow diff --git a/purchase_request_operating_unit/README.rst b/purchase_request_operating_unit/README.rst new file mode 100644 index 0000000000..f935945a30 --- /dev/null +++ b/purchase_request_operating_unit/README.rst @@ -0,0 +1,58 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +===================================== +Purchase Request with Operating Units +===================================== + +This module introduces the following features: + +* Adds the Operating Unit (OU) to the Purchase Request. +* The user’s default Operating Unit (OU) is proposed at the time of creating the Purchase Request. +* Security rules are defined to ensure that users can only see the Purchase Request of that Operating Units in which they are allowed access to. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar +* Aaron Henriquez +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/purchase_request_operating_unit/__init__.py b/purchase_request_operating_unit/__init__.py new file mode 100644 index 0000000000..6396f46584 --- /dev/null +++ b/purchase_request_operating_unit/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import model +from . import tests diff --git a/purchase_request_operating_unit/__openerp__.py b/purchase_request_operating_unit/__openerp__.py new file mode 100644 index 0000000000..5fbccf3600 --- /dev/null +++ b/purchase_request_operating_unit/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Operating Unit in Purchase Requests", + "version": "9.0.1.0.0", + "author": "Eficent" + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "category": "Purchase Management", + "depends": ["purchase_request", + "purchase_operating_unit"], + "data": [ + "view/purchase_request_view.xml", + "security/purchase_security.xml", + ], + 'installable': True, +} diff --git a/purchase_request_operating_unit/model/__init__.py b/purchase_request_operating_unit/model/__init__.py new file mode 100644 index 0000000000..b091c29d62 --- /dev/null +++ b/purchase_request_operating_unit/model/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import purchase_request diff --git a/purchase_request_operating_unit/model/purchase_request.py b/purchase_request_operating_unit/model/purchase_request.py new file mode 100644 index 0000000000..fd23b6e721 --- /dev/null +++ b/purchase_request_operating_unit/model/purchase_request.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import api, fields, models, _ + + +class PurchaseRequest(models.Model): + _inherit = 'purchase.request' + + operating_unit_id = fields.Many2one( + 'operating.unit', + string='Operating Unit', + default=lambda self: + self.env['res.users']. + operating_unit_default_get(self._uid), + ) + + @api.multi + @api.constrains('operating_unit_id', 'company_id') + def _check_company_operating_unit(self): + for rec in self: + if rec.company_id and rec.operating_unit_id and \ + rec.company_id != rec.operating_unit_id.company_id: + raise Warning(_("The Company in the Purchase Request and in " + "the Operating Unit must be the same.")) + + @api.multi + @api.constrains('operating_unit_id', 'picking_type_id') + def _check_warehouse_operating_unit(self): + for rec in self: + picking_type = rec.picking_type_id + if picking_type: + if picking_type.warehouse_id and\ + picking_type.warehouse_id.operating_unit_id\ + and rec.operating_unit_id and\ + picking_type.warehouse_id.operating_unit_id !=\ + rec.operating_unit_id: + raise Warning(_("Configuration error! The Purchase Request" + " and the Warehouse of picking type must" + " belong to the same Operating Unit.")) + + +class PurchaseRequestLine(models.Model): + _inherit = 'purchase.request.line' + + operating_unit_id = fields.Many2one( + 'operating.unit', + related='request_id.operating_unit_id', + string='Operating Unit', readonly=True, + store=True, + ) diff --git a/purchase_request_operating_unit/security/purchase_security.xml b/purchase_request_operating_unit/security/purchase_security.xml new file mode 100644 index 0000000000..29b86ea6a4 --- /dev/null +++ b/purchase_request_operating_unit/security/purchase_security.xml @@ -0,0 +1,30 @@ + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Purchase Requests from allowed operating units + + + + + + + + + + ['|',('request_id.operating_unit_id','=',False),('request_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Purchase Requests lines from allowed operating units + + + + + + + + + diff --git a/purchase_request_operating_unit/tests/__init__.py b/purchase_request_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..51e4ae06f7 --- /dev/null +++ b/purchase_request_operating_unit/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import test_purchase_request_operating_unit diff --git a/purchase_request_operating_unit/tests/test_purchase_request_operating_unit.py b/purchase_request_operating_unit/tests/test_purchase_request_operating_unit.py new file mode 100644 index 0000000000..94d75b85fe --- /dev/null +++ b/purchase_request_operating_unit/tests/test_purchase_request_operating_unit.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp.tests import common + + +class TestPurchaseRequestOperatingUnit(common.TransactionCase): + + def setUp(self): + super(TestPurchaseRequestOperatingUnit, self).setUp() + # Models + self.res_users_model = self.env['res.users'] + self.purchase_request = self.env['purchase.request'] + self.purchase_request_line = self.env['purchase.request.line'] + # Company + self.company = self.env.ref('base.main_company') + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # B2C Operating Unit + self.b2c = self.env.ref('operating_unit.b2c_operating_unit') + # Product + self.product1 = self.env.ref('product.product_product_7') + self.product_uom = self.env.ref('product.product_uom_unit') + # User + self.user_root = self.env.ref('base.user_root') + # Groups + self.grp_pr_mngr = self.env.\ + ref('purchase_request.group_purchase_request_manager') + # Picking Type + b2c_wh = self.env.ref('stock_operating_unit.stock_warehouse_b2c') + self.b2c_type_in_id = b2c_wh.in_type_id.id + self.picking_type = self.env.ref('stock.picking_type_in') + + # Creates Users and Purchase request + self.user1 = self._create_user( + 'user_1', [], self.company, [self.ou1]) + self.user2 = self._create_user( + 'user_2', self.grp_pr_mngr, self.company, [self.b2c]) + self.request1 = self._create_purchase_request(self.ou1) + self._purchase_line(self.request1) + self.request2 = self._create_purchase_request(self.b2c, + self.b2c_type_in_id) + self._purchase_line(self.request2) + + def _create_user(self, login, groups, company, operating_units, + context=None): + """ Create a user. """ + group_ids = [group.id for group in groups] + user = self.res_users_model.create({ + 'name': 'Test Purchase Request User', + 'login': login, + 'password': 'demo', + 'email': 'example@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 + + def _purchase_line(self, request): + line = self.purchase_request_line.create({ + 'request_id': request.id, + 'product_id': self.product1.id, + 'product_uom_id': self.product_uom.id, + 'product_qty': 5.0, + }) + return line + + def _create_purchase_request(self, operating_unit, picking_type=False): + if picking_type: + purchase_request = self.purchase_request.create({ + 'assigned_to': self.user_root.id, + 'picking_type_id': self.b2c_type_in_id, + 'operating_unit_id': operating_unit.id, + }) + else: + purchase_request = self.purchase_request.create({ + 'assigned_to': self.user_root.id, + 'picking_type_id': self.picking_type.id, + 'operating_unit_id': operating_unit.id, + }) + return purchase_request + + def test_purchase_request(self): + record = self.purchase_request.sudo(self.user2.id).\ + search([('id', '=', self.request1.id), + ('operating_unit_id', '=', self.ou1.id)]) + self.assertEqual(record.ids, [], 'User 2 should not have access to ' + 'OU %s' % self.ou1.name) diff --git a/purchase_request_operating_unit/view/purchase_request_view.xml b/purchase_request_operating_unit/view/purchase_request_view.xml new file mode 100644 index 0000000000..3edc97095e --- /dev/null +++ b/purchase_request_operating_unit/view/purchase_request_view.xml @@ -0,0 +1,87 @@ + + + + + + purchase.request.tree + purchase.request + + + + + + + + + + purchase.request.form + purchase.request + + + + + + + {'operating_unit_id': operating_unit_id} + + + + + + purchase.request.list.select + purchase.request + + + + + + + + + + + + + purchase.request.line.tree + purchase.request.line + + + + + + + + + + purchase.request.line.form + purchase.request.line + + + + + + + + + + purchase.request.line.search + purchase.request.line + + + + + + + + + + + + + diff --git a/purchase_request_procurement_operating_unit/README.rst b/purchase_request_procurement_operating_unit/README.rst new file mode 100644 index 0000000000..63a701666b --- /dev/null +++ b/purchase_request_procurement_operating_unit/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +================================================= +Purchase Request Procurement with Operating Units +================================================= + +This module introduces the following features: + +* This module passes the Operating Unit from the Procurement to the Purchase Request and also + ensures that the Purchase Request and the Procurement Order must belong to the same Operating Unit. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar +* Aaron Henriquez +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/purchase_request_procurement_operating_unit/__init__.py b/purchase_request_procurement_operating_unit/__init__.py new file mode 100644 index 0000000000..c977d41e4e --- /dev/null +++ b/purchase_request_procurement_operating_unit/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). diff --git a/purchase_request_procurement_operating_unit/__openerp__.py b/purchase_request_procurement_operating_unit/__openerp__.py new file mode 100644 index 0000000000..65c704380a --- /dev/null +++ b/purchase_request_procurement_operating_unit/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Purchase Request Procurement with Operating Units", + "version": "9.0.1.0.0", + "author": "Eficent" + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "category": "Purchase Management", + "depends": ["purchase_request_procurement", + "purchase_request_operating_unit", + 'procurement_operating_unit'], + 'installable': True, +} diff --git a/purchase_request_procurement_operating_unit/model/__init__.py b/purchase_request_procurement_operating_unit/model/__init__.py new file mode 100644 index 0000000000..d6badb6903 --- /dev/null +++ b/purchase_request_procurement_operating_unit/model/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import procurement diff --git a/purchase_request_procurement_operating_unit/model/procurement.py b/purchase_request_procurement_operating_unit/model/procurement.py new file mode 100644 index 0000000000..853cf9fe1c --- /dev/null +++ b/purchase_request_procurement_operating_unit/model/procurement.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import models, api, _ + + +class Procurement(models.Model): + _inherit = 'procurement.order' + + @api.model + def _prepare_purchase_request(self, procurement): + res = super(Procurement, self)._prepare_purchase_request(procurement) + if procurement.location_id.operating_unit_id: + res.update({ + 'operating_unit_id': + procurement.location_id.operating_unit_id.id + }) + return res + + @api.multi + @api.constrains('location_id', 'request_id') + def _check_purchase_request_operating_unit(self): + for rec in self: + if rec.request_id and rec.location_id.operating_unit_id and \ + rec.request_id.operating_unit_id != \ + rec.location_id.operating_unit_id: + raise Warning(_('The Purchase Request and the Procurement ' + 'Order must belong to the same Operating' + 'Unit.')) + + @api.multi + @api.constrains('location_id', 'warehouse_id') + def _check_warehouse_operating_unit(self): + for rec in self: + if rec.warehouse_id and rec.location_id.operating_unit_id and \ + rec.warehouse_id.operating_unit_id != \ + rec.location_id.operating_unit_id: + raise Warning(_('Warehouse and location of procurement order ' + 'must belong to the same Operating Unit.')) diff --git a/purchase_request_procurement_operating_unit/tests/__init__.py b/purchase_request_procurement_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..f0cb4ad3af --- /dev/null +++ b/purchase_request_procurement_operating_unit/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import test_purchase_request_procurement_operating_unit diff --git a/purchase_request_procurement_operating_unit/tests/test_purchase_request_procurement_operating_unit.py b/purchase_request_procurement_operating_unit/tests/test_purchase_request_procurement_operating_unit.py new file mode 100644 index 0000000000..24ecc31c6f --- /dev/null +++ b/purchase_request_procurement_operating_unit/tests/test_purchase_request_procurement_operating_unit.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.tests import common + + +class TestProcurement(common.TransactionCase): + + def setUp(self): + super(TestProcurement, self).setUp() + self.res_users_model = self.env['res.users'] + self.procurement_order_model = self.env['procurement.order'] + self.procurement_rule_model = self.env['procurement.rule'] + self.warehouse = self.env.ref('stock.warehouse0') + + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # B2C Operating Unit + self.b2c = self.env.ref('operating_unit.b2c_operating_unit') + + # Products + self.product1 = self.env.ref('product.product_product_9') + self.product1.write({'purchase_request': True}) + + # Picking Type + b2c_wh = self.env.ref('stock_operating_unit.stock_warehouse_b2c') + self.b2c_type_in_id = b2c_wh.in_type_id.id + self.picking_type = self.env.ref('stock.picking_type_in') + + self.rule = self._create_procurement_rule() + self.procurement_order = self._create_procurement_order() + + def _create_procurement_rule(self): + rule = self.procurement_rule_model.\ + create({'name': 'Procurement rule', + 'action': 'buy', + 'picking_type_id': self.picking_type.id + }) + return rule + + def _create_procurement_order(self): + # On change for warehouse_id + new_line = self.procurement_order_model.new() + res = new_line.change_warehouse_id(self.warehouse.id) + if res.get('value') and res.get('value').get('location_id'): + location_id = res.get('value').get('location_id') + # On change for product_id + new_line = self.procurement_order_model.new() + res = new_line.onchange_product_id(self.product1.id) + if res.get('value') and res.get('value').get('product_uom'): + product_uom = res.get('value').get('product_uom') + proc = self.procurement_order_model.\ + create({'product_id': self.product1.id, + 'product_uom': product_uom, + 'product_qty': '10', + 'name': 'Procurement Order', + 'warehouse_id': self.warehouse.id, + 'rule_id': self.rule.id, + 'location_id': location_id + }) + proc.check() + proc.run() + return proc + + def test_security(self): + self.assertEqual(self.procurement_order.location_id.operating_unit_id, + self.procurement_order.request_id.operating_unit_id, + 'The Operating Unit in Procurement Order Location' + 'does not match to Purchase Request OU.') diff --git a/purchase_request_to_requisition_operating_unit/README.rst b/purchase_request_to_requisition_operating_unit/README.rst new file mode 100644 index 0000000000..5ea6828062 --- /dev/null +++ b/purchase_request_to_requisition_operating_unit/README.rst @@ -0,0 +1,56 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +====================================================== +Purchase Request to Call for Bids with Operating Units +====================================================== + +This module introduces the following features: + +* This module pass the Operating Unit from the purchase request to the bid. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar +* Aaron Henriquez +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/purchase_request_to_requisition_operating_unit/__init__.py b/purchase_request_to_requisition_operating_unit/__init__.py new file mode 100644 index 0000000000..2d1268b146 --- /dev/null +++ b/purchase_request_to_requisition_operating_unit/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import wizard diff --git a/purchase_request_to_requisition_operating_unit/__openerp__.py b/purchase_request_to_requisition_operating_unit/__openerp__.py new file mode 100644 index 0000000000..236c7931b6 --- /dev/null +++ b/purchase_request_to_requisition_operating_unit/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Purchase Request to Call for Bids with Operating Units", + "version": "9.0.1.0.0", + "author": "Eficent" + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "category": "Purchase Management", + "depends": ["purchase_request_to_requisition", + "purchase_request_operating_unit", + "purchase_requisition_operating_unit"], + 'installable': True, +} diff --git a/purchase_request_to_requisition_operating_unit/tests/__init__.py b/purchase_request_to_requisition_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..b6c4bb2d12 --- /dev/null +++ b/purchase_request_to_requisition_operating_unit/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import test_purchase_request_to_requisition_operating_unit diff --git a/purchase_request_to_requisition_operating_unit/tests/test_purchase_request_to_requisition_operating_unit.py b/purchase_request_to_requisition_operating_unit/tests/test_purchase_request_to_requisition_operating_unit.py new file mode 100644 index 0000000000..09083d4c2b --- /dev/null +++ b/purchase_request_to_requisition_operating_unit/tests/test_purchase_request_to_requisition_operating_unit.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.tests import common +from openerp.tools import SUPERUSER_ID + + +class TestPurchaseRequestToRequisition(common.TransactionCase): + + def setUp(self): + super(TestPurchaseRequestToRequisition, self).setUp() + self.purchase_request = self.env['purchase.request'] + self.purchase_request_line_obj = self.env['purchase.request.line'] + self.wiz =\ + self.env['purchase.request.line.make.purchase.requisition'] + self.purchase_requisition_partner_model =\ + self.env['purchase.requisition.partner'] + self.purchase_order = self.env['purchase.order'] + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # Products + self.product1 = self.env.ref('product.product_product_9') + self._create_purchase_request() + + def _create_purchase_request(self): + vals = { + 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'requested_by': SUPERUSER_ID, + 'operating_unit_id': self.ou1.id + } + purchase_request = self.purchase_request.create(vals) + vals = { + 'request_id': purchase_request.id, + 'product_id': self.product1.id, + 'product_uom_id': self.env.ref('product.product_uom_unit').id, + 'product_qty': 5.0, + } + self.purchase_request_line =\ + self.purchase_request_line_obj.create(vals) + + def test_purchase_request_to_purchase_requisition(self): + wiz = self.wiz.with_context( + active_model="purchase.request.line", + active_ids=[self.purchase_request_line.id], + active_id=self.purchase_request_line.id).create({}) + wiz.make_purchase_requisition() + requisition_id =\ + self.purchase_request_line.requisition_lines.requisition_id + self.assertEqual( + requisition_id.operating_unit_id, + self.purchase_request_line.operating_unit_id, + 'Should have the same Operating Unit') diff --git a/purchase_request_to_requisition_operating_unit/wizard/__init__.py b/purchase_request_to_requisition_operating_unit/wizard/__init__.py new file mode 100644 index 0000000000..c7ea810b53 --- /dev/null +++ b/purchase_request_to_requisition_operating_unit/wizard/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import purchase_request_line_make_purchase_requisition diff --git a/purchase_request_to_requisition_operating_unit/wizard/purchase_request_line_make_purchase_requisition.py b/purchase_request_to_requisition_operating_unit/wizard/purchase_request_line_make_purchase_requisition.py new file mode 100644 index 0000000000..3b99345ed9 --- /dev/null +++ b/purchase_request_to_requisition_operating_unit/wizard/purchase_request_line_make_purchase_requisition.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp import api, fields, models, _ +from openerp.exceptions import except_orm + + +class PurchaseRequestLineMakePurchaseRequisition(models.TransientModel): + _inherit = "purchase.request.line.make.purchase.requisition" + + operating_unit_id = fields.Many2one( + 'operating.unit', + string='Operating Unit', + readonly=True, + ) + + @api.model + def default_get(self, fields): + res = super(PurchaseRequestLineMakePurchaseRequisition, self).\ + default_get(fields) + request_line_obj = self.env['purchase.request.line'] + request_line_ids = self._context.get('active_ids', []) + operating_unit_id = False + for line in request_line_obj.browse(request_line_ids): + line_operating_unit_id = line.request_id.operating_unit_id \ + and line.request_id.operating_unit_id.id or False + if operating_unit_id\ + and line_operating_unit_id != operating_unit_id: + raise except_orm( + _('Could not process !'), + _('You have to select lines ' + 'from the same operating unit.')) + else: + operating_unit_id = line_operating_unit_id + res['operating_unit_id'] = operating_unit_id + return res + + @api.model + def _prepare_purchase_requisition(self, picking_type_id, + company_id): + res = super(PurchaseRequestLineMakePurchaseRequisition, self).\ + _prepare_purchase_requisition(picking_type_id, company_id) + if self.operating_unit_id: + res.update({'operating_unit_id': self.operating_unit_id.id}) + return res diff --git a/purchase_request_to_rfq_operating_unit/README.rst b/purchase_request_to_rfq_operating_unit/README.rst new file mode 100644 index 0000000000..2fd4ef5d7b --- /dev/null +++ b/purchase_request_to_rfq_operating_unit/README.rst @@ -0,0 +1,56 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +============================================ +Purchase Request to RFQ with Operating Units +============================================ + +This module introduces the following features: + +* This module pass the Operating Unit from the purchase request to the RFQ. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar +* Aaron Henriquez +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/purchase_request_to_rfq_operating_unit/__init__.py b/purchase_request_to_rfq_operating_unit/__init__.py new file mode 100644 index 0000000000..2d1268b146 --- /dev/null +++ b/purchase_request_to_rfq_operating_unit/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import wizard diff --git a/purchase_request_to_rfq_operating_unit/__openerp__.py b/purchase_request_to_rfq_operating_unit/__openerp__.py new file mode 100644 index 0000000000..2d125968e2 --- /dev/null +++ b/purchase_request_to_rfq_operating_unit/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +{ + "name": "Purchase Request to RFQ with Operating Units", + "version": "9.0.1.0.0", + "author": "Eficent" + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "category": "Purchase Management", + "depends": ["purchase_request_to_rfq", "purchase_request_operating_unit"], + "data": [ + "wizard/purchase_request_line_make_purchase_order_view.xml", + ], + 'installable': True, +} diff --git a/purchase_request_to_rfq_operating_unit/tests/__init__.py b/purchase_request_to_rfq_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..b14059d887 --- /dev/null +++ b/purchase_request_to_rfq_operating_unit/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import test_purchase_request_to_rfq_operating_unit diff --git a/purchase_request_to_rfq_operating_unit/tests/test_purchase_request_to_rfq_operating_unit.py b/purchase_request_to_rfq_operating_unit/tests/test_purchase_request_to_rfq_operating_unit.py new file mode 100644 index 0000000000..0c30e3aa64 --- /dev/null +++ b/purchase_request_to_rfq_operating_unit/tests/test_purchase_request_to_rfq_operating_unit.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# © 2016 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.tests import common +from openerp.tools import SUPERUSER_ID + + +class TestPurchaseRequestToRfq(common.TransactionCase): + + def setUp(self): + super(TestPurchaseRequestToRfq, self).setUp() + self.purchase_request = self.env['purchase.request'] + self.purchase_request_line = self.env['purchase.request.line'] + self.wiz =\ + self.env['purchase.request.line.make.purchase.order'] + self.purchase_order = self.env['purchase.order'] + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # Products + self.product1 = self.env.ref('product.product_product_9') + self._create_purchase_request() + + def _create_purchase_request(self): + vals = { + 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'requested_by': SUPERUSER_ID, + 'operating_unit_id': self.ou1.id + } + purchase_request = self.purchase_request.create(vals) + vals = { + 'request_id': purchase_request.id, + 'product_id': self.product1.id, + 'product_uom_id': self.env.ref('product.product_uom_unit').id, + 'product_qty': 5.0, + } + self.purchase_request_line = self.purchase_request_line.create(vals) + purchase_request.button_to_approve() + purchase_request.button_approved() + + def test_purchase_request_to_purchase_requisition(self): + vals = {'supplier_id': self.env.ref('base.res_partner_12').id} + wiz_id = self.wiz.with_context( + active_model="purchase.request.line", + active_ids=[self.purchase_request_line.id], + active_id=self.purchase_request_line.id,).create(vals) + wiz_id.make_purchase_order() + purchase_id = self.purchase_request_line.purchase_lines.order_id + self.assertEqual( + purchase_id.operating_unit_id, + self.purchase_request_line.operating_unit_id, + 'Should have the same Operating Unit') diff --git a/purchase_request_to_rfq_operating_unit/wizard/__init__.py b/purchase_request_to_rfq_operating_unit/wizard/__init__.py new file mode 100644 index 0000000000..47b191dab3 --- /dev/null +++ b/purchase_request_to_rfq_operating_unit/wizard/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import purchase_request_line_make_purchase_order diff --git a/purchase_request_to_rfq_operating_unit/wizard/purchase_request_line_make_purchase_order.py b/purchase_request_to_rfq_operating_unit/wizard/purchase_request_line_make_purchase_order.py new file mode 100644 index 0000000000..57e7e454b1 --- /dev/null +++ b/purchase_request_to_rfq_operating_unit/wizard/purchase_request_line_make_purchase_order.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import fields, models, api, _ +from openerp.exceptions import except_orm + + +class PurchaseRequestLineMakePurchaseOrder(models.TransientModel): + _inherit = "purchase.request.line.make.purchase.order" + + operating_unit_id = fields.Many2one( + 'operating.unit', + string='Operating Unit', + readonly=True, + ) + + @api.model + def default_get(self, fields): + res = super(PurchaseRequestLineMakePurchaseOrder, self).\ + default_get(fields) + request_line_obj = self.env['purchase.request.line'] + request_line_ids = self._context.get('active_ids', []) + operating_unit_id = False + for line in request_line_obj.browse(request_line_ids): + line_operating_unit_id = line.request_id.operating_unit_id \ + and line.request_id.operating_unit_id.id or False + if operating_unit_id\ + and line_operating_unit_id != operating_unit_id: + raise except_orm( + _('Could not process !'), + _('You have to select lines ' + 'from the same operating unit.')) + else: + operating_unit_id = line_operating_unit_id + res['operating_unit_id'] = operating_unit_id + return res + + @api.model + def _prepare_purchase_order(self, picking_type, location, company_id): + data = super(PurchaseRequestLineMakePurchaseOrder, self).\ + _prepare_purchase_order(picking_type, location, company_id) + if self.operating_unit_id: + data['requesting_operating_unit_id'] = \ + self.operating_unit_id.id + data['operating_unit_id'] = \ + self.operating_unit_id.id + return data diff --git a/purchase_request_to_rfq_operating_unit/wizard/purchase_request_line_make_purchase_order_view.xml b/purchase_request_to_rfq_operating_unit/wizard/purchase_request_line_make_purchase_order_view.xml new file mode 100644 index 0000000000..cadcda0e04 --- /dev/null +++ b/purchase_request_to_rfq_operating_unit/wizard/purchase_request_line_make_purchase_order_view.xml @@ -0,0 +1,22 @@ + + + + + Purchase Request Line Make Purchase Order + purchase.request.line.make.purchase.order + + form + + + + + + ['|', ('operating_unit_id', '=', False), ('operating_unit_id', '=', operating_unit_id)] + + + + + + + From a34b17db3b5be668524753ea651a2b75be03dd44 Mon Sep 17 00:00:00 2001 From: OCA Git Bot Date: Wed, 14 Jun 2017 02:37:18 +0200 Subject: [PATCH 14/18] [UPD] addons table in README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c852bb6b72..1387c48bd5 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,10 @@ addon | version | summary [operating_unit](operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company [procurement_operating_unit](procurement_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company [purchase_operating_unit](purchase_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company +[purchase_request_operating_unit](purchase_request_operating_unit/) | 9.0.1.0.0 | Operating Unit in Purchase Requests +[purchase_request_procurement_operating_unit](purchase_request_procurement_operating_unit/) | 9.0.1.0.0 | Purchase Request Procurement with Operating Units +[purchase_request_to_requisition_operating_unit](purchase_request_to_requisition_operating_unit/) | 9.0.1.0.0 | Purchase Request to Call for Bids with Operating Units +[purchase_request_to_rfq_operating_unit](purchase_request_to_rfq_operating_unit/) | 9.0.1.0.0 | Purchase Request to RFQ with Operating Units [purchase_requisition_operating_unit](purchase_requisition_operating_unit/) | 9.0.1.0.0 | Operating Unit in Purchase Requisitions [sale_operating_unit](sale_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company [sale_stock_operating_unit](sale_stock_operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company From f6e6e10a7fdd327774c0e4588111d536a18ef07d Mon Sep 17 00:00:00 2001 From: OCA Git Bot Date: Wed, 14 Jun 2017 04:42:26 +0200 Subject: [PATCH 15/18] [ADD] setup.py --- .../purchase_request_operating_unit/odoo_addons/__init__.py | 1 + .../odoo_addons/purchase_request_operating_unit | 1 + setup/purchase_request_operating_unit/setup.py | 6 ++++++ .../odoo_addons/__init__.py | 1 + .../odoo_addons/purchase_request_procurement_operating_unit | 1 + setup/purchase_request_procurement_operating_unit/setup.py | 6 ++++++ .../odoo_addons/__init__.py | 1 + .../purchase_request_to_requisition_operating_unit | 1 + .../purchase_request_to_requisition_operating_unit/setup.py | 6 ++++++ .../odoo_addons/__init__.py | 1 + .../odoo_addons/purchase_request_to_rfq_operating_unit | 1 + setup/purchase_request_to_rfq_operating_unit/setup.py | 6 ++++++ 12 files changed, 32 insertions(+) create mode 100644 setup/purchase_request_operating_unit/odoo_addons/__init__.py create mode 120000 setup/purchase_request_operating_unit/odoo_addons/purchase_request_operating_unit create mode 100644 setup/purchase_request_operating_unit/setup.py create mode 100644 setup/purchase_request_procurement_operating_unit/odoo_addons/__init__.py create mode 120000 setup/purchase_request_procurement_operating_unit/odoo_addons/purchase_request_procurement_operating_unit create mode 100644 setup/purchase_request_procurement_operating_unit/setup.py create mode 100644 setup/purchase_request_to_requisition_operating_unit/odoo_addons/__init__.py create mode 120000 setup/purchase_request_to_requisition_operating_unit/odoo_addons/purchase_request_to_requisition_operating_unit create mode 100644 setup/purchase_request_to_requisition_operating_unit/setup.py create mode 100644 setup/purchase_request_to_rfq_operating_unit/odoo_addons/__init__.py create mode 120000 setup/purchase_request_to_rfq_operating_unit/odoo_addons/purchase_request_to_rfq_operating_unit create mode 100644 setup/purchase_request_to_rfq_operating_unit/setup.py diff --git a/setup/purchase_request_operating_unit/odoo_addons/__init__.py b/setup/purchase_request_operating_unit/odoo_addons/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/setup/purchase_request_operating_unit/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/purchase_request_operating_unit/odoo_addons/purchase_request_operating_unit b/setup/purchase_request_operating_unit/odoo_addons/purchase_request_operating_unit new file mode 120000 index 0000000000..813c0515c8 --- /dev/null +++ b/setup/purchase_request_operating_unit/odoo_addons/purchase_request_operating_unit @@ -0,0 +1 @@ +../../../purchase_request_operating_unit \ No newline at end of file diff --git a/setup/purchase_request_operating_unit/setup.py b/setup/purchase_request_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_request_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/purchase_request_procurement_operating_unit/odoo_addons/__init__.py b/setup/purchase_request_procurement_operating_unit/odoo_addons/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/setup/purchase_request_procurement_operating_unit/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/purchase_request_procurement_operating_unit/odoo_addons/purchase_request_procurement_operating_unit b/setup/purchase_request_procurement_operating_unit/odoo_addons/purchase_request_procurement_operating_unit new file mode 120000 index 0000000000..a83def042a --- /dev/null +++ b/setup/purchase_request_procurement_operating_unit/odoo_addons/purchase_request_procurement_operating_unit @@ -0,0 +1 @@ +../../../purchase_request_procurement_operating_unit \ No newline at end of file diff --git a/setup/purchase_request_procurement_operating_unit/setup.py b/setup/purchase_request_procurement_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_request_procurement_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/purchase_request_to_requisition_operating_unit/odoo_addons/__init__.py b/setup/purchase_request_to_requisition_operating_unit/odoo_addons/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/setup/purchase_request_to_requisition_operating_unit/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/purchase_request_to_requisition_operating_unit/odoo_addons/purchase_request_to_requisition_operating_unit b/setup/purchase_request_to_requisition_operating_unit/odoo_addons/purchase_request_to_requisition_operating_unit new file mode 120000 index 0000000000..ae6610f3a5 --- /dev/null +++ b/setup/purchase_request_to_requisition_operating_unit/odoo_addons/purchase_request_to_requisition_operating_unit @@ -0,0 +1 @@ +../../../purchase_request_to_requisition_operating_unit \ No newline at end of file diff --git a/setup/purchase_request_to_requisition_operating_unit/setup.py b/setup/purchase_request_to_requisition_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_request_to_requisition_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/purchase_request_to_rfq_operating_unit/odoo_addons/__init__.py b/setup/purchase_request_to_rfq_operating_unit/odoo_addons/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/setup/purchase_request_to_rfq_operating_unit/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/purchase_request_to_rfq_operating_unit/odoo_addons/purchase_request_to_rfq_operating_unit b/setup/purchase_request_to_rfq_operating_unit/odoo_addons/purchase_request_to_rfq_operating_unit new file mode 120000 index 0000000000..fd4a0e6c1d --- /dev/null +++ b/setup/purchase_request_to_rfq_operating_unit/odoo_addons/purchase_request_to_rfq_operating_unit @@ -0,0 +1 @@ +../../../purchase_request_to_rfq_operating_unit \ No newline at end of file diff --git a/setup/purchase_request_to_rfq_operating_unit/setup.py b/setup/purchase_request_to_rfq_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_request_to_rfq_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From d38bab6b90c30ff4904b545f6f17e4402cff1621 Mon Sep 17 00:00:00 2001 From: mreficent Date: Wed, 12 Apr 2017 12:45:13 +0200 Subject: [PATCH 16/18] [ADD] 9.0-crm_claim_operating_unit --- crm_claim_operating_unit/README.rst | 58 ++++++++++ crm_claim_operating_unit/__init__.py | 7 ++ crm_claim_operating_unit/__openerp__.py | 21 ++++ crm_claim_operating_unit/models/__init__.py | 7 ++ crm_claim_operating_unit/models/crm_claim.py | 80 +++++++++++++ crm_claim_operating_unit/models/crm_team.py | 23 ++++ .../security/crm_security.xml | 21 ++++ .../static/description/icon.png | Bin 0 -> 9455 bytes crm_claim_operating_unit/tests/__init__.py | 6 + .../tests/test_crm_claim_operating_unit.py | 106 ++++++++++++++++++ .../views/crm_claim_view.xml | 44 ++++++++ 11 files changed, 373 insertions(+) create mode 100644 crm_claim_operating_unit/README.rst create mode 100644 crm_claim_operating_unit/__init__.py create mode 100644 crm_claim_operating_unit/__openerp__.py create mode 100644 crm_claim_operating_unit/models/__init__.py create mode 100644 crm_claim_operating_unit/models/crm_claim.py create mode 100644 crm_claim_operating_unit/models/crm_team.py create mode 100644 crm_claim_operating_unit/security/crm_security.xml create mode 100644 crm_claim_operating_unit/static/description/icon.png create mode 100644 crm_claim_operating_unit/tests/__init__.py create mode 100644 crm_claim_operating_unit/tests/test_crm_claim_operating_unit.py create mode 100644 crm_claim_operating_unit/views/crm_claim_view.xml diff --git a/crm_claim_operating_unit/README.rst b/crm_claim_operating_unit/README.rst new file mode 100644 index 0000000000..229f990897 --- /dev/null +++ b/crm_claim_operating_unit/README.rst @@ -0,0 +1,58 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +============================== +CRM Claim with Operating Units +============================== + +This module introduces the following features: + +* Adds the Operating Unit (OU) to the CRM Claim. + +* User can only view and manage the claims associated to the warehouse of the Operating Units that he has access to. + + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.0 + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Eficent Business and IT Consulting Services S.L. +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/crm_claim_operating_unit/__init__.py b/crm_claim_operating_unit/__init__.py new file mode 100644 index 0000000000..871e851766 --- /dev/null +++ b/crm_claim_operating_unit/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. +# © 2015 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import models +from . import tests diff --git a/crm_claim_operating_unit/__openerp__.py b/crm_claim_operating_unit/__openerp__.py new file mode 100644 index 0000000000..5bd948376d --- /dev/null +++ b/crm_claim_operating_unit/__openerp__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2015-17 Eficent Business and IT Consulting Services S.L. +# © 2015 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Operating Unit in CRM Claims", + "version": "9.0.1.0.0", + "author": "Eficent, " + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "category": "Sales", + "depends": ["crm_claim", "operating_unit", "sales_team_operating_unit"], + "data": [ + "security/crm_security.xml", + "views/crm_claim_view.xml" + ], + 'installable': True, +} diff --git a/crm_claim_operating_unit/models/__init__.py b/crm_claim_operating_unit/models/__init__.py new file mode 100644 index 0000000000..e9d40d3be3 --- /dev/null +++ b/crm_claim_operating_unit/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2015-17 Eficent Business and IT Consulting Services S.L. +# © 2015 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import crm_claim +from . import crm_team diff --git a/crm_claim_operating_unit/models/crm_claim.py b/crm_claim_operating_unit/models/crm_claim.py new file mode 100644 index 0000000000..90cad810b3 --- /dev/null +++ b/crm_claim_operating_unit/models/crm_claim.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# © 2015-17 Eficent Business and IT Consulting Services S.L. +# © 2015 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import api, fields, models, _ +from openerp.exceptions import ValidationError + + +class CRMClaim(models.Model): + + _inherit = "crm.claim" + + @api.model + def _default_operating_unit(self): + team_id = self.env['crm.team']._get_default_team_id() + team = self.env['crm.team'].sudo().browse(team_id) + if team.operating_unit_id: + for ou in self.env.user.operating_unit_ids: + if ou.id == team.operating_unit_id.id: + return team.operating_unit_id + return self.env.user.default_operating_unit_id + else: + return self.env.user.default_operating_unit_id + + operating_unit_id = fields.Many2one( + comodel_name='operating.unit', + string='Operating Unit', + default=_default_operating_unit, + ) + + @api.onchange('team_id') + def onchange_team_id(self): + if self.team_id: + team = self.env['crm.team'].search([ + ('id', '=', self.team_id.id), + ('operating_unit_id', 'in', + [g.id for g in self.env.user.operating_unit_ids])]) + if team: + self.operating_unit_id = team.operating_unit_id + else: + self.team_id = False + self.operating_unit_id = False + + @api.onchange('operating_unit_id') + def onchange_operating_unit_id(self): + if self.operating_unit_id: + if self.operating_unit_id.id in \ + [g.id for g in self.env.user.operating_unit_ids]: + if ((not self.team_id) or + (self.team_id and self.team_id.operating_unit_id != + self.operating_unit_id)): + team = self.env['crm.team'].search( + [('operating_unit_id', 'in', + [self.operating_unit_id.id])], limit=1) + if team: + self.team_id = team + else: + self.team_id = False + else: + self.team_id = False + self.operating_unit_id = False + + @api.multi + @api.constrains('team_id') + def _check_team_operating_unit(self): + for rec in self: + if rec.operating_unit_id: + if rec.team_id and rec.team_id.operating_unit_id != \ + rec.operating_unit_id: + raise ValidationError(_('Configuration error\n' + 'The Operating Unit of the claim ' + 'must match with that of the ' + 'sales team.')) + else: + raise ValidationError(_('Configuration error\n' + 'The claim should be assigned to a ' + 'sales team and the Operating Unit ' + 'of the claim must match with that ' + 'of the sales team.')) diff --git a/crm_claim_operating_unit/models/crm_team.py b/crm_claim_operating_unit/models/crm_team.py new file mode 100644 index 0000000000..aa8819cacd --- /dev/null +++ b/crm_claim_operating_unit/models/crm_team.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2015-17 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import api, models, _ +from openerp.exceptions import ValidationError + + +class CRMTeam(models.Model): + + _inherit = "crm.team" + + @api.multi + @api.constrains('operating_unit_id') + def _check_team_operating_unit(self): + for rec in self: + claim = self.env['crm.claim'].search( + [('team_id', '=', rec.id), ('operating_unit_id', '!=', + rec.operating_unit_id.id)]) + if claim: + raise ValidationError(_('Configuration error\n' + 'Claims already exists with another ' + 'Operation Unit')) diff --git a/crm_claim_operating_unit/security/crm_security.xml b/crm_claim_operating_unit/security/crm_security.xml new file mode 100644 index 0000000000..8b924a8dc3 --- /dev/null +++ b/crm_claim_operating_unit/security/crm_security.xml @@ -0,0 +1,21 @@ + + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Claims from allowed operating units + + + + + + + + + diff --git a/crm_claim_operating_unit/static/description/icon.png b/crm_claim_operating_unit/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 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 z 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 Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/crm_claim_operating_unit/tests/__init__.py b/crm_claim_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..6465bd9113 --- /dev/null +++ b/crm_claim_operating_unit/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import test_crm_claim_operating_unit diff --git a/crm_claim_operating_unit/tests/test_crm_claim_operating_unit.py b/crm_claim_operating_unit/tests/test_crm_claim_operating_unit.py new file mode 100644 index 0000000000..c9be4c54a3 --- /dev/null +++ b/crm_claim_operating_unit/tests/test_crm_claim_operating_unit.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- +# © 2015-17 Eficent Business and IT Consulting Services S.L. +# © 2015 Serpent Consulting Services Pvt. Ltd.. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.tests import common + + +class TestCrmClaimOperatingUnit(common.TransactionCase): + + def setUp(self): + super(TestCrmClaimOperatingUnit, self).setUp() + self.res_users_model = self.env['res.users'] + self.crm_claim_model = self.env['crm.claim'] + self.crm_team_model = self.env['crm.team'] + + self.company = self.env.ref('base.main_company') + self.partner = self.env.ref('base.res_partner_1') + self.grp_sale_manager = self.env.ref('base.group_sale_manager') + + # Main Operating Unit + self.main_OU = self.env.ref('operating_unit.main_operating_unit') + # B2C Operating Unit + self.b2c_OU = self.env.ref('operating_unit.b2c_operating_unit') + + # Users + self.user1 = self._create_user('user_1', + [self.grp_sale_manager], + self.company, + [self.main_OU, self.b2c_OU]) + self.user2 = self._create_user('user_2', + [self.grp_sale_manager], + self.company, + [self.b2c_OU]) + self.user3 = self._create_user('user_3', + [self.grp_sale_manager], + self.company, + [self.main_OU, self.b2c_OU]) + # Teams + self.team1 = self._create_crm_team(self.user1.id, self.main_OU) + self.team2 = self._create_crm_team(self.user2.id, self.b2c_OU) + + # Claims + self.crm_claim1 = self._create_crm_claim(self.user1.id, self.main_OU) + self.crm_claim2 = self._create_crm_claim(self.user2.id, self.b2c_OU) + self.crm_claim3 = self._create_crm_claim(self.user3.id) + + def _create_user(self, login, groups, company, operating_units): + """Creates a user.""" + group_ids = [group.id for group in groups] + user = self.res_users_model.create({ + 'name': login, + 'login': login, + 'password': 'demo', + 'email': 'example@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 + + def _create_crm_team(self, uid, operating_unit): + """Create a CRM team.""" + context = {'mail_create_nosubscribe': True} + crm = self.crm_team_model.create({ + 'name': 'CRM team (' + operating_unit.name + ')', + 'operating_unit_id': operating_unit.id + }, context=context) + return crm + + def _create_crm_claim(self, uid, operating_unit=False): + """Creates a CRM Claim.""" + if not operating_unit: + operating_unit = self.crm_claim_model.sudo(uid).\ + _default_operating_unit() + claim = self.crm_claim_model.sudo(uid).create({ + 'name': " Damaged Products ", + 'operating_unit_id': operating_unit.id, + 'partner_id': self.partner.id, + 'user_id': uid, + 'team_id': self.crm_team_model.search( + [('operating_unit_id', 'in', [operating_unit.id])], + limit=1).id + }) + claim.onchange_team_id() + claim.onchange_operating_unit_id() + return claim + + def test_security(self): + # User 2 is only assigned to Operating Unit B2C, and cannot + # access claims of Main Operating Unit. + record = self.crm_claim_model.sudo( + self.user2.id).search([('id', '=', self.crm_claim1.id), + ('operating_unit_id', '=', + self.main_OU.id)]) + self.assertEqual(record.ids, [], 'User 2 should not have access to ' + 'OU %s.' % self.main_OU.name) + + def test_onchange(self): + + self.crm_claim3.operating_unit_id = self.b2c_OU + self.crm_claim3.onchange_operating_unit_id() + + self.assertEqual(self.crm_claim3.team_id.operating_unit_id, + self.b2c_OU, 'User 3 should have ' + 'assigned the operating unit %s.' % self.b2c_OU) diff --git a/crm_claim_operating_unit/views/crm_claim_view.xml b/crm_claim_operating_unit/views/crm_claim_view.xml new file mode 100644 index 0000000000..814d6b5d45 --- /dev/null +++ b/crm_claim_operating_unit/views/crm_claim_view.xml @@ -0,0 +1,44 @@ + + + + + + + CRM - Claims Tree + crm.claim + + + + + + + + + + CRM - Claims Form + crm.claim + + + + + + + + + + + CRM - Claims Search + crm.claim + + + + + + + + + + From 02f956b88461928c276fa3957d2b493012ec823f Mon Sep 17 00:00:00 2001 From: OCA Git Bot Date: Thu, 22 Jun 2017 02:37:31 +0200 Subject: [PATCH 17/18] [UPD] addons table in README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1387c48bd5..ae8d5d35f4 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ addon | version | summary [account_operating_unit](account_operating_unit/) | 9.0.1.0.0 | Introduces Operating Unit fields in invoices and Accounting Entries with clearing account [account_voucher_operating_unit](account_voucher_operating_unit/) | 9.0.1.0.0 | Introduces the operating unit to vouchers [analytic_operating_unit](analytic_operating_unit/) | 9.0.1.0.0 | Analytic Operating Unit +[crm_claim_operating_unit](crm_claim_operating_unit/) | 9.0.1.0.0 | Operating Unit in CRM Claims [crm_operating_unit](crm_operating_unit/) | 9.0.1.0.0 | Operating Unit in CRM [hr_contract_operating_unit](hr_contract_operating_unit/) | 9.0.1.0.0 | HR Contract Operating Unit [operating_unit](operating_unit/) | 9.0.1.0.0 | An operating unit (OU) is an organizational entity part of a company From 6408f32aa7881c9ae18c99d37636fdbaba398c10 Mon Sep 17 00:00:00 2001 From: OCA Git Bot Date: Thu, 22 Jun 2017 04:42:12 +0200 Subject: [PATCH 18/18] [ADD] setup.py --- setup/crm_claim_operating_unit/odoo_addons/__init__.py | 1 + .../odoo_addons/crm_claim_operating_unit | 1 + setup/crm_claim_operating_unit/setup.py | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 setup/crm_claim_operating_unit/odoo_addons/__init__.py create mode 120000 setup/crm_claim_operating_unit/odoo_addons/crm_claim_operating_unit create mode 100644 setup/crm_claim_operating_unit/setup.py diff --git a/setup/crm_claim_operating_unit/odoo_addons/__init__.py b/setup/crm_claim_operating_unit/odoo_addons/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/setup/crm_claim_operating_unit/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/crm_claim_operating_unit/odoo_addons/crm_claim_operating_unit b/setup/crm_claim_operating_unit/odoo_addons/crm_claim_operating_unit new file mode 120000 index 0000000000..aa836c23f4 --- /dev/null +++ b/setup/crm_claim_operating_unit/odoo_addons/crm_claim_operating_unit @@ -0,0 +1 @@ +../../../crm_claim_operating_unit \ No newline at end of file diff --git a/setup/crm_claim_operating_unit/setup.py b/setup/crm_claim_operating_unit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/crm_claim_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)