Skip to content

Commit

Permalink
Merge PR #461 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by aleuffre
  • Loading branch information
OCA-git-bot committed Oct 16, 2023
2 parents 0a77291 + 892bde4 commit bcd3b1a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,49 @@ def test_geo_assign(self):
self.assertEqual(c_es.agent_ids, agent)
self.assertEqual(c_es.commission_item_agent_ids.group_ids, self.cig_spain)

def test_geo_assign_twice(self):
c_it = self.partner_model.create(
{
"name": "Customer Italy",
"country_id": self.country_italy.id,
"state_id": self.state_genova.id,
}
)

agent = self.partner_model.create(
{
"name": "Agent Spain and Italy",
"agent": True,
"commission_id": self.commission_rules_restrict.id,
"allowed_commission_group_ids": [
(6, 0, [self.cig_italy.id, self.cig_spain.id])
],
}
)

self.commission_group_model.create(
[
{
"partner_id": agent.id,
"country_ids": [(6, 0, [self.country_italy.id])],
"commission_group_ids": [(6, 0, [self.cig_italy.id])],
},
{
"partner_id": agent.id,
"state_ids": [(6, 0, [self.state_genova.id])],
"commission_group_ids": [(6, 0, [self.cig_spain.id])],
},
]
)

wizard = self.wizard_model.with_context(active_ids=c_it.ids).create({})

# Should not raise an error
wizard.geo_assign_partner()
self.assertEqual(c_it.agent_ids, agent)
self.assertIn(self.cig_italy.id, c_it.commission_item_agent_ids.group_ids.ids)
self.assertIn(self.cig_spain.id, c_it.commission_item_agent_ids.group_ids.ids)

def test_change_commission_type(self):
agent = self.partner_model.create(
{
Expand All @@ -107,7 +150,7 @@ def test_change_commission_type(self):
"agent_zip_to": 31333,
}
)
self.assertNotEquals(agent.commission_type, "product_restricted")
self.assertNotEqual(agent.commission_type, "product_restricted")

agent.write(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,30 @@ def update_partner_data(self, partner, agent):
for line in agent.commission_geo_group_ids:
if line.is_assignable(partner):
partner.agent_ids = [(4, agent.id)]
partner.commission_item_agent_ids = [
(
0,
0,
{
"agent_id": agent.id,
"group_ids": [
(
6,
0,
line.mapped("commission_group_ids.id"),
)
],
},
)
]

commission_item = partner.commission_item_agent_ids.filtered(
lambda x: x.agent_id == agent
)
if commission_item:
commission_item.group_ids = [
(4, x) for x in line.mapped("commission_group_ids.id")
]
else:
partner.commission_item_agent_ids = [
(
0,
0,
{
"agent_id": agent.id,
"group_ids": [
(
6,
0,
line.mapped("commission_group_ids.id"),
)
],
},
)
]
else:
super().update_partner_data(partner, agent)

0 comments on commit bcd3b1a

Please sign in to comment.