[IMP] stock: logged the note when edit the initial demand on a picking and when edit the received(done) quantity on a picking done(validated) as well as backorder message is deleted for better usability

This commit is contained in:
Vandan Shah
2017-09-27 13:20:00 +02:00
committed by amoyaux
parent b509427e7a
commit 0c8e18eba6
3 changed files with 118 additions and 2 deletions
+5 -2
View File
@@ -356,7 +356,10 @@ class StockMove(models.Model):
def write(self, vals):
# FIXME: pim fix your crap
if vals.get('product_uom_qty'):
if 'product_uom_qty' in vals:
for move in self.filtered(lambda m: m.state not in ('done', 'draft') and m.picking_id):
if vals['product_uom_qty'] != move.product_uom_qty:
self.env['stock.move.line']._log_message(move.picking_id, move, 'stock.track_move_template', vals)
if self.env.context.get('do_not_unreserve') is None:
move_to_unreserve = self.filtered(lambda m: m.state not in ['draft', 'done', 'cancel'] and m.reserved_availability > vals.get('product_uom_qty'))
move_to_unreserve._do_unreserve()
@@ -995,7 +998,7 @@ class StockMove(models.Model):
'move_line_ids': [],
'backorder_id': picking.id
})
picking.message_post('Backorder Created') #message needs to be improved
picking.message_post(_('The backorder <a href=# data-oe-model=stock.picking data-oe-id=%d>%s</a> has been created.') % (backorder_picking.id, backorder_picking.name))
moves_to_backorder.write({'picking_id': backorder_picking.id})
moves_to_backorder.mapped('move_line_ids').write({'picking_id': backorder_picking.id})
moves_to_backorder._action_assign()
+21
View File
@@ -279,6 +279,11 @@ class StockMoveLine(models.Model):
Quant._update_available_quantity(product_id, location_dest_id, quantity, lot_id=lot_id, package_id=result_package_id, owner_id=owner_id, in_date=in_date)
# Unreserve and reserve following move in order to have the real reserved quantity on move_line.
next_moves |= ml.move_id.move_dest_ids.filtered(lambda move: move.state not in ('done', 'cancel'))
# Log a note
if ml.picking_id:
ml._log_message(ml.picking_id, ml, 'stock.track_move_template', vals)
res = super(StockMoveLine, self).write(vals)
# As stock_account values according to a move's `product_uom_qty`, we consider that any
@@ -383,6 +388,22 @@ class StockMoveLine(models.Model):
# Reset the reserved quantity as we just moved it to the destination location.
(self - ml_to_delete).with_context(bypass_reservation_update=True).write({'product_uom_qty': 0.00})
def _log_message(self, record, move, template, vals):
data = vals.copy()
if 'lot_id' in vals and vals['lot_id'] != move.lot_id.id:
data['lot_name'] = self.env['stock.production.lot'].browse(vals.get('lot_id')).name
if 'location_id' in vals:
data['location_name'] = self.env['stock.location_id'].browse(vals.get('location_id')).name
if 'location_dest_id' in vals:
data['location_dest_name'] = self.env['stock.location_id'].browse(vals.get('location_dest_id')).name
if 'package_id' in vals and vals['package_id'] != move.package_id.id:
data['package_name'] = self.env['stock.quant.package'].browse(vals.get('package_id')).name
if 'package_result_id' in vals and vals['package_result_id'] != move.package_result_id.id:
data['result_package_name'] = self.env['stock.quant.package'].browse(vals.get('result_package_id')).name
if 'owner_id' in vals and vals['owner_id'] != move.owner_id.id:
data['owner_name'] = self.env['res.partner'].browse(vals.get('owner_id')).name
record.message_post_with_view(template, values={'move': move, 'vals': dict(vals, **data)}, subtype_id=self.env.ref('mail.mt_note').id)
def _free_reservation(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None):
""" When editing a done move line or validating one with some forced quantities, it is
possible to impact quants that were not reserved. It is therefore necessary to edit or
+92
View File
@@ -9,4 +9,96 @@
</xpath>
</template>
<template id="message_head">
<t t-if="move.state != 'done'">
<strong>The initial demand has been updated.</strong>
</t>
<t t-if="move.state == 'done'">
<strong>
The done move line has been corrected.
</strong>
</t>
</template>
<template id="message_body">
<ul>
<li>
<t t-esc="move.product_id.display_name"/>:
</li>
<t t-if="move.state != 'done'">
<t t-if="'product_uom_qty' in vals">
<li>
Quantity : <t t-esc="move.product_uom_qty"/> -&gt; <t t-esc="float(vals.get('product_uom_qty'))"/>
</li>
</t>
</t>
<t t-if="'qty_done' in vals">
<li>
Quantity : <t t-esc="move.qty_done"/> -&gt; <t t-esc="float(vals.get('qty_done'))"/>
</li>
</t>
<t t-if="'location_id' in vals">
<li>
Source Location:
<t t-if="move.location_id">
<t t-esc="move.location_id.name"/> -&gt;
</t>
<t t-esc="vals['location_name']"/>
</li>
</t>
<t t-if="'location_dest_id' in vals">
<li>
Destination Location:
<t t-if="move.location_dest_id">
<t t-esc="move.location_dest_id.name"/> -&gt;
</t>
<t t-esc="vals['location_dest_name']"/>
</li>
</t>
<t t-if="'lot_name' in vals">
<li>
Lot/Serial :
<t t-if="move.lot_id">
<t t-esc="move.lot_id.name"/> -&gt;
</t>
<t t-esc="vals['lot_name']"/>
</li>
</t>
<t t-if="'package_name' in vals">
<li>
Source Package :
<t t-if="move.package_id">
<t t-esc="move.package_id.name"/> -&gt;
</t>
<t t-esc="vals['package_name']"/>
</li>
</t>
<t t-if="'result_package_name' in vals">
<li>
Destination Package :
<t t-if="move.result_package_id">
<t t-esc="move.result_package_id.name"/> -&gt;
</t>
<t t-esc="vals['result_package_name']"/>
</li>
</t>
<t t-if="'owner_name' in vals">
<li>
Owner :
<t t-if="move.owner_id">
<t t-esc="move.owner_id.name"/> -&gt;
</t>
<t t-esc="vals['owner_name']"/>
</li>
</t>
</ul>
</template>
<template id="track_move_template">
<div>
<t t-call="stock.message_head"/>
<t t-call="stock.message_body"/>
</div>
</template>
</odoo>