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
|
|
|
import collections |
9
|
|
|
|
10
|
|
|
from bika.lims import bikaMessageFactory as _ |
11
|
|
|
from bika.lims.api.security import check_permission |
12
|
|
|
from bika.lims.browser import BrowserView |
13
|
|
|
from bika.lims.browser.bika_listing import BikaListingView |
14
|
|
|
from bika.lims.permissions import AddPricelist |
15
|
|
|
from bika.lims.utils import get_link |
16
|
|
|
from DateTime import DateTime |
17
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class PricelistsView(BikaListingView): |
21
|
|
|
"""Listing view for Pricelists |
22
|
|
|
""" |
23
|
|
|
|
24
|
|
|
def __init__(self, context, request): |
25
|
|
|
super(PricelistsView, self).__init__(context, request) |
26
|
|
|
|
27
|
|
|
self.catalog = "portal_catalog" |
28
|
|
|
|
29
|
|
|
self.contentFilter = { |
30
|
|
|
"portal_type": "Pricelist", |
31
|
|
|
"sort_on": "sortable_title", |
32
|
|
|
"sort_order": "ascending", |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
self.context_actions = {} |
36
|
|
|
self.title = self.context.translate(_("Pricelists")) |
37
|
|
|
self.description = "" |
38
|
|
|
self.icon = "{}/{}".format( |
39
|
|
|
self.portal_url, "++resource++bika.lims.images/pricelist_big.png") |
40
|
|
|
|
41
|
|
|
self.show_select_column = True |
42
|
|
|
self.pagesize = 25 |
43
|
|
|
|
44
|
|
|
self.columns = collections.OrderedDict(( |
45
|
|
|
("Title", { |
46
|
|
|
"title": _("Title"), |
47
|
|
|
"index": "sortable_title"}), |
48
|
|
|
("getEffectiveDate", { |
49
|
|
|
"title": _("Start Date"), |
50
|
|
|
"index": "getEffectiveDate", |
51
|
|
|
"toggle": True}), |
52
|
|
|
("getExpirationDate", { |
53
|
|
|
"title": _("End Date"), |
54
|
|
|
"index": "getExpirationDate", |
55
|
|
|
"toggle": True}), |
56
|
|
|
)) |
57
|
|
|
|
58
|
|
|
now = DateTime() |
59
|
|
|
self.review_states = [ |
60
|
|
|
{ |
61
|
|
|
"id": "default", |
62
|
|
|
"title": _("Active"), |
63
|
|
|
"contentFilter": { |
64
|
|
|
"getEffectiveDate": { |
65
|
|
|
"query": now, |
66
|
|
|
"range": "max", |
67
|
|
|
}, |
68
|
|
|
"getExpirationDate": { |
69
|
|
|
"query": now, |
70
|
|
|
"range": "min", |
71
|
|
|
}, |
72
|
|
|
"is_active": True, |
73
|
|
|
}, |
74
|
|
|
"columns": self.columns.keys(), |
75
|
|
|
}, { |
76
|
|
|
"id": "inactive", |
77
|
|
|
"title": _("Inactive"), |
78
|
|
|
"contentFilter": { |
79
|
|
|
"getEffectiveDate": { |
80
|
|
|
"query": now, |
81
|
|
|
"range": "min", |
82
|
|
|
}, |
83
|
|
|
"getExpirationDate": { |
84
|
|
|
"query": now, |
85
|
|
|
"range": "max", |
86
|
|
|
}, |
87
|
|
|
"is_active": False, |
88
|
|
|
}, |
89
|
|
|
"columns": self.columns.keys(), |
90
|
|
|
}, { |
91
|
|
|
"id": "all", |
92
|
|
|
"title": _("All"), |
93
|
|
|
"contentFilter": {}, |
94
|
|
|
"columns": self.columns.keys(), |
95
|
|
|
} |
96
|
|
|
] |
97
|
|
|
|
98
|
|
|
def before_render(self): |
99
|
|
|
"""Before template render hook |
100
|
|
|
""" |
101
|
|
|
super(PricelistsView, self).before_render() |
102
|
|
|
# Render the Add button if the user has the AddPricelist permission |
103
|
|
|
if check_permission(AddPricelist, self.context): |
104
|
|
|
self.context_actions[_("Add")] = { |
|
|
|
|
105
|
|
|
"url": "createObject?type_name=Pricelist", |
106
|
|
|
"icon": "++resource++bika.lims.images/add.png" |
107
|
|
|
} |
108
|
|
|
# Don't allow any context actions on the Methods folder |
109
|
|
|
self.request.set("disable_border", 1) |
110
|
|
|
|
111
|
|
|
def folderitem(self, obj, item, index): |
112
|
|
|
"""Applies new properties to the item (Client) that is currently being |
113
|
|
|
rendered as a row in the list |
114
|
|
|
|
115
|
|
|
:param obj: client to be rendered as a row in the list |
116
|
|
|
:param item: dict representation of the client, suitable for the list |
117
|
|
|
:param index: current position of the item within the list |
118
|
|
|
:type obj: ATContentType/DexterityContentType |
119
|
|
|
:type item: dict |
120
|
|
|
:type index: int |
121
|
|
|
:return: the dict representation of the item |
122
|
|
|
:rtype: dict |
123
|
|
|
""" |
124
|
|
|
|
125
|
|
|
url = obj.absolute_url() |
126
|
|
|
title = obj.Title() |
127
|
|
|
|
128
|
|
|
item["replace"]["Title"] = get_link(url, value=title) |
129
|
|
|
|
130
|
|
|
item["getEffectiveDate"] = self.ulocalized_time( |
131
|
|
|
obj.getEffectiveDate()) |
132
|
|
|
|
133
|
|
|
item["getExpirationDate"] = self.ulocalized_time( |
134
|
|
|
obj.getExpirationDate()) |
135
|
|
|
|
136
|
|
|
return item |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
class PricelistView(BrowserView): |
140
|
|
|
"""Pricelist view |
141
|
|
|
""" |
142
|
|
|
template = ViewPageTemplateFile("templates/pricelist_view.pt") |
143
|
|
|
lineitems_pt = ViewPageTemplateFile("templates/pricelist_content.pt") |
144
|
|
|
|
145
|
|
|
def __call__(self): |
146
|
|
|
self.items = self.context.objectValues() |
147
|
|
|
self.pricelist_content = self.lineitems_pt() |
148
|
|
|
return self.template() |
149
|
|
|
|
150
|
|
|
def getPreferredCurrencyAbreviation(self): |
151
|
|
|
return self.context.bika_setup.getCurrency() |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
class PricelistPrintView(PricelistView): |
155
|
|
|
"""Pricelist print view |
156
|
|
|
""" |
157
|
|
|
template = ViewPageTemplateFile("templates/pricelist_print.pt") |
158
|
|
|
lineitems_pt = ViewPageTemplateFile("templates/pricelist_content.pt") |
159
|
|
|
|