conv_bal
watcha.h 2014-10-03 18:08:10 +07:00
parent 484676dcbb
commit 1738023cf0
5 changed files with 149 additions and 17 deletions

View File

@ -0,0 +1,6 @@
<form model="clinic.input.data">
<field name="doc_date"/>
<field name="name"/>
<field name="hn"/>
<field name="amount"/>
</form>

View File

@ -0,0 +1,6 @@
<list model="clinic.input.data">
<field name="doc_date"/>
<field name="name"/>
<field name="hn"/>
<field name="amount"/>
</list>

View File

@ -31,7 +31,13 @@
<newline/> <newline/>
<button string="Load DATA" type="warning" icon="download" method="load_data"/> <button string="Load DATA" type="warning" icon="download" method="load_data"/>
<newline/> <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>
<group span="3" columns="1"> <group span="3" columns="1">
<field name="description" width="300" height="250" nolabel="1"/> <field name="description" width="300" height="250" nolabel="1"/>
@ -41,10 +47,10 @@
<tab string="Priview"> <tab string="Priview">
<field name="input_data" count="10" nolabel="1"> <field name="input_data" count="10" nolabel="1">
<list> <list>
<field name="doc_date"/> <field name="doc_date"/>
<field name="name"/> <field name="name"/>
<field name="hn"/> <field name="hn"/>
<field name="amount"/> <field name="amount"/>
</list> </list>
</field> </field>
</tab> </tab>
@ -61,6 +67,5 @@
</tab> </tab>
</tabs> </tabs>
<foot> <foot>
<button string="Import" type="success" icon="arrow-right" method="import2journal"/>
</foot> </foot>
</form> </form>

View File

@ -4,7 +4,7 @@ class InputData(Model):
_name="clinic.input.data" _name="clinic.input.data"
_string="Input Data" _string="Input Data"
_fields={ _fields={
'doc_date': fields.Char("Doc Date"), 'doc_date': fields.Date("Doc Date"),
'name': fields.Char("Name"), 'name': fields.Char("Name"),
'hn': fields.Char("HN"), 'hn': fields.Char("HN"),
'amount': fields.Float("Amount"), 'amount': fields.Float("Amount"),

View File

@ -1,7 +1,9 @@
import time import time
import xlrd import xlrd
from datetime import datetime
from netforce.model import Model, fields, get_model 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.access import get_active_user, set_active_user
from netforce.utils import get_file_path from netforce.utils import get_file_path
from netforce.utils import get_data_path from netforce.utils import get_data_path
@ -110,23 +112,81 @@ class JE(Model):
ws=wb.sheet_by_name(sheet_name) ws=wb.sheet_by_name(sheet_name)
num_rows = ws.nrows - 1 num_rows = ws.nrows - 1
curr_row = -1 curr_row = -1
records=[] input_data=[]
import pprint
while curr_row < num_rows: while curr_row < num_rows:
curr_row += 1 curr_row += 1
# skip header
if curr_row <=1:
continue
#row=ws.row(curr_row) #row=ws.row(curr_row)
record={}
# XXX # XXX
for col in (1,2,3,4): doc_date=ws.cell_value(curr_row, 0)
record[col]=ws.cell_value(curr_row, col) doc_date=datetime(*xlrd.xldate_as_tuple(doc_date, wb.datemode))
records.append(record) doc_date=doc_date.strftime("%Y-%m-%d")
pprint.pprint(records) 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={}): 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={}): # XXX
pass 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={}): def onchange_sheet(self,context={}):
data=context["data"] data=context["data"]
@ -137,4 +197,59 @@ class JE(Model):
sheet['select']=None sheet['select']=None
return data 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() JE.register()