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-24 10:14:21 +00:00
|
|
|
from netforce.utils import get_data_path
|
2014-11-17 00:59:19 +00:00
|
|
|
|
2014-11-27 00:47:38 +00:00
|
|
|
class CycleMonthly(Model):
|
|
|
|
_name="clinic.cycle.monthly"
|
|
|
|
_string="Cycle Monthly"
|
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"),
|
2014-11-27 07:36:27 +00:00
|
|
|
'cycle_dailies': fields.One2Many("clinic.cycle.daily","cycle_monthly_id", "Cycle Dialy"),
|
2014-11-27 00:47:38 +00:00
|
|
|
'lines': fields.One2Many("clinic.cycle.monthly.line","cycle_monthly_id", "Lines"),
|
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-27 00:47:38 +00:00
|
|
|
"state": fields.Selection([("draft","Draft"),('approved','Approved')],"Status",required=True),
|
2014-11-17 00:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'company_id': lambda *a: get_active_company(),
|
2014-11-27 07:36:27 +00:00
|
|
|
'name': lambda *a: time.strftime("%Y/%m"),
|
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-27 00:47:38 +00:00
|
|
|
date=vals.get('month','')
|
2014-11-21 16:11:57 +00:00
|
|
|
if date:
|
|
|
|
vals['name']=date
|
2014-11-17 00:59:19 +00:00
|
|
|
super().write(ids,vals,**kw)
|
|
|
|
|
2014-11-27 00:47:38 +00:00
|
|
|
def approve(self,ids,context={}):
|
2014-11-21 16:11:57 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
2014-11-27 00:47:38 +00:00
|
|
|
'state': 'approved',
|
2014-11-21 16:11:57 +00:00
|
|
|
})
|
|
|
|
return {
|
|
|
|
'next': {
|
2014-11-27 00:47:38 +00:00
|
|
|
'name': 'clinic_cycle_monthly',
|
2014-11-21 16:11:57 +00:00
|
|
|
'mode': 'form',
|
|
|
|
'active_id': obj.id,
|
|
|
|
},
|
2014-11-27 00:47:38 +00:00
|
|
|
'flash':'Approved',
|
2014-11-21 16:11:57 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 00:47:38 +00:00
|
|
|
def recheck_daily(self,ids,context={}):
|
2014-11-24 01:28:46 +00:00
|
|
|
# copy cost of nurse and doctor from cycle item
|
2014-11-21 16:11:57 +00:00
|
|
|
obj=self.browse(ids)[0]
|
2014-11-24 01:28:46 +00:00
|
|
|
lines=[]
|
|
|
|
ctx=context.copy()
|
|
|
|
context['called']=True
|
2014-11-27 00:47:38 +00:00
|
|
|
for cycle_daily in obj.dailies:
|
|
|
|
lines+=cycle_daily.confirm(context=context)
|
2014-11-21 16:11:57 +00:00
|
|
|
obj.write({
|
2014-11-24 01:28:46 +00:00
|
|
|
'lines': lines,
|
2014-11-21 16:11:57 +00:00
|
|
|
})
|
2014-11-24 01:28:46 +00:00
|
|
|
context=ctx
|
2014-11-21 16:11:57 +00:00
|
|
|
return {
|
|
|
|
'next': {
|
2014-11-27 00:47:38 +00:00
|
|
|
'name': 'clinic_cycle_monthly',
|
2014-11-21 16:11:57 +00:00
|
|
|
'mode': 'form',
|
|
|
|
'active_id': obj.id,
|
|
|
|
},
|
2014-11-24 01:28:46 +00:00
|
|
|
'flash':'Recheck successfully',
|
2014-11-21 16:11:57 +00:00
|
|
|
}
|
|
|
|
|
2014-11-24 10:14:21 +00:00
|
|
|
def onchange_line(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
path=context['path']
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
qty=line['qty']
|
|
|
|
rate=line['rate']
|
|
|
|
line['amount']=qty*rate
|
|
|
|
total=0.0
|
|
|
|
for line in data['lines']:
|
|
|
|
qty=line['qty']
|
|
|
|
rate=line['rate']
|
|
|
|
total+=qty*rate
|
|
|
|
data['total']=total
|
|
|
|
return data
|
2014-11-27 01:50:15 +00:00
|
|
|
|
|
|
|
def to_draft(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'draft',
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_cycle_monthly',
|
|
|
|
'mode': 'form',
|
|
|
|
'active_id': obj.id,
|
|
|
|
},
|
|
|
|
'flash': '%s has been set to draft'%obj.name
|
|
|
|
}
|
2014-11-21 16:11:57 +00:00
|
|
|
|
2014-11-27 00:47:38 +00:00
|
|
|
CycleMonthly.register()
|