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.

25 lines
1016 B

  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 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(fields, maximum_group=maximum_group)
  13. if "ref" in fields:
  14. if "WHERE" in query:
  15. index = query.find("WHERE")
  16. query = query[: index + 6] + "ref IS NOT NULL AND " + query[index + 6 :]
  17. else:
  18. index = query.find(" GROUP BY")
  19. query = query[:index] + " WHERE ref IS NOT NULL" + query[index:]
  20. return query