From 5c5643578798e8b7645f7e962b516cc6b024d741 Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 12 Jan 2017 17:09:02 +0100 Subject: [PATCH 1/7] [ADD] stock_inventory_exclude_sublocation --- .../README.rst | 72 +++++++++++++++++++ .../__init__.py | 6 ++ .../__openerp__.py | 21 ++++++ .../models/__init__.py | 6 ++ .../models/stock_inventory.py | 60 ++++++++++++++++ .../views/stock_inventory_view.xml | 18 +++++ 6 files changed, 183 insertions(+) create mode 100644 stock_inventory_exclude_sublocation/README.rst create mode 100644 stock_inventory_exclude_sublocation/__init__.py create mode 100644 stock_inventory_exclude_sublocation/__openerp__.py create mode 100644 stock_inventory_exclude_sublocation/models/__init__.py create mode 100644 stock_inventory_exclude_sublocation/models/stock_inventory.py create mode 100644 stock_inventory_exclude_sublocation/views/stock_inventory_view.xml diff --git a/stock_inventory_exclude_sublocation/README.rst b/stock_inventory_exclude_sublocation/README.rst new file mode 100644 index 000000000000..ab258b5ee9c4 --- /dev/null +++ b/stock_inventory_exclude_sublocation/README.rst @@ -0,0 +1,72 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=================================== +Stock Inventory Exclude Sublocation +=================================== + +This module extends the functionality of Inventory Adjustment to allow you to +exclude all the sublocations when doing an inventory adjustment for a +given location. + + +Usage +===== + +To use this module, you simply need to: + +#. Create a new inventory adjustment. +#. Select the option inventory of all products. +#. Check the box "Exclude Sublocations". + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} + + +Known issues / Roadmap +====================== + +* Sometimes we just want to make an inventory adjustment of just one shelf, or +space and forget about extra subdivisions in the location. +* In other cases we do inventories of smaller locations contained in our stock, +so we don't want to count them again when doing an inventory adjustment of the +parent location. E.g. if we apply a cycle count strategy. + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Lois Rilo Antelo + + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/stock_inventory_exclude_sublocation/__init__.py b/stock_inventory_exclude_sublocation/__init__.py new file mode 100644 index 000000000000..08f93b3a4568 --- /dev/null +++ b/stock_inventory_exclude_sublocation/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/stock_inventory_exclude_sublocation/__openerp__.py b/stock_inventory_exclude_sublocation/__openerp__.py new file mode 100644 index 000000000000..1e20681bd50b --- /dev/null +++ b/stock_inventory_exclude_sublocation/__openerp__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Stock Inventory Exclude Sublocation", + "summary": "Allow to perform inventories of a location without including " + "its child locations.", + "version": "9.0.1.0.0", + "author": "Eficent Business and IT Consulting Services S.L," + "Odoo Community Association (OCA)", + "website": "https://www.odoo-community.org", + "category": "Warehouse Management", + "depends": ["stock"], + "data": [ + 'views/stock_inventory_view.xml' + ], + "license": "AGPL-3", + 'installable': True, + 'application': False, +} diff --git a/stock_inventory_exclude_sublocation/models/__init__.py b/stock_inventory_exclude_sublocation/models/__init__.py new file mode 100644 index 000000000000..8b900fe08b37 --- /dev/null +++ b/stock_inventory_exclude_sublocation/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import stock_inventory diff --git a/stock_inventory_exclude_sublocation/models/stock_inventory.py b/stock_inventory_exclude_sublocation/models/stock_inventory.py new file mode 100644 index 000000000000..9348bdf11be9 --- /dev/null +++ b/stock_inventory_exclude_sublocation/models/stock_inventory.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import fields, models, api + + +class StockInventory(models.Model): + _inherit = 'stock.inventory' + + exclude_sublocation = fields.Boolean(string='Exclude Sublocations', + default=False) + + @api.model + def _get_location_ids(self, inventory): + location_obj = self.env['stock.location'] + return location_obj.search([('id', '=', + [inventory.location_id.id])]).ids + + @api.model + def _get_inventory_lines(self, inventory): + if inventory.exclude_sublocation: + product_obj = self.env['product.product'] + location_ids = self._get_location_ids(inventory) + domain = ' location_id in %s' + args = (tuple(location_ids),) + if inventory.partner_id: + domain += ' and owner_id = %s' + args += (inventory.partner_id.id,) + if inventory.lot_id: + domain += ' and lot_id = %s' + args += (inventory.lot_id.id,) + if inventory.product_id: + domain += ' and product_id = %s' + args += (inventory.product_id.id,) + if inventory.package_id: + domain += ' and package_id = %s' + args += (inventory.package_id.id,) + + self.env.cr.execute(''' + SELECT product_id, sum(qty) as product_qty, location_id, lot_id as prod_lot_id, package_id, owner_id as partner_id + FROM stock_quant WHERE''' + domain + ''' + GROUP BY product_id, location_id, lot_id, package_id, partner_id + ''', args) + vals = [] + for product_line in self.env.cr.dictfetchall(): + #replace the None the dictionary by False, because falsy values are tested later on + for key, value in product_line.items(): + if not value: + product_line[key] = False + product_line['inventory_id'] = inventory.id + product_line['theoretical_qty'] = product_line['product_qty'] + if product_line['product_id']: + product = product_obj.browse(product_line['product_id']) + product_line['product_uom_id'] = product.uom_id.id + vals.append(product_line) + return vals + else: + return super(StockInventory, self)._get_inventory_lines(inventory) diff --git a/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml b/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml new file mode 100644 index 000000000000..4832280f83c7 --- /dev/null +++ b/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml @@ -0,0 +1,18 @@ + + + + + + Inventory form view - cycle count extension + stock.inventory + + + + + + + + + \ No newline at end of file From 579a62892803f88f94f0b76eb2cb12d8168a65e2 Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 12 Jan 2017 17:59:18 +0100 Subject: [PATCH 2/7] [UPD] Update README and manifest. [FIX] Delete not needed method. --- stock_inventory_exclude_sublocation/README.rst | 15 ++++++--------- .../__openerp__.py | 4 ++-- .../models/stock_inventory.py | 11 ++--------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/stock_inventory_exclude_sublocation/README.rst b/stock_inventory_exclude_sublocation/README.rst index ab258b5ee9c4..da57b371de03 100644 --- a/stock_inventory_exclude_sublocation/README.rst +++ b/stock_inventory_exclude_sublocation/README.rst @@ -10,6 +10,12 @@ This module extends the functionality of Inventory Adjustment to allow you to exclude all the sublocations when doing an inventory adjustment for a given location. +Sometimes we just want to make an inventory adjustment of just one shelf, or +space and forget about extra subdivisions in the location. In other cases we +do inventories of smaller locations contained in our stock, so we don't want +to count them again when doing an inventory adjustment of the parent location +. E.g. if we apply a cycle count strategy. + Usage ===== @@ -25,15 +31,6 @@ To use this module, you simply need to: :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} -Known issues / Roadmap -====================== - -* Sometimes we just want to make an inventory adjustment of just one shelf, or -space and forget about extra subdivisions in the location. -* In other cases we do inventories of smaller locations contained in our stock, -so we don't want to count them again when doing an inventory adjustment of the -parent location. E.g. if we apply a cycle count strategy. - Bug Tracker =========== diff --git a/stock_inventory_exclude_sublocation/__openerp__.py b/stock_inventory_exclude_sublocation/__openerp__.py index 1e20681bd50b..a6ba8022dc23 100644 --- a/stock_inventory_exclude_sublocation/__openerp__.py +++ b/stock_inventory_exclude_sublocation/__openerp__.py @@ -7,9 +7,9 @@ "summary": "Allow to perform inventories of a location without including " "its child locations.", "version": "9.0.1.0.0", - "author": "Eficent Business and IT Consulting Services S.L," + "author": "Eficent," "Odoo Community Association (OCA)", - "website": "https://www.odoo-community.org", + "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse Management", "depends": ["stock"], "data": [ diff --git a/stock_inventory_exclude_sublocation/models/stock_inventory.py b/stock_inventory_exclude_sublocation/models/stock_inventory.py index 9348bdf11be9..81010fef792d 100644 --- a/stock_inventory_exclude_sublocation/models/stock_inventory.py +++ b/stock_inventory_exclude_sublocation/models/stock_inventory.py @@ -12,19 +12,12 @@ class StockInventory(models.Model): exclude_sublocation = fields.Boolean(string='Exclude Sublocations', default=False) - @api.model - def _get_location_ids(self, inventory): - location_obj = self.env['stock.location'] - return location_obj.search([('id', '=', - [inventory.location_id.id])]).ids - @api.model def _get_inventory_lines(self, inventory): if inventory.exclude_sublocation: product_obj = self.env['product.product'] - location_ids = self._get_location_ids(inventory) - domain = ' location_id in %s' - args = (tuple(location_ids),) + domain = ' location_id = %s' + args = (tuple(inventory.location_id.ids)) if inventory.partner_id: domain += ' and owner_id = %s' args += (inventory.partner_id.id,) From 9a54191e512f1a88c7272f883a75ba3c910f7407 Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 12 Jan 2017 18:21:34 +0100 Subject: [PATCH 3/7] [FIX] travis --- stock_inventory_exclude_sublocation/README.rst | 4 ++-- stock_inventory_exclude_sublocation/models/stock_inventory.py | 4 ++-- .../views/stock_inventory_view.xml | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/stock_inventory_exclude_sublocation/README.rst b/stock_inventory_exclude_sublocation/README.rst index da57b371de03..b0a5df45f07e 100644 --- a/stock_inventory_exclude_sublocation/README.rst +++ b/stock_inventory_exclude_sublocation/README.rst @@ -13,8 +13,8 @@ given location. Sometimes we just want to make an inventory adjustment of just one shelf, or space and forget about extra subdivisions in the location. In other cases we do inventories of smaller locations contained in our stock, so we don't want -to count them again when doing an inventory adjustment of the parent location -. E.g. if we apply a cycle count strategy. +to count them again when doing an inventory adjustment of the parent location. +E.g. if we apply a cycle count strategy. Usage diff --git a/stock_inventory_exclude_sublocation/models/stock_inventory.py b/stock_inventory_exclude_sublocation/models/stock_inventory.py index 81010fef792d..c5391d845998 100644 --- a/stock_inventory_exclude_sublocation/models/stock_inventory.py +++ b/stock_inventory_exclude_sublocation/models/stock_inventory.py @@ -32,13 +32,13 @@ def _get_inventory_lines(self, inventory): args += (inventory.package_id.id,) self.env.cr.execute(''' - SELECT product_id, sum(qty) as product_qty, location_id, lot_id as prod_lot_id, package_id, owner_id as partner_id + SELECT product_id, sum(qty) as product_qty, location_id, lot_id + as prod_lot_id, package_id, owner_id as partner_id FROM stock_quant WHERE''' + domain + ''' GROUP BY product_id, location_id, lot_id, package_id, partner_id ''', args) vals = [] for product_line in self.env.cr.dictfetchall(): - #replace the None the dictionary by False, because falsy values are tested later on for key, value in product_line.items(): if not value: product_line[key] = False diff --git a/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml b/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml index 4832280f83c7..f193fb5a28cf 100644 --- a/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml +++ b/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml @@ -1,3 +1,4 @@ + @@ -15,4 +16,4 @@ - \ No newline at end of file + From 3b74395acc58ae5ad109dac540ff5893f8c1093e Mon Sep 17 00:00:00 2001 From: lreficent Date: Fri, 13 Jan 2017 11:17:10 +0100 Subject: [PATCH 4/7] [IMP] Add tests [FIX] Copyright year --- .../__init__.py | 3 +- .../models/__init__.py | 2 +- .../models/stock_inventory.py | 2 +- .../tests/__init__.py | 6 ++ .../tests/test_exclude_sublocation.py | 92 +++++++++++++++++++ 5 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 stock_inventory_exclude_sublocation/tests/__init__.py create mode 100644 stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py diff --git a/stock_inventory_exclude_sublocation/__init__.py b/stock_inventory_exclude_sublocation/__init__.py index 08f93b3a4568..289aba0fe0fd 100644 --- a/stock_inventory_exclude_sublocation/__init__.py +++ b/stock_inventory_exclude_sublocation/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import models +from . import tests diff --git a/stock_inventory_exclude_sublocation/models/__init__.py b/stock_inventory_exclude_sublocation/models/__init__.py index 8b900fe08b37..eff36f7938b7 100644 --- a/stock_inventory_exclude_sublocation/models/__init__.py +++ b/stock_inventory_exclude_sublocation/models/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). diff --git a/stock_inventory_exclude_sublocation/models/stock_inventory.py b/stock_inventory_exclude_sublocation/models/stock_inventory.py index c5391d845998..8421ce802966 100644 --- a/stock_inventory_exclude_sublocation/models/stock_inventory.py +++ b/stock_inventory_exclude_sublocation/models/stock_inventory.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # (http://www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). diff --git a/stock_inventory_exclude_sublocation/tests/__init__.py b/stock_inventory_exclude_sublocation/tests/__init__.py new file mode 100644 index 000000000000..f2e05e912553 --- /dev/null +++ b/stock_inventory_exclude_sublocation/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_exclude_sublocation diff --git a/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py b/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py new file mode 100644 index 000000000000..67fdec5cb905 --- /dev/null +++ b/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import openerp.tests.common as common + + +class TestStockInventoryExcludeSublocation(common.TransactionCase): + + def setUp(self): + super(TestStockInventoryExcludeSublocation, self).setUp() + self.inventory_model = self.env['stock.inventory'] + self.location_model = self.env['stock.location'] + + self.product1 = self.env['product.product'].create({ + 'name': 'Product for parent location', + 'type': 'product', + 'default_code': 'PROD1', + }) + self.product2 = self.env['product.product'].create({ + 'name': 'Product for child location', + 'type': 'product', + 'default_code': 'PROD2', + }) + self.location = self.location_model.create({ + 'name': 'Inventory tests', + 'usage': 'internal', + }) + self.sublocation = self.location_model.create({ + 'name': 'Inventory sublocation test', + 'usage': 'internal', + 'location_id': self.location.id + }) + # Add a product in each location + starting_inv = self.inventory_model.create({ + 'name': 'Starting inventory', + 'filter': 'product', + 'line_ids': [ + (0, 0, { + 'product_id': self.product1.id, + 'product_uom_id': self.env.ref( + "product.product_uom_unit").id, + 'product_qty': 2.0, + 'location_id': self.location.id, + }), + (0, 0, { + 'product_id': self.product2.id, + 'product_uom_id': self.env.ref( + "product.product_uom_unit").id, + 'product_qty': 4.0, + 'location_id': self.sublocation.id, + }), + ], + }) + starting_inv.action_done() + + def _create_inventory_all_products(self, name, location, + exclude_sublocation): + inventory = self.inventory_model.create({ + 'name': name, + 'filter': 'none', + 'location_id': location.id, + 'exclude_sublocation': exclude_sublocation + }) + return inventory + + def test_not_excluding_sublocations(self): + '''Check if products in sublocations are included into the inventory + if the excluding sublocations option is disabled.''' + inventory_location = self._create_inventory_all_products( + 'location inventory', self.location, False) + inventory_location.prepare_inventory() + inventory_location.action_done() + lines = inventory_location.line_ids + self.assertEqual(len(lines), 2, 'nope') + + def test_excluding_sublocations(self): + '''Check if products in sublocations are not included if the exclude + sublocations is enabled.''' + inventory_location = self._create_inventory_all_products( + 'location inventory', self.location, True) + inventory_sublocation = self._create_inventory_all_products( + 'sublocation inventory', self.sublocation, True) + inventory_location.prepare_inventory() + inventory_location.action_done() + inventory_sublocation.prepare_inventory() + inventory_sublocation.action_done() + lines_location = inventory_location.line_ids + lines_sublocation = inventory_sublocation.line_ids + self.assertEqual(len(lines_location), 1, 'no') + self.assertEqual(len(lines_sublocation), 1, 'nope') From 16330c28a23eea18673887ba9c6c668585563d46 Mon Sep 17 00:00:00 2001 From: lreficent Date: Fri, 13 Jan 2017 11:34:54 +0100 Subject: [PATCH 5/7] [FIX] Runbot target --- stock_inventory_exclude_sublocation/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock_inventory_exclude_sublocation/README.rst b/stock_inventory_exclude_sublocation/README.rst index b0a5df45f07e..7d18657185cd 100644 --- a/stock_inventory_exclude_sublocation/README.rst +++ b/stock_inventory_exclude_sublocation/README.rst @@ -28,7 +28,7 @@ To use this module, you simply need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} + :target: https://runbot.odoo-community.org/runbot/153/9.0 Bug Tracker From 48010343fbafef20de9de165f28e8eca6b2bceee Mon Sep 17 00:00:00 2001 From: lreficent Date: Wed, 1 Feb 2017 13:13:08 +0100 Subject: [PATCH 6/7] [IMP] Add tests to cover all the code. --- .../tests/test_exclude_sublocation.py | 79 ++++++++++++++++++- .../views/stock_inventory_view.xml | 3 +- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py b/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py index 67fdec5cb905..6d11ce1068e8 100644 --- a/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py +++ b/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py @@ -12,6 +12,9 @@ def setUp(self): super(TestStockInventoryExcludeSublocation, self).setUp() self.inventory_model = self.env['stock.inventory'] self.location_model = self.env['stock.location'] + self.lot_model = self.env['stock.production.lot'] + self.quant_model = self.env['stock.quant'] + self.package_model = self.env['stock.quant.package'] self.product1 = self.env['product.product'].create({ 'name': 'Product for parent location', @@ -32,6 +35,13 @@ def setUp(self): 'usage': 'internal', 'location_id': self.location.id }) + self.lot_a = self.lot_model.create({ + 'name': 'Lot for product1', + 'product_id': self.product1.id + }) + self.package = self.package_model.create({'name': 'PACK00TEST1'}) + + self.partner = self.ref('base.res_partner_4') # Add a product in each location starting_inv = self.inventory_model.create({ 'name': 'Starting inventory', @@ -43,6 +53,7 @@ def setUp(self): "product.product_uom_unit").id, 'product_qty': 2.0, 'location_id': self.location.id, + 'prod_lot_id': self.lot_a.id }), (0, 0, { 'product_id': self.product2.id, @@ -50,6 +61,7 @@ def setUp(self): "product.product_uom_unit").id, 'product_qty': 4.0, 'location_id': self.sublocation.id, + 'prod_lot_id': self.lot_a.id }), ], }) @@ -73,7 +85,8 @@ def test_not_excluding_sublocations(self): inventory_location.prepare_inventory() inventory_location.action_done() lines = inventory_location.line_ids - self.assertEqual(len(lines), 2, 'nope') + self.assertEqual(len(lines), 2, 'Not all expected products are ' + 'included') def test_excluding_sublocations(self): '''Check if products in sublocations are not included if the exclude @@ -88,5 +101,65 @@ def test_excluding_sublocations(self): inventory_sublocation.action_done() lines_location = inventory_location.line_ids lines_sublocation = inventory_sublocation.line_ids - self.assertEqual(len(lines_location), 1, 'no') - self.assertEqual(len(lines_sublocation), 1, 'nope') + self.assertEqual(len(lines_location), 1, + 'The products in the sublocations are not excluded') + self.assertEqual(len(lines_sublocation), 1, + 'The products in the sublocations are not excluded') + + def test_lot_excluding_sublocation(self): + '''Check if the sublocations are excluded when using lots.''' + inventory = self.inventory_model.create({ + 'name': 'Inventory lot', + 'filter': 'lot', + 'location_id': self.location.id, + 'lot_id': self.lot_a.id, + 'exclude_sublocation': True + }) + inventory.prepare_inventory() + inventory.action_done() + lines = inventory.line_ids + self.assertEqual(len(lines), 1, 'The products in the sublocations are ' + 'not excluded with lots.') + + def test_product_and_owner_excluding_sublocation(self): + '''Check if sublocations are excluded when filtering by owner and + product.''' + self.quant_model.create({ + 'product_id': self.product1.id, + 'location_id': self.location.id, + 'qty': 1, + 'owner_id': self.partner, + }) + inventory = self.inventory_model.create({ + 'name': 'Inventory lot', + 'filter': 'product_owner', + 'location_id': self.location.id, + 'product_id': self.product1.id, + 'partner_id': self.partner, + 'exclude_sublocation': True + }) + inventory.prepare_inventory() + lines = inventory.line_ids + self.assertEqual(len(lines), 1, + 'The products in the sublocations are ' + 'not excluded with product and owner filter.') + + def test_pack_excluding_sublocation(self): + '''Check if sublocations are excluded when filtering by package.''' + self.quant_model.create({ + 'product_id': self.product1.id, + 'location_id': self.location.id, + 'qty': 1, + 'package_id': self.package.id + }) + inventory = self.inventory_model.create({ + 'name': 'Inventory lot', + 'filter': 'pack', + 'location_id': self.location.id, + 'package_id': self.package.id, + 'exclude_sublocation': True + }) + inventory.prepare_inventory() + lines = inventory.line_ids + self.assertEqual(len(lines), 1, 'The products in the sublocations are ' + 'not excluded with package filter.') diff --git a/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml b/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml index f193fb5a28cf..c51b076b25f7 100644 --- a/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml +++ b/stock_inventory_exclude_sublocation/views/stock_inventory_view.xml @@ -10,8 +10,7 @@ - + From cc1cd44cfff3a30432809c673a24bf0b0ffc8b2f Mon Sep 17 00:00:00 2001 From: lreficent Date: Wed, 1 Feb 2017 13:57:27 +0100 Subject: [PATCH 7/7] [FIX] Add user properly configured to tests. --- .../tests/test_exclude_sublocation.py | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py b/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py index 6d11ce1068e8..8913dba79707 100644 --- a/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py +++ b/stock_inventory_exclude_sublocation/tests/test_exclude_sublocation.py @@ -15,6 +15,29 @@ def setUp(self): self.lot_model = self.env['stock.production.lot'] self.quant_model = self.env['stock.quant'] self.package_model = self.env['stock.quant.package'] + self.res_users_model = self.env['res.users'] + + self.company = self.env.ref('base.main_company') + self.partner = self.ref('base.res_partner_4') + self.grp_stock_manager = self.env.ref('stock.group_stock_manager') + self.grp_tracking_owner = self.env.ref('stock.group_tracking_owner') + self.grp_production_lot = self.env.ref('stock.group_production_lot') + self.grp_tracking_lot = self.env.ref('stock.group_tracking_lot') + + self.user = self.res_users_model.create({ + 'name': 'Test Account User', + 'login': 'user_1', + 'password': 'demo', + 'email': 'example@yourcompany.com', + 'company_id': self.company.id, + 'company_ids': [(4, self.company.id)], + 'groups_id': [(6, 0, [ + self.grp_stock_manager.id, + self.grp_tracking_owner.id, + self.grp_production_lot.id, + self.grp_tracking_lot.id + ])] + }) self.product1 = self.env['product.product'].create({ 'name': 'Product for parent location', @@ -41,7 +64,6 @@ def setUp(self): }) self.package = self.package_model.create({'name': 'PACK00TEST1'}) - self.partner = self.ref('base.res_partner_4') # Add a product in each location starting_inv = self.inventory_model.create({ 'name': 'Starting inventory', @@ -108,7 +130,7 @@ def test_excluding_sublocations(self): def test_lot_excluding_sublocation(self): '''Check if the sublocations are excluded when using lots.''' - inventory = self.inventory_model.create({ + inventory = self.inventory_model.sudo(self.user.id).create({ 'name': 'Inventory lot', 'filter': 'lot', 'location_id': self.location.id, @@ -130,7 +152,7 @@ def test_product_and_owner_excluding_sublocation(self): 'qty': 1, 'owner_id': self.partner, }) - inventory = self.inventory_model.create({ + inventory = self.inventory_model.sudo(self.user.id).create({ 'name': 'Inventory lot', 'filter': 'product_owner', 'location_id': self.location.id, @@ -152,7 +174,7 @@ def test_pack_excluding_sublocation(self): 'qty': 1, 'package_id': self.package.id }) - inventory = self.inventory_model.create({ + inventory = self.inventory_model.sudo(self.user.id).create({ 'name': 'Inventory lot', 'filter': 'pack', 'location_id': self.location.id,