From cb8744805d69e3e964ce07c13709de9e44d7cb55 Mon Sep 17 00:00:00 2001 From: jbeficent Date: Fri, 16 Sep 2016 01:45:49 +0200 Subject: [PATCH 01/72] stock_operating_unit --- stock_operating_unit/README.rst | 70 ++++++++ stock_operating_unit/__init__.py | 6 + stock_operating_unit/__openerp__.py | 27 +++ stock_operating_unit/data/stock_data.xml | 14 ++ stock_operating_unit/demo/stock_demo.xml | 57 +++++++ stock_operating_unit/model/__init__.py | 6 + stock_operating_unit/model/stock.py | 144 ++++++++++++++++ .../security/stock_security.xml | 63 +++++++ .../static/description/icon.png | Bin 0 -> 9455 bytes stock_operating_unit/tests/__init__.py | 8 + .../tests/test_stock_operating_unit.py | 97 +++++++++++ .../tests/test_stock_picking.py | 21 +++ .../tests/test_stock_security.py | 68 ++++++++ stock_operating_unit/view/stock.xml | 158 ++++++++++++++++++ 14 files changed, 739 insertions(+) create mode 100644 stock_operating_unit/README.rst create mode 100644 stock_operating_unit/__init__.py create mode 100644 stock_operating_unit/__openerp__.py create mode 100644 stock_operating_unit/data/stock_data.xml create mode 100644 stock_operating_unit/demo/stock_demo.xml create mode 100644 stock_operating_unit/model/__init__.py create mode 100644 stock_operating_unit/model/stock.py create mode 100644 stock_operating_unit/security/stock_security.xml create mode 100644 stock_operating_unit/static/description/icon.png create mode 100644 stock_operating_unit/tests/__init__.py create mode 100644 stock_operating_unit/tests/test_stock_operating_unit.py create mode 100644 stock_operating_unit/tests/test_stock_picking.py create mode 100644 stock_operating_unit/tests/test_stock_security.py create mode 100644 stock_operating_unit/view/stock.xml diff --git a/stock_operating_unit/README.rst b/stock_operating_unit/README.rst new file mode 100644 index 0000000000..71be286e3b --- /dev/null +++ b/stock_operating_unit/README.rst @@ -0,0 +1,70 @@ +.. image:: https://img.shields.io/badge/license-AGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +========================== +Stock with Operating Units +========================== + +This module introduces the following features: +- Adds the operating unit to the Warehouse. +- Adds the operating unit to the Stock Location. +- Adds the requesting operating unit to stock pickings. +- Implements user's security access rules. + + +Configuration +============= + +To configure this module, you need to: + +* Assign Operating Unit to Warehouses. +* Assign Operating Unit to Stock Locations. + +Usage +===== + +This module defines the operating unit entity and the user's security rules. +Other modules extend the standard Odoo apps with the OU. + +.. 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 +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://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. diff --git a/stock_operating_unit/__init__.py b/stock_operating_unit/__init__.py new file mode 100644 index 0000000000..42481c3482 --- /dev/null +++ b/stock_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 model diff --git a/stock_operating_unit/__openerp__.py b/stock_operating_unit/__openerp__.py new file mode 100644 index 0000000000..9afa5f3975 --- /dev/null +++ b/stock_operating_unit/__openerp__.py @@ -0,0 +1,27 @@ +# -*- 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": "Stock with Operating Units", + "summary": "An operating unit (OU) is an organizational entity part of a\ + company", + "version": "9.0.1.0.0", + "category": "Generic Modules/Sales & Purchases", + "author": "Eficent, Serpent Consulting Services Pvt. Ltd., " + "Odoo Community Association (OCA)", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "depends": ["stock", "account_operating_unit"], + "data": [ + "security/stock_security.xml", + "data/stock_data.xml", + "view/stock.xml", + ], + "demo": [ + "demo/stock_demo.xml", + ], + "installable": True, +} diff --git a/stock_operating_unit/data/stock_data.xml b/stock_operating_unit/data/stock_data.xml new file mode 100644 index 0000000000..7229f533bc --- /dev/null +++ b/stock_operating_unit/data/stock_data.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/stock_operating_unit/demo/stock_demo.xml b/stock_operating_unit/demo/stock_demo.xml new file mode 100644 index 0000000000..40dbb9cca9 --- /dev/null +++ b/stock_operating_unit/demo/stock_demo.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + Your company child + + + + Chicago + CH + + + + + + + + + + + + + + + + + B2B Warehouse + B2B + + + + + + + + B2C Warehouse + B2C + + + + + + + diff --git a/stock_operating_unit/model/__init__.py b/stock_operating_unit/model/__init__.py new file mode 100644 index 0000000000..49fb8dc2e9 --- /dev/null +++ b/stock_operating_unit/model/__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 stock diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py new file mode 100644 index 0000000000..49e415e390 --- /dev/null +++ b/stock_operating_unit/model/stock.py @@ -0,0 +1,144 @@ +# -*- 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.tools.translate import _ +from openerp import api, fields, models +from openerp.exceptions import Warning as UserError + + +class StockWarehouse(models.Model): + _inherit = "stock.warehouse" + + operating_unit_id = fields.Many2one('operating.unit', + '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 UserError(_('Configuration error!\nThe Company in the\ + Stock Warehouse and in the Operating Unit must be the same.')) + + +class StockLocation(models.Model): + _inherit = 'stock.location' + + operating_unit_id = fields.Many2one('operating.unit', + 'Operating Unit') + + @api.multi + @api.constrains('operating_unit_id') + def _check_warehouse_operating_unit(self): + for rec in self: + warehouse_obj = self.env['stock.warehouse'] + warehouse = warehouse_obj.search([('wh_input_stock_loc_id', 'in', + rec.ids)]) + for w in warehouse: + if rec.operating_unit_id != w.operating_unit_id: + raise UserError(_('Configuration error!\nThis location is\ + assigned to a warehouse that belongs to a\ + different operating unit.')) + warehouse = warehouse_obj.search([('lot_stock_id', 'in', rec.ids)]) + for w in warehouse: + if self.operating_unit_id != w.operating_unit_id: + raise UserError(_('Configuration error!\nThis location is\ + assigned to a warehouse that belongs to a\ + different operating unit.')) + warehouse = warehouse_obj.search([('wh_output_stock_loc_id', 'in', + rec.ids)]) + for w in warehouse: + if rec.operating_unit_id != w.operating_unit_id: + raise UserError(_('Configuration error!\nThis location is\ + assigned to a warehouse that belongs to a different\ + operating unit.')) + + @api.multi + @api.constrains('operating_unit_id') + def _check_required_operating_unit(self): + for rec in self: + if rec.usage == 'internal' and not rec.operating_unit_id: + raise UserError(_('Configuration error!\nThe operating unit\ + should be assigned to internal locations and to non other.')) + if rec.usage != 'internal' and rec.operating_unit_id: + raise UserError(_('Configuration error!\nThe operating unit\ + should be assigned to internal locations and to non other.')) + + @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 UserError(_('Configuration error!\nThe Company in the\ + Stock Location and in the Operating Unit must be the same.')) + + @api.multi + @api.constrains('operating_unit_id', 'location_id') + def _check_parent_operating_unit(self): + for rec in self: + if (rec.location_id and rec.location_id.usage == 'internal' + and rec.operating_unit_id and rec.operating_unit_id + != rec.location_id.operating_unit_id): + raise UserError(_('Configuration error!\nThe Parent\ + Stock Location must belong to the same Operating Unit.')) + + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + operating_unit_id = fields.Many2one('operating.unit', + 'Requesting 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 UserError(_('Configuration error!\nThe Company in the\ + Stock Picking and in the Operating Unit must be the same.')) + + @api.multi + @api.constrains('operating_unit_id', 'move_lines') + def _check_stock_move_operating_unit(self): + for rec in self: + if not rec.operating_unit_id: + return True + operating_unit = rec.operating_unit_id + for sm in rec.move_lines: + if ( + sm.location_id and + sm.location_id.operating_unit_id and + operating_unit != sm.location_id.operating_unit_id + ) and ( + sm.location_dest_id and + sm.location_dest_id.operating_unit_id and + operating_unit != + sm.location_dest_id.operating_unit_id + ): + raise UserError(_('Configuration error!\nThe Stock moves\ + must be related to a location (source or destination)\ + that belongs to the requesting Operating Unit.')) + + +class StockMove(models.Model): + _inherit = 'stock.move' + + operating_unit_id =\ + fields.Many2one('operating.unit', + related='location_id.operating_unit_id', + string='Source Location Operating Unit', readonly=True) + operating_unit_dest_id =\ + fields.Many2one('operating.unit', + related='location_dest_id.operating_unit_id', + string='Dest. Location Operating Unit', readonly=True) diff --git a/stock_operating_unit/security/stock_security.xml b/stock_operating_unit/security/stock_security.xml new file mode 100644 index 0000000000..80b9fd1c3c --- /dev/null +++ b/stock_operating_unit/security/stock_security.xml @@ -0,0 +1,63 @@ + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Warehouses from allowed operating units + + + + + + + + + + ['|',('warehouse_id.operating_unit_id','=',False),('warehouse_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Stock Picking Type from allowed operating units + + + + + + + + + + ['|', ('operating_unit_id','in',[g.id for g + in user.operating_unit_ids]), ('operating_unit_id','=', False)] + Stock locations from allowed operating units + + + + + + + + + + ['|',('location_id.operating_unit_id','=',False),('location_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids]), + '|',('location_dest_id.operating_unit_id','=',False),('location_dest_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Stock moves from allowed operating units + + + + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Stock pickings from allowed operating units + + + + + + + + + diff --git a/stock_operating_unit/static/description/icon.png b/stock_operating_unit/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG0I@qAOHsk$2}yTmVkBp_eHuY$A9)>P6o~I z%aQ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-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/stock_operating_unit/tests/__init__.py b/stock_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..4101fcef9f --- /dev/null +++ b/stock_operating_unit/tests/__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 test_stock_operating_unit +from . import test_stock_picking +from . import test_stock_security diff --git a/stock_operating_unit/tests/test_stock_operating_unit.py b/stock_operating_unit/tests/test_stock_operating_unit.py new file mode 100644 index 0000000000..ff97c067ff --- /dev/null +++ b/stock_operating_unit/tests/test_stock_operating_unit.py @@ -0,0 +1,97 @@ +# -*- 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.addons.stock.tests import common + + +class TestStockOperatingUnit(common.TestStockCommon): + + def setUp(self): + super(TestStockOperatingUnit, self).setUp() + self.ResUsers = self.env['res.users'] + self.WarehouseObj = self.env['stock.warehouse'] + self.LocationObj = self.env['stock.location'] + # company + self.company1 = self.env.ref('base.main_company') + # groups + self.group_purchase_user = self.env.ref('purchase.group_purchase_user') + self.group_stock_manager = self.env.ref('stock.group_stock_manager') + # 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_7') + self.product2 = self.env.ref('product.product_product_9') + self.product3 = self.env.ref('product.product_product_11') + # Locations + b2c_wh = self.env.ref('stock_operating_unit.stock_warehouse_b2c') + b2c_wh.lot_stock_id.write({'operating_unit_id': self.b2c.id}) + self.location_b2c_id = b2c_wh.lot_stock_id.id + self.b2c_type_in_id = b2c_wh.in_type_id.id + self.b2c_type_int_id = b2c_wh.int_type_id.id + # Create users + self.user1_id = self._create_user('stock_user_1', + [self.group_stock_manager], + self.company1, + [self.ou1, self.b2c]) + self.user2_id = self._create_user('stock_user_2', + [self.group_stock_manager], + self.company1, + [self.b2c]) + # Create Incoming Shipments + self.picking_in1 = self._create_picking(self.user1_id, + self.ou1.id, + self.b2c_type_in_id, + self.supplier_location, + self.stock_location) + self.picking_in2 = self._create_picking(self.user2_id, + self.b2c.id, + self.b2c_type_in_id, + self.supplier_location, + self.location_b2c_id) + # Create Internal Shipment + self.picking_int = self._create_picking(self.user1_id, + self.b2c.id, + self.b2c_type_int_id, + self.stock_location, + self.location_b2c_id) + + def _create_user(self, login, groups, company, operating_units): + """ Create a user.""" + group_ids = [group.id for group in groups] + user =\ + self.ResUsers.with_context({'no_reset_password': True}).\ + create({ + 'name': 'Stock User', + 'login': login, + 'password': 'demo', + 'email': 'chicago@yourcompany.com', + 'company_id': company.id, + 'company_ids': [(4, company.id)], + 'operating_unit_ids': [(4, ou.id) for ou in operating_units], + 'groups_id': [(6, 0, group_ids)] + }) + return user.id + + def _create_picking(self, user_id, ou_id, picking_type, src_loc_id, + dest_loc_id): + """Create a Picking.""" + picking = self.PickingObj.sudo(user_id).create({ + 'picking_type_id': picking_type, + 'location_id': src_loc_id, + 'location_dest_id': dest_loc_id, + 'operating_unit_id': ou_id, + }) + self.MoveObj.sudo(user_id).create({ + 'name': 'a move', + 'product_id': self.productA.id, + 'product_uom_qty': 3.0, + 'product_uom': self.productA.uom_id.id, + 'picking_id': picking.id, + 'location_id': src_loc_id, + 'location_dest_id': dest_loc_id, + }) + return picking diff --git a/stock_operating_unit/tests/test_stock_picking.py b/stock_operating_unit/tests/test_stock_picking.py new file mode 100644 index 0000000000..5b0f9732b5 --- /dev/null +++ b/stock_operating_unit/tests/test_stock_picking.py @@ -0,0 +1,21 @@ +# -*- 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_stock_operating_unit as test_stock_ou + + +class TestStockPicking(test_stock_ou.TestStockOperatingUnit): + + def test_stock_picking_ou(self): + """Test Pickings of Stock Operating Unit""" + picking_ids = self.PickingObj.sudo(self.user1_id).\ + search([('id', '=', self.picking_in1.id)]).ids + self.assertNotEqual(picking_ids, [], '') + picking_ids = self.PickingObj.sudo(self.user2_id).\ + search([('id', '=', self.picking_in2.id)]).ids + self.assertNotEqual(picking_ids, []) + picking_ids = self.PickingObj.sudo(self.user1_id).\ + search([('id', '=', self.picking_int.id)]).ids + self.assertNotEqual(picking_ids, []) diff --git a/stock_operating_unit/tests/test_stock_security.py b/stock_operating_unit/tests/test_stock_security.py new file mode 100644 index 0000000000..dc710d64d1 --- /dev/null +++ b/stock_operating_unit/tests/test_stock_security.py @@ -0,0 +1,68 @@ +# -*- 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_stock_operating_unit as test_stock_ou + + +class TestStockPicking(test_stock_ou.TestStockOperatingUnit): + + def test_stock_ou_security(self): + """Test Security of Stock Operating Unit""" + # User 1 can list the warehouses assigned to + # Main and B2C OU + wh_ids =\ + self.WarehouseObj.sudo(self.user1_id).\ + search([('operating_unit_id', 'in', + [self.ou1.id, self.b2c.id])]).ids + self.assertNotEqual(wh_ids, [], 'User does not have access to' + 'Warehouses which belong to Main and B2C' + 'Operating Unit.') + # User 1 can list the locations assigned to Main and b2c OU + location_ids =\ + self.LocationObj.sudo(self.user1_id).\ + search([('operating_unit_id', 'in', + [self.ou1.id, self.b2c.id])]).ids + self.assertNotEqual(location_ids, [], 'User does not have access to' + 'Locations which belong to Main and B2C' + 'Operating Unit.') + # User 2 cannot list the warehouses assigned to Main OU + wh_ids =\ + self.WarehouseObj.sudo(self.user2_id).\ + search([('operating_unit_id', '=', self.ou1.id)]).ids + self.assertEqual(wh_ids, [], 'User 2 should not be able to list' + 'the warehouses assigned to Main Operating Unit.') + # User 2 cannot list the locations assigned to Main OU + location_ids =\ + self.LocationObj.sudo(self.user2_id).\ + search([('operating_unit_id', 'in', + [self.ou1.id])]).ids + self.assertEqual(location_ids, [], 'User 2 should not be able to list' + 'the locations assigned to Main OU.') + pickings = [self.picking_in1.id, self.picking_in2.id, + self.picking_int.id] + # User 1 can list the pickings 1, 2, 3 + picking_ids =\ + self.PickingObj.sudo(self.user1_id).search([('id', 'in', + pickings)]).ids + self.assertNotEqual(picking_ids, [], 'User 1 cannot list the' + 'pickings assigned to pickings 1, 2, 3.') + # User 1 can list the stock moves assigned to pickings 1, 2, 3 + move_ids =\ + self.MoveObj.sudo(self.user1_id).search([('picking_id', 'in', + pickings)]).ids + self.assertNotEqual(move_ids, [], 'User 1 cannot list the' + 'stock moves assigned to pickings 1, 2, 3.') + # User 2 cannot list the the stock moves assigned to picking 1 + move_ids =\ + self.MoveObj.sudo(self.user2_id).\ + search([('picking_id', '=', self.picking_in1.id)]).ids + self.assertEqual(move_ids, [], 'User 2 should not be able to list' + 'the stock moves assigned to picking 1.') + # User 2 cannot list the pickings 1 + picking_ids =\ + self.PickingObj.sudo(self.user2_id).\ + search([('id', '=', self.picking_in1.id)]).ids + self.assertEqual(picking_ids, [], 'User 2 should not be able to list' + 'the picking 1.') diff --git a/stock_operating_unit/view/stock.xml b/stock_operating_unit/view/stock.xml new file mode 100644 index 0000000000..462c611953 --- /dev/null +++ b/stock_operating_unit/view/stock.xml @@ -0,0 +1,158 @@ + + + + + + stock.warehouse + stock.warehouse + + + + + + + + + + stock.warehouse.tree + stock.warehouse + + + + + + + + + + stock.location.form + stock.location + + + + + + + + + + stock.location.tree + stock.location + + + + + + + + + + stock.location.search + stock.location + + + + + + + + + + stock.picking.tree + stock.picking + + + + + + + + + + stock.picking.form + stock.picking + + + + + + + + + + stock.picking.internal.search + stock.picking + + + + + + + + + + + + + stock.move.tree + stock.move + + + + + + + + + + + + + stock.move.tree + stock.move + + + + + + + + + + + + + Stock Moves + stock.move + move_history_ids + + + + + + + + + + + + + stock.move.form + stock.move + + + + + + + + + + + + + From 21fc7e15c72d555869e7f07e983e338e20641469 Mon Sep 17 00:00:00 2001 From: jbeficent Date: Wed, 28 Sep 2016 14:07:18 +0200 Subject: [PATCH 02/72] flake8 issues --- stock_operating_unit/__init__.py | 5 ++--- stock_operating_unit/__openerp__.py | 5 ++--- stock_operating_unit/model/__init__.py | 5 ++--- stock_operating_unit/model/stock.py | 11 +++++------ .../tests/test_stock_operating_unit.py | 6 ++---- stock_operating_unit/tests/test_stock_picking.py | 5 ++--- stock_operating_unit/tests/test_stock_security.py | 5 ++--- 7 files changed, 17 insertions(+), 25 deletions(-) diff --git a/stock_operating_unit/__init__.py b/stock_operating_unit/__init__.py index 42481c3482..54776d1e38 100644 --- a/stock_operating_unit/__init__.py +++ b/stock_operating_unit/__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 +# © 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 diff --git a/stock_operating_unit/__openerp__.py b/stock_operating_unit/__openerp__.py index 9afa5f3975..c861ba0f9c 100644 --- a/stock_operating_unit/__openerp__.py +++ b/stock_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/stock_operating_unit/model/__init__.py b/stock_operating_unit/model/__init__.py index 49fb8dc2e9..a05fa0038b 100644 --- a/stock_operating_unit/model/__init__.py +++ b/stock_operating_unit/model/__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 +# © 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 stock diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 49e415e390..bf1de7cce7 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -1,11 +1,10 @@ # -*- 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.tools.translate import _ from openerp import api, fields, models -from openerp.exceptions import Warning as UserError +from openerp.exceptions import Warning as UserError class StockWarehouse(models.Model): @@ -84,8 +83,8 @@ def _check_company_operating_unit(self): def _check_parent_operating_unit(self): for rec in self: if (rec.location_id and rec.location_id.usage == 'internal' - and rec.operating_unit_id and rec.operating_unit_id - != rec.location_id.operating_unit_id): + and rec.operating_unit_id and rec.operating_unit_id != + rec.location_id.operating_unit_id): raise UserError(_('Configuration error!\nThe Parent\ Stock Location must belong to the same Operating Unit.')) diff --git a/stock_operating_unit/tests/test_stock_operating_unit.py b/stock_operating_unit/tests/test_stock_operating_unit.py index ff97c067ff..291ff1ab7c 100644 --- a/stock_operating_unit/tests/test_stock_operating_unit.py +++ b/stock_operating_unit/tests/test_stock_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.addons.stock.tests import common @@ -16,7 +15,6 @@ def setUp(self): # company self.company1 = self.env.ref('base.main_company') # groups - self.group_purchase_user = self.env.ref('purchase.group_purchase_user') self.group_stock_manager = self.env.ref('stock.group_stock_manager') # Main Operating Unit self.ou1 = self.env.ref('operating_unit.main_operating_unit') diff --git a/stock_operating_unit/tests/test_stock_picking.py b/stock_operating_unit/tests/test_stock_picking.py index 5b0f9732b5..7d0298067c 100644 --- a/stock_operating_unit/tests/test_stock_picking.py +++ b/stock_operating_unit/tests/test_stock_picking.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 . import test_stock_operating_unit as test_stock_ou diff --git a/stock_operating_unit/tests/test_stock_security.py b/stock_operating_unit/tests/test_stock_security.py index dc710d64d1..e738653d0e 100644 --- a/stock_operating_unit/tests/test_stock_security.py +++ b/stock_operating_unit/tests/test_stock_security.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 . import test_stock_operating_unit as test_stock_ou From b3d42378b5f7023c05dfa6ade43d16828aeaf876 Mon Sep 17 00:00:00 2001 From: jbeficent Date: Wed, 28 Sep 2016 14:17:11 +0200 Subject: [PATCH 03/72] flake 8 --- stock_operating_unit/model/stock.py | 10 +++++++--- stock_operating_unit/tests/test_stock_security.py | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index bf1de7cce7..9a588839d2 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -82,9 +82,13 @@ def _check_company_operating_unit(self): @api.constrains('operating_unit_id', 'location_id') def _check_parent_operating_unit(self): for rec in self: - if (rec.location_id and rec.location_id.usage == 'internal' - and rec.operating_unit_id and rec.operating_unit_id != - rec.location_id.operating_unit_id): + if ( + rec.location_id + and rec.location_id.usage == 'internal' + and rec.operating_unit_id + and rec.operating_unit_id != + rec.location_id.operating_unit_id + ): raise UserError(_('Configuration error!\nThe Parent\ Stock Location must belong to the same Operating Unit.')) diff --git a/stock_operating_unit/tests/test_stock_security.py b/stock_operating_unit/tests/test_stock_security.py index e738653d0e..20c2595eef 100644 --- a/stock_operating_unit/tests/test_stock_security.py +++ b/stock_operating_unit/tests/test_stock_security.py @@ -57,8 +57,8 @@ def test_stock_ou_security(self): move_ids =\ self.MoveObj.sudo(self.user2_id).\ search([('picking_id', '=', self.picking_in1.id)]).ids - self.assertEqual(move_ids, [], 'User 2 should not be able to list' - 'the stock moves assigned to picking 1.') + self.assertEqual(move_ids, [], 'User 2 should not be able to list the ' + 'stock moves assigned to picking 1.') # User 2 cannot list the pickings 1 picking_ids =\ self.PickingObj.sudo(self.user2_id).\ From bfa21f2564659e8901d37232cc151279f52098cb Mon Sep 17 00:00:00 2001 From: jbeficent Date: Wed, 28 Sep 2016 14:35:37 +0200 Subject: [PATCH 04/72] flake 8 --- stock_operating_unit/model/stock.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 9a588839d2..7dcbc6e491 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -83,11 +83,10 @@ def _check_company_operating_unit(self): def _check_parent_operating_unit(self): for rec in self: if ( - rec.location_id - and rec.location_id.usage == 'internal' - and rec.operating_unit_id - and rec.operating_unit_id != - rec.location_id.operating_unit_id + rec.location_id and + rec.location_id.usage == 'internal' and + rec.operating_unit_id and + rec.operating_unit_id != rec.location_id.operating_unit_id ): raise UserError(_('Configuration error!\nThe Parent\ Stock Location must belong to the same Operating Unit.')) From 01173fcf1f07fbc91a4d0f7e2bf53f100e0611a8 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Fri, 30 Sep 2016 14:09:52 +0200 Subject: [PATCH 05/72] update contributors --- stock_operating_unit/README.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stock_operating_unit/README.rst b/stock_operating_unit/README.rst index 71be286e3b..387368885c 100644 --- a/stock_operating_unit/README.rst +++ b/stock_operating_unit/README.rst @@ -51,8 +51,9 @@ Images Contributors ------------ -* Eficent -* Serpent Consulting Services Pvt. Ltd. +* Jordi Ballester Alomar +* Aaron Henriquez +* Sudhir Arya Maintainer ---------- From 06817d60f0abb06479ef7c8fac1826e88d93629c Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Tue, 4 Oct 2016 15:21:16 +0200 Subject: [PATCH 06/72] code style --- stock_operating_unit/model/stock.py | 77 ++++++++++++++--------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 7dcbc6e491..bcca89425c 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -37,26 +37,23 @@ class StockLocation(models.Model): def _check_warehouse_operating_unit(self): for rec in self: warehouse_obj = self.env['stock.warehouse'] - warehouse = warehouse_obj.search([('wh_input_stock_loc_id', 'in', - rec.ids)]) - for w in warehouse: + warehouses = warehouse_obj.search( + ['|','|',('wh_input_stock_loc_id','=',rec.ids[0]), + ('lot_stock_id', 'in', rec.ids), + ('wh_output_stock_loc_id', 'in', rec.ids)]) + for w in warehouses: if rec.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error!\nThis location is\ - assigned to a warehouse that belongs to a\ - different operating unit.')) - warehouse = warehouse_obj.search([('lot_stock_id', 'in', rec.ids)]) - for w in warehouse: + raise UserError(_('Configuration error!\nThis location is ' + 'assigned to a warehouse that belongs to' + ' a different operating unit.')) if self.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error!\nThis location is\ - assigned to a warehouse that belongs to a\ - different operating unit.')) - warehouse = warehouse_obj.search([('wh_output_stock_loc_id', 'in', - rec.ids)]) - for w in warehouse: + raise UserError(_('Configuration error!\nThis location is ' + 'assigned to a warehouse that belongs to' + ' a different operating unit.')) if rec.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error!\nThis location is\ - assigned to a warehouse that belongs to a different\ - operating unit.')) + raise UserError(_('Configuration error!\nThis location is' + ' assigned to a warehouse that belongs' + ' to a different operating unit.')) @api.multi @api.constrains('operating_unit_id') @@ -110,28 +107,6 @@ def _check_company_operating_unit(self): raise UserError(_('Configuration error!\nThe Company in the\ Stock Picking and in the Operating Unit must be the same.')) - @api.multi - @api.constrains('operating_unit_id', 'move_lines') - def _check_stock_move_operating_unit(self): - for rec in self: - if not rec.operating_unit_id: - return True - operating_unit = rec.operating_unit_id - for sm in rec.move_lines: - if ( - sm.location_id and - sm.location_id.operating_unit_id and - operating_unit != sm.location_id.operating_unit_id - ) and ( - sm.location_dest_id and - sm.location_dest_id.operating_unit_id and - operating_unit != - sm.location_dest_id.operating_unit_id - ): - raise UserError(_('Configuration error!\nThe Stock moves\ - must be related to a location (source or destination)\ - that belongs to the requesting Operating Unit.')) - class StockMove(models.Model): _inherit = 'stock.move' @@ -144,3 +119,27 @@ class StockMove(models.Model): fields.Many2one('operating.unit', related='location_dest_id.operating_unit_id', string='Dest. Location Operating Unit', readonly=True) + + + @api.multi + @api.constrains('operating_unit_id', 'location_id', + 'operating_unit_dest_id', 'location_dest_id') + def _check_stock_move_operating_unit(self): + for stock_move in self: + if not stock_move.operating_unit_id: + return True + operating_unit = stock_move.operating_unit_id + if ( + stock_move.location_id and + stock_move.location_id.operating_unit_id and + operating_unit != stock_move.location_id. + operating_unit_id + ) and ( + stock_move.location_dest_id and + stock_move.location_dest_id.operating_unit_id and + operating_unit != + stock_move.location_dest_id.operating_unit_id + ): + raise UserError(_('Configuration error!\nThe Stock moves\ + must be related to a location (source or destination)\ + that belongs to the requesting Operating Unit.')) From 5ba87af17231b5b05e0f8546781b8ca6b5aae526 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Tue, 4 Oct 2016 16:19:31 +0200 Subject: [PATCH 07/72] constraint that checks the OU in the picking matches the one in the move --- stock_operating_unit/model/stock.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index bcca89425c..b4190b981b 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -122,23 +122,26 @@ class StockMove(models.Model): @api.multi - @api.constrains('operating_unit_id', 'location_id', + @api.constrains('operating_unit_id', 'location_id', 'picking_id', 'operating_unit_dest_id', 'location_dest_id') def _check_stock_move_operating_unit(self): for stock_move in self: if not stock_move.operating_unit_id: return True operating_unit = stock_move.operating_unit_id + operating_unit_dest = stock_move.operating_unit_dest_id if ( stock_move.location_id and stock_move.location_id.operating_unit_id and - operating_unit != stock_move.location_id. + stock_move.picking_id and + operating_unit != stock_move.picking_id. operating_unit_id ) and ( stock_move.location_dest_id and stock_move.location_dest_id.operating_unit_id and - operating_unit != - stock_move.location_dest_id.operating_unit_id + stock_move.picking_id and + operating_unit_dest != + stock_move.picking_id.operating_unit_id ): raise UserError(_('Configuration error!\nThe Stock moves\ must be related to a location (source or destination)\ From 40fd7e89d273d0b7dd05a6d2296b604dffed6ebd Mon Sep 17 00:00:00 2001 From: jbeficent Date: Wed, 5 Oct 2016 17:16:13 +0200 Subject: [PATCH 08/72] the operating unit in pickings should derive from the picking type --- stock_operating_unit/model/stock.py | 32 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index b4190b981b..7a65500476 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -38,7 +38,7 @@ def _check_warehouse_operating_unit(self): for rec in self: warehouse_obj = self.env['stock.warehouse'] warehouses = warehouse_obj.search( - ['|','|',('wh_input_stock_loc_id','=',rec.ids[0]), + ['|', '|', ('wh_input_stock_loc_id', '=', rec.ids[0]), ('lot_stock_id', 'in', rec.ids), ('wh_output_stock_loc_id', 'in', rec.ids)]) for w in warehouses: @@ -93,10 +93,20 @@ class StockPicking(models.Model): _inherit = 'stock.picking' operating_unit_id = fields.Many2one('operating.unit', - 'Requesting Operating Unit', - default=lambda self: - self.env['res.users']. - operating_unit_default_get(self._uid)) + 'Requesting Operating Unit') + + @api.v7 + def onchange_picking_type(self, cr, uid, ids, picking_type_id, partner_id, + context=None): + res = super(StockPicking, self).onchange_picking_type( + cr, uid, ids, picking_type_id, partner_id, context=context) + if picking_type_id: + picking_type = self.pool.get('stock.picking.type').browse( + cr, uid, picking_type_id, context=context) or None + res['value']['operating_unit_id'] = \ + picking_type.warehouse_id.operating_unit_id and \ + picking_type.warehouse_id.operating_unit_id.id or False + return res @api.multi @api.constrains('operating_unit_id', 'company_id') @@ -107,6 +117,17 @@ def _check_company_operating_unit(self): raise UserError(_('Configuration error!\nThe Company in the\ Stock Picking and in the Operating Unit must be the same.')) + @api.multi + @api.constrains('operating_unit_id', 'picking_type_id') + def _check_picking_type_operating_unit(self): + for rec in self: + if rec.picking_type_id and rec.operating_unit_id and \ + rec.picking_type_id.warehouse_id.operating_unit_id != \ + rec.operating_unit_id: + raise UserError(_('Configuration error!\nThe Operating Unit ' + 'of the picking must be the same as that ' + 'of the warehouse of the Picking Type.')) + class StockMove(models.Model): _inherit = 'stock.move' @@ -120,7 +141,6 @@ class StockMove(models.Model): related='location_dest_id.operating_unit_id', string='Dest. Location Operating Unit', readonly=True) - @api.multi @api.constrains('operating_unit_id', 'location_id', 'picking_id', 'operating_unit_dest_id', 'location_dest_id') From 142840561abffd4ef41d19cf6a70079d31f0d03b Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Wed, 5 Oct 2016 17:52:10 +0200 Subject: [PATCH 09/72] travis issues --- stock_operating_unit/model/stock.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 7a65500476..6412d68d89 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -151,17 +151,17 @@ def _check_stock_move_operating_unit(self): operating_unit = stock_move.operating_unit_id operating_unit_dest = stock_move.operating_unit_dest_id if ( - stock_move.location_id and - stock_move.location_id.operating_unit_id and - stock_move.picking_id and + stock_move.location_id and + stock_move.location_id.operating_unit_id and + stock_move.picking_id and operating_unit != stock_move.picking_id. - operating_unit_id + operating_unit_id ) and ( - stock_move.location_dest_id and - stock_move.location_dest_id.operating_unit_id and + stock_move.location_dest_id and + stock_move.location_dest_id.operating_unit_id and stock_move.picking_id and - operating_unit_dest != - stock_move.picking_id.operating_unit_id + operating_unit_dest != + stock_move.picking_id.operating_unit_id ): raise UserError(_('Configuration error!\nThe Stock moves\ must be related to a location (source or destination)\ From 9177437903d12942e54bbb9694f5456c2f2cdd0a Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Fri, 4 Nov 2016 10:56:58 +0100 Subject: [PATCH 10/72] travis issues and test stock picking --- stock_operating_unit/model/stock.py | 16 ++++++++-------- .../tests/test_stock_operating_unit.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 6412d68d89..0a3139393c 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -152,16 +152,16 @@ def _check_stock_move_operating_unit(self): operating_unit_dest = stock_move.operating_unit_dest_id if ( stock_move.location_id and - stock_move.location_id.operating_unit_id and - stock_move.picking_id and - operating_unit != stock_move.picking_id. - operating_unit_id + stock_move.location_id.operating_unit_id and + stock_move.picking_id and + operating_unit != + stock_move.picking_id.operating_unit_id ) and ( stock_move.location_dest_id and - stock_move.location_dest_id.operating_unit_id and - stock_move.picking_id and - operating_unit_dest != - stock_move.picking_id.operating_unit_id + stock_move.location_dest_id.operating_unit_id and + stock_move.picking_id and + operating_unit_dest != + stock_move.picking_id.operating_unit_id ): raise UserError(_('Configuration error!\nThe Stock moves\ must be related to a location (source or destination)\ diff --git a/stock_operating_unit/tests/test_stock_operating_unit.py b/stock_operating_unit/tests/test_stock_operating_unit.py index 291ff1ab7c..895b0523f7 100644 --- a/stock_operating_unit/tests/test_stock_operating_unit.py +++ b/stock_operating_unit/tests/test_stock_operating_unit.py @@ -41,7 +41,7 @@ def setUp(self): [self.b2c]) # Create Incoming Shipments self.picking_in1 = self._create_picking(self.user1_id, - self.ou1.id, + self.b2c.id, self.b2c_type_in_id, self.supplier_location, self.stock_location) From 636c914962fdd4e2e4583d85b1e562ed01e4c4a6 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Fri, 4 Nov 2016 11:55:54 +0100 Subject: [PATCH 11/72] test stock security according picking 1 in test_stock_picking --- stock_operating_unit/tests/test_stock_security.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_operating_unit/tests/test_stock_security.py b/stock_operating_unit/tests/test_stock_security.py index 20c2595eef..f2a87e78e4 100644 --- a/stock_operating_unit/tests/test_stock_security.py +++ b/stock_operating_unit/tests/test_stock_security.py @@ -59,9 +59,9 @@ def test_stock_ou_security(self): search([('picking_id', '=', self.picking_in1.id)]).ids self.assertEqual(move_ids, [], 'User 2 should not be able to list the ' 'stock moves assigned to picking 1.') - # User 2 cannot list the pickings 1 + # User 2 can list the picking 1 picking_ids =\ self.PickingObj.sudo(self.user2_id).\ search([('id', '=', self.picking_in1.id)]).ids - self.assertEqual(picking_ids, [], 'User 2 should not be able to list' + self.assertEqual(len(picking_ids), 1, 'User 2 should be able to list' 'the picking 1.') From eab0f79008b605f06d6cd88fd4652ecf61ad42e2 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 16 Jan 2017 17:47:41 +0100 Subject: [PATCH 12/72] Update operating units of previous locations --- stock_operating_unit/__init__.py | 1 + stock_operating_unit/__openerp__.py | 1 + stock_operating_unit/hooks.py | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 stock_operating_unit/hooks.py diff --git a/stock_operating_unit/__init__.py b/stock_operating_unit/__init__.py index 54776d1e38..0bb5c16af1 100644 --- a/stock_operating_unit/__init__.py +++ b/stock_operating_unit/__init__.py @@ -3,3 +3,4 @@ # © 2016 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import model +from .hooks import update_operating_unit_location diff --git a/stock_operating_unit/__openerp__.py b/stock_operating_unit/__openerp__.py index c861ba0f9c..e9553966d2 100644 --- a/stock_operating_unit/__openerp__.py +++ b/stock_operating_unit/__openerp__.py @@ -23,4 +23,5 @@ "demo/stock_demo.xml", ], "installable": True, + "post_init_hook": "update_operating_unit_location", } diff --git a/stock_operating_unit/hooks.py b/stock_operating_unit/hooks.py new file mode 100644 index 0000000000..76566224d8 --- /dev/null +++ b/stock_operating_unit/hooks.py @@ -0,0 +1,20 @@ +# -*- 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 SUPERUSER_ID +from openerp.api import Environment + +def update_operating_unit_location(cr, registry): + env = Environment(cr, SUPERUSER_ID, {}) + warehouses = env['stock.warehouse'].search([]) + for warehouse in warehouses: + operating_unit = warehouse.operating_unit_id + parent_location = warehouse.view_location_id + locations = env['stock.location'].search( + [('id', 'child_of', [parent_location.id]), + ('usage', '=', 'internal')]) + for location in locations: + if operating_unit: + location.write({'operating_unit_id': operating_unit.id}) + return True From 94c5b75f1831817ebe317a7967edd4a0944edd16 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Tue, 17 Jan 2017 10:01:19 +0100 Subject: [PATCH 13/72] lint check operating_unit_id readonly in the picking --- stock_operating_unit/hooks.py | 3 ++- stock_operating_unit/model/stock.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/stock_operating_unit/hooks.py b/stock_operating_unit/hooks.py index 76566224d8..1239564667 100644 --- a/stock_operating_unit/hooks.py +++ b/stock_operating_unit/hooks.py @@ -5,6 +5,7 @@ from openerp import SUPERUSER_ID from openerp.api import Environment + def update_operating_unit_location(cr, registry): env = Environment(cr, SUPERUSER_ID, {}) warehouses = env['stock.warehouse'].search([]) @@ -13,7 +14,7 @@ def update_operating_unit_location(cr, registry): parent_location = warehouse.view_location_id locations = env['stock.location'].search( [('id', 'child_of', [parent_location.id]), - ('usage', '=', 'internal')]) + ('usage', '=', 'internal')]) for location in locations: if operating_unit: location.write({'operating_unit_id': operating_unit.id}) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 0a3139393c..8ec10c4e0b 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -93,7 +93,8 @@ class StockPicking(models.Model): _inherit = 'stock.picking' operating_unit_id = fields.Many2one('operating.unit', - 'Requesting Operating Unit') + 'Requesting Operating Unit', + readonly=1) @api.v7 def onchange_picking_type(self, cr, uid, ids, picking_type_id, partner_id, From 318428292cec3d0bcd89e2046cc6944f00af34b1 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 23 Jan 2017 11:06:22 +0100 Subject: [PATCH 14/72] Correct error message and xml files * Replace and elements by * Remove spaces in strings introduced because of \ * Remove exclamation points in error messages * Remove most of the \ where it can be replaced by parenthesis --- stock_operating_unit/__openerp__.py | 4 +- stock_operating_unit/data/stock_data.xml | 18 +- stock_operating_unit/demo/stock_demo.xml | 110 ++++--- stock_operating_unit/model/stock.py | 134 +++++---- .../security/stock_security.xml | 110 ++++--- stock_operating_unit/view/stock.xml | 284 +++++++++--------- 6 files changed, 333 insertions(+), 327 deletions(-) diff --git a/stock_operating_unit/__openerp__.py b/stock_operating_unit/__openerp__.py index e9553966d2..c6bffd06a5 100644 --- a/stock_operating_unit/__openerp__.py +++ b/stock_operating_unit/__openerp__.py @@ -5,8 +5,8 @@ { "name": "Stock with Operating Units", - "summary": "An operating unit (OU) is an organizational entity part of a\ - company", + "summary": "An operating unit (OU) is an organizational entity part of a " + "company", "version": "9.0.1.0.0", "category": "Generic Modules/Sales & Purchases", "author": "Eficent, Serpent Consulting Services Pvt. Ltd., " diff --git a/stock_operating_unit/data/stock_data.xml b/stock_operating_unit/data/stock_data.xml index 7229f533bc..11638e3b88 100644 --- a/stock_operating_unit/data/stock_data.xml +++ b/stock_operating_unit/data/stock_data.xml @@ -1,14 +1,12 @@ - - + - - - + + + - - - + + + - - + diff --git a/stock_operating_unit/demo/stock_demo.xml b/stock_operating_unit/demo/stock_demo.xml index 40dbb9cca9..b82736abea 100644 --- a/stock_operating_unit/demo/stock_demo.xml +++ b/stock_operating_unit/demo/stock_demo.xml @@ -1,57 +1,55 @@ - - - - - - - - - - - - - - - - - Your company child - - - - Chicago - CH - - - - - - - - - - - - - - - - - B2B Warehouse - B2B - - - - - - - - B2C Warehouse - B2C - - - - - - - + + + + + + + + + + + + + + + + Your company child + + + + Chicago + CH + + + + + + + + + + + + + + + + + B2B Warehouse + B2B + + + + + + + + B2C Warehouse + B2C + + + + + + diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 8ec10c4e0b..c8700090a3 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -2,28 +2,30 @@ # © 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.tools.translate import _ -from openerp import api, fields, models -from openerp.exceptions import Warning as UserError +from openerp import _, api, fields, models +from openerp.exceptions import UserError class StockWarehouse(models.Model): _inherit = "stock.warehouse" - operating_unit_id = fields.Many2one('operating.unit', - 'Operating Unit', - default=lambda self: - self.env['res.users']. - operating_unit_default_get(self._uid)) + operating_unit_id = fields.Many2one( + comodel_name='operating.unit', + string='Operating Unit', + default=lambda self: (self.env['res.users']. + operating_unit_default_get(self.env.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 UserError(_('Configuration error!\nThe Company in the\ - Stock Warehouse and in the Operating Unit must be the same.')) + if (rec.company_id and rec.operating_unit_id and + rec.company_id != rec.operating_unit_id.company_id): + raise UserError( + _('Configuration error\nThe Company in the Stock Warehouse' + ' and in the Operating Unit must be the same.') + ) class StockLocation(models.Model): @@ -43,15 +45,15 @@ def _check_warehouse_operating_unit(self): ('wh_output_stock_loc_id', 'in', rec.ids)]) for w in warehouses: if rec.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error!\nThis location is ' + raise UserError(_('Configuration error\nThis location is ' 'assigned to a warehouse that belongs to' ' a different operating unit.')) if self.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error!\nThis location is ' + raise UserError(_('Configuration error\nThis location is ' 'assigned to a warehouse that belongs to' ' a different operating unit.')) if rec.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error!\nThis location is' + raise UserError(_('Configuration error\nThis location is' ' assigned to a warehouse that belongs' ' to a different operating unit.')) @@ -60,20 +62,25 @@ def _check_warehouse_operating_unit(self): def _check_required_operating_unit(self): for rec in self: if rec.usage == 'internal' and not rec.operating_unit_id: - raise UserError(_('Configuration error!\nThe operating unit\ - should be assigned to internal locations and to non other.')) + raise UserError( + _('Configuration error\nThe operating unit should be ' + 'assigned to internal locations and to non other.') + ) if rec.usage != 'internal' and rec.operating_unit_id: - raise UserError(_('Configuration error!\nThe operating unit\ - should be assigned to internal locations and to non other.')) + raise UserError( + _('Configuration error\nThe operating unit should be ' + 'assigned to internal locations and to non other.') + ) @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 UserError(_('Configuration error!\nThe Company in the\ - Stock Location and in the Operating Unit must be the same.')) + if (rec.company_id and rec.operating_unit_id and + rec.company_id != rec.operating_unit_id.company_id): + raise UserError( + _('Configuration error\nThe Company in the Stock Location ' + 'and in the Operating Unit must be the same.')) @api.multi @api.constrains('operating_unit_id', 'location_id') @@ -85,8 +92,10 @@ def _check_parent_operating_unit(self): rec.operating_unit_id and rec.operating_unit_id != rec.location_id.operating_unit_id ): - raise UserError(_('Configuration error!\nThe Parent\ - Stock Location must belong to the same Operating Unit.')) + raise UserError( + _('Configuration error\nThe Parent Stock Location ' + 'must belong to the same Operating Unit.') + ) class StockPicking(models.Model): @@ -102,45 +111,51 @@ def onchange_picking_type(self, cr, uid, ids, picking_type_id, partner_id, res = super(StockPicking, self).onchange_picking_type( cr, uid, ids, picking_type_id, partner_id, context=context) if picking_type_id: - picking_type = self.pool.get('stock.picking.type').browse( + picking_type = self.pool['stock.picking.type'].browse( cr, uid, picking_type_id, context=context) or None - res['value']['operating_unit_id'] = \ - picking_type.warehouse_id.operating_unit_id and \ - picking_type.warehouse_id.operating_unit_id.id or False + unit = picking_type.warehouse_id.operating_unit_id + if unit: + res['value']['operating_unit_id'] = unit.id return res @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 UserError(_('Configuration error!\nThe Company in the\ - Stock Picking and in the Operating Unit must be the same.')) + if (rec.company_id and rec.operating_unit_id and + rec.company_id != rec.operating_unit_id.company_id): + raise UserError( + _('Configuration error\nThe Company in the Stock Picking ' + 'and in the Operating Unit must be the same.') + ) @api.multi @api.constrains('operating_unit_id', 'picking_type_id') def _check_picking_type_operating_unit(self): for rec in self: - if rec.picking_type_id and rec.operating_unit_id and \ - rec.picking_type_id.warehouse_id.operating_unit_id != \ - rec.operating_unit_id: - raise UserError(_('Configuration error!\nThe Operating Unit ' - 'of the picking must be the same as that ' - 'of the warehouse of the Picking Type.')) + warehouse = rec.picking_type_id.warehouse_id + if (rec.picking_type_id and rec.operating_unit_id and + warehouse.operating_unit_id != rec.operating_unit_id): + raise UserError( + _('Configuration error\nThe Operating Unit of the picking ' + 'must be the same as that of the warehouse of the ' + 'Picking Type.') + ) class StockMove(models.Model): _inherit = 'stock.move' - operating_unit_id =\ - fields.Many2one('operating.unit', - related='location_id.operating_unit_id', - string='Source Location Operating Unit', readonly=True) - operating_unit_dest_id =\ - fields.Many2one('operating.unit', - related='location_dest_id.operating_unit_id', - string='Dest. Location Operating Unit', readonly=True) + operating_unit_id = fields.Many2one( + related='location_id.operating_unit_id', + string='Source Location Operating Unit', + readonly=True, + ) + operating_unit_dest_id = fields.Many2one( + related='location_dest_id.operating_unit_id', + string='Dest. Location Operating Unit', + readonly=True, + ) @api.multi @api.constrains('operating_unit_id', 'location_id', 'picking_id', @@ -151,19 +166,18 @@ def _check_stock_move_operating_unit(self): return True operating_unit = stock_move.operating_unit_id operating_unit_dest = stock_move.operating_unit_dest_id - if ( - stock_move.location_id and + if (stock_move.location_id and stock_move.location_id.operating_unit_id and stock_move.picking_id and - operating_unit != - stock_move.picking_id.operating_unit_id - ) and ( - stock_move.location_dest_id and - stock_move.location_dest_id.operating_unit_id and - stock_move.picking_id and - operating_unit_dest != - stock_move.picking_id.operating_unit_id + operating_unit != stock_move.picking_id.operating_unit_id + ) and ( + stock_move.location_dest_id and + stock_move.location_dest_id.operating_unit_id and + stock_move.picking_id and + operating_unit_dest != stock_move.picking_id.operating_unit_id ): - raise UserError(_('Configuration error!\nThe Stock moves\ - must be related to a location (source or destination)\ - that belongs to the requesting Operating Unit.')) + raise UserError( + _('Configuration error\nThe Stock moves must ' + 'be related to a location (source or destination) ' + 'that belongs to the requesting Operating Unit.') + ) diff --git a/stock_operating_unit/security/stock_security.xml b/stock_operating_unit/security/stock_security.xml index 80b9fd1c3c..f6fc3a9cfc 100644 --- a/stock_operating_unit/security/stock_security.xml +++ b/stock_operating_unit/security/stock_security.xml @@ -1,63 +1,61 @@ - - + - - - ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] - Warehouses from allowed operating units - - - - - - + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Warehouses from allowed operating units + + + + + + - - - ['|',('warehouse_id.operating_unit_id','=',False),('warehouse_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] - Stock Picking Type from allowed operating units - - - - - - + + + ['|',('warehouse_id.operating_unit_id','=',False),('warehouse_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Stock Picking Type from allowed operating units + + + + + + - - - ['|', ('operating_unit_id','in',[g.id for g - in user.operating_unit_ids]), ('operating_unit_id','=', False)] - Stock locations from allowed operating units - - - - - - + + + ['|', ('operating_unit_id','in',[g.id for g + in user.operating_unit_ids]), ('operating_unit_id','=', False)] + Stock locations from allowed operating units + + + + + + - - - ['|',('location_id.operating_unit_id','=',False),('location_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids]), - '|',('location_dest_id.operating_unit_id','=',False),('location_dest_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] - Stock moves from allowed operating units - - - - - - + + + ['|',('location_id.operating_unit_id','=',False),('location_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids]), + '|',('location_dest_id.operating_unit_id','=',False),('location_dest_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Stock moves from allowed operating units + + + + + + - - - ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] - Stock pickings from allowed operating units - - - - - - + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Stock pickings from allowed operating units + + + + + + - - + diff --git a/stock_operating_unit/view/stock.xml b/stock_operating_unit/view/stock.xml index 462c611953..54bf6c0097 100644 --- a/stock_operating_unit/view/stock.xml +++ b/stock_operating_unit/view/stock.xml @@ -1,158 +1,156 @@ - - + - - stock.warehouse - stock.warehouse - - - - - - - + + stock.warehouse + stock.warehouse + + + + + + + - - stock.warehouse.tree - stock.warehouse - - - - - - - + + stock.warehouse.tree + stock.warehouse + + + + + + + - - stock.location.form - stock.location - - - - - - - + + stock.location.form + stock.location + + + + + + + - - stock.location.tree - stock.location - - - - - - - + + stock.location.tree + stock.location + + + + + + + - - stock.location.search - stock.location - - - - - - - + + stock.location.search + stock.location + + + + + + + - - stock.picking.tree - stock.picking - - - - - - - + + stock.picking.tree + stock.picking + + + + + + + - - stock.picking.form - stock.picking - - - - - - - + + stock.picking.form + stock.picking + + + + + + + - - stock.picking.internal.search - stock.picking - - - - - - - - + + stock.picking.internal.search + stock.picking + + + + - + + + + + - - stock.move.tree - stock.move - - - - - - - - - - + + stock.move.tree + stock.move + + + + + + + + + + - - stock.move.tree - stock.move - - - - - - - - - - + + stock.move.tree + stock.move + + + + + + + + + + - - Stock Moves - stock.move - move_history_ids - - - - - - - - - - + + Stock Moves + stock.move + move_history_ids + + + + + + + + + + - - stock.move.form - stock.move - - - - - - - - - - + + stock.move.form + stock.move + + + + + + + + + + - - + From 49fda7d94c2e097db4aed2681211c4c4756e8022 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Thu, 26 Jan 2017 14:51:00 +0100 Subject: [PATCH 15/72] [MIG] stock_operating_unit to v10.0 --- stock_operating_unit/README.rst | 2 +- stock_operating_unit/__init__.py | 4 +- .../{__openerp__.py => __manifest__.py} | 9 +++-- stock_operating_unit/data/stock_data.xml | 3 ++ stock_operating_unit/demo/stock_demo.xml | 5 ++- stock_operating_unit/hooks.py | 4 +- stock_operating_unit/model/__init__.py | 4 +- stock_operating_unit/model/stock.py | 38 +++++++++++-------- .../security/stock_security.xml | 4 +- stock_operating_unit/tests/__init__.py | 4 +- .../tests/test_stock_operating_unit.py | 4 +- .../tests/test_stock_picking.py | 4 +- .../tests/test_stock_security.py | 4 +- stock_operating_unit/view/stock.xml | 4 +- 14 files changed, 56 insertions(+), 37 deletions(-) rename stock_operating_unit/{__openerp__.py => __manifest__.py} (75%) diff --git a/stock_operating_unit/README.rst b/stock_operating_unit/README.rst index 387368885c..180248a453 100644 --- a/stock_operating_unit/README.rst +++ b/stock_operating_unit/README.rst @@ -29,7 +29,7 @@ Other modules extend the standard Odoo apps with the OU. .. 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 + :target: https://runbot.odoo-community.org/runbot/213/10.0 Bug Tracker =========== diff --git a/stock_operating_unit/__init__.py b/stock_operating_unit/__init__.py index 0bb5c16af1..44392c204f 100644 --- a/stock_operating_unit/__init__.py +++ b/stock_operating_unit/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2016 Eficent Business and IT Consulting Services S.L. -# © 2016 Serpent Consulting Services Pvt. Ltd. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import model from .hooks import update_operating_unit_location diff --git a/stock_operating_unit/__openerp__.py b/stock_operating_unit/__manifest__.py similarity index 75% rename from stock_operating_unit/__openerp__.py rename to stock_operating_unit/__manifest__.py index c6bffd06a5..f1218b8781 100644 --- a/stock_operating_unit/__openerp__.py +++ b/stock_operating_unit/__manifest__.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- -# © 2016 Eficent Business and IT Consulting Services S.L. -# © 2016 Serpent Consulting Services Pvt. Ltd. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "Stock with Operating Units", "summary": "An operating unit (OU) is an organizational entity part of a " "company", - "version": "9.0.1.0.0", + "version": "10.0.1.0.0", "category": "Generic Modules/Sales & Purchases", - "author": "Eficent, Serpent Consulting Services Pvt. Ltd., " + "author": "Eficent, " + "Serpent Consulting Services Pvt. Ltd., " "Odoo Community Association (OCA)", "license": "LGPL-3", "website": "http://www.eficent.com", diff --git a/stock_operating_unit/data/stock_data.xml b/stock_operating_unit/data/stock_data.xml index 11638e3b88..ab3f36c1b8 100644 --- a/stock_operating_unit/data/stock_data.xml +++ b/stock_operating_unit/data/stock_data.xml @@ -1,4 +1,7 @@ + diff --git a/stock_operating_unit/demo/stock_demo.xml b/stock_operating_unit/demo/stock_demo.xml index b82736abea..ceed68b222 100644 --- a/stock_operating_unit/demo/stock_demo.xml +++ b/stock_operating_unit/demo/stock_demo.xml @@ -1,4 +1,7 @@ + @@ -26,7 +29,7 @@ - + diff --git a/stock_operating_unit/hooks.py b/stock_operating_unit/hooks.py index 1239564667..7b9a5791e4 100644 --- a/stock_operating_unit/hooks.py +++ b/stock_operating_unit/hooks.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2016 Eficent Business and IT Consulting Services S.L. -# © 2016 Serpent Consulting Services Pvt. Ltd. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from openerp import SUPERUSER_ID from openerp.api import Environment diff --git a/stock_operating_unit/model/__init__.py b/stock_operating_unit/model/__init__.py index a05fa0038b..a73fea253c 100644 --- a/stock_operating_unit/model/__init__.py +++ b/stock_operating_unit/model/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Eficent Business and IT Consulting Services S.L. -# © 2016 Serpent Consulting Services Pvt. Ltd. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import stock diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index c8700090a3..5cdd09ec9d 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2016 Eficent Business and IT Consulting Services S.L. -# © 2016 Serpent Consulting Services Pvt. Ltd. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 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 UserError @@ -9,11 +9,20 @@ class StockWarehouse(models.Model): _inherit = "stock.warehouse" + def _default_operating_unit(self): + if self.company_id: + company = self.company_id + else: + company = self.env['res.company']._company_default_get( + 'stock.inventory') + for ou in self.env.user.operating_unit_ids: + if company == self.company_id: + self.operating_unit_id = ou + operating_unit_id = fields.Many2one( comodel_name='operating.unit', string='Operating Unit', - default=lambda self: (self.env['res.users']. - operating_unit_default_get(self.env.uid)) + default=_default_operating_unit ) @api.multi @@ -105,17 +114,16 @@ class StockPicking(models.Model): 'Requesting Operating Unit', readonly=1) - @api.v7 - def onchange_picking_type(self, cr, uid, ids, picking_type_id, partner_id, - context=None): - res = super(StockPicking, self).onchange_picking_type( - cr, uid, ids, picking_type_id, partner_id, context=context) - if picking_type_id: - picking_type = self.pool['stock.picking.type'].browse( - cr, uid, picking_type_id, context=context) or None - unit = picking_type.warehouse_id.operating_unit_id - if unit: - res['value']['operating_unit_id'] = unit.id + @api.onchange('picking_type_id', 'partner_id') + def onchange_picking_type(self): + res = super(StockPicking, self).onchange_picking_type() + if self.picking_type_id: + picking_type = self.env['stock.picking.type'].browse( + self.picking_type_id.id) or None + if picking_type: + unit = picking_type.warehouse_id.operating_unit_id + if unit: + res['value']['operating_unit_id'] = unit.id return res @api.multi diff --git a/stock_operating_unit/security/stock_security.xml b/stock_operating_unit/security/stock_security.xml index f6fc3a9cfc..5f5e829d32 100644 --- a/stock_operating_unit/security/stock_security.xml +++ b/stock_operating_unit/security/stock_security.xml @@ -1,6 +1,8 @@ + - ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] diff --git a/stock_operating_unit/tests/__init__.py b/stock_operating_unit/tests/__init__.py index 4101fcef9f..2aacf0c00a 100644 --- a/stock_operating_unit/tests/__init__.py +++ b/stock_operating_unit/tests/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. # - Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# © 2016-2017 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_stock_operating_unit from . import test_stock_picking diff --git a/stock_operating_unit/tests/test_stock_operating_unit.py b/stock_operating_unit/tests/test_stock_operating_unit.py index 895b0523f7..61c0549d06 100644 --- a/stock_operating_unit/tests/test_stock_operating_unit.py +++ b/stock_operating_unit/tests/test_stock_operating_unit.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2016 Eficent Business and IT Consulting Services S.L. -# © 2016 Serpent Consulting Services Pvt. Ltd. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from openerp.addons.stock.tests import common diff --git a/stock_operating_unit/tests/test_stock_picking.py b/stock_operating_unit/tests/test_stock_picking.py index 7d0298067c..29ff52b82c 100644 --- a/stock_operating_unit/tests/test_stock_picking.py +++ b/stock_operating_unit/tests/test_stock_picking.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2016 Eficent Business and IT Consulting Services S.L. -# © 2016 Serpent Consulting Services Pvt. Ltd. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_stock_operating_unit as test_stock_ou diff --git a/stock_operating_unit/tests/test_stock_security.py b/stock_operating_unit/tests/test_stock_security.py index f2a87e78e4..61001a4704 100644 --- a/stock_operating_unit/tests/test_stock_security.py +++ b/stock_operating_unit/tests/test_stock_security.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2016 Eficent Business and IT Consulting Services S.L. -# © 2016 Serpent Consulting Services Pvt. Ltd. +# © 2016-2017 Eficent Business and IT Consulting Services S.L. +# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_stock_operating_unit as test_stock_ou diff --git a/stock_operating_unit/view/stock.xml b/stock_operating_unit/view/stock.xml index 54bf6c0097..ecfbbd9094 100644 --- a/stock_operating_unit/view/stock.xml +++ b/stock_operating_unit/view/stock.xml @@ -1,6 +1,8 @@ + - stock.warehouse stock.warehouse From 8a367bdc683ab9372e90a19fe3b373b9b4ab6dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esther=20Mart=C3=ADn?= Date: Wed, 5 Apr 2017 11:39:11 +0200 Subject: [PATCH 16/72] [FIX] stock_operating_unit: correct constrain function, avoid error on pickings --- stock_operating_unit/model/stock.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 5cdd09ec9d..35c09b0169 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -57,7 +57,7 @@ def _check_warehouse_operating_unit(self): raise UserError(_('Configuration error\nThis location is ' 'assigned to a warehouse that belongs to' ' a different operating unit.')) - if self.operating_unit_id != w.operating_unit_id: + if rec.operating_unit_id != w.operating_unit_id: raise UserError(_('Configuration error\nThis location is ' 'assigned to a warehouse that belongs to' ' a different operating unit.')) @@ -118,12 +118,8 @@ class StockPicking(models.Model): def onchange_picking_type(self): res = super(StockPicking, self).onchange_picking_type() if self.picking_type_id: - picking_type = self.env['stock.picking.type'].browse( - self.picking_type_id.id) or None - if picking_type: - unit = picking_type.warehouse_id.operating_unit_id - if unit: - res['value']['operating_unit_id'] = unit.id + unit = self.picking_type_id.warehouse_id.operating_unit_id + self.operating_unit_id = unit return res @api.multi From 9d87f2546ff9ab4826e72b0d3b07d3693d03fffa Mon Sep 17 00:00:00 2001 From: aheficent Date: Thu, 28 Sep 2017 13:05:03 +0200 Subject: [PATCH 17/72] [FIX]onchange does not work with readonly fields --- stock_operating_unit/__manifest__.py | 2 +- stock_operating_unit/model/stock.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/stock_operating_unit/__manifest__.py b/stock_operating_unit/__manifest__.py index f1218b8781..34875f4855 100644 --- a/stock_operating_unit/__manifest__.py +++ b/stock_operating_unit/__manifest__.py @@ -7,7 +7,7 @@ "name": "Stock with Operating Units", "summary": "An operating unit (OU) is an organizational entity part of a " "company", - "version": "10.0.1.0.0", + "version": "10.0.1.0.1", "category": "Generic Modules/Sales & Purchases", "author": "Eficent, " "Serpent Consulting Services Pvt. Ltd., " diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 35c09b0169..fd28956e84 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -111,8 +111,7 @@ class StockPicking(models.Model): _inherit = 'stock.picking' operating_unit_id = fields.Many2one('operating.unit', - 'Requesting Operating Unit', - readonly=1) + 'Requesting Operating Unit') @api.onchange('picking_type_id', 'partner_id') def onchange_picking_type(self): From d436624184dac5c86b2968c9d77791c65b6b1e05 Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 10 Apr 2018 12:33:30 +0200 Subject: [PATCH 18/72] [FIX]stock.move._check_stock_move_operating_unit --- stock_operating_unit/model/stock.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index fd28956e84..5f3434ec35 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -161,8 +161,9 @@ class StockMove(models.Model): ) @api.multi - @api.constrains('operating_unit_id', 'location_id', 'picking_id', - 'operating_unit_dest_id', 'location_dest_id') + @api.constrains('location_id.operating_unit_id', 'picking_id', + 'location_id', 'location_dest_id.operating_unit_id', + 'location_dest_id') def _check_stock_move_operating_unit(self): for stock_move in self: if not stock_move.operating_unit_id: From 3b666e2050d16c77d8e991875707061a482f1787 Mon Sep 17 00:00:00 2001 From: aaron Date: Thu, 7 Jun 2018 10:53:31 +0200 Subject: [PATCH 19/72] [FIX]internal locations should consider all locations but customer or suppliers --- stock_operating_unit/model/stock.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index 5f3434ec35..aa5205559f 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -70,14 +70,15 @@ def _check_warehouse_operating_unit(self): @api.constrains('operating_unit_id') def _check_required_operating_unit(self): for rec in self: - if rec.usage == 'internal' and not rec.operating_unit_id: + if (rec.usage not in ('supplier', 'customer') and not + rec.operating_unit_id): raise UserError( - _('Configuration error\nThe operating unit should be ' + _('Configuration error. The operating unit should be ' 'assigned to internal locations and to non other.') ) - if rec.usage != 'internal' and rec.operating_unit_id: + if rec.usage in ('supplier', 'customer') and rec.operating_unit_id: raise UserError( - _('Configuration error\nThe operating unit should be ' + _('Configuration error. The operating unit should be ' 'assigned to internal locations and to non other.') ) From 4c85a04a27bd5aa96713acc48c48057dc3ad3a4b Mon Sep 17 00:00:00 2001 From: aheficent Date: Thu, 26 Jul 2018 17:26:11 +0200 Subject: [PATCH 20/72] [FIX]field that triggers constraint is not a valid field name --- stock_operating_unit/model/stock.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py index aa5205559f..10d30075fe 100644 --- a/stock_operating_unit/model/stock.py +++ b/stock_operating_unit/model/stock.py @@ -162,8 +162,8 @@ class StockMove(models.Model): ) @api.multi - @api.constrains('location_id.operating_unit_id', 'picking_id', - 'location_id', 'location_dest_id.operating_unit_id', + @api.constrains('operating_unit_id', 'picking_id', + 'location_id', 'operating_unit_dest_id', 'location_dest_id') def _check_stock_move_operating_unit(self): for stock_move in self: From 81482b61adc90cdc2764d8d2b8be92176a0b30a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C3=B1at=20Jimenez?= Date: Wed, 12 Dec 2018 12:36:20 +0100 Subject: [PATCH 21/72] [MIG] stock_operating_unit: Migration to v12 --- stock_operating_unit/README.rst | 73 ++- stock_operating_unit/__init__.py | 4 +- stock_operating_unit/__manifest__.py | 12 +- stock_operating_unit/data/stock_data.xml | 4 +- stock_operating_unit/demo/stock_demo.xml | 4 +- stock_operating_unit/hooks.py | 17 +- stock_operating_unit/model/__init__.py | 10 +- stock_operating_unit/model/stock.py | 188 -------- stock_operating_unit/model/stock_location.py | 67 +++ stock_operating_unit/model/stock_move.py | 42 ++ stock_operating_unit/model/stock_picking.py | 47 ++ stock_operating_unit/model/stock_rule.py | 14 + stock_operating_unit/model/stock_warehouse.py | 52 ++ stock_operating_unit/readme/CONFIGURE.rst | 4 + stock_operating_unit/readme/CONTRIBUTORS.rst | 3 + stock_operating_unit/readme/DESCRIPTION.rst | 6 + stock_operating_unit/readme/ROADMAP.rst | 3 + stock_operating_unit/readme/USAGE.rst | 2 + .../security/stock_security.xml | 49 +- .../static/description/index.html | 450 ++++++++++++++++++ stock_operating_unit/tests/__init__.py | 5 +- .../tests/test_stock_operating_unit.py | 7 +- .../tests/test_stock_picking.py | 5 +- .../tests/test_stock_security.py | 5 +- stock_operating_unit/view/stock.xml | 158 ++++-- 25 files changed, 921 insertions(+), 310 deletions(-) delete mode 100644 stock_operating_unit/model/stock.py create mode 100644 stock_operating_unit/model/stock_location.py create mode 100644 stock_operating_unit/model/stock_move.py create mode 100644 stock_operating_unit/model/stock_picking.py create mode 100644 stock_operating_unit/model/stock_rule.py create mode 100644 stock_operating_unit/model/stock_warehouse.py create mode 100644 stock_operating_unit/readme/CONFIGURE.rst create mode 100644 stock_operating_unit/readme/CONTRIBUTORS.rst create mode 100644 stock_operating_unit/readme/DESCRIPTION.rst create mode 100644 stock_operating_unit/readme/ROADMAP.rst create mode 100644 stock_operating_unit/readme/USAGE.rst create mode 100644 stock_operating_unit/static/description/index.html diff --git a/stock_operating_unit/README.rst b/stock_operating_unit/README.rst index 180248a453..ef0c9a5939 100644 --- a/stock_operating_unit/README.rst +++ b/stock_operating_unit/README.rst @@ -1,17 +1,41 @@ -.. image:: https://img.shields.io/badge/license-AGPLv3-blue.svg - :target: https://www.gnu.org/licenses/lgpl.html - :alt: License: LGPL-3 - ========================== Stock with Operating Units ========================== +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github + :target: https://github.com/OCA/operating-unit/tree/12.0/stock_operating_unit + :alt: OCA/operating-unit +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/operating-unit-12-0/operating-unit-12-0-stock_operating_unit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/213/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + This module introduces the following features: + - Adds the operating unit to the Warehouse. - Adds the operating unit to the Stock Location. - Adds the requesting operating unit to stock pickings. - Implements user's security access rules. +**Table of contents** + +.. contents:: + :local: Configuration ============= @@ -27,45 +51,52 @@ Usage This module defines the operating unit entity and the user's security rules. Other modules extend the standard Odoo apps with the OU. -.. 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/10.0 +Known issues / Roadmap +====================== + +The Manager can see the stock rules of other Operating Units but he can not +edit them. If he tries to access to one of these stock rules, he will receive +a configuration error. 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. +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Eficent +* Serpent Consulting Services Pvt. Ltd. Contributors ------------- +~~~~~~~~~~~~ * Jordi Ballester Alomar * Aaron Henriquez * Sudhir Arya -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org - -This module is maintained by the OCA. + :target: https://odoo-community.org OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +This module is part of the `OCA/operating-unit `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_operating_unit/__init__.py b/stock_operating_unit/__init__.py index 44392c204f..122296e393 100644 --- a/stock_operating_unit/__init__.py +++ b/stock_operating_unit/__init__.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + from . import model from .hooks import update_operating_unit_location diff --git a/stock_operating_unit/__manifest__.py b/stock_operating_unit/__manifest__.py index 34875f4855..242f1a5fa1 100644 --- a/stock_operating_unit/__manifest__.py +++ b/stock_operating_unit/__manifest__.py @@ -1,19 +1,17 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# © 2016-2017 Serpent Consulting Services Pvt. Ltd. +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "Stock with Operating Units", - "summary": "An operating unit (OU) is an organizational entity part of a " - "company", - "version": "10.0.1.0.1", + "summary": "Adds the concept of operating unit (OU) in stock management", + "version": "12.0.1.0.0", "category": "Generic Modules/Sales & Purchases", "author": "Eficent, " "Serpent Consulting Services Pvt. Ltd., " "Odoo Community Association (OCA)", "license": "LGPL-3", - "website": "http://www.eficent.com", + "website": "https://github.com/OCA/operating-unit", "depends": ["stock", "account_operating_unit"], "data": [ "security/stock_security.xml", diff --git a/stock_operating_unit/data/stock_data.xml b/stock_operating_unit/data/stock_data.xml index ab3f36c1b8..9b40fabd0f 100644 --- a/stock_operating_unit/data/stock_data.xml +++ b/stock_operating_unit/data/stock_data.xml @@ -1,6 +1,6 @@ - diff --git a/stock_operating_unit/demo/stock_demo.xml b/stock_operating_unit/demo/stock_demo.xml index ceed68b222..ca255a9a16 100644 --- a/stock_operating_unit/demo/stock_demo.xml +++ b/stock_operating_unit/demo/stock_demo.xml @@ -1,6 +1,6 @@ - diff --git a/stock_operating_unit/hooks.py b/stock_operating_unit/hooks.py index 7b9a5791e4..7b66a21a45 100644 --- a/stock_operating_unit/hooks.py +++ b/stock_operating_unit/hooks.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# © 2016-2017 Serpent Consulting Services Pvt. Ltd. +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp import SUPERUSER_ID -from openerp.api import Environment +from odoo import SUPERUSER_ID +from odoo.api import Environment def update_operating_unit_location(cr, registry): @@ -15,7 +14,9 @@ def update_operating_unit_location(cr, registry): locations = env['stock.location'].search( [('id', 'child_of', [parent_location.id]), ('usage', '=', 'internal')]) - for location in locations: - if operating_unit: - location.write({'operating_unit_id': operating_unit.id}) + if operating_unit: + query = '''update stock_location set operating_unit_id = %s where + location_id in %s or id in %s''' + cr.execute(query, (operating_unit.id, tuple(locations.ids), + tuple(locations.ids))) return True diff --git a/stock_operating_unit/model/__init__.py b/stock_operating_unit/model/__init__.py index a73fea253c..6ddeb2e025 100644 --- a/stock_operating_unit/model/__init__.py +++ b/stock_operating_unit/model/__init__.py @@ -1,5 +1,7 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# © 2016-2017 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from . import stock + +from . import stock_location +from . import stock_move +from . import stock_picking +from . import stock_rule +from . import stock_warehouse diff --git a/stock_operating_unit/model/stock.py b/stock_operating_unit/model/stock.py deleted file mode 100644 index 10d30075fe..0000000000 --- a/stock_operating_unit/model/stock.py +++ /dev/null @@ -1,188 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# © 2016-2017 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 UserError - - -class StockWarehouse(models.Model): - _inherit = "stock.warehouse" - - def _default_operating_unit(self): - if self.company_id: - company = self.company_id - else: - company = self.env['res.company']._company_default_get( - 'stock.inventory') - for ou in self.env.user.operating_unit_ids: - if company == self.company_id: - self.operating_unit_id = ou - - operating_unit_id = fields.Many2one( - comodel_name='operating.unit', - string='Operating Unit', - default=_default_operating_unit - ) - - @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 UserError( - _('Configuration error\nThe Company in the Stock Warehouse' - ' and in the Operating Unit must be the same.') - ) - - -class StockLocation(models.Model): - _inherit = 'stock.location' - - operating_unit_id = fields.Many2one('operating.unit', - 'Operating Unit') - - @api.multi - @api.constrains('operating_unit_id') - def _check_warehouse_operating_unit(self): - for rec in self: - warehouse_obj = self.env['stock.warehouse'] - warehouses = warehouse_obj.search( - ['|', '|', ('wh_input_stock_loc_id', '=', rec.ids[0]), - ('lot_stock_id', 'in', rec.ids), - ('wh_output_stock_loc_id', 'in', rec.ids)]) - for w in warehouses: - if rec.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error\nThis location is ' - 'assigned to a warehouse that belongs to' - ' a different operating unit.')) - if rec.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error\nThis location is ' - 'assigned to a warehouse that belongs to' - ' a different operating unit.')) - if rec.operating_unit_id != w.operating_unit_id: - raise UserError(_('Configuration error\nThis location is' - ' assigned to a warehouse that belongs' - ' to a different operating unit.')) - - @api.multi - @api.constrains('operating_unit_id') - def _check_required_operating_unit(self): - for rec in self: - if (rec.usage not in ('supplier', 'customer') and not - rec.operating_unit_id): - raise UserError( - _('Configuration error. The operating unit should be ' - 'assigned to internal locations and to non other.') - ) - if rec.usage in ('supplier', 'customer') and rec.operating_unit_id: - raise UserError( - _('Configuration error. The operating unit should be ' - 'assigned to internal locations and to non other.') - ) - - @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 UserError( - _('Configuration error\nThe Company in the Stock Location ' - 'and in the Operating Unit must be the same.')) - - @api.multi - @api.constrains('operating_unit_id', 'location_id') - def _check_parent_operating_unit(self): - for rec in self: - if ( - rec.location_id and - rec.location_id.usage == 'internal' and - rec.operating_unit_id and - rec.operating_unit_id != rec.location_id.operating_unit_id - ): - raise UserError( - _('Configuration error\nThe Parent Stock Location ' - 'must belong to the same Operating Unit.') - ) - - -class StockPicking(models.Model): - _inherit = 'stock.picking' - - operating_unit_id = fields.Many2one('operating.unit', - 'Requesting Operating Unit') - - @api.onchange('picking_type_id', 'partner_id') - def onchange_picking_type(self): - res = super(StockPicking, self).onchange_picking_type() - if self.picking_type_id: - unit = self.picking_type_id.warehouse_id.operating_unit_id - self.operating_unit_id = unit - return res - - @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 UserError( - _('Configuration error\nThe Company in the Stock Picking ' - 'and in the Operating Unit must be the same.') - ) - - @api.multi - @api.constrains('operating_unit_id', 'picking_type_id') - def _check_picking_type_operating_unit(self): - for rec in self: - warehouse = rec.picking_type_id.warehouse_id - if (rec.picking_type_id and rec.operating_unit_id and - warehouse.operating_unit_id != rec.operating_unit_id): - raise UserError( - _('Configuration error\nThe Operating Unit of the picking ' - 'must be the same as that of the warehouse of the ' - 'Picking Type.') - ) - - -class StockMove(models.Model): - _inherit = 'stock.move' - - operating_unit_id = fields.Many2one( - related='location_id.operating_unit_id', - string='Source Location Operating Unit', - readonly=True, - ) - operating_unit_dest_id = fields.Many2one( - related='location_dest_id.operating_unit_id', - string='Dest. Location Operating Unit', - readonly=True, - ) - - @api.multi - @api.constrains('operating_unit_id', 'picking_id', - 'location_id', 'operating_unit_dest_id', - 'location_dest_id') - def _check_stock_move_operating_unit(self): - for stock_move in self: - if not stock_move.operating_unit_id: - return True - operating_unit = stock_move.operating_unit_id - operating_unit_dest = stock_move.operating_unit_dest_id - if (stock_move.location_id and - stock_move.location_id.operating_unit_id and - stock_move.picking_id and - operating_unit != stock_move.picking_id.operating_unit_id - ) and ( - stock_move.location_dest_id and - stock_move.location_dest_id.operating_unit_id and - stock_move.picking_id and - operating_unit_dest != stock_move.picking_id.operating_unit_id - ): - raise UserError( - _('Configuration error\nThe Stock moves must ' - 'be related to a location (source or destination) ' - 'that belongs to the requesting Operating Unit.') - ) diff --git a/stock_operating_unit/model/stock_location.py b/stock_operating_unit/model/stock_location.py new file mode 100644 index 0000000000..61211ac91f --- /dev/null +++ b/stock_operating_unit/model/stock_location.py @@ -0,0 +1,67 @@ +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class StockLocation(models.Model): + _inherit = 'stock.location' + + operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit') + + @api.multi + @api.constrains('operating_unit_id') + def _check_warehouse_operating_unit(self): + for rec in self: + warehouse_obj = self.env['stock.warehouse'] + warehouses = warehouse_obj.search( + ['|', '|', ('wh_input_stock_loc_id', '=', rec.ids[0]), + ('lot_stock_id', 'in', rec.ids), + ('wh_output_stock_loc_id', 'in', rec.ids)]) + for w in warehouses: + if rec.operating_unit_id != w.operating_unit_id: + raise UserError(_('Configuration error. This location is ' + 'assigned to a warehouse that belongs to' + ' a different operating unit.')) + + @api.multi + @api.constrains('operating_unit_id') + def _check_required_operating_unit(self): + for rec in self: + if (rec.usage not in ('supplier', 'customer') and not + rec.operating_unit_id): + raise UserError( + _('Configuration error. The operating unit should be ' + 'assigned to internal locations only.') + ) + if rec.usage in ('supplier', 'customer') and rec.operating_unit_id: + raise UserError( + _('Configuration error. The operating unit should be ' + 'assigned to internal locations only.') + ) + + @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 UserError( + _('Configuration error. The Company in the Stock Location ' + 'and in the Operating Unit must be the same.')) + + @api.multi + @api.constrains('operating_unit_id', 'location_id') + def _check_parent_operating_unit(self): + for rec in self: + if ( + rec.location_id and + rec.location_id.usage == 'internal' and + rec.operating_unit_id and + rec.operating_unit_id != rec.location_id.operating_unit_id + ): + raise UserError( + _('Configuration error. The Parent Stock Location ' + 'must belong to the same Operating Unit.') + ) diff --git a/stock_operating_unit/model/stock_move.py b/stock_operating_unit/model/stock_move.py new file mode 100644 index 0000000000..3afe5c3c11 --- /dev/null +++ b/stock_operating_unit/model/stock_move.py @@ -0,0 +1,42 @@ +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class StockMove(models.Model): + _inherit = 'stock.move' + + operating_unit_id = fields.Many2one( + related='location_id.operating_unit_id', + string='Source Location Operating Unit', + ) + operating_unit_dest_id = fields.Many2one( + related='location_dest_id.operating_unit_id', + string='Dest. Location Operating Unit', + ) + + @api.multi + @api.constrains('picking_id', 'location_id', 'location_dest_id') + def _check_stock_move_operating_unit(self): + for stock_move in self: + if not stock_move.operating_unit_id: + return True + operating_unit = stock_move.operating_unit_id + operating_unit_dest = stock_move.operating_unit_dest_id + if (stock_move.location_id and + stock_move.location_id.operating_unit_id and + stock_move.picking_id and + operating_unit != stock_move.picking_id.operating_unit_id + ) and ( + stock_move.location_dest_id and + stock_move.location_dest_id.operating_unit_id and + stock_move.picking_id and + operating_unit_dest != stock_move.picking_id.operating_unit_id + ): + raise UserError( + _('Configuration error. The Stock moves must ' + 'be related to a location (source or destination) ' + 'that belongs to the requesting Operating Unit.') + ) diff --git a/stock_operating_unit/model/stock_picking.py b/stock_operating_unit/model/stock_picking.py new file mode 100644 index 0000000000..567b449e68 --- /dev/null +++ b/stock_operating_unit/model/stock_picking.py @@ -0,0 +1,47 @@ +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + operating_unit_id = fields.Many2one( + 'operating.unit', + 'Requesting Operating Unit', + readonly=True, + states={'draft': [('readonly', False)]}) + + @api.onchange('picking_type_id', 'partner_id') + def onchange_picking_type(self): + res = super(StockPicking, self).onchange_picking_type() + if self.picking_type_id: + unit = self.picking_type_id.warehouse_id.operating_unit_id + self.operating_unit_id = unit + return res + + @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 UserError( + _('Configuration error. The Company in the Stock Picking ' + 'and in the Operating Unit must be the same.') + ) + + @api.multi + @api.constrains('operating_unit_id', 'picking_type_id') + def _check_picking_type_operating_unit(self): + for rec in self: + warehouse = rec.picking_type_id.warehouse_id + if (rec.picking_type_id and rec.operating_unit_id and + warehouse.operating_unit_id != rec.operating_unit_id): + raise UserError( + _('Configuration error. The Operating Unit of the picking ' + 'must be the same as that of the warehouse of the ' + 'Picking Type.') + ) diff --git a/stock_operating_unit/model/stock_rule.py b/stock_operating_unit/model/stock_rule.py new file mode 100644 index 0000000000..764a8c98e7 --- /dev/null +++ b/stock_operating_unit/model/stock_rule.py @@ -0,0 +1,14 @@ +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class StockRule(models.Model): + _inherit = 'stock.rule' + + operating_unit_id = fields.Many2one( + 'operating.unit', + related='warehouse_id.operating_unit_id', + domain="[('user_ids', '=', uid)]") diff --git a/stock_operating_unit/model/stock_warehouse.py b/stock_operating_unit/model/stock_warehouse.py new file mode 100644 index 0000000000..f1832f739f --- /dev/null +++ b/stock_operating_unit/model/stock_warehouse.py @@ -0,0 +1,52 @@ +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class StockWarehouse(models.Model): + _inherit = "stock.warehouse" + + def _default_operating_unit(self): + if self.company_id: + company = self.company_id + else: + company = self.env['res.company']._company_default_get( + 'stock.inventory') + for ou in self.env.user.operating_unit_ids: + if company == self.company_id: + self.operating_unit_id = ou + + operating_unit_id = fields.Many2one( + comodel_name='operating.unit', + string='Operating Unit', + default=_default_operating_unit + ) + + @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 UserError( + _('Configuration error. The Company in the Stock Warehouse' + ' and in the Operating Unit must be the same.') + ) + + +class StockWarehouseOrderPoint(models.Model): + _inherit = 'stock.warehouse.orderpoint' + + @api.multi + @api.constrains('operating_unit_id', 'warehouse_id', 'location_id') + def _check_location(self): + for rec in self: + if (rec.warehouse_id and rec.location_id and + rec.warehouse_id.operating_unit_id != + rec.location_id.operating_unit_id): + raise UserError( + _('Configuration Error. The Operating Unit of the ' + 'Warehouse and the Location must be the same. ') + ) diff --git a/stock_operating_unit/readme/CONFIGURE.rst b/stock_operating_unit/readme/CONFIGURE.rst new file mode 100644 index 0000000000..583881a77f --- /dev/null +++ b/stock_operating_unit/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +To configure this module, you need to: + +* Assign Operating Unit to Warehouses. +* Assign Operating Unit to Stock Locations. diff --git a/stock_operating_unit/readme/CONTRIBUTORS.rst b/stock_operating_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..4244f4e535 --- /dev/null +++ b/stock_operating_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Jordi Ballester Alomar +* Aaron Henriquez +* Sudhir Arya diff --git a/stock_operating_unit/readme/DESCRIPTION.rst b/stock_operating_unit/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..6534ea9ce8 --- /dev/null +++ b/stock_operating_unit/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +This module introduces the following features: + +- Adds the operating unit to the Warehouse. +- Adds the operating unit to the Stock Location. +- Adds the requesting operating unit to stock pickings. +- Implements user's security access rules. diff --git a/stock_operating_unit/readme/ROADMAP.rst b/stock_operating_unit/readme/ROADMAP.rst new file mode 100644 index 0000000000..241598c034 --- /dev/null +++ b/stock_operating_unit/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +The Manager can see the stock rules of other Operating Units but he can not +edit them. If he tries to access to one of these stock rules, he will receive +a configuration error. diff --git a/stock_operating_unit/readme/USAGE.rst b/stock_operating_unit/readme/USAGE.rst new file mode 100644 index 0000000000..281f39c0b3 --- /dev/null +++ b/stock_operating_unit/readme/USAGE.rst @@ -0,0 +1,2 @@ +This module defines the operating unit entity and the user's security rules. +Other modules extend the standard Odoo apps with the OU. diff --git a/stock_operating_unit/security/stock_security.xml b/stock_operating_unit/security/stock_security.xml index 5f5e829d32..c76a1dbdf1 100644 --- a/stock_operating_unit/security/stock_security.xml +++ b/stock_operating_unit/security/stock_security.xml @@ -1,11 +1,14 @@ - - + - ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + ['|', + ('operating_unit_id', '=', False), + ('operating_unit_id', 'in', user.operating_unit_ids.ids)] + Warehouses from allowed operating units @@ -16,7 +19,10 @@ - ['|',('warehouse_id.operating_unit_id','=',False),('warehouse_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + ['|', + ('warehouse_id.operating_unit_id','=', False), + ('warehouse_id.operating_unit_id','in',user.operating_unit_ids.ids)] + Stock Picking Type from allowed operating units @@ -27,8 +33,10 @@ - ['|', ('operating_unit_id','in',[g.id for g - in user.operating_unit_ids]), ('operating_unit_id','=', False)] + ['|', + ('operating_unit_id', 'in',user.operating_unit_ids.ids), + ('operating_unit_id','=',False)] + Stock locations from allowed operating units @@ -39,8 +47,13 @@ - ['|',('location_id.operating_unit_id','=',False),('location_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids]), - '|',('location_dest_id.operating_unit_id','=',False),('location_dest_id.operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + ['|', + ('location_id.operating_unit_id','=',False), + ('location_id.operating_unit_id','in',user.operating_unit_ids.ids), + '|', + ('location_dest_id.operating_unit_id','=',False), + ('location_dest_id.operating_unit_id','in',user.operating_unit_ids.ids)] + Stock moves from allowed operating units @@ -51,7 +64,10 @@ - ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + ['|', + ('operating_unit_id','=',False), + ('operating_unit_id','in',user.operating_unit_ids.ids)] + Stock pickings from allowed operating units @@ -60,4 +76,17 @@ + + + ['|', + ('picking_type_id.warehouse_id.operating_unit_id','=',False), + ('picking_type_id.warehouse_id.operating_unit_id','in',user.operating_unit_ids.ids)] + + Stock pickings from allowed picking types + + + + + + diff --git a/stock_operating_unit/static/description/index.html b/stock_operating_unit/static/description/index.html new file mode 100644 index 0000000000..109b5fdd91 --- /dev/null +++ b/stock_operating_unit/static/description/index.html @@ -0,0 +1,450 @@ + + + + + + +Stock with Operating Units + + + +
+

Stock with Operating Units

+ + +

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

+

This module introduces the following features:

+
    +
  • Adds the operating unit to the Warehouse.
  • +
  • Adds the operating unit to the Stock Location.
  • +
  • Adds the requesting operating unit to stock pickings.
  • +
  • Implements user’s security access rules.
  • +
+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  • Assign Operating Unit to Warehouses.
  • +
  • Assign Operating Unit to Stock Locations.
  • +
+
+
+

Usage

+

This module defines the operating unit entity and the user’s security rules. +Other modules extend the standard Odoo apps with the OU.

+
+
+

Known issues / Roadmap

+

The Manager can see the stock rules of other Operating Units but he can not +edit them. If he tries to access to one of these stock rules, he will receive +a configuration error.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Eficent
  • +
  • Serpent Consulting Services Pvt. Ltd.
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/operating-unit project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_operating_unit/tests/__init__.py b/stock_operating_unit/tests/__init__.py index 2aacf0c00a..0e6f8d0396 100644 --- a/stock_operating_unit/tests/__init__.py +++ b/stock_operating_unit/tests/__init__.py @@ -1,8 +1,5 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# - Jordi Ballester Alomar -# © 2016-2017 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + from . import test_stock_operating_unit from . import test_stock_picking from . import test_stock_security diff --git a/stock_operating_unit/tests/test_stock_operating_unit.py b/stock_operating_unit/tests/test_stock_operating_unit.py index 61c0549d06..071368f48d 100644 --- a/stock_operating_unit/tests/test_stock_operating_unit.py +++ b/stock_operating_unit/tests/test_stock_operating_unit.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# © 2016-2017 Serpent Consulting Services Pvt. Ltd. +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp.addons.stock.tests import common +from odoo.addons.stock.tests import common class TestStockOperatingUnit(common.TestStockCommon): diff --git a/stock_operating_unit/tests/test_stock_picking.py b/stock_operating_unit/tests/test_stock_picking.py index 29ff52b82c..e601ea9e4d 100644 --- a/stock_operating_unit/tests/test_stock_picking.py +++ b/stock_operating_unit/tests/test_stock_picking.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# © 2016-2017 Serpent Consulting Services Pvt. Ltd. +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_stock_operating_unit as test_stock_ou diff --git a/stock_operating_unit/tests/test_stock_security.py b/stock_operating_unit/tests/test_stock_security.py index 61001a4704..885e29a26e 100644 --- a/stock_operating_unit/tests/test_stock_security.py +++ b/stock_operating_unit/tests/test_stock_security.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- -# © 2016-2017 Eficent Business and IT Consulting Services S.L. -# © 2016-2017 Serpent Consulting Services Pvt. Ltd. +# © 2019 Eficent Business and IT Consulting Services S.L. +# © 2019 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_stock_operating_unit as test_stock_ou diff --git a/stock_operating_unit/view/stock.xml b/stock_operating_unit/view/stock.xml index ecfbbd9094..0daf31e89e 100644 --- a/stock_operating_unit/view/stock.xml +++ b/stock_operating_unit/view/stock.xml @@ -1,17 +1,20 @@ - + stock.warehouse stock.warehouse - - + - + @@ -20,9 +23,12 @@ stock.warehouse - - - + + +
@@ -31,10 +37,12 @@ stock.location - - + - +
@@ -43,9 +51,11 @@ stock.location - - - + + +
@@ -54,9 +64,11 @@ stock.location - - - + + + @@ -65,9 +77,11 @@ stock.picking - - - + + + @@ -76,10 +90,15 @@ stock.picking - - + - + + + [('warehouse_id.operating_unit_id.user_ids', 'in', uid)] + @@ -89,12 +108,15 @@ - + - - + - + @@ -103,12 +125,16 @@ stock.move - - - - - - + + + + + + @@ -117,12 +143,34 @@ stock.move - - - - - - + + + + + + + + + + + stock.move.form + stock.move + + + + + + + + @@ -132,12 +180,16 @@ move_history_ids - - - - - - + + + + + + @@ -146,12 +198,16 @@ stock.move - - - - - - + + + + + + From ba06d5fdabda5f05906ec4d1028ab27017fd2d91 Mon Sep 17 00:00:00 2001 From: oca-travis Date: Wed, 16 Oct 2019 07:11:23 +0000 Subject: [PATCH 22/72] [UPD] Update stock_operating_unit.pot --- .../i18n/stock_operating_unit.pot | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 stock_operating_unit/i18n/stock_operating_unit.pot diff --git a/stock_operating_unit/i18n/stock_operating_unit.pot b/stock_operating_unit/i18n/stock_operating_unit.pot new file mode 100644 index 0000000000..0705b99dff --- /dev/null +++ b/stock_operating_unit/i18n/stock_operating_unit.pot @@ -0,0 +1,123 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_warehouse.py:50 +#, python-format +msgid "Configuration Error. The Operating Unit of the Warehouse and the Location must be the same. " +msgstr "" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_location.py:51 +#, python-format +msgid "Configuration error. The Company in the Stock Location and in the Operating Unit must be the same." +msgstr "" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_picking.py:32 +#, python-format +msgid "Configuration error. The Company in the Stock Picking and in the Operating Unit must be the same." +msgstr "" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_warehouse.py:34 +#, python-format +msgid "Configuration error. The Company in the Stock Warehouse and in the Operating Unit must be the same." +msgstr "" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_picking.py:44 +#, python-format +msgid "Configuration error. The Operating Unit of the picking must be the same as that of the warehouse of the Picking Type." +msgstr "" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_location.py:65 +#, python-format +msgid "Configuration error. The Parent Stock Location must belong to the same Operating Unit." +msgstr "" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_move.py:39 +#, python-format +msgid "Configuration error. The Stock moves must be related to a location (source or destination) that belongs to the requesting Operating Unit." +msgstr "" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_location.py:35 +#: code:addons/stock_operating_unit/model/stock_location.py:40 +#, python-format +msgid "Configuration error. The operating unit should be assigned to internal locations only." +msgstr "" + +#. module: stock_operating_unit +#: code:addons/stock_operating_unit/model/stock_location.py:24 +#, python-format +msgid "Configuration error. This location is assigned to a warehouse that belongs to a different operating unit." +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model.fields,field_description:stock_operating_unit.field_stock_move__operating_unit_dest_id +msgid "Dest. Location Operating Unit" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model,name:stock_operating_unit.model_stock_location +msgid "Inventory Locations" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model,name:stock_operating_unit.model_stock_warehouse_orderpoint +msgid "Minimum Inventory Rule" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model.fields,field_description:stock_operating_unit.field_stock_location__operating_unit_id +#: model:ir.model.fields,field_description:stock_operating_unit.field_stock_rule__operating_unit_id +#: model:ir.model.fields,field_description:stock_operating_unit.field_stock_warehouse__operating_unit_id +#: model_terms:ir.ui.view,arch_db:stock_operating_unit.view_picking_internal_search +msgid "Operating Unit" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model.fields,field_description:stock_operating_unit.field_stock_picking__operating_unit_id +msgid "Requesting Operating Unit" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model.fields,field_description:stock_operating_unit.field_stock_move__operating_unit_id +msgid "Source Location Operating Unit" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model,name:stock_operating_unit.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model,name:stock_operating_unit.model_stock_rule +msgid "Stock Rule" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model,name:stock_operating_unit.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: stock_operating_unit +#: model:ir.model,name:stock_operating_unit.model_stock_warehouse +msgid "Warehouse" +msgstr "" + From c9ec43725900ddeb5a72356d5e8fb3edc0aa193f Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Wed, 16 Oct 2019 07:17:48 +0000 Subject: [PATCH 23/72] [UPD] README.rst --- stock_operating_unit/static/description/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock_operating_unit/static/description/index.html b/stock_operating_unit/static/description/index.html index 109b5fdd91..af48c054dc 100644 --- a/stock_operating_unit/static/description/index.html +++ b/stock_operating_unit/static/description/index.html @@ -3,7 +3,7 @@ - + Stock with Operating Units