diff --git a/purchase_sale_inter_company/models/stock_picking.py b/purchase_sale_inter_company/models/stock_picking.py index 5a8cd922cb8..1df7f835fb9 100644 --- a/purchase_sale_inter_company/models/stock_picking.py +++ b/purchase_sale_inter_company/models/stock_picking.py @@ -116,7 +116,7 @@ def _notify_picking_problem(self, purchase): note=note, # Try to notify someone relevant user_id=( - self.env.company_id.notify_user_id.id + self.company_id.notify_user_id.id or self.sale_id.user_id.id or self.sale_id.team_id.user_id.id or SUPERUSER_ID, diff --git a/purchase_sale_inter_company/tests/test_inter_company_purchase_sale.py b/purchase_sale_inter_company/tests/test_inter_company_purchase_sale.py index d0f07071406..45f6b840b3f 100644 --- a/purchase_sale_inter_company/tests/test_inter_company_purchase_sale.py +++ b/purchase_sale_inter_company/tests/test_inter_company_purchase_sale.py @@ -679,3 +679,46 @@ def test_block_manual_validation(self): # The manual validation should be blocked with self.assertRaises(UserError): po_picking_id.with_user(self.user_company_a).button_validate() + + def test_notify_picking_problem(self): + self.company_a.sync_picking = True + self.company_b.sync_picking = True + self.company_a.sync_picking_failure_action = "notify" + self.company_b.sync_picking_failure_action = "notify" + self.company_a.notify_user_id = self.user_company_a + self.company_b.notify_user_id = self.user_company_b + + purchase = self._create_purchase_order( + self.partner_company_b, self.consumable_product + ) + purchase_2 = self._create_purchase_order( + self.partner_company_b, self.consumable_product + ) + purchase.order_line += purchase.order_line.copy({"product_qty": 2}) + sale = self._approve_po(purchase) + sale.action_confirm() + + # validate the SO picking + so_picking_id = sale.picking_ids + + # Link to a new purchase order so it can trigger + # `PO does not exist or has no receipts` in _sync_receipt_with_delivery + sale.auto_purchase_order_id = purchase_2 + + # Set quantities done on the picking and validate + for move in so_picking_id.move_lines: + move.quantity_done = move.product_uom_qty + so_picking_id.button_validate() + + # Test that picking has an activity now + self.assertTrue(len(so_picking_id.activity_ids) > 0) + activity_warning = self.env.ref("mail.mail_activity_data_warning") + warning_activity = so_picking_id.activity_ids.filtered( + lambda a: a.activity_type_id == activity_warning + ) + self.assertEqual(len(warning_activity), 1) + + # Test the user assigned to the activity + self.assertEqual( + warning_activity.user_id, so_picking_id.company_id.notify_user_id + )