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.

44 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. from odoo import models, fields, tools
  3. class ResPartnerRoot(models.Model):
  4. _name = "res.partner.hierarchy"
  5. _description = "Partners hierarchy"
  6. _auto = False
  7. name = fields.Char()
  8. active = fields.Boolean()
  9. parent_id = fields.Many2one("res.partner.hierarchy")
  10. def init(self):
  11. tools.drop_view_if_exists(self.env.cr, self._table)
  12. self.env.cr.execute(
  13. """
  14. CREATE OR REPLACE VIEW %s AS (
  15. SELECT DISTINCT id AS id,
  16. active as active,
  17. CONCAT(partner_code, ' - ', ref) AS name,
  18. NULL::int AS parent_id
  19. FROM res_partner WHERE partner_code IS NOT NULL AND ffck_network IS TRUE AND partner_scale = '1' AND (ref IS NOT NULL OR name IS NOT NULL)
  20. UNION ALL
  21. SELECT DISTINCT id AS id,
  22. active as active,
  23. CONCAT(partner_code, ' - ', ref) AS name,
  24. ffck_partner_id AS parent_id
  25. FROM res_partner WHERE partner_code IS NOT NULL AND ffck_network IS TRUE AND partner_scale = '2' AND (ref IS NOT NULL OR name IS NOT NULL)
  26. UNION ALL
  27. SELECT DISTINCT id AS id,
  28. active as active,
  29. CONCAT(partner_code, ' - ', ref) AS name,
  30. crck_partner_id AS parent_id
  31. FROM res_partner WHERE partner_code IS NOT NULL AND ffck_network IS TRUE AND partner_scale = '3' AND (ref IS NOT NULL OR name IS NOT NULL)
  32. UNION ALL
  33. SELECT DISTINCT id AS id,
  34. active as active,
  35. CONCAT(partner_code, ' - ', ref) AS name,
  36. cdck_partner_id AS parent_id
  37. FROM res_partner WHERE partner_code IS NOT NULL AND ffck_network IS TRUE AND partner_scale = '4' AND (ref IS NOT NULL OR name IS NOT NULL)
  38. )"""
  39. % (self._table,)
  40. )