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.

88 lines
3.4 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2014 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv.orm import Model
  22. from openerp.osv import fields
  23. from openerp.tools import drop_view_if_exists
  24. from res_partner_relation_type_selection import ResPartnerRelationTypeSelection
  25. class ResPartnerRelationAll(Model):
  26. _auto = False
  27. _log_access = False
  28. _name = 'res.partner.relation.all'
  29. _description = 'All (non-inverse + inverse) relations between partners'
  30. def _auto_init(self, cr, context=None):
  31. drop_view_if_exists(cr, self._table)
  32. cr.execute(
  33. '''create or replace view %s as
  34. select
  35. id * 10 as id,
  36. id as relation_id,
  37. type_id,
  38. cast('a' as char(1)) as record_type,
  39. left_partner_id as this_partner_id,
  40. right_partner_id as other_partner_id,
  41. date_start,
  42. date_end,
  43. active,
  44. type_id * 10 as type_selection_id
  45. from res_partner_relation
  46. union select
  47. id * 10 + 1,
  48. id,
  49. type_id,
  50. cast('b' as char(1)),
  51. right_partner_id,
  52. left_partner_id,
  53. date_start,
  54. date_end,
  55. active,
  56. type_id * 10 + 1
  57. from res_partner_relation''' % self._table)
  58. return super(ResPartnerRelationAll, self)._auto_init(
  59. cr, context=context)
  60. _columns = {
  61. 'record_type': fields.selection(
  62. ResPartnerRelationTypeSelection._RECORD_TYPES, 'Record type'),
  63. 'relation_id': fields.many2one(
  64. 'res.partner.relation', 'Relation'),
  65. 'type_id': fields.many2one(
  66. 'res.partner.relation.type', 'Relation type'),
  67. 'type_selection_id': fields.many2one(
  68. 'res.partner.relation.type.selection', 'Relation type'),
  69. 'this_partner_id': fields.many2one('res.partner', 'Current partner'),
  70. 'other_partner_id': fields.many2one('res.partner', 'Other partner'),
  71. 'date_start': fields.date('Starting date'),
  72. 'date_end': fields.date('Ending date'),
  73. 'active': fields.boolean('Active'),
  74. }
  75. def name_get(self, cr, uid, ids, context=None):
  76. return dict([
  77. (this.id, '%s %s %s' % (
  78. this.this_partner_id.name,
  79. this.type_selection_id.name_get()[0][1],
  80. this.other_partner_id.name,
  81. ))
  82. for this in self.browse(cr, uid, ids, context=context)])