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