|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.HEALTH. |
|
4
|
|
|
# |
|
5
|
|
|
# SENAITE.HEALTH is free software: you can redistribute it and/or modify it |
|
6
|
|
|
# under the terms of the GNU General Public License as published by the Free |
|
7
|
|
|
# Software 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-2019 by it's authors. |
|
19
|
|
|
# Some rights reserved, see README and LICENSE. |
|
20
|
|
|
|
|
21
|
|
|
from Products.CMFCore.utils import getToolByName |
|
22
|
|
|
from bika.lims import bikaMessageFactory as _ |
|
23
|
|
|
from bika.lims.browser.bika_listing import BikaListingView |
|
24
|
|
|
from bika.lims.permissions import ManageInvoices |
|
25
|
|
|
from bika.lims.utils import currency_format |
|
26
|
|
|
from plone.app.content.browser.interfaces import IFolderContentsView |
|
27
|
|
|
from zope.interface.declarations import implements |
|
28
|
|
|
|
|
29
|
|
|
""" This file contains an invoice type folder to be used in insurance company's stuff. |
|
30
|
|
|
""" |
|
31
|
|
|
|
|
32
|
|
|
class InvoiceFolderView(BikaListingView): |
|
33
|
|
|
""" |
|
34
|
|
|
This class will build a list with the invoices that comes from the current Insurance Company's |
|
35
|
|
|
patient. |
|
36
|
|
|
""" |
|
37
|
|
|
implements(IFolderContentsView) |
|
38
|
|
|
|
|
39
|
|
|
def __init__(self, context, request): |
|
40
|
|
|
super(InvoiceFolderView, self).__init__(context, request) |
|
41
|
|
|
self.catalog = 'portal_catalog' |
|
42
|
|
|
self.contentFilter = {'portal_type': 'Invoice', |
|
43
|
|
|
'sort_on': 'sortable_title', |
|
44
|
|
|
'sort_order': 'reverse'} |
|
45
|
|
|
self.context_actions = {} |
|
46
|
|
|
self.title = self.context.translate(_("Invoices")) |
|
47
|
|
|
self.icon = self.portal_url + "/++resource++bika.lims.images/invoice_big.png" |
|
48
|
|
|
self.description = "The invoices of Insurance Company's patients" |
|
49
|
|
|
self.show_sort_column = False |
|
50
|
|
|
self.show_select_row = False |
|
51
|
|
|
self.show_select_column = False |
|
52
|
|
|
self.pagesize = 25 |
|
53
|
|
|
self.columns = { |
|
54
|
|
|
'id': {'title': _('Invoice Number'), |
|
55
|
|
|
'toggle': True}, |
|
56
|
|
|
'client': {'title': _('Client'), |
|
57
|
|
|
'toggle': True}, |
|
58
|
|
|
'invoicedate': {'title': _('Invoice Date'), |
|
59
|
|
|
'toggle': True}, |
|
60
|
|
|
'subtotal': {'title': _('Subtotal')}, |
|
61
|
|
|
'vatamount': {'title': _('VAT')}, |
|
62
|
|
|
'total': {'title': _('Total')}, |
|
63
|
|
|
'patient': {'title': _('Patient'), |
|
64
|
|
|
'toggle': True}, |
|
65
|
|
|
} |
|
66
|
|
|
self.review_states = [ |
|
67
|
|
|
{ |
|
68
|
|
|
'id': 'default', |
|
69
|
|
|
'contentFilter': {}, |
|
70
|
|
|
'title': _('Default'), |
|
71
|
|
|
'transitions': [], |
|
72
|
|
|
'columns': [ |
|
73
|
|
|
'id', |
|
74
|
|
|
'client', |
|
75
|
|
|
'invoicedate', |
|
76
|
|
|
'subtotal', |
|
77
|
|
|
'vatamount', |
|
78
|
|
|
'total', |
|
79
|
|
|
], |
|
80
|
|
|
}, |
|
81
|
|
|
] |
|
82
|
|
|
|
|
83
|
|
|
def __call__(self): |
|
84
|
|
|
mtool = getToolByName(self.context, 'portal_membership') |
|
85
|
|
|
if mtool.checkPermission(ManageInvoices, self.context): |
|
86
|
|
|
self.show_select_column = True |
|
87
|
|
|
return super(InvoiceFolderView, self).__call__() |
|
88
|
|
|
|
|
89
|
|
|
def before_render(self): |
|
90
|
|
|
"""Before template render hook |
|
91
|
|
|
""" |
|
92
|
|
|
super(InvoiceFolderView, self).before_render() |
|
93
|
|
|
# Don't allow any context actions on Invoices folder |
|
94
|
|
|
self.request.set("disable_border", 1) |
|
95
|
|
|
|
|
96
|
|
|
def isItemAllowed(self, obj): |
|
97
|
|
|
""" |
|
98
|
|
|
Check if the invoice should be shown in the insurance company's invoice folder. |
|
99
|
|
|
To be shown the invoice should be related with a insurance company's patient. |
|
100
|
|
|
:obj: An invoice object. |
|
101
|
|
|
:return: True/False |
|
102
|
|
|
""" |
|
103
|
|
|
iAR = obj.getAnalysisRequest() if obj.getAnalysisRequest() else None |
|
104
|
|
|
# Get the AR's patient if the invoice has an AR related |
|
105
|
|
|
patient = iAR.Schema()['Patient'].get(iAR) if iAR else None |
|
106
|
|
|
# Get the patient's insurance company's UID if there is a patient |
|
107
|
|
|
icuid = patient.getInsuranceCompany().UID() \ |
|
108
|
|
|
if patient and patient.getInsuranceCompany() else None |
|
109
|
|
|
return icuid == self.context.UID() |
|
110
|
|
|
|
|
111
|
|
|
def folderitems(self, full_objects=False): |
|
112
|
|
|
""" |
|
113
|
|
|
:return: All the invoices related with the Insurance Company's clients. |
|
114
|
|
|
""" |
|
115
|
|
|
currency = currency_format(self.context, 'en') |
|
116
|
|
|
self.show_all = True |
|
117
|
|
|
items = BikaListingView.folderitems(self, full_objects) |
|
118
|
|
|
l = [] |
|
119
|
|
|
for item in items: |
|
120
|
|
|
obj = item['obj'] |
|
121
|
|
|
number_link = "<a href='%s'>%s</a>" % ( |
|
122
|
|
|
item['url'], obj.getId() |
|
123
|
|
|
) |
|
124
|
|
|
item['replace']['id'] = number_link |
|
125
|
|
|
item['client'] = obj.getClient().Title() |
|
126
|
|
|
item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) |
|
127
|
|
|
item['subtotal'] = currency(obj.getSubtotal()) |
|
128
|
|
|
item['vatamount'] = currency(obj.getVATAmount()) |
|
129
|
|
|
item['total'] = currency(obj.getTotal()) |
|
130
|
|
|
l.append(item) |
|
131
|
|
|
return l |
|
132
|
|
|
|