From abc487c57bacc4bcd71259088da484b20f523af9 Mon Sep 17 00:00:00 2001 From: jbeficent Date: Mon, 24 Oct 2016 18:32:54 +0200 Subject: [PATCH] [IMP] Several improvements and fixes. --- stock_orderpoint_uom/README.rst | 65 +++++++++++++++++++ stock_orderpoint_uom/__init__.py | 6 ++ stock_orderpoint_uom/__openerp__.py | 19 ++++++ stock_orderpoint_uom/models/__init__.py | 7 ++ .../models/procurement_order.py | 21 ++++++ .../models/stock_warehouse_orderpoint.py | 27 ++++++++ stock_orderpoint_uom/tests/__init__.py | 6 ++ .../test_stock_orderpoint_procure_uom.py | 58 +++++++++++++++++ .../views/stock_warehouse_orderpoint_view.xml | 31 +++++++++ 9 files changed, 240 insertions(+) create mode 100644 stock_orderpoint_uom/README.rst create mode 100644 stock_orderpoint_uom/__init__.py create mode 100644 stock_orderpoint_uom/__openerp__.py create mode 100644 stock_orderpoint_uom/models/__init__.py create mode 100644 stock_orderpoint_uom/models/procurement_order.py create mode 100644 stock_orderpoint_uom/models/stock_warehouse_orderpoint.py create mode 100644 stock_orderpoint_uom/tests/__init__.py create mode 100644 stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py create mode 100644 stock_orderpoint_uom/views/stock_warehouse_orderpoint_view.xml diff --git a/stock_orderpoint_uom/README.rst b/stock_orderpoint_uom/README.rst new file mode 100644 index 000000000..4bb323ca3 --- /dev/null +++ b/stock_orderpoint_uom/README.rst @@ -0,0 +1,65 @@ +.. 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 Orderpoint UoM +==================== + +This module allows users users to define what unit of measure should be used +in procurements created from minimum stock rules. + +A typical use case would be a product that is stocked in centimeters, and +needs to be restocked in meters from another warehouse. When the picking is +created, the quantity to be transferred will be expressed in meters, making +it easier for the people responsible for the transfers to understand the +requirement. + + +Usage +===== + +Go to 'Configuration / Reordering Rules' and indicate a Procurement UoM. + + +.. 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/8.0 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar + + +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_orderpoint_uom/__init__.py b/stock_orderpoint_uom/__init__.py new file mode 100644 index 000000000..08f93b3a4 --- /dev/null +++ b/stock_orderpoint_uom/__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_orderpoint_uom/__openerp__.py b/stock_orderpoint_uom/__openerp__.py new file mode 100644 index 000000000..10708378f --- /dev/null +++ b/stock_orderpoint_uom/__openerp__.py @@ -0,0 +1,19 @@ +# -*- 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). +{ + "name": "Stock Orderpoint UoM", + "summary": "Allows to create procurement orders in the UoM indicated in " + "the orderpoint", + "version": "8.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_warehouse_orderpoint_view.xml"], + "license": "AGPL-3", + 'installable': True, + 'application': False, +} diff --git a/stock_orderpoint_uom/models/__init__.py b/stock_orderpoint_uom/models/__init__.py new file mode 100644 index 000000000..508e43109 --- /dev/null +++ b/stock_orderpoint_uom/models/__init__.py @@ -0,0 +1,7 @@ +# -*- 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_warehouse_orderpoint +from . import procurement_order diff --git a/stock_orderpoint_uom/models/procurement_order.py b/stock_orderpoint_uom/models/procurement_order.py new file mode 100644 index 000000000..250faf038 --- /dev/null +++ b/stock_orderpoint_uom/models/procurement_order.py @@ -0,0 +1,21 @@ +# -*- 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 api, models + + +class ProcurementOrder(models.Model): + _inherit = "procurement.order" + + @api.model + def _prepare_orderpoint_procurement(self, orderpoint, product_qty): + res = super(ProcurementOrder, self)._prepare_orderpoint_procurement( + orderpoint, product_qty) + if orderpoint.procure_uom_id: + res['product_qty'] = orderpoint.procure_uom_id._compute_qty( + orderpoint.product_id.uom_id.id, product_qty, + orderpoint.procure_uom_id.id) + res['product_uom'] = orderpoint.procure_uom_id.id + return res diff --git a/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py b/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py new file mode 100644 index 000000000..a4ca61052 --- /dev/null +++ b/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py @@ -0,0 +1,27 @@ +# -*- 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 api, fields, models, _ +from openerp.exceptions import Warning as UserError + + +class StockWarehouseOrderpoint(models.Model): + _inherit = "stock.warehouse.orderpoint" + + procure_uom_id = fields.Many2one(comodel_name='product.uom', + string="Procurement UoM") + + @api.constrains('product_uom', 'procure_uom_id') + def _check_procure_uom(self): + if any(orderpoint.product_uom and + orderpoint.procure_uom_id and + orderpoint.product_uom.category_id != + orderpoint.procure_uom_id.category_id + for orderpoint in self): + raise UserError( + _('Error: The product default Unit of Measure and ' + 'the procurement Unit of Measure must be in the ' + 'same category.')) + return True diff --git a/stock_orderpoint_uom/tests/__init__.py b/stock_orderpoint_uom/tests/__init__.py new file mode 100644 index 000000000..8ab7b3f74 --- /dev/null +++ b/stock_orderpoint_uom/tests/__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 test_stock_orderpoint_procure_uom diff --git a/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py b/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py new file mode 100644 index 000000000..b59453679 --- /dev/null +++ b/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py @@ -0,0 +1,58 @@ +# -*- 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). + +import openerp.tests.common as common +from openerp.tools import mute_logger +from openerp.exceptions import ValidationError + + +class TestStockOrderpointProcureUom(common.TransactionCase): + + def setUp(self): + super(TestStockOrderpointProcureUom, self).setUp() + productObj = self.env['product.product'] + self.warehouse = self.env.ref('stock.warehouse0') + self.location_stock = self.env.ref('stock.stock_location_stock') + self.uom_unit = self.env.ref('product.product_uom_unit') + self.uom_dozen = self.env.ref('product.product_uom_dozen') + self.uom_kg = self.env.ref('product.product_uom_kgm') + + self.productA = productObj.create( + {'name': 'product A', + 'standard_price': 1, + 'type': 'product', + 'uom_id': self.uom_unit.id, + 'default_code': 'A', + }) + + def test_stock_orderpoint_procure_uom(self): + + self.env['stock.warehouse.orderpoint'].create({ + 'warehouse_id': self.warehouse.id, + 'location_id': self.location_stock.id, + 'product_id': self.productA.id, + 'product_max_qty': 24, + 'product_min_qty': 12, + 'procure_uom_id': self.uom_dozen.id, + }) + + sched = self.env['procurement.order'] + sched.run_scheduler() + proc = sched.search([('product_id', '=', self.productA.id)]) + self.assertEqual(proc.product_uom, self.uom_dozen) + self.assertEqual(proc.product_qty, 2) + + def test_stock_orderpoint_wrong_uom(self): + + with mute_logger('openerp.sql_db'): + with self.assertRaises(ValidationError): + self.env['stock.warehouse.orderpoint'].create({ + 'warehouse_id': self.warehouse.id, + 'location_id': self.location_stock.id, + 'product_id': self.productA.id, + 'product_max_qty': 24, + 'product_min_qty': 12, + 'procure_uom_id': self.uom_kg.id, + }) diff --git a/stock_orderpoint_uom/views/stock_warehouse_orderpoint_view.xml b/stock_orderpoint_uom/views/stock_warehouse_orderpoint_view.xml new file mode 100644 index 000000000..ae41f7756 --- /dev/null +++ b/stock_orderpoint_uom/views/stock_warehouse_orderpoint_view.xml @@ -0,0 +1,31 @@ + + + + + + stock.warehouse.orderpoint.tree + stock.warehouse.orderpoint + + + + + + + + + + stock.warehouse.orderpoint.form + stock.warehouse.orderpoint + + + + + + + + + +