report expense

conv_bal
watcha.h@almacom.co.th 2015-03-26 07:31:27 +07:00
parent 5b9bd61c46
commit f3968d0fea
2 changed files with 39 additions and 7 deletions

View File

@ -7,4 +7,5 @@
<field name="ptype_id" span="2"/>
<field name="reimbursable" span="2"/>
<field name="cycle_id" span="2"/>
<field name="product_id" span="2"/>
</form>

View File

@ -18,6 +18,7 @@ class ReportAccountHDCaseSummary(Model):
'ptype_id': fields.Many2One("clinic.patient.type","Patient Type"),
'reimbursable': fields.Selection([['yes','Yes'],['no','No']],'Claim'),
'cycle_id': fields.Many2One("clinic.cycle","Cycle"),
'product_id': fields.Many2One("product","Product"),
}
def default_get(self,field_names=None,context={},**kw):
@ -27,9 +28,10 @@ class ReportAccountHDCaseSummary(Model):
weekday, total_day=monthrange(int(year), int(month))
date_from=defaults.get('date_from','%s-%s-01'%(year,month))
date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day))
#XXX
date_from=defaults.get('date',date)
date_to=defaults.get('date',date)
product_id=defaults.get('product_id')
reimbursable=defaults.get('reimbursable',"yes")
branch_id=defaults.get('branch_id',None)
print('defaults ', defaults)
@ -38,13 +40,24 @@ class ReportAccountHDCaseSummary(Model):
department_id=defaults.get('department_id',None)
if department_id:
department_id=int(department_id)
select_dpt=get_model('select.company').get_select()
print('select_dpt ', select_dpt)
if select_dpt:
if not branch_id:
branch_id=select_dpt['branch_id']
if not department_id:
if select_dpt.get('department_ids'):
department_id=select_dpt['department_ids'][0]
else:
department_id=select_dpt['department_id']
res={
'date': date,
'date_from': date_from,
'date_to': date_to,
'branch_id': branch_id,
'department_id': department_id,
'reimbursable': 'yes',
'reimbursable': reimbursable,
'product_id': product_id,
}
return res
@ -57,8 +70,9 @@ class ReportAccountHDCaseSummary(Model):
date=defaults.get("date")
branch_id=defaults.get("branch_id")
department_id=defaults.get("department_id")
reimbursable=defaults.get('reimbursable','yes')
product_id=defaults.get('product_id')
ptype_id=None
reimbursable=''
cycle_id=None
if ids:
obj=self.browse(ids)[0]
@ -68,12 +82,14 @@ class ReportAccountHDCaseSummary(Model):
date_from=obj.date_from
date_to=obj.date_to
ptype_id=obj.ptype_id.id
reimbursable=obj.reimbursable
cycle_id=obj.cycle_id.id
reimbursable=obj.reimbursable
product_id=obj.product_id.id
dom=[
['hd_case_id.date','>=', date_from],
['hd_case_id.date','<=', date_to],
['hd_case_id.patient_id.walkin','=','no'],
['hd_case_id.state','in',['completed','waiting_payment','paid']],
]
if ptype_id:
dom.append(['hd_case_id.patient_type_id','=',ptype_id])
@ -85,9 +101,9 @@ class ReportAccountHDCaseSummary(Model):
dom.append(['hd_case_id.cycle_id','=',cycle_id])
if reimbursable:
dom.append(['reimbursable','=',reimbursable])
else:
dom.append(['hd_case_id.state','in',['completed','waiting_payment','paid']])
lines=[]
if product_id:
dom.append(['product_id','=',product_id])
records={}
cycles={}
for line in get_model("clinic.hd.case.line").search_browse(dom):
hdcase=line.hd_case_id
@ -154,6 +170,21 @@ class ReportAccountHDCaseSummary(Model):
vals.update({
code: sum([t['amount'] for t in item])
})
# merge 1 line of number
number=vals['number']
if number not in records.keys():
records[number]=vals
else:
for code, item in items.items():
if vals.get(code):
if not records[number].get(code):
records[number][code]=0
records[number][code]+=vals[code]
records[number]['lab']+=vals['lab']
records[number]['misc']+=vals['misc']
lines=[]
for hdnumber, vals in records.items():
lines.append(vals)
company_name=company.name or ""
if department_id: