Package Gnumed :: Package business :: Module gmBilling
[frames] | no frames]

Source Code for Module Gnumed.business.gmBilling

  1  # -*- coding: utf8 -*- 
  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  #import codecs 
 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  #class cChargeItemGroup(gmBusinessDBObject.cBusinessDBObject): 
 25  #       """An Charge Item Group 
 26  #       """ 
 27  #       _cmd_fetch_payload = u"select *, xmin from bill.ci_category where pk=%s" 
 28  #       _cmds_store_payload = [ 
 29  #               u"""update bill.ci_category set 
 30  #                               description=%(description)s 
 31  #                       where 
 32  #                               pk=%(pk)s and 
 33  #                               xmin=%(xmin)s""", 
 34  #               ] 
 35  # 
 36  #       _updatable_fields = [ 
 37  #               'description', 
 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 #------------------------------------------------------------
67 -def get_billables(active_only=True, order_by=None):
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 #def create_charge_item_group(description=None): 85 # """Creates a new charge_item_group 86 # 87 # description 88 # """ 89 # queries = [ 90 # {'cmd': u"insert into bill.ci_category (description) values (%s) returning pk", 91 # 'args': [description or u'' ] 92 # }, 93 # ] 94 # rows, idx = gmPG2.run_rw_queries(queries = queries, return_data=True) 95 # 96 # new = cChargeItemGroup(aPK_obj = rows[0][0]) 97 # return (True, new) 98 # 99 # 100 #def create_charge_item(description=None): 101 # """Creates a new charge_item 102 # 103 # description 104 # category - category 105 # """ 106 # queries = [ 107 # {'cmd': u"insert into ref.billable (description) values (%s) returning pk", 108 # 'args': [description or u'' ] 109 # }, 110 # ] 111 # rows, idx = gmPG2.run_rw_queries(queries = queries, return_data=True) 112 # 113 # new = cBillable(aPK_obj = rows[0][0]) 114 # return (True, new) 115 116 #============================================================ 117 # main 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 # from Gnumed.pycommon import gmLog2 128 # from Gnumed.pycommon import gmI18N 129 # from Gnumed.business import gmPerson 130 131 # gmI18N.activate_locale() 132 ## gmDateTime.init() 133
134 - def test_me():
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 #me['vat']=4; me.store_payload() 143 144 test_me() 145