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"> <form model="clinic.patient.type">
<head> <head>
<button string="Options" dropdown="1"> <button string="Options" dropdown="1">
<item string="New Contact" method="new_contact"/> <!--<item string="New Contact" method="new_contact"/>-->
</button> </button>
</head> </head>
<field name="name"/> <field name="name"/>

View File

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

View File

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

View File

@ -1,20 +1,33 @@
from datetime import datetime
from netforce.model import Model, fields from netforce.model import Model, fields
class PeriodLine(Model): class PeriodLine(Model):
_name="clinic.period.line" _name="clinic.period.line"
_string="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={ _fields={
"period_id": fields.Many2One("clinic.period", "Period"), "period_id": fields.Many2One("clinic.period", "Period"),
#'date_start': fields.Date("Date Start"), 'date_start': fields.Date("Date Start"),
#'date_stop': fields.Date("Date Stop"), 'date_stop': fields.Date("Date Stop"),
'date_start': fields.Char("Date Start"), 'day_total': fields.Integer("Total Day",function="_get_total"),
'date_stop': fields.Char("Date Stop"),
'state': fields.Selection([['draft','Draft'],['done','Done']],"State"), 'state': fields.Selection([['draft','Draft'],['done','Done']],"State"),
'close': fields.Boolean("Close"),
} }
_defaults={ _defaults={
'state': 'draft', 'state': 'draft',
'close': False,
} }
PeriodLine.register() PeriodLine.register()