From 68a5621d4b9c334641488226cda339937cdb0cf9 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Fri, 11 Dec 2015 11:31:56 +0700 Subject: [PATCH] recompute labor cost --- .../layouts/clinic_dialyzer_form.xml | 4 +-- netforce_clinic/models/hd_case.py | 32 +++++++++++-------- netforce_clinic/models/hd_case_dialyzer.py | 2 +- netforce_clinic/models/hd_case_payment.py | 2 ++ 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/netforce_clinic/layouts/clinic_dialyzer_form.xml b/netforce_clinic/layouts/clinic_dialyzer_form.xml index 09c0247..583ad80 100644 --- a/netforce_clinic/layouts/clinic_dialyzer_form.xml +++ b/netforce_clinic/layouts/clinic_dialyzer_form.xml @@ -2,8 +2,8 @@ diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 6ffdfe8..41dbcba 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -914,9 +914,6 @@ class HDCase(Model): use_time=dlz_line.use_time or 0 max_use_time=dlz_line.max_use_time or 0 desc=dlz_line.description or '' - #TODO when we to draft after approve hdcase it will update the wrong use time - #if use_time > (dlz.use_time or 0): - #continue if is_decrease: use_time-=1 vals={ @@ -957,7 +954,7 @@ class HDCase(Model): cycle_item_ids=cycle_item.search(dom) cycle_item_id=None if cycle_item_ids: - cycle_item_id=cycle_item_ids[0] + cycle_item_id=cycle_item_ids[-1] else: cycle_item_id=cycle_item.create({ 'date': obj.date, @@ -1013,7 +1010,6 @@ class HDCase(Model): obj.make_invoices(context=context) obj.post_invoices(context=context) obj.create_cycle_item() - #obj.do_expense(context=context) vals={ "state":"waiting_payment", # for government } @@ -1023,6 +1019,7 @@ class HDCase(Model): date=obj.date vals['time_stop']='%s %s'%(date,timenow) obj.write(vals) + obj.recompute_labor_cost() if context.get("called"): return obj.id return { @@ -1058,13 +1055,11 @@ class HDCase(Model): def undo(self,ids,context={}): obj=self.browse(ids)[0] - # recompute labor cost - lc=get_model("clinic.labor.cost").search_browse([['cycle_item_id','=',obj.cycle_item_id.id]]) - if lc: - lc.compute() context['is_decrease']=True - # in case to draft - obj.update_usetime(context=context) + # should not reset use time if not the day of treatment is not today + datenow=time.strftime("%Y-%m-%d") + if obj.date==datenow: + obj.update_usetime(context=context) for line in obj.lines: line.write({ 'state': 'draft', @@ -1087,7 +1082,7 @@ class HDCase(Model): payment.delete() for pm_line in obj.payment_lines: pm_line.delete() - + #XXX remove for exp in obj.expenes: exp.delete() @@ -1100,7 +1095,7 @@ class HDCase(Model): obj.sickbed_id.write({ 'available': False, }) - + obj.recompute_labor_cost() return { 'next': { 'name': 'clinic_hd_case', @@ -1109,7 +1104,16 @@ class HDCase(Model): }, 'flash': '%s has been undo'%obj.number, } - + + def recompute_labor_cost(self,ids,context={}): + for obj in self.browse(ids): + cit=obj.cycle_item_id + # recompute labor cost + if cit.state=='validated': + for lc in get_model("clinic.labor.cost").search_browse([['cycle_item_id','=',cit.id]]): + lc.compute() + + def view_payment(self,ids,context={}): print("clinic_view_payment") return { diff --git a/netforce_clinic/models/hd_case_dialyzer.py b/netforce_clinic/models/hd_case_dialyzer.py index e58fcf5..030bb32 100644 --- a/netforce_clinic/models/hd_case_dialyzer.py +++ b/netforce_clinic/models/hd_case_dialyzer.py @@ -31,7 +31,7 @@ class HDCaseDialyzerLine(Model): "membrane_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"), 'hdcase_date': fields.Date('Date', function="_get_all",function_multi=True), "hdcase_state": fields.Selection([("draft","Draft"),('waiting_treatment','Waiting Treatment'),("in_progress","In Progress"),("completed","Finish Treatment"),('paid','Paid'),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("cancelled","Cancelled")],"Status",required=True,function="_get_all",function_multi=True), - 'nurse_id': fields.Many2One('clinic.staff', 'Nurse',function="_get_all",function_multi=True), + 'nurse_id': fields.Many2One('clinic.staff', 'Use by',function="_get_all",function_multi=True), "state": fields.Selection([("new","New"),("active","Active"),("drop","Drop"),("expire","Expire"),('cancelled','Cancelled')],"Status",function="_get_dlz_state"), } diff --git a/netforce_clinic/models/hd_case_payment.py b/netforce_clinic/models/hd_case_payment.py index ce18120..1856c3b 100644 --- a/netforce_clinic/models/hd_case_payment.py +++ b/netforce_clinic/models/hd_case_payment.py @@ -65,6 +65,7 @@ class HDCasePayment(Model): obj.write({ 'pay_amount': hd_case.amount, }) + hd_case.recompute_labor_cost() return { 'next': { 'name': 'clinic_hd_case', @@ -85,6 +86,7 @@ class HDCasePayment(Model): 'state': 'waiting_payment', 'req_fee': 0, # force to hide button pay! }) + hd_case.recompute_labor_cost() inv_number=[] for inv in hd_case.invoices: inv_number.append(inv.number or "")