diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/README.rst b/stock_warehouse_orderpoint_stock_info_unreserved/README.rst index 9c059fb9f..c17005e49 100644 --- a/stock_warehouse_orderpoint_stock_info_unreserved/README.rst +++ b/stock_warehouse_orderpoint_stock_info_unreserved/README.rst @@ -14,7 +14,7 @@ Usage .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/153/10.0 + :target: https://runbot.odoo-community.org/runbot/153/11.0 Bug Tracker =========== diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/__init__.py b/stock_warehouse_orderpoint_stock_info_unreserved/__init__.py index f3ca9f7be..cbdaeb7e6 100644 --- a/stock_warehouse_orderpoint_stock_info_unreserved/__init__.py +++ b/stock_warehouse_orderpoint_stock_info_unreserved/__init__.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# Copyright 2018 Camptocamp SA # Copyright 2016 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/__manifest__.py b/stock_warehouse_orderpoint_stock_info_unreserved/__manifest__.py index eff397007..62ba0d022 100644 --- a/stock_warehouse_orderpoint_stock_info_unreserved/__manifest__.py +++ b/stock_warehouse_orderpoint_stock_info_unreserved/__manifest__.py @@ -1,10 +1,10 @@ -# -*- coding: utf-8 -*- +# Copyright 2018 Camptocamp SA # Copyright 2016 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Stock Warehouse Orderpoint Stock Info Unreserved", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "depends": [ "stock_warehouse_orderpoint_stock_info", "stock_available_unreserved" @@ -17,6 +17,4 @@ "data": [ "views/stock_warehouse_orderpoint_view.xml", ], - "installable": True, - "auto_install": False, } diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/models/__init__.py b/stock_warehouse_orderpoint_stock_info_unreserved/models/__init__.py index e25cf0d19..8e3be2fe2 100644 --- a/stock_warehouse_orderpoint_stock_info_unreserved/models/__init__.py +++ b/stock_warehouse_orderpoint_stock_info_unreserved/models/__init__.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# Copyright 2018 Camptocamp SA # Copyright 2016 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/models/stock_warehouse_orderpoint.py b/stock_warehouse_orderpoint_stock_info_unreserved/models/stock_warehouse_orderpoint.py index 47d704052..295241f7c 100644 --- a/stock_warehouse_orderpoint_stock_info_unreserved/models/stock_warehouse_orderpoint.py +++ b/stock_warehouse_orderpoint_stock_info_unreserved/models/stock_warehouse_orderpoint.py @@ -1,28 +1,31 @@ -# -*- coding: utf-8 -*- +# Copyright 2018 Camptocamp SA # Copyright 2016 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models from collections import defaultdict +from odoo import api, fields, models class StockWarehouseOrderpoint(models.Model): _inherit = 'stock.warehouse.orderpoint' + product_location_qty_available_not_res = fields.Float( + string='Quantity On Location (Unreserved)', + compute='_compute_product_available_qty', + ) + @api.multi def _compute_product_available_qty(self): - super(StockWarehouseOrderpoint, self)._compute_product_available_qty() - op_by_loc = defaultdict(lambda: self.env['stock.warehouse.orderpoint']) + super()._compute_product_available_qty() + op_by_loc = defaultdict(set) for order in self: - op_by_loc[order.location_id] |= order + op_by_loc[order.location_id].add(order.id) for location_id, order_in_loc in op_by_loc.items(): + order_in_loc = self.browse(order_in_loc) products = order_in_loc.mapped('product_id').with_context( - location=location_id.id)._compute_qty_available_not_res() + location=location_id.id + )._compute_qty_available_not_reserved() for order in order_in_loc: product = products[order.product_id.id] order.product_location_qty_available_not_res = \ product['qty_available_not_res'] - - product_location_qty_available_not_res = fields.Float( - string='Quantity On Location (Unreserved)', - compute='_compute_product_available_qty') diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/tests/__init__.py b/stock_warehouse_orderpoint_stock_info_unreserved/tests/__init__.py index bf747c324..8904e8ecf 100644 --- a/stock_warehouse_orderpoint_stock_info_unreserved/tests/__init__.py +++ b/stock_warehouse_orderpoint_stock_info_unreserved/tests/__init__.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# Copyright 2018 Camptocamp SA # Copyright 2016 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/tests/test_stock_warehouse_orderpoint.py b/stock_warehouse_orderpoint_stock_info_unreserved/tests/test_stock_warehouse_orderpoint.py index 41450062f..10fa94634 100644 --- a/stock_warehouse_orderpoint_stock_info_unreserved/tests/test_stock_warehouse_orderpoint.py +++ b/stock_warehouse_orderpoint_stock_info_unreserved/tests/test_stock_warehouse_orderpoint.py @@ -1,61 +1,64 @@ -# -*- coding: utf-8 -*- +# Copyright 2018 Camptocamp SA # Copyright 2016 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase +from odoo.tests.common import SavepointCase -class TestStockWarehouseOrderpoint(TransactionCase): - - def setUp(self): - super(TestStockWarehouseOrderpoint, self).setUp() +class TestStockWarehouseOrderpoint(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() # Get required Model - self.reordering_rule_model = self.env['stock.warehouse.orderpoint'] - self.stock_move_model = self.env['stock.move'] - self.product_model = self.env['product.product'] - self.product_ctg_model = self.env['product.category'] + cls.reordering_rule_model = cls.env['stock.warehouse.orderpoint'] + cls.stock_move_model = cls.env['stock.move'] + cls.product_model = cls.env['product.product'] + cls.product_ctg_model = cls.env['product.category'] # Get required Model data - self.product_uom = self.env.ref('product.product_uom_unit') - self.location_stock = self.env.ref('stock.stock_location_stock') - self.location_shelf1 = self.env.ref('stock.stock_location_components') - self.location_customer = self.env.ref('stock.stock_location_customers') - self.location_supplier = self.env.ref('stock.stock_location_suppliers') + cls.product_uom = cls.env.ref('product.product_uom_unit') + cls.location_stock = cls.env.ref('stock.stock_location_stock') + cls.location_shelf1 = cls.env.ref('stock.stock_location_components') + cls.location_customer = cls.env.ref('stock.stock_location_customers') + cls.location_supplier = cls.env.ref('stock.stock_location_suppliers') # Create product category and product - self.product_ctg = self._create_product_category() - self.product = self._create_product() + cls.product_ctg = cls._create_product_category() + cls.product = cls._create_product() # Create Reordering Rule - self.reordering_record = self.create_orderpoint() + cls.reordering_record = cls.create_orderpoint() - def _create_product_category(self): + @classmethod + def _create_product_category(cls): """Create a Product Category.""" - product_ctg = self.product_ctg_model.create({ + product_ctg = cls.product_ctg_model.create({ 'name': 'test_product_ctg', 'type': 'normal', }) return product_ctg - def _create_product(self): + @classmethod + def _create_product(cls): """Create a Stockable Product.""" - product = self.product_model.create({ + product = cls.product_model.create({ 'name': 'Test Product', - 'categ_id': self.product_ctg.id, + 'categ_id': cls.product_ctg.id, 'type': 'product', - 'uom_id': self.product_uom.id, + 'uom_id': cls.product_uom.id, }) return product - def create_orderpoint(self): + @classmethod + def create_orderpoint(cls): """Create a Reordering rule for the product.""" - record = self.reordering_rule_model.create({ + record = cls.reordering_rule_model.create({ 'name': 'Reordering Rule', - 'product_id': self.product.id, + 'product_id': cls.product.id, 'product_min_qty': '1', 'product_max_qty': '5', 'qty_multiple': '1', - 'location_id': self.location_stock.id, + 'location_id': cls.location_stock.id, }) return record @@ -64,49 +67,60 @@ class TestStockWarehouseOrderpoint(TransactionCase): 'name': 'Test move', 'product_id': self.product.id, 'product_uom': self.product_uom.id, - 'product_uom_qty': 10, + 'quantity_done': 10, 'location_id': source_location.id, - 'location_dest_id': destination_location.id} - ) + 'location_dest_id': destination_location.id + }) - move.action_confirm() + move._action_confirm() return move def test_product_qty(self): """Tests the product quantity in the Reordering rules""" # Create & process moves to test the product quantity - move_in = self.create_move(self.location_supplier, self.location_stock) - move_out = self.create_move(self.location_stock, - self.location_customer) + move_in = self.create_move( + self.location_supplier, + self.location_stock, + ) + move_out = self.create_move( + self.location_stock, + self.location_customer, + ) self.reordering_record.refresh() - self.assertEqual(self.reordering_record. - product_location_qty_available_not_res, - 0.0, - 'Quantity On Hand (Unreserved) does not match') - self.assertEqual(self.reordering_record. - product_location_qty_available_not_res, - self.product.qty_available_not_res, - 'Quantity On Hand (Unreserved) in the orderpoint ' - 'does not match with the product.') - move_in.action_done() + self.assertEqual( + self.reordering_record.product_location_qty_available_not_res, + 0.0, + 'Quantity On Hand (Unreserved) does not match', + ) + self.assertEqual( + self.reordering_record.product_location_qty_available_not_res, + self.product.qty_available_not_res, + 'Quantity On Hand (Unreserved) in the orderpoint ' + 'does not match with the product.' + ) + move_in._action_done() self.reordering_record.refresh() - self.assertEqual(self.reordering_record. - product_location_qty_available_not_res, - 10.0, - 'Quantity On Hand (Unreserved) does not match') - self.assertEqual(self.reordering_record. - product_location_qty_available_not_res, - self.product.qty_available_not_res, - 'Quantity On Hand (Unreserved) in the orderpoint ' - 'does not match with the product.') - move_out.action_assign() + self.assertEqual( + self.reordering_record.product_location_qty_available_not_res, + 10.0, + 'Quantity On Hand (Unreserved) does not match', + ) + self.assertEqual( + self.reordering_record.product_location_qty_available_not_res, + self.product.qty_available_not_res, + 'Quantity On Hand (Unreserved) in the orderpoint ' + 'does not match with the product.', + ) + move_out._action_done() self.reordering_record.refresh() - self.assertEqual(self.reordering_record. - product_location_qty_available_not_res, - 0.0, - 'Quantity On Hand (Unreserved) does not match') - self.assertEqual(self.reordering_record. - product_location_qty_available_not_res, - self.product.qty_available_not_res, - 'Quantity On Hand (Unreserved) in the orderpoint ' - 'does not match with the product.') + self.assertEqual( + self.reordering_record.product_location_qty_available_not_res, + 0.0, + 'Quantity On Hand (Unreserved) does not match', + ) + self.assertEqual( + self.reordering_record.product_location_qty_available_not_res, + self.product.qty_available_not_res, + 'Quantity On Hand (Unreserved) in the orderpoint ' + 'does not match with the product.', + )