This question has been flagged
1 Reply
3836 Views

In our database, we use two level of approval, so a manager must approve any purchase order.

When the manager approve a purchase order, a receipt is automatically created for the material bought. The only follower of this receipt is the manager who approved the purchase order.

The follower should be the user who initially created the purchase order, because he is the person who should be notified when the material is in our warehouse. Also, the manager who approved the order should not be notified.

Is there another way of doing so apart from manually following/unfollowing the receipt?

Avatar
Discard
Best Answer

You could create an Automated Action to change this behavior.

Activate Developer Mode and visit the Technical --> Automation --> Automated Actions (if this menu isn't present, please install the Automated Action rules (base_automation) module.

Create a new Automated Action:

 



Code for you to copy/paste:

# if this is a Receipt with a Source (possibly automatically made)
if record.picking_type_id.code == 'incoming' and record.origin: 
# find the PO that made the Receipt 
located_po = env['purchase.order'].search([('name','=',record.origin)]) 
# Remove existing followers  
for follower in record.message_follower_ids:   
record.message_unsubscribe([follower.partner_id.id]) 
# Add the same followers as the PO 
for follower in located_po.message_follower_ids:   
record.message_subscribe([follower.partner_id.id])


This will:

  • Check that the newly created Receipt is in fact a Receipt, and wasn't created manually.

  • Find the PO that created it

  • Remove all followers from the Receipt

  • Add the same followers from the PO to the Receipt


Note:  If there are no Followers on the PO, there will also be no Followers on the Receipt.

Avatar
Discard