diff --git a/netforce_clinic/actions/clinic_cycle_dialy.xml b/netforce_clinic/actions/clinic_cycle_dialy.xml
index 2271659..dba30fd 100644
--- a/netforce_clinic/actions/clinic_cycle_dialy.xml
+++ b/netforce_clinic/actions/clinic_cycle_dialy.xml
@@ -2,6 +2,7 @@
Cycle Dialy
multi_view
clinic.cycle.dialy
+ [["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]],["Done",[["state","=","done"]]]]
list,form
clinic_menu
diff --git a/netforce_clinic/layouts/clinic_cycle_dialy_form.xml b/netforce_clinic/layouts/clinic_cycle_dialy_form.xml
index 5215aee..4355c93 100644
--- a/netforce_clinic/layouts/clinic_cycle_dialy_form.xml
+++ b/netforce_clinic/layouts/clinic_cycle_dialy_form.xml
@@ -1,9 +1,38 @@
diff --git a/netforce_clinic/layouts/clinic_hd_case_list.xml b/netforce_clinic/layouts/clinic_hd_case_list.xml
index 5c38410..5195f48 100644
--- a/netforce_clinic/layouts/clinic_hd_case_list.xml
+++ b/netforce_clinic/layouts/clinic_hd_case_list.xml
@@ -1,9 +1,9 @@
-
-
+
+
diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml
index 82f1f88..f79e8ba 100644
--- a/netforce_clinic/layouts/clinic_menu.xml
+++ b/netforce_clinic/layouts/clinic_menu.xml
@@ -13,7 +13,7 @@
-
-
+
diff --git a/netforce_clinic/layouts/clinic_personal_form.xml b/netforce_clinic/layouts/clinic_personal_form.xml
index e0ac19d..11c7cb0 100644
--- a/netforce_clinic/layouts/clinic_personal_form.xml
+++ b/netforce_clinic/layouts/clinic_personal_form.xml
@@ -40,6 +40,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index 48ee378..638c1a0 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -1,6 +1,7 @@
-
- How labor cost affect
-
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 8cf5ac9..406b09e 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -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
diff --git a/netforce_clinic/models/cycle_dialy.py b/netforce_clinic/models/cycle_dialy.py
index 445752d..9e21a4b 100644
--- a/netforce_clinic/models/cycle_dialy.py
+++ b/netforce_clinic/models/cycle_dialy.py
@@ -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()
diff --git a/netforce_clinic/models/cycle_dialy_line.py b/netforce_clinic/models/cycle_dialy_line.py
new file mode 100644
index 0000000..26ed390
--- /dev/null
+++ b/netforce_clinic/models/cycle_dialy_line.py
@@ -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()
diff --git a/netforce_clinic/models/cycle_item.py b/netforce_clinic/models/cycle_item.py
index 5e5c6ea..cd5c94c 100644
--- a/netforce_clinic/models/cycle_item.py
+++ b/netforce_clinic/models/cycle_item.py
@@ -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({
diff --git a/netforce_clinic/models/cycle_item_line.py b/netforce_clinic/models/cycle_item_line.py
index fb407e5..8452ec3 100644
--- a/netforce_clinic/models/cycle_item_line.py
+++ b/netforce_clinic/models/cycle_item_line.py
@@ -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",),
}
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 999f7ac..4430310 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -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
diff --git a/netforce_clinic/models/personal.py b/netforce_clinic/models/personal.py
index cf9ac75..0ff227c 100644
--- a/netforce_clinic/models/personal.py
+++ b/netforce_clinic/models/personal.py
@@ -38,6 +38,15 @@ class Personal(Model):
cycle_id=cycle.id
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),
@@ -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"),
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index c3edafb..1d3301a 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -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:
diff --git a/netforce_clinic/models/visit_dialy.py b/netforce_clinic/models/visit_dialy.py
index 1007607..19be82b 100644
--- a/netforce_clinic/models/visit_dialy.py
+++ b/netforce_clinic/models/visit_dialy.py
@@ -14,7 +14,7 @@ class VisitDialy(Model):
_transient=True
_fields={
- "date": fields.Date("Month", required=True),
+ "date": fields.Date("Date", required=True),
}
_defaults={