import
parent
abc4ad9b02
commit
bf28ed43c6
|
@ -1,6 +1,6 @@
|
||||||
<action>
|
<action>
|
||||||
<field name="string">Import Payments From Government</field>
|
<field name="view_cls">form_view</field>
|
||||||
<field name="view_cls">multi_view</field>
|
|
||||||
<field name="model">clinic.import.payment</field>
|
<field name="model">clinic.import.payment</field>
|
||||||
|
<field name="view_xml">import_clinic_mg</field>
|
||||||
<field name="menu">account_menu</field>
|
<field name="menu">account_menu</field>
|
||||||
</action>
|
</action>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<action>
|
||||||
|
<field name="view_cls">form_view</field>
|
||||||
|
<field name="model">clinic.import.payment</field>
|
||||||
|
<field name="view_xml">import_clinic_nhso</field>
|
||||||
|
<field name="menu">account_menu</field>
|
||||||
|
</action>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<action>
|
||||||
|
<field name="view_cls">form_view</field>
|
||||||
|
<field name="model">clinic.import.payment</field>
|
||||||
|
<field name="view_xml">import_clinic_sc</field>
|
||||||
|
<field name="menu">account_menu</field>
|
||||||
|
</action>
|
|
@ -1,14 +0,0 @@
|
||||||
<form model="clinic.import.payment" attrs='{"readonly":[["state","in",["close"]]]}'>
|
|
||||||
<head>
|
|
||||||
<field name="state"/>
|
|
||||||
</head>
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="date_import"/>
|
|
||||||
<field name="type" required="1"/>
|
|
||||||
<field name="input_id" readonly="1"/>
|
|
||||||
<field name="mg_payment_id" readonly="1"/>
|
|
||||||
<field name="file" readonly="1"/>
|
|
||||||
<foot>
|
|
||||||
<button span="3" size="large" icon="arrow-right" string="Import" type="primary" method="import"/>
|
|
||||||
</foot>
|
|
||||||
</form>
|
|
|
@ -1,46 +0,0 @@
|
||||||
<form model="clinic.import.payment" attrs='{"readonly":[["state","in",["close"]]]}'>
|
|
||||||
<head>
|
|
||||||
<field name="state"/>
|
|
||||||
<button string="Report" icon="print" action="report"/>
|
|
||||||
</head>
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="date_import"/>
|
|
||||||
<field name="type" required="1"/>
|
|
||||||
<separator string="Select File -> Load DATA -> Click See Data"/>
|
|
||||||
<group span="6" columns="1">
|
|
||||||
<field span="6" name="file" onchange="onchange_file"/>
|
|
||||||
<button span="6" string="Load DATA" size="small" type="warning" icon="download" method="load_data" attrs='{"invisible":[["state","in",["close"]]]}'/>
|
|
||||||
<field span="6" name="input_id" readonly="1"/>
|
|
||||||
</group>
|
|
||||||
<group span="6" 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" 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" 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" 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,5 +0,0 @@
|
||||||
<list model="clinic.import.payment">
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="date_import"/>
|
|
||||||
<field name="state"/>
|
|
||||||
</list>
|
|
|
@ -2,11 +2,11 @@
|
||||||
<item string="Settings" position="before">
|
<item string="Settings" position="before">
|
||||||
<item string="Ratchawat">
|
<item string="Ratchawat">
|
||||||
<header string="IMPORT PAYMENT"/>
|
<header string="IMPORT PAYMENT"/>
|
||||||
<item string="Medical Government" action="clinic_import_payment"/>
|
<item string="Medical Government" action="import_clinic_mg"/>
|
||||||
<item string="Social Security" action="clinic_import_payment"/>
|
<item string="Social Security" action="import_clinic_sc"/>
|
||||||
<item string="NHSO 30฿" action="clinic_import_payment"/>
|
<item string="NHSO 30฿" action="import_clinic_nhso"/>
|
||||||
<divider/>
|
<divider/>
|
||||||
<header string="REPORTS"/>
|
<header string="IMPORT DATA"/>
|
||||||
<item string="Medical Government" action="clinic_import_payment"/>
|
<item string="Medical Government" action="clinic_import_payment"/>
|
||||||
<item string="Social Security" action="clinic_import_payment"/>
|
<item string="Social Security" action="clinic_import_payment"/>
|
||||||
<item string="NHSO 30฿" action="clinic_import_payment"/>
|
<item string="NHSO 30฿" action="clinic_import_payment"/>
|
||||||
|
|
|
@ -1,18 +1,2 @@
|
||||||
<form model="clinic.setting" title="Financial Settings">
|
<form model="clinic.setting" title="Clinic Settings">
|
||||||
<tabs>
|
|
||||||
<tab string="Accounting">
|
|
||||||
<separator string="Account Setting Medical Govelopment"/>
|
|
||||||
<field name="mg_partner_id" />
|
|
||||||
<field name="ar_mg_id" />
|
|
||||||
<field name="ap_mg_id" />
|
|
||||||
<separator string="Account Setting NHSO 30B"/>
|
|
||||||
<field name="nhso_partner_id" />
|
|
||||||
<field name="ar_nhso_id" />
|
|
||||||
<field name="ap_nhso_id" />
|
|
||||||
<separator string="Account Setting Social Security"/>
|
|
||||||
<field name="sc_partner_id" />
|
|
||||||
<field name="ar_sc_id" />
|
|
||||||
<field name="ap_sc_id" />
|
|
||||||
</tab>
|
|
||||||
</tabs>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<inherit model="settings" inherit="fin_settings">
|
||||||
|
<field name="retained_earnings_account_id" position="after">
|
||||||
|
<separator string="Clinic"/>
|
||||||
|
<field name="mg_account_id"/>
|
||||||
|
<field name="sc_account_id"/>
|
||||||
|
<field name="nhso_account_id"/>
|
||||||
|
</field>
|
||||||
|
</inherit>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<form title="Import Medical Government">
|
||||||
|
<field name="file"/>
|
||||||
|
<foot replace="1">
|
||||||
|
<button string="Import Data" method="import_mg" type="primary" icon="arrow-right"/>
|
||||||
|
</foot>
|
||||||
|
</form>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<form title="Import NHSO">
|
||||||
|
<field name="file"/>
|
||||||
|
<foot replace="1">
|
||||||
|
<button string="Import Data" method="import_nhso" type="primary" icon="arrow-right"/>
|
||||||
|
</foot>
|
||||||
|
</form>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<form title="Import Social Security">
|
||||||
|
<field name="file"/>
|
||||||
|
<foot replace="1">
|
||||||
|
<button string="Import Data" method="import_sc" type="primary" icon="arrow-right"/>
|
||||||
|
</foot>
|
||||||
|
</form>
|
|
@ -32,3 +32,7 @@ from . import report_hd_summary
|
||||||
from . import report_hd_madical
|
from . import report_hd_madical
|
||||||
from . import payment
|
from . import payment
|
||||||
from . import input_data
|
from . import input_data
|
||||||
|
from . import fin_setting
|
||||||
|
from . import import_data_mg
|
||||||
|
from . import import_data_nhso
|
||||||
|
from . import import_data_sc
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
from netforce.model import Model, fields
|
||||||
|
|
||||||
|
class Settings(Model):
|
||||||
|
_inherit="settings"
|
||||||
|
_fields={
|
||||||
|
"mg_account_id": fields.Many2One("account.account","Account Payment Medical Government"),
|
||||||
|
"nhso_account_id": fields.Many2One("account.account","Account Payment NHSO 30B"),
|
||||||
|
"sc_account_id": fields.Many2One("account.account","Account Payment Social Security"),
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings.register()
|
|
@ -0,0 +1,11 @@
|
||||||
|
from netforce.model import Model, fields
|
||||||
|
|
||||||
|
class ImportDataMG(Model):
|
||||||
|
_name="clinic.data.mg"
|
||||||
|
_transient=True
|
||||||
|
_fields={
|
||||||
|
'name': fields.Char("Name"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ImportDataMG.register()
|
|
@ -0,0 +1,11 @@
|
||||||
|
from netforce.model import Model, fields
|
||||||
|
|
||||||
|
class ImportDataNHSO(Model):
|
||||||
|
_name="clinic.data.nhso"
|
||||||
|
_transient=True
|
||||||
|
_fields={
|
||||||
|
'name': fields.Char("Name"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ImportDataNHSO.register()
|
|
@ -0,0 +1,11 @@
|
||||||
|
from netforce.model import Model, fields
|
||||||
|
|
||||||
|
class ImportDataSC(Model):
|
||||||
|
_name="clinic.data.sc"
|
||||||
|
_transient=True
|
||||||
|
_fields={
|
||||||
|
'name': fields.Char("Name"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ImportDataSC.register()
|
|
@ -7,436 +7,58 @@ from netforce.utils import get_file_path
|
||||||
from netforce.utils import get_data_path
|
from netforce.utils import get_data_path
|
||||||
from netforce.database import get_connection
|
from netforce.database import get_connection
|
||||||
|
|
||||||
PAMENT_TYPE={
|
|
||||||
"mg":"Medical Government",
|
|
||||||
"sc":"Social Security",
|
|
||||||
"nhso":"NHSO (30฿)",
|
|
||||||
"personal": "Personal",
|
|
||||||
"others": "Others",
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImportPayment(Model):
|
class ImportPayment(Model):
|
||||||
_name="clinic.import.payment"
|
_name="clinic.import.payment"
|
||||||
_string="Import Payment"
|
_transient=True
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
'name': fields.Char("Name"),
|
'date': fields.DateTime("Date"),
|
||||||
"type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)")],"Type"),
|
|
||||||
'date_import': fields.DateTime("Date"),
|
|
||||||
'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"),
|
|
||||||
'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"),
|
|
||||||
'partner_id': fields.Many2One("partner","Contact"),
|
|
||||||
'input_id': fields.Many2One("clinic.input.data", "Data"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_order="date_import desc"
|
|
||||||
|
|
||||||
def _get_name(self,context={}):
|
|
||||||
timenow=time.strftime("%Y-%m-%d")
|
|
||||||
return 'Import Payment - %s'%timenow
|
|
||||||
|
|
||||||
_defaults={
|
_defaults={
|
||||||
'date_import': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
'name': _get_name,
|
|
||||||
'state': 'draft',
|
|
||||||
'type': 'mg',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def load_data(self,ids,context):
|
def read_excel(self,fpath=None):
|
||||||
obj=self.browse(ids[0])
|
data={}
|
||||||
fname=obj.file
|
if fpath:
|
||||||
if not fname:
|
|
||||||
raise Exception("Please select file!")
|
|
||||||
fpath=get_file_path(fname)
|
|
||||||
suffix=fpath.split(".")[-1]
|
suffix=fpath.split(".")[-1]
|
||||||
if suffix not in ('xls', 'xlsx'):
|
if suffix not in ('xls', 'xlsx'):
|
||||||
raise Exception("ERROR : file support only xls, xlsx")
|
raise Exception("ERROR : please should file xls or xlsx")
|
||||||
wb=xlrd.open_workbook(fpath)
|
wb=xlrd.open_workbook(fpath)
|
||||||
worksheet=wb.sheet_by_name("Sheet1")
|
worksheet=wb.sheet_by_name("Sheet1")
|
||||||
num_rows=worksheet.nrows-1
|
num_rows=worksheet.nrows-1
|
||||||
curr_row=-1
|
curr_row=-1
|
||||||
cols={
|
|
||||||
'hn': 38,
|
|
||||||
'dttran': 71,
|
|
||||||
'name14': 39,
|
|
||||||
'hcode18': 65, # remove -1
|
|
||||||
'amount23': 74,
|
|
||||||
'cur': 91,
|
|
||||||
'epoadm29': 93,
|
|
||||||
'eponame': 98,
|
|
||||||
'ln': 99,
|
|
||||||
'st': 101,
|
|
||||||
'allow37': 109,
|
|
||||||
}
|
|
||||||
|
|
||||||
while curr_row < num_rows:
|
while curr_row < num_rows:
|
||||||
curr_row +=1
|
curr_row +=1
|
||||||
vals={
|
worksheet.cell_value(curr_row,1)
|
||||||
'date': worksheet.cell_value(curr_row,cols['dttran']),
|
return data
|
||||||
'name': worksheet.cell_value(curr_row,cols['name14']),
|
|
||||||
'hn': worksheet.cell_value(curr_row,cols['hn']),
|
|
||||||
'amount': worksheet.cell_value(curr_row,cols['amount23']),
|
|
||||||
'hct': worksheet.cell_value(curr_row,cols['amount23']),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
def read_xml(self,fpath=None):
|
||||||
def load_sheet(self,ids,context={}):
|
data={}
|
||||||
obj=self.browse(ids[0])
|
if fpath:
|
||||||
fname=obj.file
|
|
||||||
if not fname:
|
|
||||||
raise Exception("Please select file!")
|
|
||||||
fpath=get_file_path(fname)
|
|
||||||
suffix=fpath.split(".")[-1]
|
suffix=fpath.split(".")[-1]
|
||||||
if suffix not in ('xls', 'xlsx'):
|
if suffix not in ('xml'):
|
||||||
raise Exception("ERROR : file support only xls, xlsx")
|
raise Exception("ERROR : please should file xml")
|
||||||
|
|
||||||
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
|
return data
|
||||||
|
|
||||||
def onchange_file(self,context={}):
|
def import_mg(self,ids,context={}):
|
||||||
data=context['data']
|
|
||||||
data['sheets']=[]
|
|
||||||
print("data ", data)
|
|
||||||
return data
|
|
||||||
|
|
||||||
def clear_sheet(self,ids,context={}):
|
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
for sheet in obj.sheets:
|
fname=obj.file
|
||||||
sheet.delete()
|
fpath=get_file_path(fname)
|
||||||
return {
|
print("fpath ", fpath)
|
||||||
'next': {
|
|
||||||
'name': 'clinic_import_payment',
|
|
||||||
'mode': 'form',
|
|
||||||
'active_id': obj.id,
|
|
||||||
},
|
|
||||||
'flash': "Clear Sheet OK",
|
|
||||||
}
|
|
||||||
|
|
||||||
def find_invoice(self,ids,context={}):
|
def import_nhso(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):
|
|
||||||
print(invoice)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
#db=get_connection()
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
## XX
|
|
||||||
#sql="update clinic_import_payment set sc_payment_id=%s where id = %s" % (payment_id,obj.id)
|
|
||||||
#import pdb; pdb.set_trace()
|
|
||||||
#db.query(sql)
|
|
||||||
#db.commit()
|
|
||||||
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:
|
|
||||||
if obj.sc_payment_id.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
|
|
||||||
if obj.mg_payment_id.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
|
|
||||||
if obj.nhso_payment_id.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=self.browse(ids)[0]
|
||||||
obj.make_payment()
|
fname=obj.file
|
||||||
return {
|
fpath=get_file_path(fname)
|
||||||
'next': {
|
print("fpath ", fpath)
|
||||||
'name': 'clinic_import_payment',
|
|
||||||
'mode': 'form',
|
|
||||||
'active_id': obj.id,
|
|
||||||
},
|
|
||||||
'flash': 'Import Payment OK',
|
|
||||||
}
|
|
||||||
|
|
||||||
def post_mg(self,ids,context={}):
|
def import_sc(self,ids,context={}):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
payment_id=obj.mg_payment_id
|
fname=obj.file
|
||||||
if not payment_id:
|
fpath=get_file_path(fname)
|
||||||
raise Exception("Payment not create yet.")
|
print("fpath ", fpath)
|
||||||
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 or "Payment"))
|
|
||||||
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 or "Payment"))
|
|
||||||
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 or "Payment"))
|
|
||||||
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'})
|
|
||||||
|
|
||||||
def to_draft(self,ids,context={}):
|
|
||||||
obj=self.browse(ids)[0]
|
|
||||||
obj.write({'state': 'draft'})
|
|
||||||
|
|
||||||
def onchange_type(self,context={}):
|
|
||||||
data=context['data']
|
|
||||||
# find partner and set to partner_id
|
|
||||||
return data
|
|
||||||
|
|
||||||
ImportPayment.register()
|
ImportPayment.register()
|
||||||
|
|
Loading…
Reference in New Issue