Master fix package pim

[IMP] stock: don't show move fully in package

When the move lines in a move are all linked to a package level,
we don't want to see the move anymore. We cannot keep only a domain on
moves their-selves as it depends on the move lines linked to it.

So we use a compute field to filter the moves to show, and the inverse
function just appends the new/modified moves to the move_lines.

TASK-ID: 1865671

closes odoo/odoo#28401
This commit is contained in:
Robot Odoo
2018-11-05 17:14:33 +01:00
committed by GitHub
4 changed files with 52 additions and 6 deletions
+18 -1
View File
@@ -27,7 +27,7 @@ class StockPackageLevel(models.Model):
],string='State', compute='_compute_state')
is_fresh_package = fields.Boolean(compute='_compute_fresh_pack')
picking_source_location = fields.Many2one('stock.location', related='picking_id.location_id', readonly=False)
picking_type_code = fields.Selection(related='picking_id.picking_type_code')
show_lots_m2o = fields.Boolean(compute='_compute_show_lot')
show_lots_text = fields.Boolean(compute='_compute_show_lot')
@@ -182,3 +182,20 @@ class StockPackageLevel(models.Model):
pl.location_id = pl.move_line_ids[0].location_id
else:
pl.location_id = pl.picking_id.location_id
def action_show_package_details(self):
self.ensure_one()
view = self.env.ref('stock.package_level_form_view')
return {
'name': _('Package Content'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'stock.package_level',
'views': [(view.id, 'form')],
'view_id': view.id,
'target': 'new',
'res_id': self.id,
'flags': {'mode': 'readonly'},
}
+20 -1
View File
@@ -239,7 +239,7 @@ class Picking(models.Model):
readonly=True, required=True,
states={'draft': [('readonly', False)]})
move_lines = fields.One2many('stock.move', 'picking_id', string="Stock Moves", copy=True)
move_ids_without_package = fields.One2many('stock.move', 'picking_id', string="Stock moves not in package", domain=['|',('package_level_id', '=', False), ('picking_type_entire_packs', '=', False)])
move_ids_without_package = fields.One2many('stock.move', 'picking_id', string="Stock moves not in package", compute='_compute_move_without_package', inverse='_set_move_without_package')
has_scrap_move = fields.Boolean(
'Has Scrap Moves', compute='_has_scrap_move')
picking_type_id = fields.Many2one(
@@ -626,6 +626,25 @@ class Picking(models.Model):
self.write({'date_done': fields.Datetime.now()})
return True
@api.depends('state', 'move_lines', 'move_lines.state', 'move_lines.package_level_id')
def _compute_move_without_package(self):
for picking in self:
move_ids_without_package = self.env['stock.move']
if picking.picking_type_entire_packs == False:
move_ids_without_package = picking.move_lines
else:
for move in picking.move_lines:
if not move.package_level_id:
if move.state in ('assigned', 'done'):
if any(not ml.package_level_id for ml in move.move_line_ids):
move_ids_without_package |= move
else:
move_ids_without_package |= move
self.move_ids_without_package = move_ids_without_package
def _set_move_without_package(self):
self.move_lines |= self.move_ids_without_package
def _check_move_lines_map_quant_package(self, package):
""" This method checks that all product of the package (quant) are well present in the move_line_ids of the picking. """
all_in = True
+9
View File
@@ -63,7 +63,11 @@ class TestPacking(TransactionCase):
packing_picking = pack_move_a.picking_id
shipping_picking = ship_move_a.picking_id
pick_picking.picking_type_entire_packs = True
packing_picking.picking_type_entire_packs = True
shipping_picking.picking_type_entire_packs = True
pick_picking.action_assign()
self.assertEqual(len(pick_picking.move_ids_without_package), 2)
pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productA).qty_done = 1.0
pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productB).qty_done = 2.0
@@ -73,7 +77,10 @@ class TestPacking(TransactionCase):
pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productA and ml.qty_done == 0.0).qty_done = 4.0
pick_picking.move_line_ids.filtered(lambda ml: ml.product_id == self.productB and ml.qty_done == 0.0).qty_done = 3.0
second_pack = pick_picking.put_in_pack()
self.assertEqual(len(pick_picking.move_ids_without_package), 0)
self.assertEqual(len(packing_picking.move_ids_without_package), 2)
pick_picking.button_validate()
self.assertEqual(len(packing_picking.move_ids_without_package), 0)
self.assertEqual(len(first_pack.quant_ids), 2)
self.assertEqual(len(second_pack.quant_ids), 2)
packing_picking.action_assign()
@@ -91,6 +98,7 @@ class TestPacking(TransactionCase):
'location_dest_id': self.stock_location.id,
'state': 'draft',
})
picking.picking_type_entire_packs = True
package_level = self.env['stock.package_level'].create({
'package_id': pack.id,
'picking_id': picking.id,
@@ -99,6 +107,7 @@ class TestPacking(TransactionCase):
self.assertEquals(package_level.state, 'draft',
'The package_level should be in draft as it has no moves, move lines and is not confirmed')
picking.action_confirm()
self.assertEqual(len(picking.move_ids_without_package), 0)
self.assertEqual(len(picking.move_lines), 1,
'One move should be created when the package_level has been confirmed')
self.assertEquals(len(package_level.move_ids), 1,
@@ -4,19 +4,19 @@
<field name="name">Package Level</field>
<field name="model">stock.package_level</field>
<field name="arch" type="xml">
<form>
<form create="false" edit="false">
<header>
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,assigned,done" />
</header>
<group>
<field name="picking_id" invisible="1"/>
<field name="picking_source_location" invisible="1"/>
<field name="show_lots_m2o" invisible="1"/>
<field name="show_lots_text" invisible="1"/>
<field name="picking_type_code" invisible="1"/>
<group>
<field name="package_id"/>
<field name="location_id" groups="stock.group_stock_multi_locations"/>
<field name="location_dest_id" groups="stock.group_stock_multi_locations"/>
<field name="location_id" attrs="{'invisible': [('picking_type_code', '=', 'incoming')]}" groups="stock.group_stock_multi_locations"/>
<field name="location_dest_id" attrs="{'invisible': [('picking_type_code', '=', 'outgoing')]}" groups="stock.group_stock_multi_locations"/>
<field name="is_done"/>
</group>
<field name="move_ids" attrs="{'invisible': [('state', 'in', ('new', 'draft', 'assigned', 'done'))]}">
@@ -57,6 +57,7 @@
<field name="location_dest_id" domain="[('id', 'child_of', parent.location_dest_id)]" attrs="{'column_invisible': [('parent.picking_type_code', '=', 'outgoing')]}" groups="stock.group_stock_multi_locations"/>
<field name="state"/>
<field name="is_done" attrs="{'readonly': ['|', ('parent.state', 'in', ('draft', 'new', 'done')), ('is_fresh_package', '=', True)]}"/>
<button name="action_show_package_details" string="Display package content" type="object" icon="fa-list" />
</tree>
</field>
</record>