clean
parent
e51f94fd0b
commit
7549200b84
|
@ -1,6 +0,0 @@
|
|||
<action>
|
||||
<field name="string">Import Journal Entry</field>
|
||||
<field name="view_cls">multi_view</field>
|
||||
<field name="model">clinic.je</field>
|
||||
<field name="menu">clinic_menu</field>
|
||||
</action>
|
|
@ -9,8 +9,8 @@
|
|||
<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"/>
|
||||
<button string="Load Sheet" size="small" type="warning" icon="download" method="load_sheet" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
<button string="Clear Sheet" size="small" type="danger" icon="remove" method="clear_sheet" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
</group>
|
||||
<field name="sheets" count="3" nolabel="1">
|
||||
<list>
|
||||
|
@ -21,8 +21,8 @@
|
|||
<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"]]]}'/>
|
||||
<!--<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>
|
||||
<group span="4" columns="1">
|
||||
|
@ -30,27 +30,30 @@
|
|||
<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"/>
|
||||
<button string="POST" size="small" type="success" method="post_mg" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
<button string="UNDO" size="small" type="danger" method="undo_mg" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
</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"/>
|
||||
<button string="POST" size="small" type="success" method="post_sc" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
<button string="UNDO" size="small" type="danger" method="undo_sc" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
</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"/>
|
||||
<button string="POST" size="small" type="success" method="post_nhso" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
<button string="UNDO" size="small" type="danger" method="undo_nhso" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
</group>
|
||||
|
||||
</group>
|
||||
<foot>
|
||||
<button span="3" string="Import" type="success" icon="arrow-right" method="import_payment" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
<button span="3" string="Close" type="danger" method="close" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
||||
<button span="3" string="To Draft" icon="refresh" type="default" method="to_draft" attrs='{"invisible":[["state","in",["draft"]]]}'/>
|
||||
</foot>
|
||||
</form>
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
<form model="clinic.je">
|
||||
<head>
|
||||
<field name="state"/>
|
||||
</head>
|
||||
<group span="6" columns="1">
|
||||
<field name="number"/>
|
||||
<field name="name"/>
|
||||
<field name="type" onchange="onchange_type" required="1"/>
|
||||
</group>
|
||||
<group span="6" columns="1">
|
||||
<field name="date_import"/>
|
||||
<field name="file"/>
|
||||
<field name="payment_id" readonly="1"/>
|
||||
</group>
|
||||
<tabs>
|
||||
<tab string="File Information">
|
||||
<group span="6" columns="1">
|
||||
<separator string="Sheets"/>
|
||||
<field name="sheets" count="5" nolabel="1">
|
||||
<list>
|
||||
<field name="name"/>
|
||||
<field name="select" onchange="onchange_sheet"/>
|
||||
</list>
|
||||
</field>
|
||||
</group>
|
||||
<group span="6" columns="1">
|
||||
<separator string="Options"/>
|
||||
<group span="3" columns="1">
|
||||
<button string="Load Sheet" type="primary" icon="download" method="load_sheet"/>
|
||||
<newline/>
|
||||
<button string="Load Payment" type="warning" icon="download" method="load_payment"/>
|
||||
<newline/>
|
||||
<button offset="10" string="Match Invoice" type="success" icon="search" method="find_invoice"/>
|
||||
<newline/>
|
||||
<button offset="10" string="Make Payment" type="primary" icon="arrow-right" method="make_payment"/>
|
||||
<newline/>
|
||||
<button string="Post" type="success" icon="arrow-right" method="post_payment"/>
|
||||
<newline/>
|
||||
<button string="Undo" type="danger" icon="circle" method="undo"/>
|
||||
<newline/>
|
||||
<button string="Clear" type="default" icon="remove" method="clear"/>
|
||||
</group>
|
||||
<group span="3" columns="1">
|
||||
<field name="description" width="300" height="250" nolabel="1"/>
|
||||
</group>
|
||||
</group>
|
||||
</tab>
|
||||
<tab string="Payments">
|
||||
<field name="payment_lines" 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="invoice_lines" count="10" nolabel="1">
|
||||
<list>
|
||||
<field name="invoice_id"/>
|
||||
<field name="amount"/>
|
||||
</list>
|
||||
</field>
|
||||
</tab>
|
||||
</tabs>
|
||||
<foot>
|
||||
</foot>
|
||||
</form>
|
|
@ -1,6 +0,0 @@
|
|||
<list model="clinic.je" colors='{"#ccc":[["state","=","fail"]]}'>
|
||||
<field name="number"/>
|
||||
<field name="name"/>
|
||||
<field name="date_import"/>
|
||||
<field name="state"/>
|
||||
</list>
|
|
@ -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]],"orange":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>
|
||||
<calendar model="clinic.visit" states='waiting_treatment' date_field="date_visit" 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"/>
|
||||
|
|
|
@ -1,317 +0,0 @@
|
|||
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()
|
|
@ -1,30 +1,24 @@
|
|||
from . import comorbidity
|
||||
from . import morbidity
|
||||
from . import patient
|
||||
from . import patient_cause_line
|
||||
from . import patient_comorbidity_line
|
||||
from . import patient_morbidity_line
|
||||
from . import doctor
|
||||
from . import nurse
|
||||
from . import visit
|
||||
from . import hd_case
|
||||
from . import hd_case_line
|
||||
from . import hd_case_discont
|
||||
from . import dialyzer
|
||||
from . import dialyzer_line
|
||||
from . import department
|
||||
from . import education
|
||||
from . import setting
|
||||
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_nhso_sheet
|
||||
from . import file_sc_sheet
|
||||
from . import file_mg_sheet
|
||||
from . import payment
|
||||
from . import import_payment
|
||||
from . import patient
|
||||
from . import patient_cause_line
|
||||
from . import patient_comorbidity_line
|
||||
from . import patient_morbidity_line
|
||||
from . import department
|
||||
from . import doctor
|
||||
from . import nurse
|
||||
from . import visit
|
||||
from . import visit_plan
|
||||
from . import hd_case
|
||||
from . import hd_case_line
|
||||
from . import hd_case_discont
|
||||
from . import dialyzer
|
||||
from . import dialyzer_line
|
||||
from . import import_payment
|
||||
from . import file_sheet
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
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()
|
|
@ -1,14 +0,0 @@
|
|||
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()
|
|
@ -1,14 +0,0 @@
|
|||
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()
|
|
@ -8,7 +8,6 @@ class FileSheet(Model):
|
|||
'name': fields.Char("Name"),
|
||||
'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"),
|
||||
}
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ class ImportPayment(Model):
|
|||
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)
|
||||
raise Exception("%s is not post yet"%(payment_id.number or "Payment"))
|
||||
payment_id.to_draft()
|
||||
obj.write({
|
||||
'mg_move_id': None,
|
||||
|
@ -336,7 +336,7 @@ class ImportPayment(Model):
|
|||
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)
|
||||
raise Exception("%s is not post yet"%(payment_id.number or "Payment"))
|
||||
payment_id.to_draft()
|
||||
obj.write({
|
||||
'sc_move_id': None,
|
||||
|
@ -381,7 +381,7 @@ class ImportPayment(Model):
|
|||
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)
|
||||
raise Exception("%s is not post yet"%(payment_id.number or "Payment"))
|
||||
payment_id.to_draft()
|
||||
obj.write({
|
||||
'nhso_move_id': None,
|
||||
|
@ -400,4 +400,8 @@ class ImportPayment(Model):
|
|||
obj=self.browse(ids)[0]
|
||||
obj.write({'state': 'close'})
|
||||
|
||||
def to_draft(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
obj.write({'state': 'draft'})
|
||||
|
||||
ImportPayment.register()
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
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()
|
|
@ -1,13 +0,0 @@
|
|||
from netforce.model import Model, fields
|
||||
|
||||
class Invoice(Model):
|
||||
_name="clinic.invoice"
|
||||
_string="Clinic Invoice"
|
||||
|
||||
_fields={
|
||||
'je_id': fields.Many2One("clinic.je","Journal Entry"),
|
||||
'invoice_id': fields.Many2One("account.invoice","NF Invoice"),
|
||||
'amount': fields.Float("Amount"),
|
||||
}
|
||||
|
||||
Invoice.register()
|
|
@ -1,273 +0,0 @@
|
|||
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 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"),
|
||||
'payment_lines': fields.One2Many("clinic.payment","je_id", "Payments"),
|
||||
'invoice_lines': fields.One2Many("clinic.invoice","je_id", "Invoices"),
|
||||
'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'),('payment_load','Payment Load'),('posted','Posted'),("fail","Fail"),("done","Done")],"Status",required=True),
|
||||
'description': fields.Text("Description")
|
||||
}
|
||||
|
||||
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 load_payment(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
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
|
||||
payment_lines=[]
|
||||
while curr_row < num_rows:
|
||||
curr_row += 1
|
||||
# skip header
|
||||
if curr_row <=1:
|
||||
continue
|
||||
#row=ws.row(curr_row)
|
||||
# XXX
|
||||
doc_date=ws.cell_value(curr_row, 0)
|
||||
doc_date=datetime(*xlrd.xldate_as_tuple(doc_date, wb.datemode))
|
||||
doc_date=doc_date.strftime("%Y-%m-%d")
|
||||
data={
|
||||
'doc_date':doc_date,
|
||||
'name':ws.cell_value(curr_row, 1),
|
||||
'hn':ws.cell_value(curr_row, 2),
|
||||
'amount':ws.cell_value(curr_row, 3),
|
||||
}
|
||||
payment_lines.append(('create',data))
|
||||
|
||||
data_ids=[data.id for data in obj.invoice_lines]
|
||||
get_model("clinic.payment").delete(data_ids)
|
||||
obj.write({
|
||||
'payment_lines': payment_lines,
|
||||
'description': 'see -> payments',
|
||||
})
|
||||
|
||||
|
||||
def clear(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
invoice_ids=[invoice.id for invoice in obj.invoice_lines]
|
||||
get_model("clinic.invoice").delete(invoice_ids)
|
||||
payment_ids=[payment.id for payment in obj.payment_lines]
|
||||
get_model("clinic.payment").delete(payment_ids)
|
||||
|
||||
def find_invoice(self,ids,context={}):
|
||||
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):
|
||||
print(invoice.id, " ", invoice.number, " ", invoice.amount_total),
|
||||
line={
|
||||
'invoice_id': invoice.id,
|
||||
'amount': invoice.amount_total,
|
||||
}
|
||||
invoice_lines.append(('create',line))
|
||||
obj.write({
|
||||
'invoice_lines': invoice_lines,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_je',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash':'Invoice Load!',
|
||||
}
|
||||
|
||||
def post_payment(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
if not obj.payment_lines:
|
||||
raise Exception("No invoice to post")
|
||||
|
||||
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 make_payment(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
if obj.payment_id:
|
||||
if obj.payment_lines:
|
||||
if obj.payment_id.invoice_lines:
|
||||
return
|
||||
vals={
|
||||
'invoice_lines':[],
|
||||
}
|
||||
# XXX
|
||||
for line in obj.invoice_lines:
|
||||
line={
|
||||
'invoice_id': line.invoice_id.id,
|
||||
'amount': line.amount,
|
||||
}
|
||||
vals['invoice_lines'].append(('create',line))
|
||||
obj.payment_id.write(vals)
|
||||
return
|
||||
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
|
||||
}
|
||||
payment_id=get_model("account.payment").create(vals,context={'type': 'in'})
|
||||
obj.write({
|
||||
'payment_id': payment_id,
|
||||
})
|
||||
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_je',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash': "Make payment ok !",
|
||||
}
|
||||
|
||||
def onchange_type(self,context={}):
|
||||
data=context['data']
|
||||
payment_type=PAMENT_TYPE.get(data['type'],"")
|
||||
data['name']="%s Payment for %s"%(payment_type,time.strftime("%Y-%m-%d"))
|
||||
return data
|
||||
|
||||
JE.register()
|
|
@ -1,7 +1,18 @@
|
|||
|
||||
===== todo
|
||||
Account Receivable -> invoice
|
||||
Account Payable -> payment
|
||||
|
||||
|
||||
|
||||
issue:
|
||||
date of visit is not copy after click from calendar
|
||||
======
|
||||
!!! this night
|
||||
- import payment
|
||||
|
||||
setting account
|
||||
- debit
|
||||
- credit
|
||||
patient
|
||||
- type
|
||||
-nhso สปสช
|
||||
|
|
Loading…
Reference in New Issue