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.

28 lines
1.1 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 openerp import fields, models
  4. class BasePartnerMergeAutomaticWizard(models.TransientModel):
  5. _inherit = "base.partner.merge.automatic.wizard"
  6. group_by_ref = fields.Boolean('Reference')
  7. def _generate_query(self, fields, maximum_group=100):
  8. """Inject the additional criteria 'ref IS NOT NULL' when needed.
  9. There's no better way to do it, as there are no hooks for adding
  10. this criteria regularly.
  11. """
  12. query = super()._generate_query(
  13. fields, maximum_group=maximum_group)
  14. if 'ref' in fields:
  15. if 'WHERE' in query:
  16. index = query.find('WHERE')
  17. query = (query[:index + 6] + "ref IS NOT NULL AND " +
  18. query[index + 6:])
  19. else:
  20. index = query.find(' GROUP BY')
  21. query = (query[:index] + " WHERE ref IS NOT NULL" +
  22. query[index:])
  23. return query