root / lib / pyzinn / erp / Iparty.py @ a899390a2a8aca3b3b4617dd7cd96a19e64b489c

View | Annotate | Download (3.4 KB)

1
# Copyright (c) 2009 Lost Oasis, IELO <info@ielo.net>
2
#
3
# This file is part of ZINN.
4
# 
5
# SINN is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your
8
# option) any later version.
9
# 
10
# SINN is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
# for more details.
14
# 
15
# You should have received a copy of the GNU General Public License
16
# along with ZINN.  If not, see <http://www.gnu.org/licenses/>.
17
18
"""
19
    Common interface that erp party (client) plugins must implement
20
"""
21
22
class IErpTransport(object):
23
    def __init__(self, dsn):
24
        self.dsn = dsn
25
26
class Iparty(object):
27
    fields = [
28
            'id',
29
            #'addresses',
30
            'label',
31
            'name',
32
            'active',
33
            #'full_name',
34
            #'email',
35
            #'mobile',
36
            #'phone',
37
            #'fax',
38
            #'website',
39
            #'telephone',
40
            'siren',
41
            'vat_country',
42
            'vat_number'
43
            ]
44
45
    def __init__(self, transport):
46
        pass
47
48
    def getAttributes(self, onlyMutables=False):
49
        """
50
        @param onlyMutables: bool (optionnal) filters unmutable attributes.
51
        """
52
        if onlyMutables:
53
            return [a for a in self.getAttributes() if a not in ('label', 'full_name')]
54
        else:
55
            return [a for a in self.fields if a not in ('id', 'name', 'addresses')]
56
57
    def AttributesFilter(self, attributes, default=None):
58
        mutables = self.getAttributes(onlyMutables=True)
59
        args = default if isinstance(default, dict) else {}
60
        if isinstance(attributes, dict):
61
            for k, v in attributes.iteritems():
62
                if k in mutables:
63
                    args[k] = v
64
        return args
65
66
    def list(self, label):
67
        '''
68
        Get a party by its label
69
70
        :param label : a string, party label
71
        '''
72
        raise NotImplementedError
73
74
    def create(self, label, attributes):
75
        '''
76
        Create a party
77
78
        :param values : a dictionary with fields names as key
79
                        and created values as value
80
        '''
81
        raise NotImplementedError
82
83
    def update(self, label, attributes):
84
        raise NotImplementedError
85
86
    def delete(self, label):
87
        raise NotImplementedError
88
89
    def attributes(self, onlyMutables=False):
90
        raise NotImplementedError
91
92
    def byLabel(self, label=None, fields=[]):
93
        '''
94
        Get a party by its label
95
96
        :param id : an integer, party label
97
        '''
98
        raise NotImplementedError
99
100
    def _filter(self, party):
101
        #return party
102
        r = {}
103
        fields = self.getAttributes()
104
        if len(party) > 0:
105
            for k, v in party.iteritems():
106
                if k in fields: r[k] = v
107
        return r
108
109
    def _decorate(self, parties):
110
        ret = []
111
        for party in parties:
112
            party['label'] = party['name']
113
            party = self._filter(party)
114
            # TODO: list party addresses
115
            #party['addresses'] = self.address.list(party['name'])
116
            ret.append(party)
117
        return ret
118
119
# vim: tabstop=4 expandtab shiftwidth=4 textwidth=79