import data
parent
b0e869067c
commit
e51f94fd0b
|
@ -1,6 +1,6 @@
|
|||
<action>
|
||||
<field name="name">clinic_board</field>
|
||||
<field name="string">Clinic Board</field>
|
||||
<field name="string">Visit Board</field>
|
||||
<field name="view_cls">board</field>
|
||||
<field name="view_xml">clinic_board</field>
|
||||
<field name="menu">clinic_menu</field>
|
||||
|
|
|
@ -1,32 +1,56 @@
|
|||
<form model="clinic.import.payment" attrs='{"readonly":[["state","in",["success"]]]}'>
|
||||
<form model="clinic.import.payment" attrs='{"readonly":[["state","in",["close"]]]}'>
|
||||
<head>
|
||||
<field name="state"/>
|
||||
</head>
|
||||
<field name="name"/>
|
||||
<field name="date_import"/>
|
||||
<separator string="Medical Government"/>
|
||||
<field name="mg_file"/>
|
||||
<group span="6">
|
||||
<field name="mg_payment_id" readonly="1"/>
|
||||
<button string="Post" type="success" method="post_mg"/>
|
||||
<button string="Undo" type="danger" method="undo_mg" attrs='{"invisible":[["state","in",["success"]]]}'/>
|
||||
<field name="type" required="1"/>
|
||||
<separator string="Select File -> Load Sheet -> Select Sheet(only one) -> Click Import"/>
|
||||
<group span="8" columns="1">
|
||||
<group span="12">
|
||||
<field name="file" nolabel="1" onchange="onchange_file"/>
|
||||
<button string="Load Sheet" size="small" type="warning" icon="download" method="load_sheet"/>
|
||||
<button string="Clear Sheet" size="small" type="danger" icon="remove" method="clear_sheet"/>
|
||||
</group>
|
||||
<field name="sheets" count="3" nolabel="1">
|
||||
<list>
|
||||
<field name="name"/>
|
||||
<field name="select" onchange="onchange_sheet"/>
|
||||
</list>
|
||||
</field>
|
||||
<group span="6">
|
||||
</group>
|
||||
<group span="6">
|
||||
<button span="3" string="Import" type="success" icon="arrow-right" method="import_payment" attrs='{"invisible":[["state","in",["success"]]]}'/>
|
||||
<button span="3" string="Close" type="danger" method="close_import" attrs='{"invisible":[["state","in",["success"]]]}'/>
|
||||
</group>
|
||||
</group>
|
||||
<separator string="Social Security"/>
|
||||
<field name="sc_file"/>
|
||||
<group span="6">
|
||||
<field name="sc_payment_id" readonly="1"/>
|
||||
<button string="Post" type="success" method="post_sc"/>
|
||||
<button string="Undo" type="danger" method="undo_sc" attrs='{"invisible":[["state","in",["success"]]]}'/>
|
||||
</group>
|
||||
<separator string="NHSO (30฿)"/>
|
||||
<field name="nhso_file"/>
|
||||
<group span="6">
|
||||
<field name="nhso_payment_id" readonly="1"/>
|
||||
<button string="Post" type="success" method="post_nhso"/>
|
||||
<button string="Undo" type="danger" method="undo_nhso" attrs='{"invisible":[["state","in",["success"]]]}'/>
|
||||
<group span="4" columns="1">
|
||||
<group attrs='{"invisible":[["type","!=","mg"]]}'>
|
||||
<separator string="Medical Government"/>
|
||||
<field name="mg_payment_id" readonly="1"/>
|
||||
<field name="mg_move_id" readonly="1"/>
|
||||
<button string="POST" size="small" type="success" method="post_mg"/>
|
||||
<button string="UNDO" size="small" type="danger" method="undo_mg"/>
|
||||
</group>
|
||||
|
||||
<group attrs='{"invisible":[["type","!=","sc"]]}'>
|
||||
<separator string="Social Security"/>
|
||||
<field name="sc_payment_id" readonly="1"/>
|
||||
<field name="sc_move_id" readonly="1"/>
|
||||
<button string="POST" size="small" type="success" method="post_sc"/>
|
||||
<button string="UNDO" size="small" type="danger" method="undo_sc"/>
|
||||
</group>
|
||||
|
||||
<group attrs='{"invisible":[["type","!=","nhso"]]}'>
|
||||
<separator string="NHSO (30฿)"/>
|
||||
<field name="nhso_payment_id" readonly="1"/>
|
||||
<field name="nhso_move_id" readonly="1"/>
|
||||
<button string="POST" size="small" type="success" method="post_nhso"/>
|
||||
<button string="UNDO" size="small" type="danger" method="undo_nhso"/>
|
||||
</group>
|
||||
|
||||
</group>
|
||||
<foot>
|
||||
<button string="Import" type="success" icon="arrow-right" method="import_payment" attrs='{"invisible":[["state","in",["success"]]]}'/>
|
||||
<button string="Close" type="danger" method="close_import" attrs='{"invisible":[["state","in",["success"]]]}'/>
|
||||
</foot>
|
||||
</form>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!--<calendar model="clinic.visit" states='waiting_treatment' date_field="date_visit" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"#ebff00":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>-->
|
||||
<calendar model="clinic.visit" states='waiting_treatment' start_field="time_start" end_field="time_stop" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"#ebff00":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>
|
||||
<calendar model="clinic.visit" states='waiting_treatment' start_field="time_start" end_field="time_stop" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"orange":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>
|
||||
<field name="patient_id"/>
|
||||
<field name="cycle"/>
|
||||
<field name="number"/>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<button string="Print" icon="print" action="print_visit"/>
|
||||
<button string="Options" dropdown="1">
|
||||
<item string="Copy" method="copy"/>
|
||||
<item string="Create Dialyzer" method="create_dialyzer"/>
|
||||
</button>
|
||||
</head>
|
||||
<tabs>
|
||||
|
|
|
@ -0,0 +1,317 @@
|
|||
import re
|
||||
import time
|
||||
import xlrd
|
||||
from datetime import datetime
|
||||
|
||||
from netforce.model import Model, fields, get_model
|
||||
from netforce.access import get_active_company
|
||||
from netforce.access import get_active_user, set_active_user
|
||||
from netforce.utils import get_file_path
|
||||
from netforce.utils import get_data_path
|
||||
|
||||
PAMENT_TYPE={
|
||||
"mg":"Medical Government",
|
||||
"sc":"Social Security",
|
||||
"nhso":"NHSO (30฿)",
|
||||
"personal": "Personal",
|
||||
"others": "Others",
|
||||
}
|
||||
|
||||
class ImportPayment(Model):
|
||||
_name="clinic.import.payment"
|
||||
_string="Import Payment"
|
||||
|
||||
_fields={
|
||||
'name': fields.Char("Name"),
|
||||
"type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)")],"Type"),
|
||||
'date_import': fields.DateTime("Date"),
|
||||
'file': fields.File("File"),
|
||||
'sheets': fields.One2Many("clinic.file.sheet","imp_id", "Sheets"),
|
||||
'mg_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'mg_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
'sc_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'sc_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
'nhso_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'nhso_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
"state": fields.Selection([("draft","Draft"),("success","Succes"),("fail","Fail")],"Status"),
|
||||
'note': fields.Text("Note"),
|
||||
}
|
||||
|
||||
_order="date_import desc"
|
||||
|
||||
def _get_name(self,context={}):
|
||||
timenow=time.strftime("%Y-%m-%d")
|
||||
return 'Import Payment - %s'%timenow
|
||||
|
||||
_defaults={
|
||||
'date_import': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'name': _get_name,
|
||||
'state': 'draft',
|
||||
'type': 'mg',
|
||||
}
|
||||
|
||||
def load_data(self,ids,context):
|
||||
records=[1,2,]
|
||||
del records[0]
|
||||
fmt1="%y-%m-%d"
|
||||
fmt2="%Y-%m-%d"
|
||||
for record in records:
|
||||
row=record.split(",")
|
||||
doc_date=row[0]
|
||||
if doc_date:
|
||||
#'%m/%d/%y
|
||||
pt="(\d+)/(\d+)/(\d+)"
|
||||
res=re.search(pt,doc_date)
|
||||
if res:
|
||||
doc_date="%s-%s-%s" % (res.group(3),res.group(1),res.group(2))
|
||||
newdate=datetime.strptime(doc_date,fmt1)
|
||||
print(newdate.strftime(fmt2))
|
||||
|
||||
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_import_payment",
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Load sheet successfully",
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
def onchange_file(self,context={}):
|
||||
data=context['data']
|
||||
data['sheets']=[]
|
||||
print("data ", data)
|
||||
return data
|
||||
|
||||
def clear_sheet(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
for sheet in obj.sheets:
|
||||
sheet.delete()
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Clear Sheet OK",
|
||||
}
|
||||
|
||||
def find_invoice(self,ids,context={}):
|
||||
# return invoice line
|
||||
obj=self.browse(ids[0])
|
||||
partner_id=None
|
||||
setting=get_model("clinic.setting").browse(1)
|
||||
if obj.type=='sc':
|
||||
partner_id=setting.sc_partner_id.id
|
||||
elif obj.type=='mg':
|
||||
partner_id=setting.mg_partner_id.id
|
||||
elif obj.type=='nhso':
|
||||
partner_id=setting.nhso_partner_id.id
|
||||
if not partner_id:
|
||||
raise Exception("No partner")
|
||||
|
||||
# XXX
|
||||
if obj.payment_lines:
|
||||
for line in obj.payment_lines:
|
||||
line.delete()
|
||||
dom=[]
|
||||
dom.append(['state','=','waiting_payment'])
|
||||
dom.append(['partner_id','=',partner_id])
|
||||
invoice_lines=[]
|
||||
for invoice in get_model("account.invoice").search_browse(dom):
|
||||
line={
|
||||
'invoice_id': invoice.id,
|
||||
'amount': invoice.amount_total,
|
||||
}
|
||||
#invoice_lines.append(('create',line))
|
||||
invoice_lines.append(('create',line))
|
||||
return invoice_lines
|
||||
|
||||
def make_payment(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
company_id=get_active_company()
|
||||
timenow=time.strftime("%Y-%m-%d")
|
||||
setting=get_model("clinic.setting").browse(1)
|
||||
account_id=None
|
||||
partner_id=None
|
||||
if obj.type=='sc':
|
||||
account_id=setting.ar_sc_id.id
|
||||
partner_id=setting.sc_partner_id.id
|
||||
elif obj.type=='mg':
|
||||
account_id=setting.ar_mg_id.id
|
||||
partner_id=setting.mg_partner_id.id
|
||||
elif obj.type=='nhso':
|
||||
account_id=setting.ar_nhso_id.id
|
||||
partner_id=setting.nhso_partner_id.id
|
||||
vals={
|
||||
"partner_id": partner_id,
|
||||
"company_id": company_id,
|
||||
"type": "in",
|
||||
"pay_type": "invoice",
|
||||
"date": timenow,
|
||||
"account_id": account_id,
|
||||
'lines': [], # TODO find invoice matching
|
||||
}
|
||||
if obj.type=='sc':
|
||||
if not obj.sc_payment_id:
|
||||
payment_id=get_model("account.payment").create(vals,context={'type': 'in'})
|
||||
obj.write({
|
||||
'sc_payment_id': payment_id,
|
||||
})
|
||||
invoice_lines=obj.find_invoice()
|
||||
print("="*30)
|
||||
for line in invoice_lines:
|
||||
print(line)
|
||||
print("="*30)
|
||||
# TODO update payment
|
||||
# remove invoice, udpate invoice
|
||||
if invoice_lines:
|
||||
# clear old invoice lines
|
||||
for line in obj.sc_payment_id.invoice_lines:
|
||||
line.delete()
|
||||
# update new
|
||||
obj.sc_payment_id.write({
|
||||
'invoice_lines': invoice_lines,
|
||||
})
|
||||
elif obj.type=='mg':
|
||||
if not obj.mg_payment_id:
|
||||
payment_id=get_model("account.payment").create(vals,context={'type': 'in'})
|
||||
obj.write({
|
||||
'mg_payment_id': payment_id,
|
||||
})
|
||||
invoice_lines=obj.find_invoice()
|
||||
print("="*30)
|
||||
for line in invoice_lines:
|
||||
print(line)
|
||||
print("="*30)
|
||||
if invoice_lines:
|
||||
# clear old invoice lines
|
||||
for line in obj.mg_payment_id.invoice_lines:
|
||||
line.delete()
|
||||
# update new
|
||||
obj.mg_payment_id.write({
|
||||
'invoice_lines': invoice_lines,
|
||||
})
|
||||
elif obj.type=='nhso':
|
||||
if not obj.nhso_payment_id:
|
||||
payment_id=get_model("account.payment").create(vals,context={'type': 'in'})
|
||||
obj.write({
|
||||
'nhso_payment_id': payment_id,
|
||||
})
|
||||
invoice_lines=obj.find_invoice()
|
||||
if invoice_lines:
|
||||
# clear old invoice lines
|
||||
for line in obj.nhso_payment_id.invoice_lines:
|
||||
line.delete()
|
||||
# update new
|
||||
obj.nhso_payment_id.write({
|
||||
'invoice_lines': invoice_lines,
|
||||
})
|
||||
|
||||
def import_payment(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
obj.make_payment()
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': 'Import Payment OK',
|
||||
}
|
||||
|
||||
def post_mg(self,ids,context={}):
|
||||
pass
|
||||
|
||||
def undo_mg(self,ids,context={}):
|
||||
pass
|
||||
|
||||
def post_sc(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
payment_id=obj.sc_payment_id
|
||||
#move_id=obj.sc_move_id
|
||||
if not payment_id:
|
||||
raise Exception("Payment not create yet.")
|
||||
# XXX check state
|
||||
if payment_id.state=='posted':
|
||||
raise Exception("%s has been posted."%payment_id.number)
|
||||
payment_id.post()
|
||||
print("move_id ", payment_id.move_id.id)
|
||||
obj.write({
|
||||
'sc_move_id': payment_id.move_id.id,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "%s has been posted"%payment_id.number,
|
||||
}
|
||||
|
||||
|
||||
def undo_sc(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
move_id=obj.sc_move_id
|
||||
payment_id=obj.sc_payment_id
|
||||
if not move_id:
|
||||
raise Exception("%s is not post yet"%payment_id.number)
|
||||
payment_id.to_draft()
|
||||
obj.write({
|
||||
#'sc_payment_id': None,
|
||||
'sc_move_id': None,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Undo OK",
|
||||
}
|
||||
|
||||
def post_nhso(self,ids,context={}):
|
||||
pass
|
||||
|
||||
def undo_nhso(self,ids,context={}):
|
||||
pass
|
||||
|
||||
|
||||
ImportPayment.register()
|
|
@ -22,6 +22,9 @@ from . import cause_chronic
|
|||
from . import je
|
||||
from . import input_line
|
||||
from . import file_sheet
|
||||
from . import file_nhso_sheet
|
||||
from . import file_sc_sheet
|
||||
from . import file_mg_sheet
|
||||
from . import payment
|
||||
from . import import_payment
|
||||
from . import visit_plan
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
from netforce.model import Model, fields
|
||||
|
||||
class FileMGSheet(Model):
|
||||
_name="clinic.file.mg.sheet"
|
||||
_string="File Sheet"
|
||||
|
||||
_fields={
|
||||
'name': fields.Char("Name"),
|
||||
'index': fields.Integer("Index"),
|
||||
"select": fields.Selection([("yes","Yes"),("no","No")],"Select"),
|
||||
'imp_id': fields.Many2One("clinic.import.payment","Import Payment"),
|
||||
}
|
||||
|
||||
FileMGSheet.register()
|
|
@ -0,0 +1,14 @@
|
|||
from netforce.model import Model, fields
|
||||
|
||||
class FileNHSOSheet(Model):
|
||||
_name="clinic.file.nhso.sheet"
|
||||
_string="File Sheet"
|
||||
|
||||
_fields={
|
||||
'name': fields.Char("Name"),
|
||||
'index': fields.Integer("Index"),
|
||||
"select": fields.Selection([("yes","Yes"),("no","No")],"Select"),
|
||||
'imp_id': fields.Many2One("clinic.import.payment","Import Payment"),
|
||||
}
|
||||
|
||||
FileNHSOSheet.register()
|
|
@ -0,0 +1,14 @@
|
|||
from netforce.model import Model, fields
|
||||
|
||||
class FileSCSheet(Model):
|
||||
_name="clinic.file.sc.sheet"
|
||||
_string="File Sheet"
|
||||
|
||||
_fields={
|
||||
'name': fields.Char("Name"),
|
||||
'index': fields.Integer("Index"),
|
||||
"select": fields.Selection([("yes","Yes"),("no","No")],"Select"),
|
||||
'imp_id': fields.Many2One("clinic.import.payment","Import Payment"),
|
||||
}
|
||||
|
||||
FileSCSheet.register()
|
|
@ -9,6 +9,7 @@ class FileSheet(Model):
|
|||
'index': fields.Integer("Index"),
|
||||
"select": fields.Selection([("yes","Yes"),("no","No")],"Select"),
|
||||
'je_id': fields.Many2One("clinic.je","Journal Entry"),
|
||||
'imp_id': fields.Many2One("clinic.import.payment","Import Payment"),
|
||||
}
|
||||
|
||||
FileSheet.register()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
import time
|
||||
import xlrd
|
||||
from datetime import datetime
|
||||
|
@ -7,6 +8,7 @@ from netforce.access import get_active_company
|
|||
from netforce.access import get_active_user, set_active_user
|
||||
from netforce.utils import get_file_path
|
||||
from netforce.utils import get_data_path
|
||||
from netforce.database import get_connection
|
||||
|
||||
PAMENT_TYPE={
|
||||
"mg":"Medical Government",
|
||||
|
@ -22,14 +24,17 @@ class ImportPayment(Model):
|
|||
|
||||
_fields={
|
||||
'name': fields.Char("Name"),
|
||||
"type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)")],"Type"),
|
||||
'date_import': fields.DateTime("Date"),
|
||||
'mg_file': fields.File("File"),
|
||||
'sc_file': fields.File("File"),
|
||||
'nhso_file': fields.File("File"),
|
||||
'file': fields.File("File"),
|
||||
'sheets': fields.One2Many("clinic.file.sheet","imp_id", "Sheets"),
|
||||
'mg_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'mg_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
'sc_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'sc_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
'nhso_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
"state": fields.Selection([("draft","Draft"),("success","Succes"),("fail","Fail")],"Status"),
|
||||
'nhso_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
"state": fields.Selection([("draft","Draft"),("success","Succes"),("fail","Fail"),('close','Close')],"Status"),
|
||||
'note': fields.Text("Note"),
|
||||
}
|
||||
|
||||
|
@ -43,6 +48,356 @@ class ImportPayment(Model):
|
|||
'date_import': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'name': _get_name,
|
||||
'state': 'draft',
|
||||
'type': 'mg',
|
||||
}
|
||||
|
||||
def load_data(self,ids,context):
|
||||
records=[1,2,]
|
||||
del records[0]
|
||||
fmt1="%y-%m-%d"
|
||||
fmt2="%Y-%m-%d"
|
||||
for record in records:
|
||||
row=record.split(",")
|
||||
doc_date=row[0]
|
||||
if doc_date:
|
||||
#'%m/%d/%y
|
||||
pt="(\d+)/(\d+)/(\d+)"
|
||||
res=re.search(pt,doc_date)
|
||||
if res:
|
||||
doc_date="%s-%s-%s" % (res.group(3),res.group(1),res.group(2))
|
||||
newdate=datetime.strptime(doc_date,fmt1)
|
||||
print(newdate.strftime(fmt2))
|
||||
|
||||
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_import_payment",
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Load sheet successfully",
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
def onchange_file(self,context={}):
|
||||
data=context['data']
|
||||
data['sheets']=[]
|
||||
print("data ", data)
|
||||
return data
|
||||
|
||||
def clear_sheet(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
for sheet in obj.sheets:
|
||||
sheet.delete()
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Clear Sheet OK",
|
||||
}
|
||||
|
||||
def find_invoice(self,ids,context={}):
|
||||
# return invoice line
|
||||
obj=self.browse(ids[0])
|
||||
partner_id=None
|
||||
setting=get_model("clinic.setting").browse(1)
|
||||
if obj.type=='sc':
|
||||
partner_id=setting.sc_partner_id.id
|
||||
elif obj.type=='mg':
|
||||
partner_id=setting.mg_partner_id.id
|
||||
elif obj.type=='nhso':
|
||||
partner_id=setting.nhso_partner_id.id
|
||||
if not partner_id:
|
||||
raise Exception("No partner")
|
||||
|
||||
# XXX
|
||||
if obj.payment_lines:
|
||||
for line in obj.payment_lines:
|
||||
line.delete()
|
||||
dom=[]
|
||||
dom.append(['state','=','waiting_payment'])
|
||||
dom.append(['partner_id','=',partner_id])
|
||||
invoice_lines=[]
|
||||
for invoice in get_model("account.invoice").search_browse(dom):
|
||||
line={
|
||||
'invoice_id': invoice.id,
|
||||
'amount': invoice.amount_total,
|
||||
}
|
||||
#invoice_lines.append(('create',line))
|
||||
invoice_lines.append(('create',line))
|
||||
return invoice_lines
|
||||
|
||||
def make_payment(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
company_id=get_active_company()
|
||||
timenow=time.strftime("%Y-%m-%d")
|
||||
setting=get_model("clinic.setting").browse(1)
|
||||
account_id=None
|
||||
partner_id=None
|
||||
if obj.type=='sc':
|
||||
account_id=setting.ar_sc_id.id
|
||||
partner_id=setting.sc_partner_id.id
|
||||
elif obj.type=='mg':
|
||||
account_id=setting.ar_mg_id.id
|
||||
partner_id=setting.mg_partner_id.id
|
||||
elif obj.type=='nhso':
|
||||
account_id=setting.ar_nhso_id.id
|
||||
partner_id=setting.nhso_partner_id.id
|
||||
vals={
|
||||
"partner_id": partner_id,
|
||||
"company_id": company_id,
|
||||
"type": "in",
|
||||
"pay_type": "invoice",
|
||||
"date": timenow,
|
||||
"account_id": account_id,
|
||||
'lines': [], # TODO find invoice matching
|
||||
}
|
||||
if obj.type=='sc':
|
||||
if not obj.sc_payment_id:
|
||||
payment_id=get_model("account.payment").create(vals,context={'type': 'in'})
|
||||
obj.write({
|
||||
'sc_payment_id': payment_id,
|
||||
})
|
||||
invoice_lines=obj.find_invoice()
|
||||
print("="*30)
|
||||
for line in invoice_lines:
|
||||
print(line)
|
||||
print("="*30)
|
||||
# TODO update payment
|
||||
# remove invoice, udpate invoice
|
||||
if invoice_lines:
|
||||
# clear old invoice lines
|
||||
for line in obj.sc_payment_id.invoice_lines:
|
||||
line.delete()
|
||||
# update new
|
||||
obj.sc_payment_id.write({
|
||||
'invoice_lines': invoice_lines,
|
||||
})
|
||||
elif obj.type=='mg':
|
||||
if not obj.mg_payment_id:
|
||||
payment_id=get_model("account.payment").create(vals,context={'type': 'in'})
|
||||
obj.write({
|
||||
'mg_payment_id': payment_id,
|
||||
})
|
||||
invoice_lines=obj.find_invoice()
|
||||
print("="*30)
|
||||
for line in invoice_lines:
|
||||
print(line)
|
||||
print("="*30)
|
||||
if invoice_lines:
|
||||
# clear old invoice lines
|
||||
for line in obj.mg_payment_id.invoice_lines:
|
||||
line.delete()
|
||||
# update new
|
||||
obj.mg_payment_id.write({
|
||||
'invoice_lines': invoice_lines,
|
||||
})
|
||||
elif obj.type=='nhso':
|
||||
if not obj.nhso_payment_id:
|
||||
payment_id=get_model("account.payment").create(vals,context={'type': 'in'})
|
||||
obj.write({
|
||||
'nhso_payment_id': payment_id,
|
||||
})
|
||||
invoice_lines=obj.find_invoice()
|
||||
if invoice_lines:
|
||||
# clear old invoice lines
|
||||
for line in obj.nhso_payment_id.invoice_lines:
|
||||
line.delete()
|
||||
# update new
|
||||
obj.nhso_payment_id.write({
|
||||
'invoice_lines': invoice_lines,
|
||||
})
|
||||
|
||||
def import_payment(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
obj.make_payment()
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': 'Import Payment OK',
|
||||
}
|
||||
|
||||
def post_mg(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
payment_id=obj.mg_payment_id
|
||||
if not payment_id:
|
||||
raise Exception("Payment not create yet.")
|
||||
if payment_id.state=='posted':
|
||||
raise Exception("%s has been posted."%payment_id.number)
|
||||
payment_id.post()
|
||||
# XXX
|
||||
db=get_connection()
|
||||
res=db.query("select move_id from account_payment where id =%s"%payment_id.id)
|
||||
if res:
|
||||
move_id=res[0]['move_id']
|
||||
obj.write({
|
||||
'mg_move_id': move_id,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "%s has been posted"%payment_id.number,
|
||||
}
|
||||
pass
|
||||
|
||||
def undo_mg(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
move_id=obj.mg_move_id
|
||||
payment_id=obj.mg_payment_id
|
||||
if not move_id:
|
||||
raise Exception("%s is not post yet"%payment_id.number)
|
||||
payment_id.to_draft()
|
||||
obj.write({
|
||||
'mg_move_id': None,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Undo OK",
|
||||
}
|
||||
|
||||
pass
|
||||
|
||||
def post_sc(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
payment_id=obj.sc_payment_id
|
||||
if not payment_id:
|
||||
raise Exception("Payment not create yet.")
|
||||
if payment_id.state=='posted':
|
||||
raise Exception("%s has been posted."%payment_id.number)
|
||||
payment_id.post()
|
||||
# XXX
|
||||
db=get_connection()
|
||||
res=db.query("select move_id from account_payment where id =%s"%payment_id.id)
|
||||
if res:
|
||||
move_id=res[0]['move_id']
|
||||
obj.write({
|
||||
'sc_move_id': move_id,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "%s has been posted"%payment_id.number,
|
||||
}
|
||||
|
||||
|
||||
def undo_sc(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
move_id=obj.sc_move_id
|
||||
payment_id=obj.sc_payment_id
|
||||
if not move_id:
|
||||
raise Exception("%s is not post yet"%payment_id.number)
|
||||
payment_id.to_draft()
|
||||
obj.write({
|
||||
'sc_move_id': None,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Undo OK",
|
||||
}
|
||||
|
||||
def post_nhso(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
payment_id=obj.nhso_payment_id
|
||||
if not payment_id:
|
||||
raise Exception("Payment not create yet.")
|
||||
if payment_id.state=='posted':
|
||||
raise Exception("%s has been posted."%payment_id.number)
|
||||
payment_id.post()
|
||||
# XXX
|
||||
db=get_connection()
|
||||
res=db.query("select move_id from account_payment where id =%s"%payment_id.id)
|
||||
if res:
|
||||
move_id=res[0]['move_id']
|
||||
obj.write({
|
||||
'nhso_move_id': move_id,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "%s has been posted"%payment_id.number,
|
||||
}
|
||||
pass
|
||||
|
||||
def undo_nhso(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
move_id=obj.nhso_move_id
|
||||
payment_id=obj.nhso_payment_id
|
||||
if not move_id:
|
||||
raise Exception("%s is not post yet"%payment_id.number)
|
||||
payment_id.to_draft()
|
||||
obj.write({
|
||||
'nhso_move_id': None,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_import_payment',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Undo OK",
|
||||
}
|
||||
pass
|
||||
|
||||
def close(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
obj.write({'state': 'close'})
|
||||
|
||||
ImportPayment.register()
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
import re
|
||||
import time
|
||||
import xlrd
|
||||
from datetime import datetime
|
||||
|
||||
from netforce.model import Model, fields, get_model
|
||||
from netforce.access import get_active_company
|
||||
from netforce.access import get_active_user, set_active_user
|
||||
from netforce.utils import get_file_path
|
||||
from netforce.utils import get_data_path
|
||||
|
||||
PAMENT_TYPE={
|
||||
"mg":"Medical Government",
|
||||
"sc":"Social Security",
|
||||
"nhso":"NHSO (30฿)",
|
||||
"personal": "Personal",
|
||||
"others": "Others",
|
||||
}
|
||||
|
||||
class ImportPayment(Model):
|
||||
_name="clinic.import.payment"
|
||||
_string="Import Payment"
|
||||
|
||||
_fields={
|
||||
'name': fields.Char("Name"),
|
||||
'date_import': fields.DateTime("Date"),
|
||||
|
||||
'mg_file': fields.File("File"),
|
||||
'mg_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'mg_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
'mg_sheets': fields.One2Many("clinic.file.mg.sheet","imp_id", "Sheets"),
|
||||
|
||||
'sc_file': fields.File("File"),
|
||||
'sc_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'sc_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
'sc_sheets': fields.One2Many("clinic.file.sc.sheet","imp_id", "Sheets"),
|
||||
|
||||
'nhso_file': fields.File("File"),
|
||||
'nhso_payment_id': fields.Many2One("account.payment","Payment"),
|
||||
'nhso_move_id': fields.Many2One("account.move","Journal Entry"),
|
||||
'nhso_sheets': fields.One2Many("clinic.file.nhso.sheet","imp_id", "Sheets"),
|
||||
|
||||
"state": fields.Selection([("draft","Draft"),("success","Succes"),("fail","Fail")],"Status"),
|
||||
'note': fields.Text("Note"),
|
||||
}
|
||||
|
||||
_order="date_import desc"
|
||||
|
||||
def _get_name(self,context={}):
|
||||
timenow=time.strftime("%Y-%m-%d")
|
||||
return 'Import Payment - %s'%timenow
|
||||
|
||||
_defaults={
|
||||
'date_import': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'name': _get_name,
|
||||
'state': 'draft',
|
||||
}
|
||||
|
||||
def load_data(self,ids,context):
|
||||
records=[1,2,]
|
||||
del records[0]
|
||||
fmt1="%y-%m-%d"
|
||||
fmt2="%Y-%m-%d"
|
||||
for record in records:
|
||||
row=record.split(",")
|
||||
doc_date=row[0]
|
||||
if doc_date:
|
||||
#'%m/%d/%y
|
||||
pt="(\d+)/(\d+)/(\d+)"
|
||||
res=re.search(pt,doc_date)
|
||||
if res:
|
||||
doc_date="%s-%s-%s" % (res.group(3),res.group(1),res.group(2))
|
||||
newdate=datetime.strptime(doc_date,fmt1)
|
||||
print(newdate.strftime(fmt2))
|
||||
|
||||
|
||||
ImportPayment.register()
|
|
@ -315,6 +315,8 @@ class Visit(Model):
|
|||
timevisit=timenow
|
||||
# XXX
|
||||
timevisit=data['time_start'][11:20]
|
||||
if not timevisit:
|
||||
timevisit=timenow
|
||||
fmt_date="%Y-%m-%d %H:%M:%S"
|
||||
fix_hrs=data['time_use'] or 0
|
||||
time_start=datetime.datetime.strptime("%s %s"%(start_date,timevisit),fmt_date)
|
||||
|
@ -326,5 +328,14 @@ class Visit(Model):
|
|||
line['state']='open'
|
||||
|
||||
return data
|
||||
|
||||
def create_dialyzer(self,ids,context={}):
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_dialyzer',
|
||||
'mode': 'form',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Visit.register()
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
======
|
||||
!!! this night
|
||||
- import payment
|
||||
|
||||
patient
|
||||
- type
|
||||
-nhso สปสช
|
||||
- center office of healthcare information
|
||||
- sc ประักนสังคม
|
||||
- mg
|
||||
|
||||
task
|
||||
1. find invoice
|
||||
2. match invoice
|
||||
- date, number for patient (HN)
|
||||
3. if have invoice create payment if not review input data again
|
||||
4. post payment to journal
|
||||
|
||||
===========================
|
||||
- main
|
||||
- create journal entry from file import
|
||||
- detail (if have some time need to approve)
|
||||
|
|
Loading…
Reference in New Issue