gen period

conv_bal
watcha.h 2014-12-16 00:46:43 +07:00
parent 5401f44a1c
commit ecbb73c7ac
4 changed files with 61 additions and 21 deletions

View File

@ -1,7 +1,7 @@
<form model="clinic.patient.type">
<head>
<button string="Options" dropdown="1">
<item string="New Contact" method="new_contact"/>
<!--<item string="New Contact" method="new_contact"/>-->
</button>
</head>
<field name="name"/>

View File

@ -7,12 +7,14 @@
<group form_layout="stacked">
<field name="name" span="3"/>
<field name="date_start" span="3"/>
<field name="duration" span="3"/>
<field name="date_stop" span="3"/>
<field name="nmonth" span="3"/>
<field name="lines" nolabel="1">
<list>
<field name="date_start"/>
<field name="date_stop"/>
<field name="day_total"/>
<field name="close"/>
</list>
</field>
</group>

View File

@ -1,5 +1,6 @@
from datetime import datetime, timedelta
import time
from datetime import datetime, timedelta
from calendar import monthrange
from netforce.model import Model, fields
@ -9,9 +10,10 @@ class Period(Model):
_fields={
"name": fields.Char("Name",required=True,search=True),
'date_start': fields.Date("Start Date",required=True),
'duration': fields.Integer("Day in Period",required=True),
'nmonth': fields.Integer("Number of Month",required=True),
'date_start': fields.Date("From",required=True),
'date_stop': fields.Date("To",required=True),
#'duration': fields.Integer("Day in Period",required=True),
'nmonth': fields.Integer("Total Copy",required=True),
'lines': fields.One2Many("clinic.period.line","period_id", "Lines"),
}
@ -19,10 +21,14 @@ class Period(Model):
year=time.strftime("%Y")
return '%s-01-01'%year
def _get_stop(self,context={}):
year=time.strftime("%Y")
return '%s-01-30'%year
_defaults={
'name': lambda *a: time.strftime("%Y"),
'date_start': _get_start,
'duration': 30,
'date_stop': _get_stop,
'nmonth': 12,
}
@ -30,21 +36,40 @@ class Period(Model):
obj=self.browse(ids)[0]
for line in obj.lines:
line.delete()
fmt="%Y-%m-%d"
start=obj.date_start
year,month,day=[int(x) for x in obj.date_start.split("-")]
tyear,tmonth,tday=[int(x) for x in obj.date_stop.split("-")]
lines=[]
for i in range(obj.nmonth):
start=datetime.strptime(start,fmt)
stop=start+timedelta(days=obj.duration)
def _zfill(n):
return str(n).zfill(2)
for m in range(1,obj.nmonth):
if tmonth >12:
tmonth=1
tyear+=1
weekday, ttotal_day=monthrange(int(tyear), int(tmonth))
weekday, total_day=monthrange(int(year), int(month))
if day > total_day:
day=total_day
if tday > ttotal_day:
tday=ttotal_day
lines.append(('create',{
'date_start': start.strftime(fmt),
'date_stop': stop.strftime(fmt),
'date_start': '%s-%s-%s'%(year,_zfill(month),_zfill(day)),
'date_stop': '%s-%s-%s'%(tyear,_zfill(tmonth),_zfill(tday)),
}))
print(i+1, ' ', start.strftime(fmt), ' ', stop.strftime(fmt))
stop=stop+timedelta(days=1)
start=stop.strftime(fmt)
if month==tmonth:
tmonth+=1
month=tmonth
year=tyear
tmonth+=1
obj.write({
'lines': lines,
})
return {
'next': {
'name': 'clinic_period',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Generate successfully',
}
Period.register()

View File

@ -1,20 +1,33 @@
from datetime import datetime
from netforce.model import Model, fields
class PeriodLine(Model):
_name="clinic.period.line"
_string="Period Line"
def _get_total(self,ids,context={}):
res={}
fmt='%Y-%m-%d'
for obj in self.browse(ids):
start=datetime.strptime(obj.date_start,fmt)
stop=datetime.strptime(obj.date_stop,fmt)
days=(stop-start).days
res[obj.id]=days
return res
_fields={
"period_id": fields.Many2One("clinic.period", "Period"),
#'date_start': fields.Date("Date Start"),
#'date_stop': fields.Date("Date Stop"),
'date_start': fields.Char("Date Start"),
'date_stop': fields.Char("Date Stop"),
'date_start': fields.Date("Date Start"),
'date_stop': fields.Date("Date Stop"),
'day_total': fields.Integer("Total Day",function="_get_total"),
'state': fields.Selection([['draft','Draft'],['done','Done']],"State"),
'close': fields.Boolean("Close"),
}
_defaults={
'state': 'draft',
'close': False,
}
PeriodLine.register()