recompute labor cost

production
watcha.h 2015-12-11 11:31:56 +07:00
parent 091e327db3
commit 68a5621d4b
4 changed files with 23 additions and 17 deletions

View File

@ -2,8 +2,8 @@
<head> <head>
<field name="state"/> <field name="state"/>
<button string="Options" dropdown="1"> <button string="Options" dropdown="1">
<item string="Copy" method="copy" states="active"/> <item string="Copy" method="copy" states="active,drop,expire"/>
<item string="To Draft" method="to_draft" states="drop,active,expire"/> <item string="To Draft" method="to_draft" states="active"/>
</button> </button>
</head> </head>
<group span="6" columns="1"> <group span="6" columns="1">

View File

@ -914,9 +914,6 @@ class HDCase(Model):
use_time=dlz_line.use_time or 0 use_time=dlz_line.use_time or 0
max_use_time=dlz_line.max_use_time or 0 max_use_time=dlz_line.max_use_time or 0
desc=dlz_line.description or '' 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: if is_decrease:
use_time-=1 use_time-=1
vals={ vals={
@ -957,7 +954,7 @@ class HDCase(Model):
cycle_item_ids=cycle_item.search(dom) cycle_item_ids=cycle_item.search(dom)
cycle_item_id=None cycle_item_id=None
if cycle_item_ids: if cycle_item_ids:
cycle_item_id=cycle_item_ids[0] cycle_item_id=cycle_item_ids[-1]
else: else:
cycle_item_id=cycle_item.create({ cycle_item_id=cycle_item.create({
'date': obj.date, 'date': obj.date,
@ -1013,7 +1010,6 @@ class HDCase(Model):
obj.make_invoices(context=context) obj.make_invoices(context=context)
obj.post_invoices(context=context) obj.post_invoices(context=context)
obj.create_cycle_item() obj.create_cycle_item()
#obj.do_expense(context=context)
vals={ vals={
"state":"waiting_payment", # for government "state":"waiting_payment", # for government
} }
@ -1023,6 +1019,7 @@ class HDCase(Model):
date=obj.date date=obj.date
vals['time_stop']='%s %s'%(date,timenow) vals['time_stop']='%s %s'%(date,timenow)
obj.write(vals) obj.write(vals)
obj.recompute_labor_cost()
if context.get("called"): if context.get("called"):
return obj.id return obj.id
return { return {
@ -1058,13 +1055,11 @@ class HDCase(Model):
def undo(self,ids,context={}): def undo(self,ids,context={}):
obj=self.browse(ids)[0] 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 context['is_decrease']=True
# in case to draft # should not reset use time if not the day of treatment is not today
obj.update_usetime(context=context) datenow=time.strftime("%Y-%m-%d")
if obj.date==datenow:
obj.update_usetime(context=context)
for line in obj.lines: for line in obj.lines:
line.write({ line.write({
'state': 'draft', 'state': 'draft',
@ -1087,7 +1082,7 @@ class HDCase(Model):
payment.delete() payment.delete()
for pm_line in obj.payment_lines: for pm_line in obj.payment_lines:
pm_line.delete() pm_line.delete()
#XXX remove
for exp in obj.expenes: for exp in obj.expenes:
exp.delete() exp.delete()
@ -1100,7 +1095,7 @@ class HDCase(Model):
obj.sickbed_id.write({ obj.sickbed_id.write({
'available': False, 'available': False,
}) })
obj.recompute_labor_cost()
return { return {
'next': { 'next': {
'name': 'clinic_hd_case', 'name': 'clinic_hd_case',
@ -1110,6 +1105,15 @@ class HDCase(Model):
'flash': '%s has been undo'%obj.number, '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={}): def view_payment(self,ids,context={}):
print("clinic_view_payment") print("clinic_view_payment")
return { return {

View File

@ -31,7 +31,7 @@ class HDCaseDialyzerLine(Model):
"membrane_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"), "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_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), "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"), "state": fields.Selection([("new","New"),("active","Active"),("drop","Drop"),("expire","Expire"),('cancelled','Cancelled')],"Status",function="_get_dlz_state"),
} }

View File

@ -65,6 +65,7 @@ class HDCasePayment(Model):
obj.write({ obj.write({
'pay_amount': hd_case.amount, 'pay_amount': hd_case.amount,
}) })
hd_case.recompute_labor_cost()
return { return {
'next': { 'next': {
'name': 'clinic_hd_case', 'name': 'clinic_hd_case',
@ -85,6 +86,7 @@ class HDCasePayment(Model):
'state': 'waiting_payment', 'state': 'waiting_payment',
'req_fee': 0, # force to hide button pay! 'req_fee': 0, # force to hide button pay!
}) })
hd_case.recompute_labor_cost()
inv_number=[] inv_number=[]
for inv in hd_case.invoices: for inv in hd_case.invoices:
inv_number.append(inv.number or "") inv_number.append(inv.number or "")