diff --git a/stock_quant_reserved_qty_uom/README.rst b/stock_quant_reserved_qty_uom/README.rst new file mode 100644 index 000000000..29cf9615c --- /dev/null +++ b/stock_quant_reserved_qty_uom/README.rst @@ -0,0 +1,56 @@ +.. 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 Quant Reserved Qty UoM +============================ + +This module allows to display the quantity of a quant in the unit of measure +defined in the reservation move. + + +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 +======= + +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_quant_reserved_qty_uom/__init__.py b/stock_quant_reserved_qty_uom/__init__.py new file mode 100644 index 000000000..8332fe071 --- /dev/null +++ b/stock_quant_reserved_qty_uom/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/stock_quant_reserved_qty_uom/__openerp__.py b/stock_quant_reserved_qty_uom/__openerp__.py new file mode 100644 index 000000000..9823c187d --- /dev/null +++ b/stock_quant_reserved_qty_uom/__openerp__.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Stock Quant Reserved Qty UoM', + 'version': '9.0.1.0.0', + 'category': 'Inventory, Logistic, Storage', + 'license': 'AGPL-3', + "author": "Eficent, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + 'depends': ['stock'], + 'data': ['views/stock_quant_view.xml'], + 'installable': True, +} diff --git a/stock_quant_reserved_qty_uom/models/__init__.py b/stock_quant_reserved_qty_uom/models/__init__.py new file mode 100644 index 000000000..8acb8ec46 --- /dev/null +++ b/stock_quant_reserved_qty_uom/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import stock_quant diff --git a/stock_quant_reserved_qty_uom/models/stock_quant.py b/stock_quant_reserved_qty_uom/models/stock_quant.py new file mode 100644 index 000000000..94303a709 --- /dev/null +++ b/stock_quant_reserved_qty_uom/models/stock_quant.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# © 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models +import openerp.addons.decimal_precision as dp + +UNIT = dp.get_precision('Product Unit of Measure') + + +class StockQuant(models.Model): + + _inherit = 'stock.quant' + + @api.multi + @api.depends('qty', 'reservation_id') + def _compute_reserved_qty_uom(self): + uom_obj = self.env['product.uom'] + for rec in self: + if rec.reservation_id: + rec.reserved_qty_uom = uom_obj._compute_qty_obj( + rec.product_id.uom_id, + rec.qty, + rec.reservation_id.product_uom) + + reserved_qty_uom = fields.Float(string="Qty in reservation UoM", + compute="_compute_reserved_qty_uom", + help="Quantity expressed in the unit of " + "measure of the move", + digits=UNIT, readonly=True) + reservation_uom = fields.Many2one(string="Reservation UoM", + comodel_name="product.uom", + readonly=True, + related='reservation_id.product_uom') diff --git a/stock_quant_reserved_qty_uom/static/description/icon.png b/stock_quant_reserved_qty_uom/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_quant_reserved_qty_uom/static/description/icon.png differ diff --git a/stock_quant_reserved_qty_uom/tests/__init__.py b/stock_quant_reserved_qty_uom/tests/__init__.py new file mode 100644 index 000000000..d91642579 --- /dev/null +++ b/stock_quant_reserved_qty_uom/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 (https://www.gnu.org/licenses/agpl.html). + +from . import test_stock_quant_reserved_qty_uom diff --git a/stock_quant_reserved_qty_uom/tests/test_stock_quant_reserved_qty_uom.py b/stock_quant_reserved_qty_uom/tests/test_stock_quant_reserved_qty_uom.py new file mode 100644 index 000000000..70893b21f --- /dev/null +++ b/stock_quant_reserved_qty_uom/tests/test_stock_quant_reserved_qty_uom.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase + + +class TestStockQuantReservedQtyUom(TransactionCase): + + def test01(self): + """checking that the reserved_qty_uom is expressed in the unit of + measure of the reservation move.""" + pickingObj = self.env['stock.picking'] + productObj = self.env['product.product'] + supplier_location = self.env.ref('stock.stock_location_suppliers') + stock_location = self.env.ref('stock.stock_location_stock') + customer_location = self.env.ref('stock.stock_location_customers') + uom_unit = self.env.ref('product.product_uom_unit') + uom_dozen = self.env.ref('product.product_uom_dozen') + + # Create product A + productA = productObj.create( + {'name': 'product A', + 'standard_price': 1.0, + 'type': 'product', + 'uom_id': uom_unit.id, + 'default_code': 'A', + }) + + # Create a picking move from INCOMING to STOCK + pickingInA = pickingObj.create({ + 'picking_type_id': self.ref('stock.picking_type_in'), + 'location_id': supplier_location.id, + 'location_dest_id': stock_location.id, + 'move_lines': [ + (0, 0, { + 'name': 'Test move', + 'product_id': productA.id, + 'product_uom': productA.uom_id.id, + 'product_uom_qty': 12.0, + 'location_id': supplier_location.id, + 'location_dest_id': stock_location.id, + })] + }) + + pickingInA.action_confirm() + pickingInA.action_assign() + pickingInA.action_done() + + # Create a picking from STOCK to CUSTOMER + pickingOutA = pickingObj.create({ + 'picking_type_id': self.ref('stock.picking_type_out'), + 'location_id': stock_location.id, + 'location_dest_id': customer_location.id, + 'move_lines': [ + (0, 0, { + 'name': 'Test move', + 'product_id': productA.id, + 'product_uom': uom_dozen.id, + 'product_uom_qty': 1.0, + 'location_id': stock_location.id, + 'location_dest_id': customer_location.id, + })] + }) + pickingOutA.action_confirm() + pickingOutA.action_assign() + + for move in pickingOutA.move_lines: + for quant in move.reserved_quant_ids: + quant._compute_reserved_qty_uom() + self.assertEqual(quant.reserved_qty_uom, 1) + self.assertEqual(quant.qty, 12) diff --git a/stock_quant_reserved_qty_uom/views/stock_quant_view.xml b/stock_quant_reserved_qty_uom/views/stock_quant_view.xml new file mode 100644 index 000000000..86a51dfa0 --- /dev/null +++ b/stock_quant_reserved_qty_uom/views/stock_quant_view.xml @@ -0,0 +1,29 @@ + + + + stock.quant.tree + stock.quant + + + + + + + + + + + + stock.quant.form + stock.quant + + + + + + + + + + +