~hbrunn/+junk/partner_relations

« back to all changes in this revision

Viewing changes to partner_relations/model/res_partner_relation_type.py

  • Committer: Holger Brunn
  • Date: 2014-06-02 19:28:04 UTC
  • Revision ID: hbrunn@therp.nl-20140602192804-9p0msf4nzwkarg30
[ADD] partner_relations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
'''Define model res.partner.relation.type'''
 
3
##############################################################################
 
4
#
 
5
#    OpenERP, Open Source Management Solution
 
6
#    This module copyright (C) 2013 Therp BV (<http://therp.nl>).
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU Affero General Public License as
 
10
#    published by the Free Software Foundation, either version 3 of the
 
11
#    License, or (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
from openerp.osv.orm import Model
 
23
from openerp.osv import fields
 
24
 
 
25
 
 
26
class ResPartnerRelationType(Model):
 
27
    '''Model that defines relation types that might exist between partners'''
 
28
    _name = 'res.partner.relation.type'
 
29
    _description = 'Parter relation type'
 
30
    _order = 'name'
 
31
 
 
32
    def _get_partner_types(self, cr, uid, context=None):
 
33
        return (('c', 'Company'), ('p', 'Person'),)
 
34
 
 
35
    _columns = {
 
36
        'name': fields.char(
 
37
            'Name', size=128, required=True, translate=True),
 
38
        'name_inverse': fields.char(
 
39
            'Inverse name', size=128, required=True, translate=True),
 
40
        'contact_type_left': fields.selection(
 
41
            _get_partner_types, 'Left partner type'),
 
42
        'contact_type_right': fields.selection(
 
43
            _get_partner_types, 'Right partner type'),
 
44
        'partner_category_left': fields.many2one(
 
45
            'res.partner.category', 'Left partner category'),
 
46
        'partner_category_right': fields.many2one(
 
47
            'res.partner.category', 'Right partner category'),
 
48
        }
 
49
 
 
50
 
 
51
class ResPartnerRelationTypeInverse(Model):
 
52
    '''Model to describe inverse of model res.partner.relation.type'''
 
53
    _name = 'res.partner.relation.type.inverse'
 
54
    _description = 'Parter relation type'
 
55
    _auto = False
 
56
 
 
57
    def name_search(
 
58
            self, cr, uid, name='', args=None, operator='ilike',
 
59
            context=None, limit=100):
 
60
        type_model = self.pool['res.partner.relation.type']
 
61
        type_ids = type_model.search(
 
62
            cr, uid,
 
63
            (args or []) + [('name_inverse', operator, name)],
 
64
            context=context
 
65
        )
 
66
        type_records = type_model.read(
 
67
            cr, uid, type_ids, ['name_inverse'], context=context)
 
68
        return [(r['id'], r['name_inverse']) for r in type_records]
 
69