Skip to content

Commit

Permalink
[IMP] sale_double_validation: Replace deprecated sudo(user) by with_u…
Browse files Browse the repository at this point in the history
…ser(user)
  • Loading branch information
majouda committed Jul 29, 2024
1 parent c99523f commit 7e82b7d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions sale_double_validation/tests/test_double_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,21 @@ def test_one_step(self):
self.user_employee.company_id.sudo().so_double_validation = "one_step"
so = self.create_so_by_user_employee()
# confirm quotation
self.assertEquals(so.state, "draft")
self.assertEqual(so.state, "draft")

def test_two_steps_under_limit(self):
self.user_employee.company_id.sudo().so_double_validation = "two_step"
self.user_employee.company_id.sudo().so_double_validation_amount = 100000
so = self.create_so_by_user_employee()
# confirm quotation
self.assertEquals(so.state, "draft")
self.assertEqual(so.state, "draft")

def test_two_steps_manager(self):
self.user_employee.company_id.sudo().so_double_validation = "two_step"
self.user_employee.company_id.sudo().so_double_validation_amount = 10
so = (
self.env["sale.order"]
.sudo(self.user_manager)
.with_user(self.user_manager)
.create(
{
"partner_id": self.partner_customer_usd.id,
Expand All @@ -158,7 +158,7 @@ def test_two_steps_manager(self):
)
)
# confirm quotation
self.assertEquals(so.state, "draft")
self.assertEqual(so.state, "draft")

def test_two_steps_limit(self):
so_double_validation_amount = sum(
Expand All @@ -170,7 +170,7 @@ def test_two_steps_limit(self):
)

so_total_price = sum([2 * p.list_price for (_, p) in self.product_map.items()])
self.assertEquals(so_double_validation_amount, so_total_price)
self.assertEqual(so_double_validation_amount, so_total_price)

# create quotation
so = self.create_so_by_user_employee()
Expand All @@ -184,42 +184,42 @@ def test_two_steps_limit(self):
)
<= 0
)
self.assertEquals(compare_amount, True)
self.assertEqual(compare_amount, True)

# batch of condition tests, to set the SO state to `to_approve`
self.assertEquals(so.company_id.so_double_validation, "two_step")
self.assertEqual(so.company_id.so_double_validation, "two_step")
self.assertFalse(self.user_employee.has_group("sales_team.group_sale_manager"))
self.assertTrue(so.is_amount_to_approve())

# state must be set to `to_approve` if condition above is satisfied
state = "to_approve"
self.assertEquals(so.state, state)
self.assertEqual(so.state, state)

def test_two_steps_above_limit(self):
self.user_employee.company_id.sudo().so_double_validation = "two_step"
self.user_employee.company_id.sudo().so_double_validation_amount = 10
# create quotation
so = self.create_so_by_user_employee()
# confirm quotation
self.assertEquals(so.state, "to_approve")
so.sudo(self.user_manager).action_approve()
self.assertEquals(so.state, "draft")
self.assertEqual(so.state, "to_approve")
so.with_user(self.user_manager).action_approve()
self.assertEqual(so.state, "draft")

def test_confirm_so_above_limit_with_user_employee(self):
self.user_employee.company_id.sudo().so_double_validation = "two_step"
self.user_employee.company_id.sudo().so_double_validation_amount = 10
# create quotation
so = self.create_so_by_user_employee()
# confirm quotation
self.assertEquals(so.state, "to_approve")
so.sudo(self.user_manager).action_approve()
so.sudo(self.user_employee).action_confirm()
self.assertEquals(so.state, "sale")
self.assertEqual(so.state, "to_approve")
so.with_user(self.user_manager).action_approve()
so.with_user(self.user_employee).action_confirm()
self.assertEqual(so.state, "sale")

def create_so_by_user_employee(self):
so = (
self.env["sale.order"]
.sudo(self.user_employee)
.with_user(self.user_employee)
.create(
{
"partner_id": self.partner_customer_usd.id,
Expand Down

0 comments on commit 7e82b7d

Please sign in to comment.