matching uc
parent
b1d8f317ac
commit
3c4b45e937
|
@ -41,6 +41,7 @@
|
||||||
<tab string="Accounting">
|
<tab string="Accounting">
|
||||||
<field name="cash_account_id"/>
|
<field name="cash_account_id"/>
|
||||||
<field name="income_account_id" string="Account Receivable"/>
|
<field name="income_account_id" string="Account Receivable"/>
|
||||||
|
<field name="import_account_id"/>
|
||||||
</tab>
|
</tab>
|
||||||
</tabs>
|
</tabs>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<form model="clinic.matching.payment" title="Matching Payment">
|
<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" onchange="onchange_date" mode="month" span="3"/>
|
||||||
<field name="date_from" span="3"/>
|
<field name="date_from" span="3"/>
|
||||||
<field name="date_to" span="3"/>
|
<field name="date_to" span="3"/>
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
<field name="hcode_id" span="3"/>
|
<field name="hcode_id" span="3"/>
|
||||||
<foot replace="1">
|
<foot replace="1">
|
||||||
<button string="Match" method="match" icon="ok" type="success"/>
|
<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>
|
</foot>
|
||||||
<related>
|
<related>
|
||||||
<field name="expenes"/>
|
<field name="expenes"/>
|
||||||
|
|
|
@ -477,6 +477,7 @@ class HDCase(Model):
|
||||||
"type": "out",
|
"type": "out",
|
||||||
"inv_type": "invoice",
|
"inv_type": "invoice",
|
||||||
"tax_type": "tax_in",
|
"tax_type": "tax_in",
|
||||||
|
'date': obj.date, #XXX
|
||||||
'due_date': due_date,
|
'due_date': due_date,
|
||||||
"ref": '%s (%s)'%(patient.name or '',patient.number or ''),
|
"ref": '%s (%s)'%(patient.name or '',patient.number or ''),
|
||||||
'department_id': obj.department_id.id,
|
'department_id': obj.department_id.id,
|
||||||
|
|
|
@ -3,6 +3,8 @@ from calendar import monthrange
|
||||||
|
|
||||||
from netforce.model import Model, fields, get_model
|
from netforce.model import Model, fields, get_model
|
||||||
from netforce.utils import get_file_path
|
from netforce.utils import get_file_path
|
||||||
|
from netforce.database import get_connection
|
||||||
|
from netforce.access import get_active_company
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ class MatchingPayment(Model):
|
||||||
if obj.pcode=='SSO':
|
if obj.pcode=='SSO':
|
||||||
hcode=obj.hcode_id.code or ""
|
hcode=obj.hcode_id.code or ""
|
||||||
if not hcode:
|
if not hcode:
|
||||||
raise Exception("Please input hcode")
|
raise Exception("Wrong HCode")
|
||||||
n,sf=fname.split(".")
|
n,sf=fname.split(".")
|
||||||
if sf not in ('xls','xlsx'):
|
if sf not in ('xls','xlsx'):
|
||||||
raise Exception("File should be xls or xlsx")
|
raise Exception("File should be xls or xlsx")
|
||||||
|
@ -80,6 +82,9 @@ class MatchingPayment(Model):
|
||||||
def match(self,ids,context={}):
|
def match(self,ids,context={}):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
lines=obj.get_line()
|
lines=obj.get_line()
|
||||||
|
|
||||||
|
db=get_connection()
|
||||||
|
db.execute("truncate m2m_clinic_hd_case_expense_clinic_matching_payment;")
|
||||||
matches1={}
|
matches1={}
|
||||||
matches2={}
|
matches2={}
|
||||||
if obj.pcode=='SSO':
|
if obj.pcode=='SSO':
|
||||||
|
@ -120,28 +125,82 @@ class MatchingPayment(Model):
|
||||||
matches1[key1]=0
|
matches1[key1]=0
|
||||||
if not matches2.get(key2):
|
if not matches2.get(key2):
|
||||||
matches2[key2]=0
|
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=[]
|
exp_ids=[]
|
||||||
dom=[]
|
dom=[]
|
||||||
dom.append(['date',">=",obj.date_from])
|
dom.append(['date',">=",obj.date_from])
|
||||||
dom.append(['date',"<=",obj.date_to])
|
dom.append(['date',"<=",obj.date_to])
|
||||||
|
dom.append(['patient_id.type_id',"=",obj.patient_type_id.id])
|
||||||
return
|
dom.append(['state','!=', 'completed'])
|
||||||
for exp in get_model('clinic.hd.case.expense').search_browse(dom):
|
for exp in get_model('clinic.hd.case.expense').search_browse(dom):
|
||||||
exp_ids.append(exp.id)
|
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({
|
obj.write({
|
||||||
'expenes': [('add',exp_ids)]
|
'expenes': [('add',exp_ids)]
|
||||||
})
|
})
|
||||||
|
print("Done!")
|
||||||
|
flash='Succesfully'
|
||||||
|
if not exp_ids:
|
||||||
|
flash="No match"
|
||||||
return {
|
return {
|
||||||
'next': {
|
'next': {
|
||||||
'name': 'clinic_matching_payment',
|
'name': 'clinic_matching_payment',
|
||||||
'mode': 'form',
|
'mode': 'form',
|
||||||
'active_id': obj.id,
|
'active_id': obj.id,
|
||||||
},
|
},
|
||||||
'flash': 'Succesfully',
|
'flash': flash,
|
||||||
}
|
}
|
||||||
|
|
||||||
def onchange_date(self,context={}):
|
def onchange_date(self,context={}):
|
||||||
|
@ -161,4 +220,56 @@ class MatchingPayment(Model):
|
||||||
data['pcode']=t.code or ""
|
data['pcode']=t.code or ""
|
||||||
return data
|
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()
|
MatchingPayment.register()
|
||||||
|
|
|
@ -33,6 +33,7 @@ class ClinicSetting(Model):
|
||||||
'shop_type_id': fields.Many2One("clinic.patient.type","Patient Type"),
|
'shop_type_id': fields.Many2One("clinic.patient.type","Patient Type"),
|
||||||
"cash_account_id": fields.Many2One("account.account","Cash Account",multi_company=True),
|
"cash_account_id": fields.Many2One("account.account","Cash Account",multi_company=True),
|
||||||
"income_account_id": fields.Many2One("account.account","Income 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={
|
_defaults={
|
||||||
|
|
|
@ -174,6 +174,7 @@ class Visit(Model):
|
||||||
'dialyzers': [],
|
'dialyzers': [],
|
||||||
'staffs': [],
|
'staffs': [],
|
||||||
'state': 'waiting_treatment',
|
'state': 'waiting_treatment',
|
||||||
|
'date': obj.visit_date, #XXX
|
||||||
}
|
}
|
||||||
|
|
||||||
st=get_model("clinic.setting").browse(1)
|
st=get_model("clinic.setting").browse(1)
|
||||||
|
|
Loading…
Reference in New Issue