From 28311d870010ec0258eab7905d4d93ec2cc19b3f Mon Sep 17 00:00:00 2001 From: oihane Date: Wed, 14 Oct 2015 13:35:57 +0200 Subject: [PATCH] [IMP] stock_quant_manual_assign: added tests --- stock_quant_manual_assign/README.rst | 40 ++++++- stock_quant_manual_assign/__openerp__.py | 12 ++- stock_quant_manual_assign/tests/__init__.py | 5 + .../tests/test_stock_quant_manual_assign.py | 102 ++++++++++++++++++ .../wizard/assign_manual_quants.py | 16 ++- .../wizard/assign_manual_quants_view.xml | 1 + 6 files changed, 161 insertions(+), 15 deletions(-) create mode 100644 stock_quant_manual_assign/tests/__init__.py create mode 100644 stock_quant_manual_assign/tests/test_stock_quant_manual_assign.py diff --git a/stock_quant_manual_assign/README.rst b/stock_quant_manual_assign/README.rst index fc32eaf26..f9c0d3b5d 100644 --- a/stock_quant_manual_assign/README.rst +++ b/stock_quant_manual_assign/README.rst @@ -1,14 +1,52 @@ +.. 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 + +=========================== Manual assignment of quants =========================== With this module, user can change manually the automatic selection of quants +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/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 `here `_. + + Credits ======= Contributors ------------ + * Mikel Arregi * Pedro M. Baeza -* Ana Juaristi \ No newline at end of file +* Ana Juaristi +* Oihane Crucelaegui + +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 http://odoo-community.org. diff --git a/stock_quant_manual_assign/__openerp__.py b/stock_quant_manual_assign/__openerp__.py index 58170e7d2..e18784afc 100644 --- a/stock_quant_manual_assign/__openerp__.py +++ b/stock_quant_manual_assign/__openerp__.py @@ -7,14 +7,16 @@ "version": "8.0.1.0.0", "category": "Warehouse Management", "license": "AGPL-3", - "author": "OdooMRP team," - "AvanzOSC," - "Serv. Tecnol. Avanzados - Pedro M. Baeza", + "author": "OdooMRP team, " + "AvanzOSC, " + "Serv. Tecnol. Avanzados - Pedro M. Baeza, " + "Odoo Community Association (OCA)", "website": "http://www.odoomrp.com", "contributors": [ - "Ana Juaristi Olalde ", - "Pedro Manuel Baeza Romero " "Mikel Arregi ", + "Ana Juaristi Olalde ", + "Pedro Manuel Baeza Romero " + "Oihane Crucelaegui ", ], "depends": [ "stock", diff --git a/stock_quant_manual_assign/tests/__init__.py b/stock_quant_manual_assign/tests/__init__.py new file mode 100644 index 000000000..ba4c7dd5c --- /dev/null +++ b/stock_quant_manual_assign/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import test_stock_quant_manual_assign diff --git a/stock_quant_manual_assign/tests/test_stock_quant_manual_assign.py b/stock_quant_manual_assign/tests/test_stock_quant_manual_assign.py new file mode 100644 index 000000000..cbab4dee9 --- /dev/null +++ b/stock_quant_manual_assign/tests/test_stock_quant_manual_assign.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +import openerp.tests.common as common + + +class TestStockQuantManualAssign(common.TransactionCase): + + def setUp(self): + super(TestStockQuantManualAssign, self).setUp() + self.quant_model = self.env['stock.quant'] + self.move_model = self.env['stock.move'] + self.quant_assign_wizard = self.env['assign.manual.quants'] + self.product = self.env['product.product'].create({ + 'name': 'Product 4 test', + 'type': 'product', + }) + self.location_src = self.env.ref( + 'stock.stock_location_locations_virtual') + self.location_dst = self.env.ref('stock.stock_location_customers') + self.location1 = self.env.ref('stock.location_inventory') + self.location2 = self.env.ref('stock.location_procurement') + self.location3 = self.env.ref('stock.location_production') + self.quant1 = self.quant_model.sudo().create({ + 'product_id': self.product.id, + 'qty': 100.0, + 'location_id': self.location1.id, + }) + self.quant2 = self.quant_model.sudo().create({ + 'product_id': self.product.id, + 'qty': 100.0, + 'location_id': self.location2.id, + }) + self.quant3 = self.quant_model.sudo().create({ + 'product_id': self.product.id, + 'qty': 100.0, + 'location_id': self.location3.id, + }) + self.move = self.move_model.create({ + 'name': self.product.name, + 'product_id': self.product.id, + 'product_uom_qty': 400.0, + 'product_uom': self.product.uom_id.id, + 'location_id': self.location_src.id, + 'location_dest_id': self.location_dst.id, + }) + self.move.action_confirm() + + def test_quant_assign_wizard(self): + wizard = self.quant_assign_wizard.with_context( + active_id=self.move.id).create({ + 'name': 'New wizard', + }) + self.assertEqual(len(wizard.quants_lines.ids), 3, + 'Three quants created, three quants got by default') + self.assertEqual(len(wizard.quants_lines.filtered('selected').ids), 0, + 'None of the quants must have been selected') + self.assertEqual(wizard.lines_qty, 0.0, + 'None selected must give 0') + for line in wizard.quants_lines: + if line.quant in self.move.reserved_quant_ids: + self.assertTrue(line.selected) + else: + self.assertFalse(line.selected) + self.assertEqual(wizard.move_qty, self.move.product_uom_qty) + + def test_quant_manual_assign(self): + wizard = self.quant_assign_wizard.with_context( + active_id=self.move.id).create({ + 'name': 'New wizard', + }) + self.assertEqual(len(wizard.quants_lines.ids), 3, + 'Three quants created, three quants got by default') + wizard.quants_lines[0].write({ + 'selected': True, + 'qty': 100.0, + }) + wizard.quants_lines[1].write({ + 'selected': True, + 'qty': 50.0, + }) + self.assertEqual(wizard.lines_qty, 150.0) + self.assertEqual(wizard.move_qty, 250.0) + + def test_quant_assign_wizard_after_availability_check(self): + self.move.action_assign() + wizard = self.quant_assign_wizard.with_context( + active_id=self.move.id).create({ + 'name': 'New wizard', + }) + self.assertEqual(len(wizard.quants_lines.ids), 3, + 'Three quants created, three quants got by default') + self.assertEqual(len(wizard.quants_lines.filtered('selected').ids), 3, + 'All the quants must have been selected') + self.assertEqual(wizard.lines_qty, 300.0) + self.assertEqual(wizard.move_qty, 100.0) + for line in wizard.quants_lines: + if line.quant in self.move.reserved_quant_ids: + self.assertTrue(line.selected) + else: + self.assertFalse(line.selected) diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py index decb17d05..a2e2c800f 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants.py +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -10,10 +10,6 @@ import openerp.addons.decimal_precision as dp class AssignManualQuants(models.TransientModel): _name = 'assign.manual.quants' - @api.depends('quants_lines') - def lines_qty(self): - self.lines_qty = sum(self.quants_lines.mapped('qty')) - @api.multi @api.constrains('quants_lines') def check_qty(self): @@ -25,16 +21,18 @@ class AssignManualQuants(models.TransientModel): raise exceptions.Warning( _('Quantity is higher than the needed one')) - @api.depends('quants_lines') - def get_move_qty(self): + @api.depends('quants_lines', 'quants_lines.qty') + def _compute_qties(self): move = self.env['stock.move'].browse(self.env.context['active_id']) - self.move_qty = move.product_uom_qty - self.lines_qty + lines_qty = sum(self.quants_lines.mapped('qty')) + self.lines_qty = lines_qty + self.move_qty = move.product_uom_qty - lines_qty name = fields.Char(string='Name') lines_qty = fields.Float( - string='Reserved qty', compute='lines_qty', + string='Reserved qty', compute='_compute_qties', digits=dp.get_precision('Product Unit of Measure')) - move_qty = fields.Float(string='Remaining qty', compute='get_move_qty', + move_qty = fields.Float(string='Remaining qty', compute='_compute_qties', digits=dp.get_precision('Product Unit of Measure')) quants_lines = fields.One2many('assign.manual.quants.lines', 'assign_wizard', string='Quants') diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml index 141ce934a..1602463cc 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml +++ b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml @@ -22,6 +22,7 @@ +