diff --git a/netforce_clinic/models/report_account_hd_case_summary.py b/netforce_clinic/models/report_account_hd_case_summary.py index bfab66b..0a2c9e2 100644 --- a/netforce_clinic/models/report_account_hd_case_summary.py +++ b/netforce_clinic/models/report_account_hd_case_summary.py @@ -110,27 +110,28 @@ class ReportAccountHDCaseSummary(Model): records={} cycles={} context['reimbursable']=reimbursable + categ_prods=[] + for cat_prod in get_model("product.categ").search_read([],['code']): + code=(cat_prod['code'] or "").lower() + categ_prods.append(code) for line in get_model("clinic.hd.case.line").search_browse(dom,context=context): hdcase=line.hd_case_id - items={} - amt=line.amount or 0 - categ=line.product_categ_id - code=(categ.code or "").lower() - if not code in items.keys(): - items[code]=[] - items[code].append({ - 'amount': amt, - }) - pm_number=','.join([pm.number for pm in hdcase.payments if pm.number]) + pm_numbers=[] + pm_id=None + for pm in hdcase.payments: + if pm.number: + pm_numbers.append(pm.number) + pm_id=pm.id #XXX + pm_number=','.join([pnum for pnum in pm_numbers]) prods={ 'yes': [], 'no': [], '': [], } #get the right invoice - for line in hdcase.lines: - prod=line.product_id - reim=line.reimbursable + for hline in hdcase.lines: + prod=hline.product_id + reim=hline.reimbursable if prod: prods[reim].append(prod.id) inv_number="" @@ -138,8 +139,8 @@ class ReportAccountHDCaseSummary(Model): inv_id=None for inv in hdcase.invoices: inv_prods=[] - for line in inv.lines: - prod=line.product_id + for inv_line in inv.lines: + prod=inv_line.product_id if prod: if prod.id in prods[reimbursable]: inv_prods.append(prod.id) @@ -158,15 +159,15 @@ class ReportAccountHDCaseSummary(Model): cycle_item=hdcase.cycle_item_id if cycle.id not in cycles.keys(): cycles[cycle.id]=[] - for line in cycle_item.lines: - nurse=line.nurse_id + for cline in cycle_item.lines: + nurse=cline.nurse_id cycles[cycle.id].append(nurse.name) vals={ 'hdcase_id': hdcase.id, 'number': hdcase.number or "", 'date': hdcase.date, 'hct': hdcase.hct or 0, - 'epo_name': hdcase.epo or 0, + 'epo_name': hdcase.epo or "", 'ptype': ptype.name or "", 'ptype_color': ptype.color or "default", 'dname': hdcase.doctor_id.name or "", @@ -177,39 +178,43 @@ class ReportAccountHDCaseSummary(Model): 'idcard': patient.card_no or "", 'cseq': cycle.sequence or 0, 'cycle_item_id': cycle_item.id, - 'pm_number': pm_number and pm_number or "-", - 'inv_number': inv_number and inv_number or "-", + 'pm_number': pm_number and pm_number or "", + 'pm_id': pm_id, + 'inv_number': inv_number and inv_number or "", 'inv_id': inv_id, - 'mdc': hdcase.mdc, 'mdc_name': hdcase.mdc_name, 'dlz_name': hdcase.dlz_name, 'dlz_id': hdcase.dlz_id and hdcase.dlz_id or 0, - 'dlz_price': hdcase.dlz_price, - 'lab': hdcase.lab, - 'misc': hdcase.misc, - 'inv_ref': inv_ref and inv_ref or "-", - 'pick_ref': pick_ref and pick_ref or "-", + 'inv_ref': inv_ref and inv_ref or "", + 'pick_ref': pick_ref and pick_ref or "", 'pick_id': pick_id, } - for code, item in items.items(): - 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 - #FIXME please check - #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'] + hdcase_id=vals['hdcase_id'] + if not records.get(hdcase_id): + for categ_prod in categ_prods: + vals[categ_prod]=0 + vals['misc']=0 + records[hdcase_id]=vals + amt=line.amount or 0 + categ=line.product_categ_id + if categ: + code=(categ.code or "").lower() + if code: + code=code.replace("epo","mdc") #XXX + records[hdcase_id][code]+=amt + else: + if categ.parent_id: + code=categ.parent_id.code or '' + if code: + code=code.lower() + records[hdcase_id][code]+=amt + else: + records[hdcase_id]['misc']+=amt + else: + records[hdcase_id]['misc']+=amt lines=[] - for hdnumber, vals in records.items(): + for hdcase_id, vals in records.items(): lines.append(vals) company_name=company.name or "" if department_id: diff --git a/netforce_clinic/reports/report_account_hd_case_summary.xlsx b/netforce_clinic/reports/report_account_hd_case_summary.xlsx index 931cf90..be763ec 100644 Binary files a/netforce_clinic/reports/report_account_hd_case_summary.xlsx and b/netforce_clinic/reports/report_account_hd_case_summary.xlsx differ diff --git a/netforce_clinic/templates/report_account_hd_case_summary.hbs b/netforce_clinic/templates/report_account_hd_case_summary.hbs index cfb8e7b..5a6ac69 100644 --- a/netforce_clinic/templates/report_account_hd_case_summary.hbs +++ b/netforce_clinic/templates/report_account_hd_case_summary.hbs @@ -79,9 +79,15 @@