clean
parent
484676dcbb
commit
1738023cf0
|
@ -0,0 +1,6 @@
|
|||
<form model="clinic.input.data">
|
||||
<field name="doc_date"/>
|
||||
<field name="name"/>
|
||||
<field name="hn"/>
|
||||
<field name="amount"/>
|
||||
</form>
|
|
@ -0,0 +1,6 @@
|
|||
<list model="clinic.input.data">
|
||||
<field name="doc_date"/>
|
||||
<field name="name"/>
|
||||
<field name="hn"/>
|
||||
<field name="amount"/>
|
||||
</list>
|
|
@ -31,7 +31,13 @@
|
|||
<newline/>
|
||||
<button string="Load DATA" type="warning" icon="download" method="load_data"/>
|
||||
<newline/>
|
||||
<button string="Find Invoice" type="success" icon="search" method="find_invoice"/>
|
||||
<button offset="10" string="Find 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="Clear DATA" type="default" icon="remove" method="clear_data"/>
|
||||
</group>
|
||||
<group span="3" columns="1">
|
||||
<field name="description" width="300" height="250" nolabel="1"/>
|
||||
|
@ -41,10 +47,10 @@
|
|||
<tab string="Priview">
|
||||
<field name="input_data" count="10" nolabel="1">
|
||||
<list>
|
||||
<field name="doc_date"/>
|
||||
<field name="name"/>
|
||||
<field name="hn"/>
|
||||
<field name="amount"/>
|
||||
<field name="doc_date"/>
|
||||
<field name="name"/>
|
||||
<field name="hn"/>
|
||||
<field name="amount"/>
|
||||
</list>
|
||||
</field>
|
||||
</tab>
|
||||
|
@ -61,6 +67,5 @@
|
|||
</tab>
|
||||
</tabs>
|
||||
<foot>
|
||||
<button string="Import" type="success" icon="arrow-right" method="import2journal"/>
|
||||
</foot>
|
||||
</form>
|
||||
|
|
|
@ -4,7 +4,7 @@ class InputData(Model):
|
|||
_name="clinic.input.data"
|
||||
_string="Input Data"
|
||||
_fields={
|
||||
'doc_date': fields.Char("Doc Date"),
|
||||
'doc_date': fields.Date("Doc Date"),
|
||||
'name': fields.Char("Name"),
|
||||
'hn': fields.Char("HN"),
|
||||
'amount': fields.Float("Amount"),
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
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
|
||||
|
@ -110,23 +112,81 @@ class JE(Model):
|
|||
ws=wb.sheet_by_name(sheet_name)
|
||||
num_rows = ws.nrows - 1
|
||||
curr_row = -1
|
||||
records=[]
|
||||
import pprint
|
||||
input_data=[]
|
||||
while curr_row < num_rows:
|
||||
curr_row += 1
|
||||
# skip header
|
||||
if curr_row <=1:
|
||||
continue
|
||||
#row=ws.row(curr_row)
|
||||
record={}
|
||||
# XXX
|
||||
for col in (1,2,3,4):
|
||||
record[col]=ws.cell_value(curr_row, col)
|
||||
records.append(record)
|
||||
pprint.pprint(records)
|
||||
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),
|
||||
}
|
||||
input_data.append(('create',data))
|
||||
data_ids=[data.id for data in obj.input_data]
|
||||
get_model("clinic.input.data").delete(data_ids)
|
||||
obj.write({
|
||||
'input_data': input_data,
|
||||
'description': 'see preview',
|
||||
})
|
||||
|
||||
|
||||
def clear_data(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
data_ids=[data.id for data in obj.input_data]
|
||||
get_model("clinic.input.data").delete(data_ids)
|
||||
|
||||
def find_invoice(self,ids,context={}):
|
||||
pass
|
||||
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")
|
||||
|
||||
def import2journal(self,ids,context={}):
|
||||
pass
|
||||
# XXX
|
||||
if obj.lines:
|
||||
for line in obj.lines:
|
||||
line.delete()
|
||||
dom=[]
|
||||
dom.append(['state','=','waiting_payment'])
|
||||
dom.append(['partner_id','=',partner_id])
|
||||
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,
|
||||
}
|
||||
lines.append(('create',line))
|
||||
obj.write({
|
||||
'lines': lines,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_je',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash':'Load invoice OK!',
|
||||
}
|
||||
|
||||
def post_payment(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
if not obj.lines:
|
||||
raise Exception("No invoice to post")
|
||||
|
||||
def onchange_sheet(self,context={}):
|
||||
data=context["data"]
|
||||
|
@ -137,4 +197,59 @@ class JE(Model):
|
|||
sheet['select']=None
|
||||
return data
|
||||
|
||||
def make_payment(self,ids,context={}):
|
||||
obj=self.browse(ids[0])
|
||||
if obj.payment_id:
|
||||
if obj.lines:
|
||||
if obj.payment_id.invoice_lines:
|
||||
return
|
||||
vals={
|
||||
'invoice_lines':[],
|
||||
}
|
||||
for line in obj.lines:
|
||||
line={
|
||||
'invoice_id': line.invoice_id.id,
|
||||
'amount': line.amount,
|
||||
}
|
||||
vals['invoice_lines'].append(('create',line))
|
||||
obj.payment_id.write(vals)
|
||||
print("add invoice to payment")
|
||||
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 !",
|
||||
}
|
||||
|
||||
JE.register()
|
||||
|
|
Loading…
Reference in New Issue