test_res_partner.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.addons.crm.tests.common import TestCrmCommon
  4. from odoo.tests.common import Form
  5. from odoo.tests import tagged, users
  6. @tagged('res_partner')
  7. class TestPartner(TestCrmCommon):
  8. @users('user_sales_leads')
  9. def test_parent_sync_sales_rep(self):
  10. """ Test team_id / user_id sync from parent to children if the contact
  11. is a person. Company children are not updated. """
  12. contact_company = self.contact_company.with_env(self.env)
  13. contact_company_1 = self.contact_company_1.with_env(self.env)
  14. self.assertFalse(contact_company.team_id)
  15. self.assertFalse(contact_company.user_id)
  16. self.assertFalse(contact_company_1.team_id)
  17. self.assertFalse(contact_company_1.user_id)
  18. child = self.contact_1.with_env(self.env)
  19. self.assertEqual(child.parent_id, self.contact_company_1)
  20. self.assertFalse(child.team_id)
  21. self.assertFalse(child.user_id)
  22. # update comppany sales rep info
  23. contact_company.user_id = self.env.uid
  24. contact_company.team_id = self.sales_team_1.id
  25. # change child parent: shold update sales rep info
  26. child.parent_id = contact_company.id
  27. self.assertEqual(child.user_id, self.env.user)
  28. # test form tool
  29. # <field name="team_id" groups="base.group_no_one"/>
  30. with self.debug_mode():
  31. partner_form = Form(self.env['res.partner'], 'base.view_partner_form')
  32. partner_form.parent_id = contact_company
  33. partner_form.company_type = 'person'
  34. partner_form.name = 'Hermes Conrad'
  35. self.assertEqual(partner_form.team_id, self.sales_team_1)
  36. self.assertEqual(partner_form.user_id, self.env.user)
  37. partner_form.parent_id = contact_company_1
  38. self.assertEqual(partner_form.team_id, self.sales_team_1)
  39. self.assertEqual(partner_form.user_id, self.env.user)
  40. # test form tool
  41. # <field name="team_id" groups="base.group_no_one"/>
  42. with self.debug_mode():
  43. partner_form = Form(self.env['res.partner'], 'base.view_partner_form')
  44. # `parent_id` is invisible when `is_company` is True (`company_type == 'company'`)
  45. # and parent_id is not set
  46. # So, set a temporary `parent_id` before setting the contact as company
  47. # to make `parent_id` visible in the interface while being a company
  48. # <field name="parent_id"
  49. # attrs="{
  50. # 'invisible': [
  51. # '|',
  52. # '&amp;', ('is_company','=', True),('parent_id', '=', False),
  53. # ('company_name', '!=', False),('company_name', '!=', '')
  54. # ]
  55. # }"
  56. # />
  57. partner_form.parent_id = contact_company_1
  58. partner_form.company_type = 'company'
  59. partner_form.parent_id = contact_company
  60. partner_form.name = 'Mom Corp'
  61. self.assertFalse(partner_form.team_id)
  62. self.assertFalse(partner_form.user_id)