You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.4 KiB

  1. # Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, fields, models
  4. class BasePartnerMergeAutomaticWizard(models.TransientModel):
  5. _inherit = "base.partner.merge.automatic.wizard"
  6. exclude_is_company = fields.Boolean("'Is a company?' field selected")
  7. exclude_not_parent = fields.Boolean("Parent company not set")
  8. exclude_parent = fields.Boolean("Parent company set (Contacts)")
  9. @api.multi
  10. def _process_query(self, query):
  11. if any([self.exclude_is_company, self.exclude_not_parent,
  12. self.exclude_parent]):
  13. filters = []
  14. if self.exclude_is_company:
  15. filters.append("is_company = False")
  16. if self.exclude_not_parent:
  17. filters.append("parent_id IS NOT NULL")
  18. if self.exclude_parent:
  19. filters.append("parent_id IS NULL")
  20. index_where = query.find('WHERE')
  21. index_group_by = query.find('GROUP BY')
  22. subquery = "%s" % ' AND '.join(filters)
  23. if index_where > 0:
  24. subquery = "AND (%s) " % subquery
  25. else: # pragma: no cover
  26. subquery = "WHERE %s " % subquery
  27. query = query[:index_group_by] + subquery + query[index_group_by:]
  28. return super(BasePartnerMergeAutomaticWizard, self)._process_query(
  29. query)