[MIG] stock_move_location to v12

[FIX] improvement move line generation
This commit is contained in:
Joan Sisquella
2019-11-06 12:30:57 +01:00
committed by Alex Cuellar
parent b14d0656af
commit 29471fa294
9 changed files with 32 additions and 42 deletions

View File

@@ -89,6 +89,7 @@ Contributors
* Mathieu Vatel <mathieu@julius.fr>
* Mykhailo Panarin <m.panarin@mobilunity.com>
* Sergio Teruel <sergio.teruel@tecnativa.com>
* Joan Sisquella <joan.sisquella@eficent.com>
Maintainers
~~~~~~~~~~~

View File

@@ -4,7 +4,7 @@
{
"name": "Move Stock Location",
"version": "11.0.1.1.0",
"version": "12.0.1.1.0",
"author": "Julius Network Solutions, "
"Odoo Community Association (OCA)",
"summary": "This module allows to move all stock "

View File

@@ -15,5 +15,5 @@ class StockMove(models.Model):
@api.depends("location_move")
def _compute_show_details_visible(self):
super()._compute_show_details_visible()
for move in self:
move.show_details_visible = move.location_move
for move in self.filtered(lambda x: x.location_move):
move.show_details_visible = True

View File

@@ -1,3 +1,4 @@
* Mathieu Vatel <mathieu@julius.fr>
* Mykhailo Panarin <m.panarin@mobilunity.com>
* Sergio Teruel <sergio.teruel@tecnativa.com>
* Joan Sisquella <joan.sisquella@eficent.com>

View File

@@ -26,18 +26,18 @@ class TestsCommon(common.SavepointCase):
"usage": "internal",
"active": True,
})
cls.uom_unit = cls.env.ref('product.product_uom_unit')
cls.uom_unit = cls.env.ref('uom.product_uom_unit')
cls.product_no_lots = product_obj.create({
"name": "Pineapple",
"type": "product",
"tracking": "none",
'categ_id': cls.env.ref('product.product_category_all').id,
'category_id': cls.env.ref('product.product_category_all').id,
})
cls.product_lots = product_obj.create({
"name": "Pineapple",
"type": "product",
"tracking": "lot",
'categ_id': cls.env.ref('product.product_category_all').id,
'category_id': cls.env.ref('product.product_category_all').id,
})
cls.lot1 = cls.env['stock.production.lot'].create({
'product_id': cls.product_lots.id,

View File

@@ -21,7 +21,7 @@ class TestMoveLocation(TestsCommon):
def test_move_location_wizard(self):
"""Test a simple move."""
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.add_lines()
wizard.onchange_origin_location()
wizard.action_move_location()
self.check_product_amount(
self.product_no_lots, self.internal_loc_1, 0,
@@ -51,14 +51,14 @@ class TestMoveLocation(TestsCommon):
def test_move_location_wizard_amount(self):
"""Can't move more than exists."""
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.add_lines()
wizard.onchange_origin_location()
with self.assertRaises(ValidationError):
wizard.stock_move_location_line_ids[0].move_quantity += 1
def test_move_location_wizard_ignore_reserved(self):
"""Can't move more than exists."""
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.add_lines()
wizard.onchange_origin_location()
# reserve some quants
self.quant_obj._update_reserved_quantity(
self.product_no_lots,
@@ -86,7 +86,7 @@ class TestMoveLocation(TestsCommon):
def test_wizard_clear_lines(self):
"""Test lines getting cleared properly."""
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.add_lines()
wizard.onchange_origin_location()
self.assertEqual(len(wizard.stock_move_location_line_ids), 4)
wizard._onchange_destination_location_id()
self.assertEqual(len(wizard.stock_move_location_line_ids), 4)
@@ -99,7 +99,7 @@ class TestMoveLocation(TestsCommon):
def test_planned_transfer(self):
"""Test planned transfer."""
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
wizard.add_lines()
wizard.onchange_origin_location()
wizard.with_context({'planned': True}).action_move_location()
picking = wizard.picking_id
self.assertEqual(picking.state, 'draft')

View File

@@ -9,6 +9,7 @@ from odoo.fields import first
class StockMoveLocationWizard(models.TransientModel):
_name = "wiz.stock.move.location"
_description = 'Wizard move location'
origin_location_id = fields.Many2one(
string='Origin Location',
@@ -22,10 +23,9 @@ class StockMoveLocationWizard(models.TransientModel):
required=True,
domain=lambda self: self._get_locations_domain(),
)
stock_move_location_line_ids = fields.One2many(
stock_move_location_line_ids = fields.Many2many(
string="Move Location lines",
comodel_name="wiz.stock.move.location.line",
inverse_name="move_location_wizard_id",
)
picking_id = fields.Many2one(
string="Connected Picking",
@@ -175,23 +175,24 @@ class StockMoveLocationWizard(models.TransientModel):
# cursor returns None instead of False
'lot_id': group.get("lot_id") or False,
'product_uom_id': product.uom_id.id,
'move_location_wizard_id': self.id,
'custom': False,
})
return product_data
def add_lines(self):
self.ensure_one()
line_model = self.env["wiz.stock.move.location.line"]
if not self.stock_move_location_line_ids:
@api.onchange('origin_location_id')
def onchange_origin_location(self):
lines = []
if self.origin_location_id:
line_model = self.env["wiz.stock.move.location.line"]
for line_val in self._get_stock_move_location_lines_values():
if line_val.get('max_quantity') <= 0:
continue
line = line_model.create(line_val)
line.onchange_product_id()
return {
"type": "ir.actions.do_nothing",
}
line.max_quantity = line.get_max_quantity()
lines.append(line)
# self.stock_move_location_line_ids = [(4, line.id)]
self.update({'stock_move_location_line_ids': [
(6, 0, [line.id for line in lines])]})
def clear_lines(self):
self._clear_lines()

View File

@@ -11,15 +11,11 @@
<field name="origin_location_id" invisible="context.get('origin_location_disable', False)"/>
<field name="destination_location_id"/>
</group>
<group name="button" invisible="context.get('origin_location_disable', False)">
<button name="add_lines" string="Add all" type="object" class="btn-primary"/>
<button name="clear_lines" string="Clear all" type="object" class="btn-primary"/>
</group>
<group name="lines">
<field name="stock_move_location_line_ids" nolabel="1" >
<tree string="Inventory Details" editable="bottom" decoration-info="move_quantity != max_quantity" decoration-danger="(move_quantity &lt; 0) or (move_quantity > max_quantity)">
<tree string="Inventory Details" editable="bottom" decoration-info="move_quantity != max_quantity" decoration-danger="(move_quantity &lt; 0) or (move_quantity > max_quantity)" create="0">
<field name="product_id" domain="[('type','=','product')]"/>
<field name="product_uom_id" string="UoM" groups="product.group_uom"/>
<field name="product_uom_id" string="UoM" groups="uom.group_uom"/>
<field name="origin_location_id" readonly="1" force_save="1"/>
<field name="destination_location_id" readonly="1" force_save="1"/>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot" options="{'no_create': True}"/>

View File

@@ -10,13 +10,8 @@ from odoo.tools import float_compare
class StockMoveLocationWizardLine(models.TransientModel):
_name = "wiz.stock.move.location.line"
_description = 'Wizard move location line'
move_location_wizard_id = fields.Many2one(
string="Move location Wizard",
comodel_name="wiz.stock.move.location",
ondelete="cascade",
required=True,
)
product_id = fields.Many2one(
string="Product",
comodel_name="product.product",
@@ -32,7 +27,7 @@ class StockMoveLocationWizardLine(models.TransientModel):
)
product_uom_id = fields.Many2one(
string='Product Unit of Measure',
comodel_name='product.uom',
comodel_name='uom.uom',
)
lot_id = fields.Many2one(
string='Lot/Serial Number',
@@ -71,12 +66,10 @@ class StockMoveLocationWizardLine(models.TransientModel):
"Move quantity can not exceed max quantity or be negative"
))
@api.onchange('product_id', 'lot_id')
def onchange_product_id(self):
def get_max_quantity(self):
self.product_uom_id = self.product_id.uom_id
wiz = self.move_location_wizard_id
search_args = [
('location_id', '=', wiz.origin_location_id.id),
('location_id', '=', self.origin_location_id.id),
('product_id', '=', self.product_id.id),
]
if self.lot_id:
@@ -85,9 +78,7 @@ class StockMoveLocationWizardLine(models.TransientModel):
search_args.append(('lot_id', '=', False))
res = self.env['stock.quant'].read_group(search_args, ['quantity'], [])
max_quantity = res[0]['quantity']
self.max_quantity = max_quantity
self.origin_location_id = wiz.origin_location_id
self.destination_location_id = wiz.destination_location_id
return max_quantity
def create_move_lines(self, picking, move):
for line in self: