cycle item

conv_bal
watcha.h 2014-11-21 23:11:57 +07:00
parent c06b7fa06c
commit d870a49af0
17 changed files with 236 additions and 25 deletions

View File

@ -2,6 +2,7 @@
<field name="string">Cycle Dialy</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.cycle.dialy</field>
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]],["Done",[["state","=","done"]]]]</field>
<field name="modes">list,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -1,9 +1,38 @@
<form model="clinic.cycle.dialy">
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="To Draft" method="to_draft" states="confirmed"/>
</button>
</head>
<tabs>
<tab string="General">
<field name="date"/>
<field name="lines" nolabel="1">
<list>
<field name="cycle_id"/>
<field name="personal_id"/>
<field name="type"/>
<field name="paid_amount"/>
</list>
<form>
<field name="cycle_id"/>
<field name="personal_id"/>
<field name="type"/>
<field name="paid_amount"/>
</form>
</field>
<group span="12">
<field name="total" span="2" offset="10"/>
</group>
</tab>
<tab string="Confirmation">
<field name="user_id"/>
</tab>
</tabs>
<foot>
<button string="Confirm" type="success" method="confirm" states="draft" />
</foot>
<related>
<field name="cycle_items">
<list colors='{"#cfc":[["state","=","done"]]}'>

View File

@ -1,3 +1,4 @@
<list model="clinic.cycle.dialy">
<field name="name"/>
<field name="state"/>
</list>

View File

@ -9,7 +9,7 @@
<field name="cycle_id" required="1"/>
<field name="date"/>
<tabs>
<tab string="Nurse">
<tab string="Nurses">
<field name="nurses" nolabel="1">
<list>
<field name="nurse_id" onchange="onchange_nurse"/>
@ -21,6 +21,7 @@
<group form_layout="stacked">
<field name="var_k" span="3"/>
<field name="var_pt" span="3"/>
<field name="var_ptx" span="3"/>
<field name="manual" span="3" help="Help"/>
<field name="lines" nolabel="1">
<list colors='{"red":[["state","=","fail"]]}'>
@ -34,7 +35,6 @@
</group>
<group span="6" columns="1">
<field name="var_fml1" span="6" offset="6"/>
<field name="var_ptx" span="6" offset="6"/>
<field name="var_fml2" span="6" offset="6"/>
<field name="var_fml3" span="6" offset="6"/>
<field name="var_x" span="6" offset="6"/>
@ -46,13 +46,16 @@
<tab string="Other Info">
<field name="cycle_dialy_id" domain="[['date','=',date]]"/>
</tab>
<tab string="Validation">
<field name="user_id"/>
</tab>
</tabs>
<foot>
<button string="Validate" type="success" method="validate" icon="ok" states="draft" />
<button string="To Draft" type="default" method="to_draft" icon="repeat" states="done" />
</foot>
<related>
<field name="visits"/>
<field name="hd_cases"/>
<field name="visits"/>
</related>
</form>

View File

@ -1,9 +1,9 @@
<list model="clinic.hd.case" colors='{"#cfc":[["state","=","completed"]],"#bcbbb9":[["state","=","cancelled"]]}'>
<field name="number"/>
<field name="time_start"/>
<field name="time_stop"/>
<field name="date"/>
<field name="cycle_id"/>
<field name="patient_id"/>
<field name="doctor_id"/>
<field name="department_id"/>
<field name="nurse_id"/>
<field name="state"/>

View File

@ -13,7 +13,7 @@
<item string="Levels" action="clinic_personal_level"/>
</item>
<item string="Patients">
<item string="Register" action="clinic_patient" action_options="mode=form"/>
<item string="New Patient" action="clinic_patient" action_options="mode=form"/>
<item string="Patients" action="clinic_patient"/>
<item string="Dialyzers" action="clinic_dialyzer"/>
<divider/>

View File

@ -40,6 +40,7 @@
<field name="level_id" domain="[['type','=',type]]"/>
<field name="prof_license_expiry" attrs='{"invisible":[["type","in",["personal"]]]}'/>
<field name="cycle_id"/>
<field name="base"/>
</tab>
<tab string="Note">
<field name="note" nolabel="1"/>

View File

@ -1,6 +1,7 @@
<form model="clinic.setting" title="Clinic Settings">
<tabs>
<tab string="Labor Cost">
<separator string="Nurse"/>
<field name="var_k"/>
<field name="levels" nolabel="1">
<list>
@ -18,9 +19,8 @@
<field name="formular"/>
</form>
</field>
<html span="5" offset="1">
<h5 style="color:#666">How labor cost affect</h5>
</html>
<separator string="Doctor"/>
<field name="cost_per_case"/>
</tab>
<tab string="Testing">
<group form_layout="stacked">

View File

@ -32,6 +32,7 @@ from . import cycle_item_nurse
from . import cycle_item_doctor
from . import cycle_item_line
from . import cycle_dialy
from . import cycle_dialy_line
from . import gen_visit
from . import gen_visit_line
from . import report_clinic

View File

@ -1,27 +1,90 @@
import time
from netforce.model import Model, fields
from netforce.access import get_active_company
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):
vals['name']=vals['date']
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()

View File

@ -0,0 +1,22 @@
from netforce.model import Model, fields
from netforce.access import get_active_company
class CycleDialyLine(Model):
_name="clinic.cycle.dialy.line"
_string="Cycle Dialy Line"
_fields={
"cycle_dialy_id": fields.Many2One("clinic.cycle.dialy","Cycle Dialy"),
'cycle_id': fields.Many2One("clinic.cycle", "Cycle"),
'personal_id': fields.Many2One("clinic.personal", "Personal"),
'paid_amount': fields.Float("Paid Amount"),
'company_id': fields.Many2One("company","Company"),
"type": fields.Selection([("doctor","Doctor"),('nurse','Nurse'),("personal","Personal")],"Type",required=True),
}
_defaults={
'company_id': lambda *a: get_active_company(),
}
CycleDialyLine.register()

View File

@ -1,7 +1,7 @@
import time
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
from netforce.access import get_active_company, get_active_user
from netforce.utils import get_data_path
class CycleItem(Model):
@ -53,12 +53,13 @@ class CycleItem(Model):
'var_k': fields.Float("K"),
'var_pt': fields.Integer("PT", function="_get_all",function_multi=True),
'var_ptx': fields.Char("PT x K:", function="_get_all",function_multi=True),
'var_fml1': fields.Char("FML1:",function="_get_all",function_multi=True),
'var_fml2': fields.Char("FML2:",function="_get_all",function_multi=True),
'var_fml3': fields.Char("FML3:",function="_get_all",function_multi=True),
'var_fml1': fields.Char("Step 1:",function="_get_all",function_multi=True),
'var_fml2': fields.Char("Step 2:",function="_get_all",function_multi=True),
'var_fml3': fields.Char("X:",function="_get_all",function_multi=True),
'var_x': fields.Char("X:",function="_get_all",function_multi=True),
'total': fields.Float("Total",function="_get_all",function_multi=True),
'manual': fields.Boolean("Manual"),
'user_id': fields.Many2One("base.user","User"),
}
def _get_vark(self,context={}):
@ -69,6 +70,7 @@ class CycleItem(Model):
'state': 'draft',
'company_id': lambda *a: get_active_company(),
'date': lambda *a: time.strftime("%Y-%m-%d"),
'user_id': lambda *a: get_active_user(),
'var_k': _get_vark,
}
@ -113,10 +115,76 @@ class CycleItem(Model):
def validate(self,ids,context={}):
obj=self.browse(ids)[0]
# copy list of nurse to cycle.dialy.line
levels={}
for line in obj.lines:
level=line.level_id
levels[level.id]=line.amount or 0
lines=[]
# cost's nurses
for nr in obj.nurses:
nurse=nr.nurse_id
level=nr.level_id
lines.append(('create',{
'cycle_id': obj.cycle_id.id,
'personal_id': nurse.id,
'paid_amount': levels[level.id] or 0.0,
'type': 'nurse',
}))
# cost's doctor
st=get_model('clinic.setting').browse(1)
cost_per_case=st.cost_per_case or 0
personal_total={}
for hd_case in obj.hd_cases:
personals=hd_case.personals
for ps in personals:
personal=ps.personal_id
base=personal.base
if not base:
base=cost_per_case
if not personal_total.get(personal.id):
personal_total[personal.id]={
'base': 0,
'type': ps.type,
}
personal_total[personal.id]['base']+=base
for doctor_id, value in personal_total.items():
base=value['base']
type=value['type']
lines.append(('create',{
'cycle_id': obj.cycle_id.id,
'personal_id': doctor_id,
'paid_amount': base,
'type': type,
}))
cycle_dialy=obj.cycle_dialy_id
# clear cost line
for line in cycle_dialy.lines:
cycle=line.cycle_id
if obj.cycle_id.id==cycle.id: # only own cycle
line.delete()
cycle_dialy.write({
'lines': lines,
})
obj.write({
'state': 'done',
})
return {
'next': {
'name': 'clinic_cycle_dialy',
'mode': 'form',
'active_id': cycle_dialy.id,
},
'flash': 'Cycle Item has been confirmed, please see detail of cost below.',
}
def to_draft(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({

View File

@ -19,10 +19,10 @@ class CycleItemLine(Model):
'qty': fields.Integer("Qty"),
'var_a': fields.Float("A"),
'var_b': fields.Float("B"),
'formular_org': fields.Char("Formular Original", size=100),
'formular': fields.Char("Formular", size=100),
'formular_org': fields.Char("FML1 (Setting)", size=100),
'formular': fields.Char("FML2", size=100),
'rate': fields.Float("Rate"),
'amount': fields.Float("Amount"),
'amount': fields.Float("Result",scale=2),
'company_id': fields.Many2One('company','Company'),
"state": fields.Selection([["fail","Fail"],["success","Success"]],"Status",),
}

View File

@ -32,7 +32,7 @@ class HDCase(Model):
"number": fields.Char("Number",required=True,search=True),
"time_start": fields.DateTime("Time Start",required=True,search=True),
"time_stop": fields.DateTime("Time Stop",required=True,search=True),
"date": fields.Date("Time stop",required=True,search=True),
"date": fields.Date("Date",required=True,search=True),
"patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True),
"nurse_id": fields.Many2One("clinic.personal","Approve By", domain=[['type','=','nurse']]),
"department_id": fields.Many2One("clinic.department", "Department",search=True),
@ -75,6 +75,7 @@ class HDCase(Model):
'dlz_id': fields.Many2One("clinic.dialyzer","Dialyzer"), # for link
"total_doctor": fields.Integer("Total Doctor",function="get_personal",function_multi=True),
"total_nurse": fields.Integer("Total Nurse",function="get_personal",function_multi=True),
'doctor_id': fields.Many2One("clinic.personal","Doctor",domain=[['type','=','doctor']],function="get_personal",function_multi=True),
}
def _get_number(self,context={}):
@ -685,14 +686,19 @@ class HDCase(Model):
for obj in self.browse(ids):
doctor=0
nurse=0
for personal in obj.personals:
if personal.type=="doctor":
doctor_id=None
for ps in obj.personals:
if ps.type=="doctor":
if ps.priop=='owner':
doctor_id=ps.personal_id.id
doctor+= 1
else:
nurse+=1
print('doctor ', doctor_id)
res[obj.id]={
'total_doctor': doctor,
'total_nurse': nurse,
'doctor_id': doctor_id,
}
return res

View File

@ -39,6 +39,15 @@ class Personal(Model):
res[obj.id]=cycle_id
return res
def _get_base(self,ids,context={}):
res={}
for obj in self.browse(ids):
base=0
for mv in obj.moves:
base=mv.wage
res[obj.id]=base
return res
_fields={
"number": fields.Char("Ref.",required=True,search=True),
"name": fields.Char("Name",required=True,search=True),
@ -74,7 +83,7 @@ class Personal(Model):
'level_id': fields.Many2One("clinic.personal.level", "Personal Level", function="_get_level"),
'active': fields.Boolean("Active"),
'date': fields.Date("Register Date"),
'base': fields.Float("Base Amount"),
'base': fields.Float("Base Amount", function="_get_base"),
'hire_date': fields.Date("Hire Date"),
'resign_date': fields.Date("Resign Date"),
"documents": fields.One2Many("document","related_id","Documents"),

View File

@ -6,7 +6,7 @@ import xmltodict
from netforce.model import Model, fields, get_model
from netforce.utils import get_file_path
from netforce.database import get_connection
from netforce.access import get_active_company
class ClinicSetting(Model):
_name="clinic.setting"
@ -15,8 +15,15 @@ class ClinicSetting(Model):
"var_k": fields.Float("K"),
'file': fields.File("File"),
'levels': fields.One2Many("clinic.setting.level","setting_id","Levels"),
'cost_per_case': fields.Float("Cost Per Case"),
'company_id': fields.Many2One("company", 'Company'),
}
_defaults={
"company_id": lambda *a: get_active_company(),
}
def read_excel(self,fpath=None):
data={}
if fpath:

View File

@ -14,7 +14,7 @@ class VisitDialy(Model):
_transient=True
_fields={
"date": fields.Date("Month", required=True),
"date": fields.Date("Date", required=True),
}
_defaults={