[IMP] stock: rework of immediate transfers.

The transfers are either 'planned' or 'immediate' but the process are sensibly the
same. This commit separate clearly the two possible pickings (with a new boolean field)
and simplify the view of immediate ones. This kind of transfer is pretty straightforward
so only the 'Done' column remains and the text stays written in black.
This commit is contained in:
Darshil Trivedi
2018-05-18 08:28:11 +02:00
committed by William Henrotin
parent d9feb74ae8
commit ffb79761c1
5 changed files with 19 additions and 28 deletions
+3 -3
View File
@@ -184,7 +184,7 @@ class StockMove(models.Model):
has_package = move.move_line_ids.mapped('package_id') | move.move_line_ids.mapped('result_package_id') has_package = move.move_line_ids.mapped('package_id') | move.move_line_ids.mapped('result_package_id')
consignment_enabled = self.user_has_groups('stock.group_tracking_owner') consignment_enabled = self.user_has_groups('stock.group_tracking_owner')
if move.picking_id.picking_type_id.show_operations is False\ if move.picking_id.picking_type_id.show_operations is False\
and (move.state != 'draft' or (not self._context.get('planned_picking') and move.state == 'draft'))\ and (move.state != 'draft' or (move.picking_id.immediate_transfer and move.state == 'draft'))\
and (multi_locations_enabled or move.has_tracking != 'none' or len(move.move_line_ids) > 1 or has_package or consignment_enabled): and (multi_locations_enabled or move.has_tracking != 'none' or len(move.move_line_ids) > 1 or has_package or consignment_enabled):
move.show_details_visible = True move.show_details_visible = True
else: else:
@@ -200,7 +200,7 @@ class StockMove(models.Model):
@api.depends('state', 'picking_id') @api.depends('state', 'picking_id')
def _compute_is_initial_demand_editable(self): def _compute_is_initial_demand_editable(self):
for move in self: for move in self:
if self._context.get('planned_picking'): if not move.picking_id.immediate_transfer:
move.is_initial_demand_editable = True move.is_initial_demand_editable = True
elif not move.picking_id.is_locked and move.state != 'done' and move.picking_id: elif not move.picking_id.is_locked and move.state != 'done' and move.picking_id:
move.is_initial_demand_editable = True move.is_initial_demand_editable = True
@@ -213,7 +213,7 @@ class StockMove(models.Model):
for move in self: for move in self:
if not move.product_id: if not move.product_id:
move.is_quantity_done_editable = False move.is_quantity_done_editable = False
elif self._context.get('planned_picking') and move.picking_id.state == 'draft': elif not move.picking_id.immediate_transfer and move.picking_id.state == 'draft':
move.is_quantity_done_editable = False move.is_quantity_done_editable = False
elif move.picking_id.is_locked and move.state in ('done', 'cancel'): elif move.picking_id.is_locked and move.state in ('done', 'cancel'):
move.is_quantity_done_editable = False move.is_quantity_done_editable = False
+7 -19
View File
@@ -303,6 +303,7 @@ class Picking(models.Model):
show_operations = fields.Boolean(compute='_compute_show_operations') show_operations = fields.Boolean(compute='_compute_show_operations')
show_lots_text = fields.Boolean(compute='_compute_show_lots_text') show_lots_text = fields.Boolean(compute='_compute_show_lots_text')
has_tracking = fields.Boolean(compute='_compute_has_tracking') has_tracking = fields.Boolean(compute='_compute_has_tracking')
immediate_transfer = fields.Boolean()
_sql_constraints = [ _sql_constraints = [
('name_uniq', 'unique(name, company_id)', 'Reference must be unique per company!'), ('name_uniq', 'unique(name, company_id)', 'Reference must be unique per company!'),
@@ -319,7 +320,7 @@ class Picking(models.Model):
picking.show_operations = True picking.show_operations = True
continue continue
if picking.picking_type_id.show_operations: if picking.picking_type_id.show_operations:
if (picking.state == 'draft' and not self.env.context.get('planned_picking')) or picking.state != 'draft': if (picking.state == 'draft' and picking.immediate_transfer) or picking.state != 'draft':
picking.show_operations = True picking.show_operations = True
else: else:
picking.show_operations = False picking.show_operations = False
@@ -437,7 +438,7 @@ class Picking(models.Model):
for picking in self: for picking in self:
if not picking.move_lines: if not picking.move_lines:
picking.show_mark_as_todo = False picking.show_mark_as_todo = False
elif self._context.get('planned_picking') and picking.state == 'draft': elif not (picking.immediate_transfer) and picking.state == 'draft':
picking.show_mark_as_todo = True picking.show_mark_as_todo = True
elif picking.state != 'draft' or not picking.id: elif picking.state != 'draft' or not picking.id:
picking.show_mark_as_todo = False picking.show_mark_as_todo = False
@@ -448,7 +449,7 @@ class Picking(models.Model):
@api.depends('state', 'is_locked') @api.depends('state', 'is_locked')
def _compute_show_validate(self): def _compute_show_validate(self):
for picking in self: for picking in self:
if self._context.get('planned_picking') and picking.state == 'draft': if not (picking.immediate_transfer) and picking.state == 'draft':
picking.show_validate = False picking.show_validate = False
elif picking.state not in ('draft', 'waiting', 'confirmed', 'assigned') or not picking.is_locked: elif picking.state not in ('draft', 'waiting', 'confirmed', 'assigned') or not picking.is_locked:
picking.show_validate = False picking.show_validate = False
@@ -562,19 +563,7 @@ class Picking(models.Model):
# call `_action_assign` on every confirmed move which location_id bypasses the reservation # call `_action_assign` on every confirmed move which location_id bypasses the reservation
self.filtered(lambda picking: picking.location_id.usage in ('supplier', 'inventory', 'production') and picking.state == 'confirmed')\ self.filtered(lambda picking: picking.location_id.usage in ('supplier', 'inventory', 'production') and picking.state == 'confirmed')\
.mapped('move_lines')._action_assign() .mapped('move_lines')._action_assign()
if self.env.context.get('planned_picking') and len(self) == 1: return True
action = self.env.ref('stock.action_picking_form')
result = action.read()[0]
result['res_id'] = self.id
result['context'] = {
'search_default_picking_type_id': [self.picking_type_id.id],
'default_picking_type_id': self.picking_type_id.id,
'contact_display': 'partner_address',
'planned_picking': False,
}
return result
else:
return True
@api.multi @api.multi
def action_assign(self): def action_assign(self):
@@ -793,9 +782,8 @@ class Picking(models.Model):
@api.multi @api.multi
def _autoconfirm_picking(self): def _autoconfirm_picking(self):
if not self._context.get('planned_picking'): for picking in self.filtered(lambda picking: picking.immediate_transfer and picking.state not in ('done', 'cancel') and picking.move_lines):
for picking in self.filtered(lambda picking: picking.state not in ('done', 'cancel') and picking.move_lines): picking.action_confirm()
picking.action_confirm()
def _get_overprocessed_stock_moves(self): def _get_overprocessed_stock_moves(self):
self.ensure_one() self.ensure_one()
+1
View File
@@ -3549,6 +3549,7 @@ class StockMove(TransactionCase):
'location_id': self.supplier_location.id, 'location_id': self.supplier_location.id,
'location_dest_id': self.stock_location.id, 'location_dest_id': self.stock_location.id,
'picking_type_id': self.env.ref('stock.picking_type_in').id, 'picking_type_id': self.env.ref('stock.picking_type_in').id,
'immediate_transfer': True,
}) })
move1 = self.env['stock.move'].create({ move1 = self.env['stock.move'].create({
'name': 'test_transit_1', 'name': 'test_transit_1',
+7 -6
View File
@@ -283,8 +283,9 @@
</page> </page>
<page string="Operations"> <page string="Operations">
<field name="id" invisible="1"/> <field name="id" invisible="1"/>
<field name="move_lines" attrs="{'readonly': ['|', '&amp;', ('show_operations', '=', True), '|', ('is_locked', '=', True), ('state', '=', 'done'), '&amp;', ('state', '=', 'done'), ('is_locked', '=', True)]}" context="{'picking_type_code': picking_type_code, 'default_picking_id': id, 'form_view_ref':'stock.view_move_picking_form', 'address_in_id': partner_id, 'default_picking_type_id': picking_type_id, 'default_location_id': location_id, 'default_location_dest_id': location_dest_id}"> <field name="immediate_transfer" invisible="1"/>
<tree decoration-danger="state != 'done' and quantity_done > reserved_availability and show_reserved_availability" decoration-muted="scrapped == True or state == 'cancel' or (state == 'done' and is_locked == True)" string="Stock Moves" editable="bottom"> <field name="move_lines" attrs="{'readonly': ['|', ('show_operations', '=', True), '&amp;', ('state', '=', 'done'), ('is_locked', '=', True)]}" context="{'picking_type_code': picking_type_code, 'default_picking_id': id, 'form_view_ref':'stock.view_move_picking_form', 'address_in_id': partner_id, 'default_picking_type_id': picking_type_id, 'default_location_id': location_id, 'default_location_dest_id': location_dest_id}">
<tree decoration-danger="not parent.immediate_transfer and state != 'done' and quantity_done > reserved_availability and show_reserved_availability" decoration-muted="scrapped == True or state == 'cancel' or (state == 'done' and is_locked == True)" string="Stock Moves" editable="bottom">
<field name="name" invisible="1"/> <field name="name" invisible="1"/>
<field name="date_expected" invisible="1"/> <field name="date_expected" invisible="1"/>
<field name="state" invisible="1" readonly="0"/> <field name="state" invisible="1" readonly="0"/>
@@ -303,8 +304,8 @@
<field name="product_id" required="1" attrs="{'readonly': ['|', '&amp;', ('state', '!=', 'draft'), ('additional', '=', False), ('has_move_lines', '=', True)]}"/> <field name="product_id" required="1" attrs="{'readonly': ['|', '&amp;', ('state', '!=', 'draft'), ('additional', '=', False), ('has_move_lines', '=', True)]}"/>
<field name="is_initial_demand_editable" invisible="1"/> <field name="is_initial_demand_editable" invisible="1"/>
<field name="is_quantity_done_editable" invisible="1"/> <field name="is_quantity_done_editable" invisible="1"/>
<field name="product_uom_qty" string="Initial Demand" attrs="{'readonly': [('is_initial_demand_editable', '=', False)]}"/> <field name="product_uom_qty" string="Initial Demand" attrs="{'column_invisible': [('parent.immediate_transfer', '=', True), ('parent.is_locked', '=', True)], 'readonly': [('is_initial_demand_editable', '=', False)]}"/>
<field name="reserved_availability" string="Reserved" attrs="{'column_invisible': ['|', ('parent.state','=', 'done'), ('parent.picking_type_code', '=', 'incoming')]}"/> <field name="reserved_availability" string="Reserved" attrs="{'column_invisible': (['|','&amp;', ('parent.state','=', 'done'), ('parent.picking_type_code', '=', 'incoming'),('parent.immediate_transfer', '=', True), ('parent.is_locked', '=', True)])}"/>
<field name="quantity_done" string="Done" attrs="{'readonly': [('is_quantity_done_editable', '=', False)]}"/> <field name="quantity_done" string="Done" attrs="{'readonly': [('is_quantity_done_editable', '=', False)]}"/>
<field name="product_uom" attrs="{'readonly': [('state', '!=', 'draft'), ('additional', '=', False)]}" options="{'no_open': True, 'no_create': True}" string="Unit of Measure" groups="uom.group_uom"/> <field name="product_uom" attrs="{'readonly': [('state', '!=', 'draft'), ('additional', '=', False)]}" options="{'no_open': True, 'no_create': True}" string="Unit of Measure" groups="uom.group_uom"/>
<button name="action_show_details" string="Register lots, packs, location" type="object" icon="fa-list" attrs="{'invisible': [('show_details_visible', '=', False)]}" options='{"warn": true}'/> <button name="action_show_details" string="Register lots, packs, location" type="object" icon="fa-list" attrs="{'invisible': [('show_details_visible', '=', False)]}" options='{"warn": true}'/>
@@ -710,10 +711,10 @@
<span>New</span> <span>New</span>
</div> </div>
<div> <div>
<a name="%(action_picking_form)d" type="action">Immediate Transfer</a> <a name="%(action_picking_form)d" type="action" context="{'default_immediate_transfer': True}">Immediate Transfer</a>
</div> </div>
<div> <div>
<a name="%(action_picking_form)d" type="action" context="{'planned_picking': True}">Planned Transfer</a> <a name="%(action_picking_form)d" type="action">Planned Transfer</a>
</div> </div>
</div> </div>
</div> </div>
@@ -82,6 +82,7 @@ class TestLifoPrice(common.TransactionCase):
# Let us send some goods # Let us send some goods
out_form = Form(self.env['stock.picking']) out_form = Form(self.env['stock.picking'])
out_form.picking_type_id = self.env.ref('stock.picking_type_out') out_form.picking_type_id = self.env.ref('stock.picking_type_out')
out_form.immediate_transfer = True
with out_form.move_lines.new() as move: with out_form.move_lines.new() as move:
move.product_id = product_lifo_icecream move.product_id = product_lifo_icecream
move.quantity_done = 20.0 move.quantity_done = 20.0