diff --git a/netforce_clinic/layouts/clinic_je_form.xml b/netforce_clinic/layouts/clinic_je_form.xml
index 2dafca6..8d25b1e 100644
--- a/netforce_clinic/layouts/clinic_je_form.xml
+++ b/netforce_clinic/layouts/clinic_je_form.xml
@@ -5,7 +5,7 @@
-
+
@@ -19,17 +19,35 @@
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -38,7 +56,11 @@
+
+
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 871bf4f..6ab7b29 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -19,6 +19,6 @@ from . import nation
from . import race
from . import cause_chronic
from . import je
+from . import input_data
from . import input_line
from . import file_sheet
-from . import file_column
diff --git a/netforce_clinic/models/file_column.py b/netforce_clinic/models/file_column.py
deleted file mode 100644
index aa944a4..0000000
--- a/netforce_clinic/models/file_column.py
+++ /dev/null
@@ -1,13 +0,0 @@
-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
index 2ea9b1e..cdf814c 100644
--- a/netforce_clinic/models/file_sheet.py
+++ b/netforce_clinic/models/file_sheet.py
@@ -7,8 +7,7 @@ class FileSheet(Model):
_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"),
+ "select": fields.Selection([("yes","Yes"),("no","No")],"Select"),
'je_id': fields.Many2One("clinic.je","Journal Entry"),
}
diff --git a/netforce_clinic/models/input_data.py b/netforce_clinic/models/input_data.py
new file mode 100644
index 0000000..fa3a061
--- /dev/null
+++ b/netforce_clinic/models/input_data.py
@@ -0,0 +1,14 @@
+from netforce.model import Model, fields
+
+class InputData(Model):
+ _name="clinic.input.data"
+ _string="Input Data"
+ _fields={
+ 'doc_date': fields.Char("Doc Date"),
+ 'name': fields.Char("Name"),
+ 'hn': fields.Char("HN"),
+ 'amount': fields.Float("Amount"),
+ 'je_id': fields.Many2One("clinic.je","Journal Entry"),
+ }
+
+InputData.register()
diff --git a/netforce_clinic/models/je.py b/netforce_clinic/models/je.py
index eda4bd8..1ed389a 100644
--- a/netforce_clinic/models/je.py
+++ b/netforce_clinic/models/je.py
@@ -4,6 +4,7 @@ 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
+from netforce.utils import get_data_path
class JE(Model):
_name="clinic.je"
@@ -13,13 +14,15 @@ class JE(Model):
"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"),
+ "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"),
+ 'input_data': fields.One2Many("clinic.input.data","je_id", "Input Data"),
'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),
+ 'description': fields.Text("Description")
}
def _get_number(self,context={}):
@@ -85,10 +88,53 @@ class JE(Model):
'flash': "Load sheet successfully",
}
- def process(self,ids,context={}):
+ def load_data(self,ids,context={}):
obj=self.browse(ids[0])
+ if not obj.file:
+ raise Exception("Please select some file!")
+
if not obj.sheets:
- raise Exception("No Sheet yet!")
+ raise Exception("Please load sheet!")
+ indexes=[]
+ for sheet in obj.sheets:
+ if sheet.select=='yes':
+ indexes.append((sheet.index,sheet.name))
+ if not indexes:
+ raise Exception("Please select some sheet!")
+ if len(indexes) > 1:
+ raise Exception("Only one sheet can select!")
+ sheet_name=indexes[0][1]
+ fname=obj.file
+ fpath=get_file_path(fname)
+ wb=xlrd.open_workbook(fpath)
+ ws=wb.sheet_by_name(sheet_name)
+ num_rows = ws.nrows - 1
+ curr_row = -1
+ records=[]
+ import pprint
+ while curr_row < num_rows:
+ curr_row += 1
+ #row=ws.row(curr_row)
+ record={}
+ # XXX
+ for col in (1,2,3,4):
+ record[col]=ws.cell_value(curr_row, col)
+ records.append(record)
+ pprint.pprint(records)
+ def find_invoice(self,ids,context={}):
+ pass
+
+ def import2journal(self,ids,context={}):
+ pass
+
+ def onchange_sheet(self,context={}):
+ data=context["data"]
+ path=context["path"]
+ line=get_data_path(data,path,parent=True)
+ for sheet in data['sheets']:
+ if sheet['name']!=line['name']:
+ sheet['select']=None
+ return data
JE.register()