conv_bal
watcha.h@almacom.co.th 2015-06-20 17:01:37 +07:00
parent b4296e54a3
commit a881dfadda
7 changed files with 69 additions and 25 deletions

View File

@ -1,7 +1,7 @@
<form model="clinic.period">
<head>
<button string="Options" dropdown="1">
<!--<item string="Copy" method="copy"/>-->
<item string="Generate Period" method="gen_period"/>
</button>
</head>
<group form_layout="stacked">
@ -15,11 +15,11 @@
<field name="date_start"/>
<field name="date_stop"/>
<field name="day_total"/>
<field name="close"/>
<field name="state"/>
</list>
</field>
</group>
<foot>
<button string="Generate" type="default" icon="arrow-right" method="gen_period"/>
<button string="Close Period" type="danger" method="close_period"/>
</foot>
</form>

View File

@ -1,6 +1,6 @@
<form model="clinic.report.labor.cost">
<field name="period_id" span="2"/>
<field name="date" mode="month" onchange="onchange_date" span="2"/>
<field name="period_id" onchange="onchange_period" domain='[["state","=","open"]]' span="2"/>
<!--<field name="date" mode="month" onchange="onchange_date" span="2"/>-->
<field name="date_from" onchange="onchange_from" required="1" span="2"/>
<field name="date_to" required="1" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/>

View File

@ -12,7 +12,7 @@ class Period(Model):
for obj in self.browse(ids):
last_id=None
for line in obj.lines:
if line.close:
if line.state=='close':
last_id=line.id
res[obj.id]=last_id
return res
@ -25,7 +25,7 @@ class Period(Model):
'lines': fields.One2Many("clinic.period.line","period_id", "Lines"),
'last_period_id': fields.Many2One("clinic.period.line","Last Period",function="_get_last_period"),
}
def _get_start(self,context={}):
year=time.strftime("%Y")
return '%s-01-01'%year
@ -40,6 +40,13 @@ class Period(Model):
'date_stop': _get_stop,
'nmonth': 12,
}
def close_period(self,ids,context={}):
obj=self.browse(ids)[0]
for line in obj.lines:
line.write({
'state': 'close',
})
def gen_period(self,ids,context={}):
obj=self.browse(ids)[0]

View File

@ -31,14 +31,18 @@ class PeriodLine(Model):
'date_stop': fields.Date("Date End"),
'day_total': fields.Integer("Duration (Day)",function="_get_total"),
'state': fields.Selection([['open','Open'],['close','Close']],"State"),
'close': fields.Boolean("Close"),
}
_defaults={
'state': 'open',
'close': False,
}
def delete(self,ids,context={}):
for obj in self.browse(ids):
if obj.state=='close':
raise Exception("Can delete object which state is closed!")
super().delete(ids,context)
def create(self,vals,**kw):
id=super().create(vals,**kw)
self.function_store([id])
@ -74,5 +78,4 @@ class PeriodLine(Model):
},
}
PeriodLine.register()

View File

@ -38,7 +38,16 @@ class ReportLaborCost(Model):
date_to=defaults.get("date_to", self._get_date_to())
report_type=defaults.get("report_type","cross")
print('defaults ', defaults)
yearnow=date_from.split("-")[0]
for period in get_model('clinic.period').search_browse([['name','=',yearnow]]):
for line in period.lines:
if line.state=='open':
period_id=line.id
date_from=line.date_start
date_to=line.date_stop
break
res={
'period_id': period_id,
'date': time.strftime("%Y-%m-%d"),
'date_from': date_from,
'date_to': date_to,
@ -344,6 +353,18 @@ class ReportLaborCost(Model):
nlines[-1]['qty']+=nline['qty'] or 0
nlines[-1]['cost']+=nline['cost'] or 0
nlines[-1]['total']+=nline['total'] or 0
def conv2line(keys=[],lines=[]):
lines2=[]
for key in keys:
no=0
vals={}
for line in lines:
vals[no]=line[key]
no+=1
lines2.append(vals)
return lines2
data={
'company_name': '%s %s' % (company.name or "", sub_name),
'date': date,
@ -351,7 +372,9 @@ class ReportLaborCost(Model):
'date_to': date_to,
'lines': lines,
'dlines': dlines,
'dlines2': conv2line(['name','qty','qty2','total_qty','cost'],dlines),
'nlines': nlines,
'nlines2': [],
'ctlines': ctlines,
'total_hdcase': total_hdcase,
'branch_id': branch_id,
@ -359,6 +382,15 @@ class ReportLaborCost(Model):
'show_detail': show_detail,
'report_type': report_type,
}
for key in ('name', 'qty', 'cost'):
no=0
vals={}
for nline in data['nlines']:
vals[no]=nline[key]
no+=1
data['nlines2'].append(vals)
return data
def onchange_date(self,context={}):
@ -379,5 +411,13 @@ class ReportLaborCost(Model):
data=context['data']
data['date_to']=data['date_from']
return data
def onchange_period(self,context={}):
data=context['data']
period_id=data['period_id']
period=get_model('clinic.period.line').browse(period_id)
data['date_from']=period.date_start
data['date_to']=period.date_stop
return data
ReportLaborCost.register()

View File

@ -1,3 +1,4 @@
import time
from datetime import datetime, timedelta
from calendar import monthrange
@ -161,21 +162,14 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
categ_ids=get_model('product.categ').search([['parent_id.code','=','MDC']])
for prod in get_model("product").search_browse([['categ_id','in',categ_ids]]):
prod.write({
'report_visible': True,
})
#for dt in get_model("district").search_browse([]):
#name=(dt.name or "")[0:1]
#dt.write({
#'sort_name': name,
#})
#for sdt in get_model("subdistrict").search_browse([]):
#name=(sdt.name or "")[0:1]
#sdt.write({
#'sort_name': name,
#})
datenow=time.strftime("%Y-%m-%d")
vdom=[
['visit_date','>',datenow],
['state','=','pending'],
['manual','=',False],
]
visit_ids=get_model("clinic.visit").search(vdom)
get_model("clinic.visit").delete(visit_ids)
print("Done!")
def merge_staff(self,ids,context={}):