|
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-2021 by it's authors. |
|
19
|
|
|
# Some rights reserved, see README and LICENSE. |
|
20
|
|
|
|
|
21
|
|
|
import collections |
|
22
|
|
|
|
|
23
|
|
|
from bika.lims import api |
|
24
|
|
|
from bika.lims import senaiteMessageFactory as _ |
|
25
|
|
|
from bika.lims.utils import get_email_link |
|
26
|
|
|
from bika.lims.utils import get_link |
|
27
|
|
|
from plone.memoize import view |
|
28
|
|
|
from Products.CMFCore.permissions import AddPortalContent |
|
29
|
|
|
from senaite.app.listing import ListingView |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class ClientsView(ListingView): |
|
33
|
|
|
"""Listing view for Clients |
|
34
|
|
|
""" |
|
35
|
|
|
|
|
36
|
|
|
def __init__(self, context, request): |
|
37
|
|
|
super(ClientsView, self).__init__(context, request) |
|
38
|
|
|
|
|
39
|
|
|
self.contentFilter = { |
|
40
|
|
|
"portal_type": "Client", |
|
41
|
|
|
"sort_on": "sortable_title", |
|
42
|
|
|
"sort_order": "ascending" |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
self.title = self.context.translate(_("Clients")) |
|
46
|
|
|
|
|
47
|
|
|
self.show_select_column = True |
|
48
|
|
|
self.show_select_all_checkbox = False |
|
49
|
|
|
|
|
50
|
|
|
self.context_actions = { |
|
51
|
|
|
_("Add"): { |
|
52
|
|
|
"url": "createObject?type_name=Client", |
|
53
|
|
|
'permission': AddPortalContent, |
|
54
|
|
|
"icon": "add.png" |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
self.columns = collections.OrderedDict(( |
|
59
|
|
|
("title", { |
|
60
|
|
|
"title": _("Name"), |
|
61
|
|
|
"index": "sortable_title"},), |
|
62
|
|
|
("getClientID", { |
|
63
|
|
|
"title": _("Client ID")}), |
|
64
|
|
|
("EmailAddress", { |
|
65
|
|
|
"title": _("Email Address"), |
|
66
|
|
|
"sortable": False}), |
|
67
|
|
|
("getCountry", { |
|
68
|
|
|
"toggle": False, |
|
69
|
|
|
"sortable": False, |
|
70
|
|
|
"title": _("Country")}), |
|
71
|
|
|
("getProvince", { |
|
72
|
|
|
"toggle": False, |
|
73
|
|
|
"sortable": False, |
|
74
|
|
|
"title": _("Province")}), |
|
75
|
|
|
("getDistrict", { |
|
76
|
|
|
"toggle": False, |
|
77
|
|
|
"sortable": False, |
|
78
|
|
|
"title": _("District")}), |
|
79
|
|
|
("Phone", { |
|
80
|
|
|
"title": _("Phone"), |
|
81
|
|
|
"sortable": False}), |
|
82
|
|
|
("Fax", { |
|
83
|
|
|
"toggle": False, |
|
84
|
|
|
"sortable": False, |
|
85
|
|
|
"title": _("Fax")}), |
|
86
|
|
|
("BulkDiscount", { |
|
87
|
|
|
"toggle": False, |
|
88
|
|
|
"sortable": False, |
|
89
|
|
|
"title": _("Bulk Discount")}), |
|
90
|
|
|
("MemberDiscountApplies", { |
|
91
|
|
|
"toggle": False, |
|
92
|
|
|
"sortable": False, |
|
93
|
|
|
"title": _("Member Discount")}), |
|
94
|
|
|
)) |
|
95
|
|
|
|
|
96
|
|
|
self.review_states = [ |
|
97
|
|
|
{ |
|
98
|
|
|
"id": "default", |
|
99
|
|
|
"contentFilter": {"review_state": "active"}, |
|
100
|
|
|
"title": _("Active"), |
|
101
|
|
|
"columns": self.columns.keys(), |
|
102
|
|
|
}, { |
|
103
|
|
|
"id": "inactive", |
|
104
|
|
|
"title": _("Inactive"), |
|
105
|
|
|
"contentFilter": {"review_state": "inactive"}, |
|
106
|
|
|
"columns": self.columns.keys(), |
|
107
|
|
|
}, { |
|
108
|
|
|
"id": "all", |
|
109
|
|
|
"title": _("All"), |
|
110
|
|
|
"contentFilter": {}, |
|
111
|
|
|
"columns": self.columns.keys(), |
|
112
|
|
|
}, |
|
113
|
|
|
] |
|
114
|
|
|
|
|
115
|
|
|
def folderitem(self, obj, item, index): |
|
116
|
|
|
"""Applies new properties to the item (Client) that is currently being |
|
117
|
|
|
rendered as a row in the list |
|
118
|
|
|
|
|
119
|
|
|
:param obj: client to be rendered as a row in the list |
|
120
|
|
|
:param item: dict representation of the client, suitable for the list |
|
121
|
|
|
:param index: current position of the item within the list |
|
122
|
|
|
:type obj: CatalogBrain |
|
123
|
|
|
:type item: dict |
|
124
|
|
|
:type index: int |
|
125
|
|
|
:return: the dict representation of the item |
|
126
|
|
|
:rtype: dict |
|
127
|
|
|
""" |
|
128
|
|
|
obj = api.get_object(obj) |
|
129
|
|
|
obj_url = self.get_client_url(obj) |
|
130
|
|
|
phone = obj.getPhone() |
|
131
|
|
|
item["replace"].update({ |
|
132
|
|
|
"title": get_link(obj_url, api.get_title(obj)), |
|
133
|
|
|
"getClientID": get_link(obj_url, obj.getClientID()), |
|
134
|
|
|
"EmailAddress": get_email_link(obj.getEmailAddress()), |
|
135
|
|
|
"BulkDiscount": obj.getBulkDiscount(), |
|
136
|
|
|
"MemberDiscountApplies": obj.getMemberDiscountApplies(), |
|
137
|
|
|
"Phone": phone and get_link("tel:{}".format(phone), phone) or "", |
|
138
|
|
|
}) |
|
139
|
|
|
return item |
|
140
|
|
|
|
|
141
|
|
|
def get_client_url(self, client): |
|
142
|
|
|
"""Returns the url to the client's landing page |
|
143
|
|
|
""" |
|
144
|
|
|
landing = self.get_client_landing_page() |
|
145
|
|
|
return "{}/{}".format(api.get_url(client), landing) |
|
146
|
|
|
|
|
147
|
|
|
@view.memoize |
|
148
|
|
|
def get_client_landing_page(self): |
|
149
|
|
|
"""Returns the id of the view from inside Client to which the user has |
|
150
|
|
|
to be redirected when clicking to the link of a Client |
|
151
|
|
|
""" |
|
152
|
|
|
record_key = "bika.lims.client.default_landing_page" |
|
153
|
|
|
return api.get_registry_record(record_key, default="analysisrequests") |
|
154
|
|
|
|