[IMP] stock_quant_manual_assign: added tests

This commit is contained in:
oihane
2015-10-14 13:35:57 +02:00
committed by Tony Gu
parent b26b66424b
commit 28311d8700
6 changed files with 161 additions and 15 deletions

View File

@@ -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 <https://github.com/OCA/oca-stock-logistics-warehouse/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 <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_quant_manual_assign%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Mikel Arregi <mikelarregi@avanzosc.es>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Ana Juaristi <ajuaristio@gmail.com>
* Ana Juaristi <anajuaristi@avanzosc.es>
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
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.

View File

@@ -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 <ajuaristio@gmail.com>",
"Pedro Manuel Baeza Romero <pedro.baeza@serviciosbaeza.com>"
"Mikel Arregi <mikelarregi@avanzosc.es>",
"Ana Juaristi Olalde <anajuaristi@avanzosc.es>",
"Pedro Manuel Baeza Romero <pedro.baeza@serviciosbaeza.com>"
"Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>",
],
"depends": [
"stock",

View File

@@ -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

View File

@@ -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)

View File

@@ -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')

View File

@@ -22,6 +22,7 @@
</form>
</field>
<field name="move_qty" colspan="2" readonly="1"/>
<field name="lines_qty" invisible="1" />
</group>
<footer>
<button name="assign_quants" type="object"