From 15274d0ceea731e1bdb4a4aafc90d27d729ae795 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Tue, 30 May 2017 14:43:13 +0200 Subject: [PATCH] [ADD] new module 'stock_warehouse_orderpoint_stock_info_unreserved' --- .../README.rst | 51 ++++++++ .../__init__.py | 5 + .../__openerp__.py | 22 ++++ .../models/__init__.py | 5 + .../models/stock_warehouse_orderpoint.py | 23 ++++ .../tests/__init__.py | 5 + .../tests/test_stock_warehouse_orderpoint.py | 112 ++++++++++++++++++ .../views/stock_warehouse_orderpoint_view.xml | 29 +++++ 8 files changed, 252 insertions(+) create mode 100644 stock_warehouse_orderpoint_stock_info_unreserved/README.rst create mode 100644 stock_warehouse_orderpoint_stock_info_unreserved/__init__.py create mode 100644 stock_warehouse_orderpoint_stock_info_unreserved/__openerp__.py create mode 100644 stock_warehouse_orderpoint_stock_info_unreserved/models/__init__.py create mode 100644 stock_warehouse_orderpoint_stock_info_unreserved/models/stock_warehouse_orderpoint.py create mode 100644 stock_warehouse_orderpoint_stock_info_unreserved/tests/__init__.py create mode 100644 stock_warehouse_orderpoint_stock_info_unreserved/tests/test_stock_warehouse_orderpoint.py create mode 100644 stock_warehouse_orderpoint_stock_info_unreserved/views/stock_warehouse_orderpoint_view.xml diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/README.rst b/stock_warehouse_orderpoint_stock_info_unreserved/README.rst new file mode 100644 index 000000000..8a6e23476 --- /dev/null +++ b/stock_warehouse_orderpoint_stock_info_unreserved/README.rst @@ -0,0 +1,51 @@ +.. 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 + +====================================== +Reordering Rules stock info unreserved +====================================== + +This modules allows to display the availability of stock on hand and +unreserved on a reordering rule. + +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/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 +======= + +Contributors +------------ +* Jordi Ballester Alomar + + + +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_warehouse_orderpoint_stock_info_unreserved/__init__.py b/stock_warehouse_orderpoint_stock_info_unreserved/__init__.py new file mode 100644 index 000000000..f3ca9f7be --- /dev/null +++ b/stock_warehouse_orderpoint_stock_info_unreserved/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/__openerp__.py b/stock_warehouse_orderpoint_stock_info_unreserved/__openerp__.py new file mode 100644 index 000000000..0e053289f --- /dev/null +++ b/stock_warehouse_orderpoint_stock_info_unreserved/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Reordering rules stock info unreserved", + "version": "9.0.1.0.0", + "depends": [ + "stock_warehouse_orderpoint_stock_info", + "stock_available_unreserved" + ], + "author": "Eficent, " + "Odoo Community Association (OCA)", + "website": "http://www.eficent.com", + "category": "Warehouse", + "license": "AGPL-3", + "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 new file mode 100644 index 000000000..e25cf0d19 --- /dev/null +++ b/stock_warehouse_orderpoint_stock_info_unreserved/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import stock_warehouse_orderpoint 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 new file mode 100644 index 000000000..6739d8f37 --- /dev/null +++ b/stock_warehouse_orderpoint_stock_info_unreserved/models/stock_warehouse_orderpoint.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields, api + + +class StockWarehouseOrderpoint(models.Model): + _inherit = 'stock.warehouse.orderpoint' + + @api.multi + def _compute_product_available_qty(self): + super(StockWarehouseOrderpoint, self)._compute_product_available_qty() + for rec in self: + product_available = rec.product_id.with_context( + location=rec.location_id.id + )._product_available()[rec.product_id.id] + rec.product_location_qty_available_not_res = \ + product_available['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 new file mode 100644 index 000000000..bf747c324 --- /dev/null +++ b/stock_warehouse_orderpoint_stock_info_unreserved/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_stock_warehouse_orderpoint 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 new file mode 100644 index 000000000..d2edc8f95 --- /dev/null +++ b/stock_warehouse_orderpoint_stock_info_unreserved/tests/test_stock_warehouse_orderpoint.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests import common + + +class TestStockWarehouseOrderpoint(common.TransactionCase): + + def setUp(self): + super(TestStockWarehouseOrderpoint, self).setUp() + # 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'] + + # 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') + + # Create product category and product + self.product_ctg = self._create_product_category() + self.product = self._create_product() + + # Create Reordering Rule + self.reordering_record = self.create_orderpoint() + + def _create_product_category(self): + """Create a Product Category.""" + product_ctg = self.product_ctg_model.create({ + 'name': 'test_product_ctg', + 'type': 'normal', + }) + return product_ctg + + def _create_product(self): + """Create a Stockable Product.""" + product = self.product_model.create({ + 'name': 'Test Product', + 'categ_id': self.product_ctg.id, + 'type': 'product', + 'uom_id': self.product_uom.id, + }) + return product + + def create_orderpoint(self): + """Create a Reordering rule for the product.""" + record = self.reordering_rule_model.create({ + 'name': 'Reordering Rule', + 'product_id': self.product.id, + 'product_min_qty': '1', + 'product_max_qty': '5', + 'qty_multiple': '1', + 'location_id': self.location_stock.id, + }) + return record + + def create_move(self, source_location, destination_location): + move = self.env['stock.move'].create({ + 'name': 'Test move', + 'product_id': self.product.id, + 'product_uom': self.product_uom.id, + 'product_uom_qty': 10, + 'location_id': source_location.id, + 'location_dest_id': destination_location.id} + ) + + 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) + 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.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.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.') diff --git a/stock_warehouse_orderpoint_stock_info_unreserved/views/stock_warehouse_orderpoint_view.xml b/stock_warehouse_orderpoint_stock_info_unreserved/views/stock_warehouse_orderpoint_view.xml new file mode 100644 index 000000000..2b7c27b7c --- /dev/null +++ b/stock_warehouse_orderpoint_stock_info_unreserved/views/stock_warehouse_orderpoint_view.xml @@ -0,0 +1,29 @@ + + + + + stock.warehouse.orderpoint.tree + stock.warehouse.orderpoint + + + + + + + + + + stock.warehouse.orderpoint.form + stock.warehouse.orderpoint + + + + + + + + + +