Skip to content

Commit

Permalink
[ADD] More test coverage for notify_user
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiplangatdan committed Aug 2, 2024
1 parent 7a0b48d commit 02d7fea
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion purchase_sale_inter_company/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 02d7fea

Please sign in to comment.