91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
import time
|
|
|
|
from netforce.model import Model, fields
|
|
from netforce.access import get_active_company, get_active_user
|
|
|
|
class CycleDialy(Model):
|
|
_name="clinic.cycle.dialy"
|
|
_string="Cycle Dialy"
|
|
|
|
def _get_all(self,ids,context={}):
|
|
res={}
|
|
for obj in self.browse(ids):
|
|
total=0.0
|
|
for line in obj.lines:
|
|
total+=(line.paid_amount or 0)
|
|
res[obj.id]={
|
|
'total': total,
|
|
}
|
|
return res
|
|
|
|
_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"),
|
|
'lines': fields.One2Many("clinic.cycle.dialy.line","cycle_dialy_id", "Lines"),
|
|
"state": fields.Selection([("draft","Draft"),('confirmed','Confirmed'),("done","Done")],"Status",required=True),
|
|
'company_id': fields.Many2One("company","Company"),
|
|
'total': fields.Float("Total",function="_get_all", function_multi=True),
|
|
'user_id': fields.Many2One("base.user","User"),
|
|
}
|
|
|
|
_defaults={
|
|
'company_id': lambda *a: get_active_company(),
|
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
|
'name': lambda *a: time.strftime("%Y-%m-%d"),
|
|
'user_id': lambda *a: get_active_user(),
|
|
'state': 'draft',
|
|
}
|
|
|
|
def write(self,ids,vals,**kw):
|
|
date=vals.get('date','')
|
|
if date:
|
|
vals['name']=date
|
|
super().write(ids,vals,**kw)
|
|
|
|
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 post(self,ids,context={}):
|
|
# create journal entry
|
|
obj=self.browse(ids)[0]
|
|
obj.write({
|
|
'state': 'done',
|
|
})
|
|
return {
|
|
'next': {
|
|
'name': 'clinic_cycle_dialy',
|
|
'mode': 'form',
|
|
'active_id': obj.id,
|
|
},
|
|
'flash':'Done!',
|
|
}
|
|
|
|
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!',
|
|
}
|
|
|
|
CycleDialy.register()
|