diff --git a/netforce_clinic/actions/clinic_cycle_item.xml b/netforce_clinic/actions/clinic_cycle_item.xml
new file mode 100644
index 0000000..09c4581
--- /dev/null
+++ b/netforce_clinic/actions/clinic_cycle_item.xml
@@ -0,0 +1,7 @@
+
+ Cycle Items
+ multi_view
+ clinic.cycle.item
+ list,form
+ clinic_menu
+
diff --git a/netforce_clinic/actions/clinic_nurse_categ.xml b/netforce_clinic/actions/clinic_nurse_categ.xml
new file mode 100644
index 0000000..4528b4c
--- /dev/null
+++ b/netforce_clinic/actions/clinic_nurse_categ.xml
@@ -0,0 +1,7 @@
+
+ Nurse Categories
+ multi_view
+ clinic.nurse.categ
+ list,page,form
+ clinic_menu
+
diff --git a/netforce_clinic/layouts/clinic_cycle_form.xml b/netforce_clinic/layouts/clinic_cycle_form.xml
index f5ef225..bf3fb2e 100644
--- a/netforce_clinic/layouts/clinic_cycle_form.xml
+++ b/netforce_clinic/layouts/clinic_cycle_form.xml
@@ -6,10 +6,8 @@
-
-
-
+
diff --git a/netforce_clinic/layouts/clinic_cycle_item_form.xml b/netforce_clinic/layouts/clinic_cycle_item_form.xml
new file mode 100644
index 0000000..01aa6ed
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_cycle_item_form.xml
@@ -0,0 +1,34 @@
+
diff --git a/netforce_clinic/layouts/clinic_cycle_item_list.xml b/netforce_clinic/layouts/clinic_cycle_item_list.xml
new file mode 100644
index 0000000..f17931f
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_cycle_item_list.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml
index a7467fd..077aecf 100644
--- a/netforce_clinic/layouts/clinic_menu.xml
+++ b/netforce_clinic/layouts/clinic_menu.xml
@@ -3,6 +3,9 @@
-
+
+
+
-
@@ -16,7 +19,10 @@
-
+ -
+
+
+
-
@@ -26,7 +32,7 @@
-
+
-
diff --git a/netforce_clinic/layouts/clinic_nurse_categ_form.xml b/netforce_clinic/layouts/clinic_nurse_categ_form.xml
new file mode 100644
index 0000000..6fc66ea
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_nurse_categ_form.xml
@@ -0,0 +1,6 @@
+
diff --git a/netforce_clinic/layouts/clinic_nurse_categ_list.xml b/netforce_clinic/layouts/clinic_nurse_categ_list.xml
new file mode 100644
index 0000000..8435896
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_nurse_categ_list.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index fa6e9ab..4e1a480 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -1,2 +1,4 @@
diff --git a/netforce_clinic/models/:w b/netforce_clinic/models/:w
new file mode 100644
index 0000000..778177c
--- /dev/null
+++ b/netforce_clinic/models/:w
@@ -0,0 +1,53 @@
+import time
+
+from netforce.model import Model, fields, get_model
+from netforce.access import get_active_company
+
+class CycleItem(Model):
+ _name="clinic.cycle.item"
+ _string="Cycle Item"
+
+ def _get_x(self,ids,context):
+ res={}
+ for obj in self.browse(ids):
+ hd_total=len([hd_case for hd_case in obj.hd_cases if hd_case.state=='completed']) # XXX
+ pt=(hd_total or 0.0)
+ k=(obj.var_k or 0.0)
+ pt_k=pt*k
+ x=(pt_k + 1275)/13.5
+ res[obj.id]=x
+ return res
+
+ _fields={
+ 'company_id': fields.Many2One("company", "Company"),
+ 'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True),
+ 'date': fields.Date("Date",search=True),
+ 'var_k': fields.Float("K"),
+ 'var_x': fields.Float("X", function="_get_x"),
+ "state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True),
+ 'hd_cases': fields.One2Many("clinic.hd.case","cycle_item_id", "HD Cases"),
+ 'lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Lines'),
+ }
+
+ _defaults={
+ 'state': 'draft',
+ 'company_id': lambda *a: get_active_company(),
+ 'date': lambda *a: time.strftime("%Y-%m-%d"),
+ 'var_k': 450,
+ }
+
+ def compute(self,ids,context={}):
+ for obj in self.browse(ids):
+ nurer_categ_ids=[line.nurse_categ.id for line in obj.lines]
+ vals={
+ 'lines': [],
+ }
+ for nurse_categ in get_model("clinic.nurse.categ").search_browse([]):
+ vals['lines'].append(('create',{
+ 'nurse_categ': nurse_categ.id,
+ 'formular': nurse_categ.formular or "",
+ 'qty': 1,
+ }))
+ pass
+ obj.write(vals)
+CycleItem.register()
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 71a28cf..3ba6e67 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -7,6 +7,7 @@ from . import graduation
from . import morbidity
from . import nation
from . import nurse
+from . import nurse_categ
from . import address
from . import patient
from . import patient_cause_line
@@ -27,6 +28,8 @@ from . import dialyzer_line
from . import import_payment
from . import file_sheet
from . import cycle
+from . import cycle_item
+from . import cycle_item_line
from . import gen_visit
from . import gen_visit_line
from . import report_hd_detail
diff --git a/netforce_clinic/models/cycle.py b/netforce_clinic/models/cycle.py
index 30cf40d..329f532 100644
--- a/netforce_clinic/models/cycle.py
+++ b/netforce_clinic/models/cycle.py
@@ -12,9 +12,8 @@ class Cycle(Model):
'company_id': fields.Many2One("company", "Company"),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_id", "HD Cases"),
'visits': fields.One2Many("clinic.visit","cycle_id", "Visits"),
+ 'cycle_items': fields.One2Many("clinic.cycle.item","cycle_id", "Cycle Items"),
'var_k': fields.Float("K"),
- 'var_x': fields.Float("X"),
-
}
_defaults={
diff --git a/netforce_clinic/models/cycle_item.py b/netforce_clinic/models/cycle_item.py
new file mode 100644
index 0000000..000e716
--- /dev/null
+++ b/netforce_clinic/models/cycle_item.py
@@ -0,0 +1,96 @@
+import time
+
+from netforce.model import Model, fields, get_model
+from netforce.access import get_active_company
+
+class CycleItem(Model):
+ _name="clinic.cycle.item"
+ _string="Cycle Item"
+
+ def _get_all(self,ids,context):
+ res={}
+ for obj in self.browse(ids):
+ hd_total=len([hd_case for hd_case in obj.hd_cases if hd_case.state=='completed']) # XXX
+ pt=(hd_total or 0.0)
+ k=(obj.var_k or 0.0)
+ pt_k=pt*k
+ x=(pt_k + 1275)/13.5
+ total=0.0
+ for line in obj.lines:
+ total+=line.amount
+ res[obj.id]={
+ 'var_x': x,
+ 'total_pt': hd_total,
+ 'total_amount': hd_total*k,
+ 'total': total,
+ }
+ return res
+
+ _fields={
+ 'company_id': fields.Many2One("company", "Company"),
+ 'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True),
+ 'date': fields.Date("Date",search=True),
+ 'var_k': fields.Float("K"),
+ 'var_x': fields.Float("X", function="_get_all",function_multi=True),
+ 'total_pt': fields.Float("PT", function="_get_all",function_multi=True),
+ 'total_amount': fields.Float("PT*K", function="_get_all",function_multi=True),
+ 'total': fields.Float("Total", function="_get_all",function_multi=True),
+ "state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True),
+ 'hd_cases': fields.One2Many("clinic.hd.case","cycle_item_id", "HD Cases"),
+ 'lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Lines'),
+ }
+
+ _defaults={
+ 'state': 'draft',
+ 'company_id': lambda *a: get_active_company(),
+ 'date': lambda *a: time.strftime("%Y-%m-%d"),
+ 'var_k': 450,
+ }
+
+ def compute(self,ids,context={}):
+ for obj in self.browse(ids):
+ #nurer_categ_ids=[line.nurse_categ.id for line in obj.lines]
+ # XXX
+ vals_dict={}
+ for hd_case in obj.hd_cases:
+ if hd_case.state=='completed':
+ nurse_code=hd_case.nurse_id.categ_id.code or ""
+ print("nurse_code ", nurse_code)
+ if not vals_dict.get(nurse_code):
+ vals_dict[nurse_code]=0
+ vals_dict[nurse_code]+=1
+
+ for line in obj.lines:
+ line.delete()
+
+ vals={
+ 'lines': [],
+ }
+ print(vals_dict)
+ for nurse_categ in get_model("clinic.nurse.categ").search_browse([]):
+ formular=nurse_categ.formular or ""
+ rate=0
+ try:
+ var_x="%s"%(round(obj.var_x,2))
+ formulared=formular.replace("x",var_x)
+ rate=eval(formulared)
+ except:
+ rate=0
+ vals['lines'].append(('create',{
+ 'nurse_categ': nurse_categ.id,
+ 'formular': formular,
+ 'qty': vals_dict.get(nurse_categ.code,0),
+ 'rate': rate,
+ }))
+ obj.write(vals)
+
+ return {
+ 'next': {
+ 'name': 'clinic_cycle_item',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },
+ 'flash': 'Compute OK',
+ }
+
+CycleItem.register()
diff --git a/netforce_clinic/models/cycle_item_line.py b/netforce_clinic/models/cycle_item_line.py
new file mode 100644
index 0000000..3069675
--- /dev/null
+++ b/netforce_clinic/models/cycle_item_line.py
@@ -0,0 +1,31 @@
+from netforce.model import Model, fields, get_model
+from netforce.access import get_active_company
+
+class CycleItemLine(Model):
+ _name="clinic.cycle.item.line"
+ _string="Cycle Item Line"
+
+ def all_amount(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ res[obj.id]={
+ 'amount': (obj.qty or 0) * (obj.rate or 0.0),
+ }
+ return res
+
+ _fields={
+ 'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
+ 'nurse_categ': fields.Many2One("clinic.nurse.categ", "Nurse Category"),
+ 'formular': fields.Char("Formular", size=100),
+ 'qty': fields.Integer("Qty"),
+ 'rate': fields.Float("Rate"),
+ 'amount': fields.Float("Amount",function="all_amount", function_multi=True),
+ 'company_id': fields.Many2One('company','Company'),
+ }
+
+ _defaults={
+ "company_id": lambda *a: get_active_company(),
+ }
+
+
+CycleItemLine.register()
diff --git a/netforce_clinic/models/gen_visit.py b/netforce_clinic/models/gen_visit.py
index 6437192..c8d2211 100644
--- a/netforce_clinic/models/gen_visit.py
+++ b/netforce_clinic/models/gen_visit.py
@@ -133,6 +133,7 @@ class GenVisit(Model):
dom.append(['time_start','>=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 23:59:59')])
dom.append(['patient_id', '=', line.patient_id.id])
+ dom.append(['cycle_id', '=', obj.cycle_id.id]) #XXX
dom.append(['state','=','draft'])
vids=visit_obj.search(dom)
visit_obj.delete(vids)
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 859394f..81994d7 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -68,6 +68,7 @@ class HDCase(Model):
'fee_paid': fields.Boolean("Fee Paid"),
'note': fields.Text("Note"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
+ "cycle_item_id": fields.Many2One("clinic.cycle.item","Cycle Item"), # compute labor cost
'pay_amount': fields.Float("Amount",function="get_pay_amount"),
'pay_date': fields.Date("Pay Date"),
'pay_account_id': fields.Many2One("account.account","Account"),
@@ -462,11 +463,30 @@ class HDCase(Model):
})
return True
+ def create_cycle_item(self,ids,context={}):
+ for obj in self.browse(ids):
+ cycle_item=get_model("clinic.cycle.item")
+ datenow=time.strftime('%Y-%m-%d')
+ cycle_id=obj.cycle_id.id
+ cycle_item_ids=cycle_item.search([['date','=',datenow],['cycle_id','=',cycle_id]])
+ cycle_item_id=None
+ if cycle_item_ids:
+ cycle_item_id=cycle_item_ids[0]
+ else:
+ cycle_item_id=cycle_item.create({
+ 'cycle_id': obj.cycle_id.id,
+ })
+ obj.write({
+ 'cycle_item_id': cycle_item_id,
+ })
+ return True
+
def complete(self,ids,context={}):
obj=self.browse(ids)[0]
obj.make_invoices()
obj.post_invoices()
obj.update_usetime()
+ obj.create_cycle_item()
obj.write({
"state":"completed",
})
@@ -551,6 +571,7 @@ class HDCase(Model):
payment.delete()
for pm_line in obj.payment_lines:
pm_line.delete()
+
state=context.get("state","in_progress") #force state
obj.write({
'state': state,
diff --git a/netforce_clinic/models/hd_case_payment.py b/netforce_clinic/models/hd_case_payment.py
index f24855a..bf96ae1 100644
--- a/netforce_clinic/models/hd_case_payment.py
+++ b/netforce_clinic/models/hd_case_payment.py
@@ -51,6 +51,7 @@ class HDCasePayment(Model):
if obj.pay_amount:
hd_case.make_payment(context=context)
if obj.complete:
+ hd_case.create_cycle_item()
hd_case.write({
'state': 'completed',
})
@@ -71,6 +72,7 @@ class HDCasePayment(Model):
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
hd_case.make_invoices()
hd_case.post_invoices()
+ hd_case.create_cycle_item()
#if obj.complete:
hd_case.write({
'state': 'completed',
diff --git a/netforce_clinic/models/nurse.py b/netforce_clinic/models/nurse.py
index 0f3af7e..11f421e 100644
--- a/netforce_clinic/models/nurse.py
+++ b/netforce_clinic/models/nurse.py
@@ -44,7 +44,7 @@ class Nurse(Model):
"user_id": fields.Many2One("base.user","User"),
'picture': fields.File("Picture"),
'note': fields.Text("Note"),
- 'categ_id': fields.Many2One("product.categ","Category"),
+ 'categ_id': fields.Many2One("clinic.nurse.categ","Category"),
}
def _get_number(self,context={}):
diff --git a/netforce_clinic/models/nurse_categ.py b/netforce_clinic/models/nurse_categ.py
new file mode 100644
index 0000000..dd60d3e
--- /dev/null
+++ b/netforce_clinic/models/nurse_categ.py
@@ -0,0 +1,22 @@
+from netforce.model import Model, fields
+from netforce.access import get_active_company
+
+class NurseCateg(Model):
+ _name="clinic.nurse.categ"
+ _string="Nurse Categ"
+
+ _fields={
+ "name": fields.Char("Name",required=True,search=True),
+ "code": fields.Char("Code",required=True,search=True),
+ 'formular': fields.Text("Formular"),
+ 'sequence': fields.Integer("Sequence"),
+ }
+
+ _defaults={
+ "company_id": lambda *a: get_active_company(),
+ 'sequence': 0,
+ }
+
+ _order="sequence"
+
+NurseCateg.register()
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 4dd86c3..8e55df9 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -1,25 +1,10 @@
from netforce.model import Model, fields, get_model
-from netforce.utils import get_data_path
-import time
-from netforce.access import get_active_user
-from netforce.access import get_active_company
class ClinicSetting(Model):
_name="clinic.setting"
_string="Setting"
_fields={
- "mg_partner_id": fields.Many2One("partner","Partner Medical Govement"),
- "ar_mg_id": fields.Many2One("account.account","Account Receivable Medical Govement"),
- "ap_mg_id": fields.Many2One("account.account","Account Payment Medical Govement"),
- "nhso_partner_id": fields.Many2One("partner","Partner NHSO 30B"),
- "ar_nhso_id": fields.Many2One("account.account","Account Receiveble NHSO 30B"),
- "ap_nhso_id": fields.Many2One("account.account","Account Payment NHSO 30B"),
- "sc_partner_id": fields.Many2One("partner","Partner Social Security"),
- "ar_sc_id": fields.Many2One("account.account","Account Receiveble Social Security"),
- "ap_sc_id": fields.Many2One("account.account","Account Payment Social Security"),
- #"ori_str": fields.Char("ori_str","Original String"),
- #"translate": fields.Char("translate","Translation"),
-
+ "var_k": fields.Float("K"),
}
ClinicSetting.register()