clinic/netforce_clinic/models/import_payment.py

65 lines
1.8 KiB
Python

import time
import xlrd
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
from netforce.utils import get_file_path
from netforce.utils import get_data_path
from netforce.database import get_connection
class ImportPayment(Model):
_name="clinic.import.payment"
_transient=True
_fields={
'date': fields.DateTime("Date"),
'file': fields.File("File"),
}
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
}
def read_excel(self,fpath=None):
data={}
if fpath:
suffix=fpath.split(".")[-1]
if suffix not in ('xls', 'xlsx'):
raise Exception("ERROR : please should file xls or xlsx")
wb=xlrd.open_workbook(fpath)
worksheet=wb.sheet_by_name("Sheet1")
num_rows=worksheet.nrows-1
curr_row=-1
while curr_row < num_rows:
curr_row +=1
worksheet.cell_value(curr_row,2)
return data
def read_xml(self,fpath=None):
data={}
if fpath:
suffix=fpath.split(".")[-1]
if suffix not in ('xml'):
raise Exception("ERROR : please should file xml")
return data
def import_mg(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
print("fpath ", fpath)
def import_nhso(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
print("fpath ", fpath)
def import_sc(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
print("fpath ", fpath)
ImportPayment.register()