res_partner.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 import api, models
  5. from lxml import etree
  6. class ResPartner(models.Model):
  7. _inherit = 'res.partner'
  8. @api.model
  9. def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
  10. submenu=False):
  11. """Patch view to inject the default value for the section_id."""
  12. res = super(ResPartner, self).fields_view_get(
  13. view_id=view_id, view_type=view_type, toolbar=toolbar,
  14. submenu=submenu)
  15. if view_type == 'form':
  16. eview = etree.fromstring(res['arch'])
  17. xml_fields = eview.xpath("//field[@name='child_ids']")
  18. if xml_fields:
  19. context_str = xml_fields[0].get('context', '{}').replace(
  20. '{', "{'default_section_id': section_id, ", 1,
  21. )
  22. xml_fields[0].set('context', context_str)
  23. res['arch'] = etree.tostring(eview)
  24. return res
  25. @api.multi
  26. def onchange_address(self, use_parent_address, parent_id):
  27. res = super(ResPartner, self).onchange_address(
  28. use_parent_address, parent_id)
  29. if parent_id:
  30. parent = self.browse(parent_id)
  31. if parent.section_id:
  32. value = res.setdefault('value', {})
  33. value['section_id'] = parent.section_id.id
  34. return res