1
2 """Billing code.
3
4 license: GPL v2 or later
5 """
6
7 __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>"
8
9 import sys
10 import logging
11
12
13
14 if __name__ == '__main__':
15 sys.path.insert(0, '../../')
16 from Gnumed.pycommon import gmPG2
17 from Gnumed.pycommon import gmBusinessDBObject
18 from Gnumed.pycommon import gmTools
19
20
21 _log = logging.getLogger('gm.bill')
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 _SQL_get_billable_fields = u"""SELECT * FROM ref.v_billables WHERE %s"""
42
43 -class cBillable(gmBusinessDBObject.cBusinessDBObject):
44 """Items which can be billed to patients."""
45
46 _cmd_fetch_payload = _SQL_get_billable_fields % u"""pk_billable = %s"""
47 _cmds_store_payload = [
48 u"""UPDATE ref.billable SET
49 code = %(billable_code)s,
50 term = %(billable_description)s,
51 amount = %(raw_amount)s,
52 currency = %(currency)s,
53 vat_multiplier = %(vat_multiplier)s
54 WHERE
55 pk = %(pk_billabs)s
56 AND
57 xmin = %(xmin_billable)s"""
58 ]
59
60 _updatable_fields = [
61 'billable_description',
62 'raw_amount',
63 'vat_multiplier',
64 ]
65
66
68
69 if order_by is None:
70 order_by = u' ORDER BY catalog_long, catalog_version, billable_code'
71 else:
72 order_by = u' ORDER BY %s' % order_by
73
74 if active_only:
75 where = u'active IS true'
76 else:
77 where = u'true'
78
79 cmd = (_SQL_get_billable_fields % where) + order_by
80 rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd}], get_col_idx = True)
81 return [ cBillable(row = {'data': r, 'idx': idx, 'pk_field': 'pk_billable'}) for r in rows ]
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 if __name__ == "__main__":
120
121 if len(sys.argv) < 2:
122 sys.exit()
123
124 if sys.argv[1] != 'test':
125 sys.exit()
126
127
128
129
130
131
132
133
135 print "\test"
136 print "--------------"
137 me = cBillable(aPK_obj=1)
138 fields = me.get_fields()
139 for field in fields:
140 print field, ':', me[field]
141 print "updatable:", me.get_updatable_fields()
142
143
144 test_me()
145