[IMP]stock: add user and delivery contact as follower
======= PURPOSE ======= Avoid communication being lost on transfers due to the fact that nobody is following. ============= SPECIFICATION ============= When setting a delivery address, add the contact in question as a follower of the transfer. When a user validates a transfer, he should be automatically added as a follower of this transfer. =========== LINKS =========== task 2172675 pr #44350 closes odoo/odoo#45498 X-original-commit: d6a981039005080e4803cb9c75287dfa4ada712b Related: odoo/enterprise#8483 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -601,11 +601,24 @@ class Picking(models.Model):
|
||||
move[2]['company_id'] = picking_type.company_id.id
|
||||
res = super(Picking, self).create(vals)
|
||||
res._autoconfirm_picking()
|
||||
|
||||
# set partner as follower
|
||||
if vals.get('partner_id'):
|
||||
for picking in res.filtered(lambda p: p.location_id.usage == 'supplier' or p.location_dest_id.usage == 'customer'):
|
||||
picking.message_subscribe([vals.get('partner_id')])
|
||||
|
||||
return res
|
||||
|
||||
def write(self, vals):
|
||||
if vals.get('picking_type_id') and self.state != 'draft':
|
||||
raise UserError(_("Changing the operation type of this record is forbidden at this point."))
|
||||
# set partner as a follower and unfollow old partner
|
||||
if vals.get('partner_id'):
|
||||
for picking in self:
|
||||
if picking.location_id.usage == 'supplier' or picking.location_dest_id.usage == 'customer':
|
||||
if picking.partner_id:
|
||||
picking.message_unsubscribe(picking.partner_id.ids)
|
||||
picking.message_subscribe([vals.get('partner_id')])
|
||||
res = super(Picking, self).write(vals)
|
||||
if vals.get('signature'):
|
||||
for picking in self:
|
||||
@@ -815,6 +828,7 @@ class Picking(models.Model):
|
||||
if not picking.move_lines and not picking.move_line_ids:
|
||||
pickings_without_moves |= picking
|
||||
|
||||
picking.message_subscribe([self.env.user.partner_id.id])
|
||||
picking_type = picking.picking_type_id
|
||||
precision_digits = self.env['decimal.precision'].precision_get('Product Unit of Measure')
|
||||
no_quantities_done = all(float_is_zero(move_line.qty_done, precision_digits=precision_digits) for move_line in picking.move_line_ids.filtered(lambda m: m.state not in ('done', 'cancel')))
|
||||
|
||||
Reference in New Issue
Block a user