|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.CORE |
|
4
|
|
|
# |
|
5
|
|
|
# Copyright 2018 by it's authors. |
|
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
|
7
|
|
|
|
|
8
|
|
|
from AccessControl import ClassSecurityInfo |
|
9
|
|
|
from bika.lims import bikaMessageFactory as _ |
|
10
|
|
|
from bika.lims.browser.fields import AddressField |
|
11
|
|
|
from bika.lims.browser.widgets import AddressWidget |
|
12
|
|
|
from bika.lims.config import PROJECTNAME |
|
13
|
|
|
from bika.lims.content.bikaschema import BikaFolderSchema |
|
14
|
|
|
from bika.lims.content.bikaschema import BikaSchema |
|
15
|
|
|
from plone.app.folder.folder import ATFolder |
|
16
|
|
|
from Products.Archetypes.public import ManagedSchema |
|
17
|
|
|
from Products.Archetypes.public import StringField |
|
18
|
|
|
from Products.Archetypes.public import StringWidget |
|
19
|
|
|
from Products.Archetypes.public import registerType |
|
20
|
|
|
from Products.CMFPlone.utils import safe_unicode |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
schema = BikaFolderSchema.copy() + BikaSchema.copy() + ManagedSchema(( |
|
24
|
|
|
|
|
25
|
|
|
StringField( |
|
26
|
|
|
"Name", |
|
27
|
|
|
required=1, |
|
28
|
|
|
searchable=True, |
|
29
|
|
|
widget=StringWidget( |
|
30
|
|
|
label=_("Name"), |
|
31
|
|
|
), |
|
32
|
|
|
), |
|
33
|
|
|
|
|
34
|
|
|
StringField( |
|
35
|
|
|
"TaxNumber", |
|
36
|
|
|
widget=StringWidget( |
|
37
|
|
|
label=_("VAT number"), |
|
38
|
|
|
), |
|
39
|
|
|
), |
|
40
|
|
|
|
|
41
|
|
|
StringField( |
|
42
|
|
|
"Phone", |
|
43
|
|
|
widget=StringWidget( |
|
44
|
|
|
label=_("Phone"), |
|
45
|
|
|
), |
|
46
|
|
|
), |
|
47
|
|
|
|
|
48
|
|
|
StringField( |
|
49
|
|
|
"Fax", |
|
50
|
|
|
widget=StringWidget( |
|
51
|
|
|
label=_("Fax"), |
|
52
|
|
|
), |
|
53
|
|
|
), |
|
54
|
|
|
|
|
55
|
|
|
StringField( |
|
56
|
|
|
"EmailAddress", |
|
57
|
|
|
schemata="Address", |
|
58
|
|
|
widget=StringWidget( |
|
59
|
|
|
label=_("Email Address"), |
|
60
|
|
|
), |
|
61
|
|
|
validators=("isEmail", ) |
|
62
|
|
|
), |
|
63
|
|
|
|
|
64
|
|
|
AddressField( |
|
65
|
|
|
"PhysicalAddress", |
|
66
|
|
|
schemata="Address", |
|
67
|
|
|
widget=AddressWidget( |
|
68
|
|
|
label=_("Physical address"), |
|
69
|
|
|
), |
|
70
|
|
|
subfield_validators={ |
|
71
|
|
|
"country": "inline_field_validator", |
|
72
|
|
|
"state": "inline_field_validator", |
|
73
|
|
|
"district": "inline_field_validator", |
|
74
|
|
|
}, |
|
75
|
|
|
), |
|
76
|
|
|
|
|
77
|
|
|
AddressField( |
|
78
|
|
|
"PostalAddress", |
|
79
|
|
|
schemata="Address", |
|
80
|
|
|
widget=AddressWidget( |
|
81
|
|
|
label=_("Postal address"), |
|
82
|
|
|
), |
|
83
|
|
|
subfield_validators={ |
|
84
|
|
|
"country": "inline_field_validator", |
|
85
|
|
|
"state": "inline_field_validator", |
|
86
|
|
|
"district": "inline_field_validator", |
|
87
|
|
|
}, |
|
88
|
|
|
), |
|
89
|
|
|
|
|
90
|
|
|
AddressField( |
|
91
|
|
|
"BillingAddress", |
|
92
|
|
|
schemata="Address", |
|
93
|
|
|
widget=AddressWidget( |
|
94
|
|
|
label=_("Billing address"), |
|
95
|
|
|
), |
|
96
|
|
|
subfield_validators={ |
|
97
|
|
|
"country": "inline_field_validator", |
|
98
|
|
|
"state": "inline_field_validator", |
|
99
|
|
|
"district": "inline_field_validator", |
|
100
|
|
|
}, |
|
101
|
|
|
), |
|
102
|
|
|
|
|
103
|
|
|
StringField( |
|
104
|
|
|
"AccountType", |
|
105
|
|
|
schemata="Bank details", |
|
106
|
|
|
widget=StringWidget( |
|
107
|
|
|
label=_("Account Type"), |
|
108
|
|
|
), |
|
109
|
|
|
), |
|
110
|
|
|
|
|
111
|
|
|
StringField( |
|
112
|
|
|
"AccountName", |
|
113
|
|
|
schemata="Bank details", |
|
114
|
|
|
widget=StringWidget( |
|
115
|
|
|
label=_("Account Name"), |
|
116
|
|
|
), |
|
117
|
|
|
), |
|
118
|
|
|
|
|
119
|
|
|
StringField( |
|
120
|
|
|
"AccountNumber", |
|
121
|
|
|
schemata="Bank details", |
|
122
|
|
|
widget=StringWidget( |
|
123
|
|
|
label=_("Account Number"), |
|
124
|
|
|
), |
|
125
|
|
|
), |
|
126
|
|
|
|
|
127
|
|
|
StringField( |
|
128
|
|
|
"BankName", |
|
129
|
|
|
schemata="Bank details", |
|
130
|
|
|
widget=StringWidget( |
|
131
|
|
|
label=_("Bank name"), |
|
132
|
|
|
), |
|
133
|
|
|
), |
|
134
|
|
|
|
|
135
|
|
|
StringField( |
|
136
|
|
|
"BankBranch", |
|
137
|
|
|
schemata="Bank details", |
|
138
|
|
|
widget=StringWidget( |
|
139
|
|
|
label=_("Bank branch"), |
|
140
|
|
|
), |
|
141
|
|
|
), |
|
142
|
|
|
), |
|
143
|
|
|
) |
|
144
|
|
|
|
|
145
|
|
|
IdField = schema["id"] |
|
146
|
|
|
IdField.widget.visible = {"edit": "visible", "view": "invisible"} |
|
147
|
|
|
|
|
148
|
|
|
TitleField = schema["title"] |
|
149
|
|
|
TitleField.required = 0 |
|
150
|
|
|
TitleField.widget.visible = {"edit": "hidden", "view": "invisible"} |
|
151
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
class Organisation(ATFolder): |
|
154
|
|
|
"""Base class for Clients, Suppliers and for the Laboratory |
|
155
|
|
|
""" |
|
156
|
|
|
|
|
157
|
|
|
security = ClassSecurityInfo() |
|
158
|
|
|
displayContentsTab = False |
|
159
|
|
|
schema = schema |
|
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
def Title(self): |
|
162
|
|
|
"""Return the name of the Organisation |
|
163
|
|
|
""" |
|
164
|
|
|
field = self.getField("Name") |
|
165
|
|
|
field = field and field.get(self) or "" |
|
166
|
|
|
return safe_unicode(field).encode("utf-8") |
|
167
|
|
|
|
|
168
|
|
|
def setTitle(self, value): |
|
169
|
|
|
"""Set the name of the Organisation |
|
170
|
|
|
""" |
|
171
|
|
|
return self.setName(value) |
|
172
|
|
|
|
|
173
|
|
|
def getPossibleAddresses(self): |
|
174
|
|
|
"""Get the possible address fields |
|
175
|
|
|
""" |
|
176
|
|
|
return ["PhysicalAddress", "PostalAddress", "BillingAddress"] |
|
177
|
|
|
|
|
178
|
|
|
def getPrintAddress(self): |
|
179
|
|
|
"""Get an address for printing |
|
180
|
|
|
""" |
|
181
|
|
|
address_lines = [] |
|
182
|
|
|
|
|
183
|
|
|
addresses = [ |
|
184
|
|
|
self.getPostalAddress(), |
|
185
|
|
|
self.getPhysicalAddress(), |
|
186
|
|
|
self.getBillingAddress(), |
|
187
|
|
|
] |
|
188
|
|
|
|
|
189
|
|
|
for address in addresses: |
|
190
|
|
|
city = address.get("city", "") |
|
191
|
|
|
zip = address.get("zip", "") |
|
192
|
|
|
state = address.get("state", "") |
|
193
|
|
|
country = address.get("country", "") |
|
194
|
|
|
|
|
195
|
|
|
if city: |
|
196
|
|
|
address_lines = [ |
|
197
|
|
|
address["address"].strip(), |
|
198
|
|
|
"{} {}".format(city, zip).strip(), |
|
199
|
|
|
"{} {}".format(state, country).strip(), |
|
200
|
|
|
] |
|
201
|
|
|
break |
|
202
|
|
|
|
|
203
|
|
|
return address_lines |
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
registerType(Organisation, PROJECTNAME) |
|
207
|
|
|
|