import data

conv_bal
watcha.h 2014-10-03 15:24:53 +07:00
parent c4fda2bb58
commit 484676dcbb
6 changed files with 92 additions and 24 deletions

View File

@ -5,7 +5,7 @@
<group span="6" columns="1">
<field name="number"/>
<field name="name"/>
<!--<field name="type" required="1"/>-->
<field name="type" required="1"/>
</group>
<group span="6" columns="1">
<field name="date_import"/>
@ -19,17 +19,35 @@
<field name="sheets" count="5" nolabel="1">
<list>
<field name="name"/>
<field name="process_type"/>
<field name="select" onchange="onchange_sheet"/>
<!--<field name="process_type"/>-->
</list>
</field>
</group>
<group span="6" columns="1">
<separator string="Options"/>
<button string="Load Sheet" type="primary" icon="download" method="load_sheet"/>
<newline/>
<button string="Process" type="success" icon="arrow-right" method="process"/>
<group span="3" columns="1">
<button string="Load Sheet" type="primary" icon="download" method="load_sheet"/>
<newline/>
<button string="Load DATA" type="warning" icon="download" method="load_data"/>
<newline/>
<button string="Find Invoice" type="success" icon="search" method="find_invoice"/>
</group>
<group span="3" columns="1">
<field name="description" width="300" height="250" nolabel="1"/>
</group>
</group>
</tab>
<tab string="Priview">
<field name="input_data" count="10" nolabel="1">
<list>
<field name="doc_date"/>
<field name="name"/>
<field name="hn"/>
<field name="amount"/>
</list>
</field>
</tab>
<tab string="Invoices">
<field name="lines" count="10" nolabel="1">
<list>
@ -38,7 +56,11 @@
</list>
</field>
</tab>
<tab string="History">
<separator string="TODO"/>
</tab>
</tabs>
<foot>
<button string="Import" type="success" icon="arrow-right" method="import2journal"/>
</foot>
</form>

View File

@ -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

View File

@ -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()

View File

@ -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"),
}

View File

@ -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()

View File

@ -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.sheets:
raise Exception("No Sheet yet!")
if not obj.file:
raise Exception("Please select some file!")
if not obj.sheets:
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()