test_sales_team_security.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Tecnativa - Pedro M. Baeza
  3. # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
  4. from openerp.tests import common
  5. from ..hooks import assign_contacts_team
  6. from lxml import etree
  7. class TestSalesTeamSecurity(common.SavepointCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(TestSalesTeamSecurity, cls).setUpClass()
  11. cls.section = cls.env['crm.case.section'].create({
  12. 'name': 'Test section',
  13. })
  14. cls.partner = cls.env['res.partner'].create({
  15. 'name': 'Test partner',
  16. 'section_id': cls.section.id,
  17. })
  18. def test_onchange_parent_id(self):
  19. res = self.env['res.partner'].onchange_address(True, self.partner.id)
  20. self.assertEqual(res['value']['section_id'], self.section.id)
  21. def test_assign_contacts_team(self):
  22. contact = self.env['res.partner'].create({
  23. 'name': 'Test contact',
  24. 'parent_id': self.partner.id,
  25. 'section_id': False,
  26. })
  27. assign_contacts_team(self.env.cr, self.env.registry)
  28. contact.refresh()
  29. self.assertEqual(contact.section_id, self.partner.section_id)
  30. def test_partner_fields_view_get(self):
  31. res = self.env['res.partner'].fields_view_get(
  32. view_id=self.ref('base.view_partner_form'))
  33. eview = etree.fromstring(res['arch'])
  34. xml_fields = eview.xpath("//field[@name='child_ids']")
  35. self.assertTrue(xml_fields)
  36. self.assertTrue(
  37. 'default_section_id' in xml_fields[0].get('context', ''))