Passed
Push — 2.x ( 4f65d0...ad582b )
by Jordi
06:22
created

Organization.getAccountName()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE.
4
#
5
# SENAITE.CORE 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 Software
7
# Foundation, version 2.
8
#
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
# details.
13
#
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 51
16
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
#
18
# Copyright 2018-2024 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
import copy
22
23
from AccessControl import ClassSecurityInfo
24
from bika.lims import senaiteMessageFactory as _
25
from senaite.core.schema import AddressField
26
from senaite.core.schema.addressfield import BILLING_ADDRESS
27
from senaite.core.schema.addressfield import PHYSICAL_ADDRESS
28
from senaite.core.schema.addressfield import POSTAL_ADDRESS
29
from senaite.core.z3cform.widgets.address import AddressWidget
30
from senaite.core.content.base import Container
31
from plone.supermodel import model
32
from plone.schema.email import Email
33
from plone.autoform import directives
34
from Products.CMFCore import permissions
35
from Products.CMFPlone.utils import safe_unicode
36
from zope import schema
37
from zope.interface import implementer
38
39
40
class IOrganizationSchema(model.Schema):
41
    """Base schema for Supplier schema and etc.
42
    """
43
44
    title = schema.TextLine(
45
        title=_(
46
            u"title_organization_name",
47
            default=u"Name"
48
        ),
49
        required=True,
50
    )
51
52
    tax_number = schema.TextLine(
53
        title=_(
54
            u"title_organization_tax_number",
55
            default=u"VAT number"
56
        ),
57
        required=False,
58
    )
59
60
    phone = schema.TextLine(
61
        title=_(
62
            u"title_organization_phone",
63
            default=u"Phone"
64
        ),
65
        required=False,
66
    )
67
68
    fax = schema.TextLine(
69
        title=_(
70
            u"title_organization_fax",
71
            default=u"Fax"
72
        ),
73
        required=False,
74
    )
75
76
    model.fieldset(
77
        "addresses",
78
        label=_(
79
            u"title_addresses_tab",
80
            default=u"Address"
81
        ),
82
        fields=[
83
            "email",
84
            "address",
85
        ]
86
    )
87
88
    email = Email(
89
        title=_(
90
            u"title_organization_email",
91
            default=u"Email"
92
        ),
93
        required=False,
94
    )
95
96
    directives.widget("address", AddressWidget)
97
    address = AddressField(
98
        address_types=(
99
            PHYSICAL_ADDRESS, POSTAL_ADDRESS, BILLING_ADDRESS,
100
        ),
101
        required=False,
102
    )
103
104
    model.fieldset(
105
        "bank_details",
106
        label=_(
107
            u"title_bank_details_tab",
108
            default=u"Bank Details"
109
        ),
110
        fields=[
111
            "account_type",
112
            "account_name",
113
            "account_number",
114
            "bank_name",
115
            "bank_branch",
116
        ]
117
    )
118
119
    account_type = schema.TextLine(
120
        title=_(
121
            u"title_organization_account_type",
122
            default=u"Account Type"
123
        ),
124
        required=False,
125
    )
126
127
    account_name = schema.TextLine(
128
        title=_(
129
            u"title_organization_account_name",
130
            default=u"Account Name"
131
        ),
132
        required=False,
133
    )
134
135
    account_number = schema.TextLine(
136
        title=_(
137
            u"title_organization_account_number",
138
            default=u"Account Number"
139
        ),
140
        required=False,
141
    )
142
143
    bank_name = schema.TextLine(
144
        title=_(
145
            u"title_organization_account_bank_name",
146
            default=u"Bank Name"
147
        ),
148
        required=False,
149
    )
150
151
    bank_branch = schema.TextLine(
152
        title=_(
153
            u"title_organization_account_bank_branch",
154
            default=u"Bank Branch"
155
        ),
156
        required=False,
157
    )
158
159
160
@implementer(IOrganizationSchema)
161
class Organization(Container):
162
    """Base class for Supplier content type
163
    """
164
165
    security = ClassSecurityInfo()
166
167
    # for backward compatibility: title -> name
168
    @security.protected(permissions.View)
169
    def getName(self):
170
        accessor = self.accessor("title")
171
        return accessor(self).encode("utf-8")
172
173
    # for backward compatibility: name -> title
174
    @security.protected(permissions.ModifyPortalContent)
175
    def setName(self, value):
176
        mutator = self.mutator("title")
177
        mutator(self, safe_unicode(value))
178
179
    # BBB: AT schema field property
180
    Name = property(getName, setName)
181
182
    @security.protected(permissions.View)
183
    def getTaxNumber(self):
184
        accessor = self.accessor("tax_number")
185
        value = accessor(self) or ""
186
        return value.encode("utf-8")
187
188
    @security.protected(permissions.ModifyPortalContent)
189
    def setTaxNumber(self, value):
190
        mutator = self.mutator("tax_number")
191
        mutator(self, safe_unicode(value))
192
193
    # BBB: AT schema field property
194
    TaxNumber = property(getTaxNumber, setTaxNumber)
195
196
    @security.protected(permissions.View)
197
    def getPhone(self):
198
        accessor = self.accessor("phone")
199
        value = accessor(self) or ""
200
        return value.encode("utf-8")
201
202
    @security.protected(permissions.ModifyPortalContent)
203
    def setPhone(self, value):
204
        mutator = self.mutator("phone")
205
        mutator(self, safe_unicode(value))
206
207
    # BBB: AT schema field property
208
    Phone = property(getPhone, setPhone)
209
210
    @security.protected(permissions.View)
211
    def getFax(self):
212
        accessor = self.accessor("fax")
213
        value = accessor(self) or ""
214
        return value.encode("utf-8")
215
216
    @security.protected(permissions.ModifyPortalContent)
217
    def setFax(self, value):
218
        mutator = self.mutator("fax")
219
        mutator(self, safe_unicode(value))
220
221
    # BBB: AT schema field property
222
    Fax = property(getFax, setFax)
223
224
    @security.protected(permissions.View)
225
    def getEmail(self):
226
        accessor = self.accessor("email")
227
        value = accessor(self) or ""
228
        return value.encode("utf-8")
229
230
    @security.protected(permissions.ModifyPortalContent)
231
    def setEmail(self, value):
232
        mutator = self.mutator("email")
233
        mutator(self, safe_unicode(value))
234
235
    # for backward compatibility
236
    @security.protected(permissions.View)
237
    def getEmailAddress(self):
238
        return self.getEmail()
239
240
    # for backward compatibility
241
    @security.protected(permissions.ModifyPortalContent)
242
    def setEmailAddress(self, value):
243
        self.setEmail(value)
244
245
    # BBB: AT schema field property
246
    EmailAddress = property(getEmailAddress, setEmailAddress)
247
248
    @security.protected(permissions.View)
249
    def getAccountType(self):
250
        accessor = self.accessor("account_type")
251
        value = accessor(self) or ""
252
        return value.encode("utf-8")
253
254
    @security.protected(permissions.ModifyPortalContent)
255
    def setAccountType(self, value):
256
        mutator = self.mutator("account_type")
257
        mutator(self, safe_unicode(value))
258
259
    # BBB: AT schema field property
260
    AccountType = property(getAccountType, setAccountType)
261
262
    @security.protected(permissions.View)
263
    def getAccountName(self):
264
        accessor = self.accessor("account_name")
265
        value = accessor(self) or ""
266
        return value.encode("utf-8")
267
268
    @security.protected(permissions.ModifyPortalContent)
269
    def setAccountName(self, value):
270
        mutator = self.mutator("account_name")
271
        mutator(self, safe_unicode(value))
272
273
    # BBB: AT schema field property
274
    AccountName = property(getAccountName, setAccountName)
275
276
    @security.protected(permissions.View)
277
    def getAccountNumber(self):
278
        accessor = self.accessor("account_number")
279
        value = accessor(self) or ""
280
        return value.encode("utf-8")
281
282
    @security.protected(permissions.ModifyPortalContent)
283
    def setAccountNumber(self, value):
284
        mutator = self.mutator("account_number")
285
        mutator(self, safe_unicode(value))
286
287
    # BBB: AT schema field property
288
    AccountNumber = property(getAccountNumber, setAccountNumber)
289
290
    @security.protected(permissions.View)
291
    def getBankName(self):
292
        accessor = self.accessor("bank_name")
293
        value = accessor(self) or ""
294
        return value.encode("utf-8")
295
296
    @security.protected(permissions.ModifyPortalContent)
297
    def setBankName(self, value):
298
        mutator = self.mutator("bank_name")
299
        mutator(self, safe_unicode(value))
300
301
    # BBB: AT schema field property
302
    BankName = property(getBankName, setBankName)
303
304
    @security.protected(permissions.View)
305
    def getBankBranch(self):
306
        accessor = self.accessor("bank_branch")
307
        value = accessor(self) or ""
308
        return value.encode("utf-8")
309
310
    @security.protected(permissions.ModifyPortalContent)
311
    def setBankBranch(self, value):
312
        mutator = self.mutator("bank_branch")
313
        mutator(self, safe_unicode(value))
314
315
    # BBB: AT schema field property
316
    BankBranch = property(getBankBranch, setBankBranch)
317
318
    @security.protected(permissions.View)
319
    def getAddress(self):
320
        accessor = self.accessor("address")
321
        value = accessor(self) or []
322
        return value
323
324
    @security.protected(permissions.ModifyPortalContent)
325
    def setAddress(self, value):
326
        mutator = self.mutator("address")
327
        mutator(self, value)
328
329
    @security.protected(permissions.View)
330
    def getPhysicalAddress(self):
331
        for address in self.getAddress():
332
            if address.get("type") == PHYSICAL_ADDRESS:
333
                return copy.deepcopy(address)
334
        return {}
335
336
    @security.protected(permissions.ModifyPortalContent)
337
    def setPhysicalAddress(self, value):
338
        addresses = self.getAddress()
339
        for address in addresses:
340
            if address.get("type") == PHYSICAL_ADDRESS:
341
                address.update(value)
342
        self.setAddress(addresses)
343
344
    # BBB: AT schema field property
345
    PhysicalAddress = property(getPhysicalAddress, setPhysicalAddress)
346
347
    @security.protected(permissions.View)
348
    def getPostalAddress(self):
349
        for address in self.getAddress():
350
            if address.get("type") == POSTAL_ADDRESS:
351
                return copy.deepcopy(address)
352
        return {}
353
354
    @security.protected(permissions.ModifyPortalContent)
355
    def setPostalAddress(self, value):
356
        addresses = self.getAddress()
357
        for address in addresses:
358
            if address.get("type") == POSTAL_ADDRESS:
359
                address.update(value)
360
        self.setAddress(addresses)
361
362
    # BBB: AT schema field property
363
    PostalAddress = property(getPostalAddress, setPostalAddress)
364
365
    @security.protected(permissions.View)
366
    def getBillingAddress(self):
367
        for address in self.getAddress():
368
            if address.get("type") == BILLING_ADDRESS:
369
                return copy.deepcopy(address)
370
        return {}
371
372
    @security.protected(permissions.ModifyPortalContent)
373
    def setBillingAddress(self, value):
374
        addresses = self.getAddress()
375
        for address in addresses:
376
            if address.get("type") == BILLING_ADDRESS:
377
                address.update(value)
378
        self.setAddress(addresses)
379
380
    # BBB: AT schema field property
381
    BillingAddress = property(getBillingAddress, setBillingAddress)
382