clinic/netforce_clinic/models/cycle_dialy.py

98 lines
2.9 KiB
Python
Raw Normal View History

2014-11-17 00:59:19 +00:00
import time
from netforce.model import Model, fields
2014-11-21 16:11:57 +00:00
from netforce.access import get_active_company, get_active_user
2014-11-17 00:59:19 +00:00
class CycleDialy(Model):
_name="clinic.cycle.dialy"
2014-11-21 02:39:26 +00:00
_string="Cycle Dialy"
2014-11-17 00:59:19 +00:00
2014-11-21 16:11:57 +00:00
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
total=0.0
for line in obj.lines:
2014-11-23 15:39:41 +00:00
total+=(line.amount or 0)
2014-11-21 16:11:57 +00:00
res[obj.id]={
'total': total,
}
return res
2014-11-17 00:59:19 +00:00
_fields={
"name": fields.Char("Name"),
'date': fields.Date("Date", required=True, search=True),
'cycle_items': fields.One2Many("clinic.cycle.item","cycle_dialy_id", "Cycle Items"),
2014-11-21 16:11:57 +00:00
'lines': fields.One2Many("clinic.cycle.dialy.line","cycle_dialy_id", "Lines"),
"state": fields.Selection([("draft","Draft"),('confirmed','Confirmed'),("done","Done")],"Status",required=True),
2014-11-17 00:59:19 +00:00
'company_id': fields.Many2One("company","Company"),
2014-11-21 16:11:57 +00:00
'total': fields.Float("Total",function="_get_all", function_multi=True),
'user_id': fields.Many2One("base.user","User"),
2014-11-17 00:59:19 +00:00
}
_defaults={
'company_id': lambda *a: get_active_company(),
'date': lambda *a: time.strftime("%Y-%m-%d"),
'name': lambda *a: time.strftime("%Y-%m-%d"),
2014-11-21 16:11:57 +00:00
'user_id': lambda *a: get_active_user(),
'state': 'draft',
2014-11-17 00:59:19 +00:00
}
def write(self,ids,vals,**kw):
2014-11-21 16:11:57 +00:00
date=vals.get('date','')
if date:
vals['name']=date
2014-11-17 00:59:19 +00:00
super().write(ids,vals,**kw)
2014-11-21 16:11:57 +00:00
def confirm(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({
'state': 'confirmed',
})
return {
'next': {
'name': 'clinic_cycle_dialy',
'mode': 'form',
'active_id': obj.id,
},
'flash':'Confirmed',
}
def recheck_item(self,ids,context={}):
# copy cost of nurse and doctor from cycle item
2014-11-21 16:11:57 +00:00
obj=self.browse(ids)[0]
lines=[]
ctx=context.copy()
context['called']=True
# sorted by sequence of cycle
for cycle_item in sorted(obj.cycle_items, key=lambda x: x.cycle_id.sequence):
lines+=cycle_item.validate(context=context)
2014-11-21 16:11:57 +00:00
obj.write({
'lines': lines,
2014-11-21 16:11:57 +00:00
})
context=ctx
2014-11-21 16:11:57 +00:00
return {
'next': {
'name': 'clinic_cycle_dialy',
'mode': 'form',
'active_id': obj.id,
},
'flash':'Recheck successfully',
2014-11-21 16:11:57 +00:00
}
def to_draft(self,ids,context={}):
obj=self.browse(ids)[0]
# remove journal entry
obj.write({
'state': 'draft',
})
return {
'next': {
'name': 'clinic_cycle_dialy',
'mode': 'form',
'active_id': obj.id,
},
'flash':'Draft!',
}
2014-11-17 00:59:19 +00:00
CycleDialy.register()