diff --git a/netforce_clinic/actions/clinic_je.xml b/netforce_clinic/actions/clinic_je.xml
new file mode 100644
index 0000000..e590f86
--- /dev/null
+++ b/netforce_clinic/actions/clinic_je.xml
@@ -0,0 +1,6 @@
+
+ Import Journal Entry
+ multi_view
+ clinic.je
+ clinic_menu
+
diff --git a/netforce_clinic/layouts/clinic_je_form.xml b/netforce_clinic/layouts/clinic_je_form.xml
new file mode 100644
index 0000000..2dafca6
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_je_form.xml
@@ -0,0 +1,44 @@
+
diff --git a/netforce_clinic/layouts/clinic_je_list.xml b/netforce_clinic/layouts/clinic_je_list.xml
new file mode 100644
index 0000000..2fa354c
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_je_list.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml
index ea97292..25bdf10 100644
--- a/netforce_clinic/layouts/clinic_menu.xml
+++ b/netforce_clinic/layouts/clinic_menu.xml
@@ -11,8 +11,8 @@
-
- -
-
+ -
+
-
diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index b5dadb4..f043fe4 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -9,10 +9,11 @@
+
-
+
diff --git a/netforce_clinic/layouts/clinic_patient_list.xml b/netforce_clinic/layouts/clinic_patient_list.xml
index 752b2b2..b723099 100644
--- a/netforce_clinic/layouts/clinic_patient_list.xml
+++ b/netforce_clinic/layouts/clinic_patient_list.xml
@@ -1,5 +1,6 @@
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 07648b8..871bf4f 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -18,3 +18,7 @@ from . import graduation
from . import nation
from . import race
from . import cause_chronic
+from . import je
+from . import input_line
+from . import file_sheet
+from . import file_column
diff --git a/netforce_clinic/models/dialyzer.py b/netforce_clinic/models/dialyzer.py
index 669ef2a..14d35ca 100644
--- a/netforce_clinic/models/dialyzer.py
+++ b/netforce_clinic/models/dialyzer.py
@@ -160,6 +160,10 @@ class Dialyzer(Model):
def renew(self,ids,context={}):
obj=self.browse(ids[0])
+ # XXX
+ if obj.use_time > obj.max_use_time:
+ raise Exception("No long to use it (use time > max use time")
+ obj.cancel()
obj.write({"state": "new"})
def drop(self,ids,context={}):
diff --git a/netforce_clinic/models/file_column.py b/netforce_clinic/models/file_column.py
new file mode 100644
index 0000000..aa944a4
--- /dev/null
+++ b/netforce_clinic/models/file_column.py
@@ -0,0 +1,13 @@
+from netforce.model import Model, fields
+
+class FileColumn(Model):
+ _name="clinic.file.column"
+ _string="File Column"
+
+ _fields={
+ 'name': fields.Char("Name"),
+ 'index': fields.Integer("Index"),
+ 'je_id': fields.Many2One("clinic.je","Journal Entry"),
+ }
+
+FileColumn.register()
diff --git a/netforce_clinic/models/file_sheet.py b/netforce_clinic/models/file_sheet.py
new file mode 100644
index 0000000..2ea9b1e
--- /dev/null
+++ b/netforce_clinic/models/file_sheet.py
@@ -0,0 +1,15 @@
+from netforce.model import Model, fields
+
+class FileSheet(Model):
+ _name="clinic.file.sheet"
+ _string="File Sheet"
+
+ _fields={
+ 'name': fields.Char("Name"),
+ 'index': fields.Integer("Index"),
+ #"select": fields.Selection([("yes","Yes"),("no","No")],"Select",required=True),
+ "process_type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)")],"Import Type"),
+ 'je_id': fields.Many2One("clinic.je","Journal Entry"),
+ }
+
+FileSheet.register()
diff --git a/netforce_clinic/models/input_line.py b/netforce_clinic/models/input_line.py
new file mode 100644
index 0000000..a8fe254
--- /dev/null
+++ b/netforce_clinic/models/input_line.py
@@ -0,0 +1,14 @@
+import time
+from netforce.model import Model, fields
+
+class InputLine(Model):
+ _name="clinic.input.line"
+ _string="Input Line"
+
+ _fields={
+ 'je_id': fields.Many2One("clinic.je","Journal Entry"),
+ 'invoice_id': fields.Many2One("account.invoice","Invoice"),
+ 'amount': fields.Float("Amount"),
+ }
+
+InputLine.register()
diff --git a/netforce_clinic/models/je.py b/netforce_clinic/models/je.py
new file mode 100644
index 0000000..eda4bd8
--- /dev/null
+++ b/netforce_clinic/models/je.py
@@ -0,0 +1,94 @@
+import time
+import xlrd
+
+from netforce.model import Model, fields, get_model
+from netforce.access import get_active_user, set_active_user
+from netforce.utils import get_file_path
+
+class JE(Model):
+ _name="clinic.je"
+ _string="Import Journal Entry"
+
+ _fields={
+ "number": fields.Char("Number"),
+ "name": fields.Char("Description"),
+ "date_import": fields.DateTime("Date Import"),
+ #"type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)")],"Type"),
+ 'file': fields.File("File"),
+ 'payment_id': fields.Many2One("account.payment","Payment"),
+ 'lines': fields.One2Many("clinic.input.line","je_id", "Input Line"),
+ 'sheets': fields.One2Many("clinic.file.sheet","je_id", "Sheets"),
+ 'columns': fields.One2Many("clinic.file.column","je_id", "Columns"),
+ "state": fields.Selection([("draft","Draft"),('sheet_loaded','Sheet Loaded'),("fail","Fail"),("done","Done")],"Status",required=True),
+ }
+
+ def _get_number(self,context={}):
+ while 1:
+ seq_id=get_model("sequence").find_sequence(name="Clinic Import JE")
+ num=get_model("sequence").get_next_number(seq_id,context=context)
+ if not num:
+ return None
+ user_id=get_active_user()
+ set_active_user(1)
+ res=self.search([["number","=",num]])
+ set_active_user(user_id)
+ if not res:
+ return num
+ get_model("sequence").increment_number(seq_id,context=context)
+
+ def _get_name(self,context={}):
+ timenow=time.strftime("%Y-%m-%d")
+ return 'Import Journal Entry - %s'%timenow
+
+ _defaults={
+ 'date_import': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
+ 'number': _get_number,
+ 'name': _get_name,
+ 'state': 'draft',
+ }
+
+ def load_sheet(self,ids,context={}):
+ obj=self.browse(ids[0])
+ fname=obj.file
+ if not fname:
+ raise Exception("Please select file!")
+ fpath=get_file_path(fname)
+ suffix=fpath.split(".")[-1]
+ if suffix not in ('xls', 'xlsx'):
+ raise Exception("ERROR : file support only xls, xlsx")
+
+ wb=xlrd.open_workbook(fpath)
+ sheets=wb.sheet_names()
+ index=0
+ # XXX clear old sheet
+ for sheet in obj.sheets:
+ sheet.delete()
+
+ vals={
+ 'sheets': [],
+ }
+
+ for sheet in sheets:
+ line={
+ 'index': index,
+ 'name': sheet,
+ }
+ vals["sheets"].append(("create",line))
+ vals['state']='sheet_loaded'
+ obj.write(vals)
+ return {
+ 'next': {
+ 'name': "clinic_je",
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },
+ 'flash': "Load sheet successfully",
+ }
+
+ def process(self,ids,context={}):
+ obj=self.browse(ids[0])
+ if not obj.sheets:
+ raise Exception("No Sheet yet!")
+
+
+JE.register()
diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py
index ac40bf7..38ba8e2 100644
--- a/netforce_clinic/models/patient.py
+++ b/netforce_clinic/models/patient.py
@@ -31,6 +31,7 @@ class Patient(Model):
_fields={
"type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("others","Others")],"Patient Type",required=True),
"number": fields.Char("Patient No.",required=True,search=True),
+ "hn": fields.Char("HN",search=True),
"name": fields.Char("Name",required=True,search=True),
"reg_date": fields.Date("Register Date",required=False,search=True),
"birthday": fields.Date("Birthday",required=False,search=True),
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index f3a54c6..50de21f 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -147,7 +147,7 @@ class Visit(Model):
data['doctor_id']=visit.doctor_id.id
data['department_id']=visit.department_id.id
else:
- data['patient_id']=None
+ data['doctor_id']=None
data['department_id']=None
return data