matching uc

conv_bal
watcha.h 2015-02-05 02:02:44 +07:00
parent b1d8f317ac
commit 3c4b45e937
6 changed files with 124 additions and 9 deletions

View File

@ -41,6 +41,7 @@
<tab string="Accounting">
<field name="cash_account_id"/>
<field name="income_account_id" string="Account Receivable"/>
<field name="import_account_id"/>
</tab>
</tabs>
</form>

View File

@ -1,5 +1,5 @@
<form model="clinic.matching.payment" title="Matching Payment">
<separator string="1. Click Match > 2. Review Items > 3. Import Payment"/>
<separator string="1. Click Match > 2. Check Items > 3. Import Payment"/>
<field name="date" onchange="onchange_date" mode="month" span="3"/>
<field name="date_from" span="3"/>
<field name="date_to" span="3"/>
@ -10,7 +10,7 @@
<field name="hcode_id" span="3"/>
<foot replace="1">
<button string="Match" method="match" icon="ok" type="success"/>
<button string="Import Payment" method="pay" icon="arrow-right" type="default"/>
<button string="Import Payment" method="do_import" icon="arrow-right" type="default"/>
</foot>
<related>
<field name="expenes"/>

View File

@ -477,6 +477,7 @@ class HDCase(Model):
"type": "out",
"inv_type": "invoice",
"tax_type": "tax_in",
'date': obj.date, #XXX
'due_date': due_date,
"ref": '%s (%s)'%(patient.name or '',patient.number or ''),
'department_id': obj.department_id.id,

View File

@ -3,6 +3,8 @@ from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.utils import get_file_path
from netforce.database import get_connection
from netforce.access import get_active_company
from . import utils
@ -58,7 +60,7 @@ class MatchingPayment(Model):
if obj.pcode=='SSO':
hcode=obj.hcode_id.code or ""
if not hcode:
raise Exception("Please input hcode")
raise Exception("Wrong HCode")
n,sf=fname.split(".")
if sf not in ('xls','xlsx'):
raise Exception("File should be xls or xlsx")
@ -80,6 +82,9 @@ class MatchingPayment(Model):
def match(self,ids,context={}):
obj=self.browse(ids)[0]
lines=obj.get_line()
db=get_connection()
db.execute("truncate m2m_clinic_hd_case_expense_clinic_matching_payment;")
matches1={}
matches2={}
if obj.pcode=='SSO':
@ -120,28 +125,82 @@ class MatchingPayment(Model):
matches1[key1]=0
if not matches2.get(key2):
matches2[key2]=0
elif obj.pcode=='UC':
pass
elif obj.pcode=='UC':
for line in lines:
#{'amount': '1500.0000',
#'cstat': None,
#'dttran': '2014-09-27T10:00:00',
#'epostat': 'E',
#'hdflag': 'COU',
#'hdrate': '1500.0000',
#'hn': '98511252',
#'hreg': 'NHSO1',
#'invno': '437941480',
#'paid': '0.0000',
#'paychk': '1',
#'reimbpay': '0.0000',
#'rid': '2190',
#'station': '01'}
date,time=(line['dttran'] or "").split("T")
amt=line['amount'] or "0"
amt=float(amt)
if date and time:
key1='%s-%s-%s'%(
line['hn'],
date,
amt,
)
if not matches1.get(key1):
matches1[key1]={
'invno': line['invno'],
}
#print("="*50)
#for key, values in matches1.items():
#x=key.split("-")
#hn=x[0]
#if hn=='11712556':
#print(key)
#print("="*50)
exp_ids=[]
dom=[]
dom.append(['date',">=",obj.date_from])
dom.append(['date',"<=",obj.date_to])
return
dom.append(['patient_id.type_id',"=",obj.patient_type_id.id])
dom.append(['state','!=', 'completed'])
for exp in get_model('clinic.hd.case.expense').search_browse(dom):
exp_ids.append(exp.id)
#TODO Checking
if obj.pcode=='UC':
pt=exp.patient_id
hdcase=exp.hd_case_id
date=hdcase.date
fee_amt=0
for line in hdcase.lines:
categ=line.product_categ_id
if categ.code=='FEE':
fee_amt+=line.amount or 0
key='%s-%s-%s'%(pt.hn_no,date,amt)
#if pt.hn_no=='11712556':
#print('key ', key)
found=matches1.get(key)
if found:
exp.write({
'state': 'match',
})
obj.write({
'expenes': [('add',exp_ids)]
})
print("Done!")
flash='Succesfully'
if not exp_ids:
flash="No match"
return {
'next': {
'name': 'clinic_matching_payment',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Succesfully',
'flash': flash,
}
def onchange_date(self,context={}):
@ -160,5 +219,57 @@ class MatchingPayment(Model):
t=get_model('clinic.patient.type').browse(type_id)
data['pcode']=t.code or ""
return data
def do_import(self,ids,context={}):
st=get_model("clinic.setting").browse(1)
if not st.import_account_id:
raise Exception("Import account not found (Ratchawat Setting -> Accounting)")
obj=self.browse(ids)[0]
if not obj.expenes:
raise Exception("Nothing to import")
obj=self.browse(ids)[0]
partner=obj.patient_type_id.contact_id
company_id=get_active_company()
vals={
"partner_id": partner.id,
"company_id": company_id,
"type": "in",
"pay_type": "invoice",
'date': time.strftime("%Y-%m-%d"),
"account_id": st.import_account_id.id,
'invoice_lines': [],
}
for exp in obj.expenes:
if exp.state=='match':
for inv in exp.hd_case_id.invoices:
if inv.partner_id.id==partner.id:
vals['invoice_lines'].append(('create',{
'invoice_id': inv.id,
'amount': inv.amount_due or 0,
}))
#should not match again
exp.write({
'state': 'completed',
})
hdcase=exp.hd_case_id
if hdcase:
hdcase.write({
'state': 'paid',
})
if not vals['invoice_lines']:
raise Exception("Nothing to import")
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
return {
'next': {
'name': 'payment',
'mode': 'form',
'active_id': payment_id,
},
'flash': 'Create Payment successfully',
}
MatchingPayment.register()

View File

@ -33,6 +33,7 @@ class ClinicSetting(Model):
'shop_type_id': fields.Many2One("clinic.patient.type","Patient Type"),
"cash_account_id": fields.Many2One("account.account","Cash Account",multi_company=True),
"income_account_id": fields.Many2One("account.account","Income Account",multi_company=True),
"import_account_id": fields.Many2One("account.account","Import Account",multi_company=True),
}
_defaults={

View File

@ -174,6 +174,7 @@ class Visit(Model):
'dialyzers': [],
'staffs': [],
'state': 'waiting_treatment',
'date': obj.visit_date, #XXX
}
st=get_model("clinic.setting").browse(1)