-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] partner_contact_sale_info_propagation: Migration to 17.0
TT52337
- Loading branch information
1 parent
0dda1f3
commit 9517021
Showing
8 changed files
with
89 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
- Ernesto Tejeda | ||
- Pedro M. Baeza | ||
- César A. Sánchez | ||
- Juan Carlos Oñate |
12 changes: 6 additions & 6 deletions
12
partner_contact_sale_info_propagation/readme/DESCRIPTION.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
This module propagates Salesperson and Sales Channel from Company to | ||
This module propagates Salesperson and Sales Teams from Company to | ||
Contacts | ||
|
||
- Put the *Salesperson* or *Sales Channel* of the parent company when | ||
the contact doesn't have a *Salesperson* or *Sales Channel* and this | ||
- Put the *Salesperson* or *Sales Teams* of the parent company when | ||
the contact doesn't have a *Salesperson* or *Sales Teams* and this | ||
parent company is assigned. | ||
- When the company changes the *Salesperson*, it fills with the same | ||
*Salesperson* all the contacts that don't have any or have the | ||
previous *Salesperson* of the parent company. | ||
- When the company changes the *Sales Channel*, it fills with the same | ||
*Sales Channel* all the contacts that don't have any or have the | ||
previous *Sales Channel* of the parent company. | ||
- When the company changes the *Sales Teams*, it fills with the same | ||
*Sales Teams* all the contacts that don't have any or have the | ||
previous *Sales Teams* of the parent company. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 48 additions & 46 deletions
94
partner_contact_sale_info_propagation/tests/test_partner_contact_sale_info_propagation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,69 @@ | ||
# Copyright 2019 Tecnativa - Ernesto Tejeda | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo.tests.common import TransactionCase | ||
|
||
from lxml import etree | ||
|
||
from odoo.tests.common import Form, TransactionCase | ||
|
||
|
||
class TestPartnerContactSaleInfoPropagation(TransactionCase): | ||
class TestResPartner(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.partner_model = self.env["res.partner"].with_context(test_propagation=True) | ||
self.parent_company = self.partner_model.create( | ||
self.salesperson = self.env["res.users"].create( | ||
{ | ||
"name": "Test Salesperson", | ||
"login": "[email protected]", | ||
} | ||
) | ||
self.team = self.env["crm.team"].create({"name": "Sales Team A"}) | ||
self.company = self.partner_model.create( | ||
{ | ||
"name": "Parent company", | ||
"name": "Company A", | ||
"company_type": "company", | ||
"user_id": self.ref("base.user_demo"), | ||
"team_id": self.ref("sales_team.crm_team_1"), | ||
"user_id": self.salesperson.id, | ||
"team_id": self.team.id, | ||
} | ||
) | ||
|
||
def check_same_user_id_team_id(self, parent, child): | ||
self.assertEqual(parent.user_id, child.user_id) | ||
self.assertEqual(parent.team_id, child.team_id) | ||
|
||
def test_create_partner_child(self): | ||
partner_child = self.partner_model.create( | ||
{"name": "Parent child", "parent_id": self.parent_company.id} | ||
self.child_contact = self.partner_model.create( | ||
{ | ||
"name": "Child Contact", | ||
"parent_id": self.company.id, | ||
} | ||
) | ||
self.check_same_user_id_team_id(self.parent_company, partner_child) | ||
|
||
def test_write_parent_company(self): | ||
partner_child = self.partner_model.create( | ||
{"name": "Parent child", "parent_id": self.parent_company.id} | ||
) | ||
self.parent_company.write( | ||
def test_propagate_user_id(self): | ||
"""Test that changing user_id propagates to child contacts""" | ||
new_salesperson = self.env["res.users"].create( | ||
{ | ||
"user_id": self.ref("base.demo_user0"), | ||
"team_id": self.ref("sales_team.team_sales_department"), | ||
"name": "New Salesperson", | ||
"login": "[email protected]", | ||
} | ||
) | ||
self.check_same_user_id_team_id(self.parent_company, partner_child) | ||
self.company.write({"user_id": new_salesperson.id}) | ||
self.assertEqual(self.child_contact.user_id, new_salesperson) | ||
|
||
partner_child.write({"user_id": False, "team_id": False}) | ||
self.parent_company.write( | ||
def test_propagate_team_id(self): | ||
"""Test that changing team_id propagates to child contacts""" | ||
new_team = self.env["crm.team"].create({"name": "Sales Team B"}) | ||
self.company.write({"team_id": new_team.id}) | ||
self.assertEqual(self.child_contact.team_id, new_team) | ||
|
||
def test_inherit_team_id_on_creation(self): | ||
"""Test that a new contact inherits team_id from parent""" | ||
new_contact = self.partner_model.create( | ||
{ | ||
"user_id": self.ref("base.user_demo"), | ||
"team_id": self.ref("sales_team.crm_team_1"), | ||
"name": "New Contact", | ||
"parent_id": self.company.id, | ||
} | ||
) | ||
self.check_same_user_id_team_id(self.parent_company, partner_child) | ||
|
||
def test_onchange_parent_id_with_values_false(self): | ||
form_partner = Form(self.env["res.partner"]) | ||
with form_partner as form: | ||
form.name = self.parent_company.name | ||
form.parent_id = self.parent_company | ||
form_partner.save() | ||
self.assertEqual(form_partner.user_id, self.parent_company.user_id) | ||
self.assertEqual(form_partner.team_id, self.parent_company.team_id) | ||
self.assertEqual(new_contact.team_id, self.team) | ||
|
||
def test_fields_view_get(self): | ||
partner_xml = etree.XML(self.partner_model.get_view()["arch"]) | ||
partner_field = partner_xml.xpath("//field[@name='child_ids']")[0] | ||
context = partner_field.attrib.get("context", "{}") | ||
sub_ctx = "'default_user_id': user_id, 'default_team_id': team_id," | ||
self.assertIn(sub_ctx, context) | ||
def test_change_parent_id_updates_team_id(self): | ||
"""Test that changing parent_id updates team_id if not set""" | ||
new_company = self.partner_model.create( | ||
{ | ||
"name": "Company B", | ||
"company_type": "company", | ||
"team_id": self.team.id, | ||
} | ||
) | ||
self.child_contact.write({"parent_id": new_company.id}) | ||
self.assertEqual(self.child_contact.team_id, self.team) |
16 changes: 0 additions & 16 deletions
16
partner_contact_sale_info_propagation/views/res_partner_view.xml
This file was deleted.
Oops, something went wrong.