customize payment
parent
27b95b6d77
commit
280e663e0b
|
@ -0,0 +1,5 @@
|
||||||
|
<inherit model="account.payment" inherit="payment_form">
|
||||||
|
<field name="default_line_desc" position="before">
|
||||||
|
<field name="rd_cust" span="2"/>
|
||||||
|
</field>
|
||||||
|
</inherit>
|
|
@ -1,10 +1,13 @@
|
||||||
<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. Review Items > 3. Import Payment"/>
|
||||||
<group form_layout="stacked">
|
<field name="date" onchange="onchange_date" mode="month" span="3"/>
|
||||||
<field name="file" span="3"/>
|
<field name="date_from" span="3"/>
|
||||||
<field name="patient_type_id" span="3"/>
|
<field name="date_to" span="3"/>
|
||||||
<field name="hcode_id" span="3"/>
|
<newline/>
|
||||||
</group>
|
<field name="file" span="3"/>
|
||||||
|
<field name="patient_type_id" onchange="onchange_ptype" span="3"/>
|
||||||
|
<field name="pcode" 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="pay" icon="arrow-right" type="default"/>
|
||||||
|
|
|
@ -2,6 +2,9 @@ from netforce.model import Model, fields, get_model
|
||||||
|
|
||||||
class AccountPayment(Model):
|
class AccountPayment(Model):
|
||||||
_inherit="account.payment"
|
_inherit="account.payment"
|
||||||
|
_fields={
|
||||||
|
'rd_cust': fields.Boolean("RD Customize"),
|
||||||
|
}
|
||||||
|
|
||||||
def run_report(self,ids,context={}):
|
def run_report(self,ids,context={}):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
|
@ -31,5 +34,93 @@ class AccountPayment(Model):
|
||||||
'refer_id': ids[0], #XXX
|
'refer_id': ids[0], #XXX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def post(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
res=None
|
||||||
|
if obj.rd_cust:
|
||||||
|
res={}
|
||||||
|
print("RD Customize")
|
||||||
|
desc="Recieved %s"%obj.partner_id.name
|
||||||
|
for ivline in obj.invoice_lines:
|
||||||
|
invoice=ivline.invoice_id
|
||||||
|
partner_id=invoice.partner_id.id
|
||||||
|
for mline in invoice.move_id.lines:
|
||||||
|
if mline.debit>0:
|
||||||
|
amt=mline.debit or 0
|
||||||
|
account_id=mline.account_id.id
|
||||||
|
if not res.get(account_id):
|
||||||
|
res[account_id]={
|
||||||
|
'credit': 0,
|
||||||
|
'debit': 0,
|
||||||
|
'description': desc,
|
||||||
|
'partner_id': partner_id
|
||||||
|
}
|
||||||
|
res[account_id]['credit']+=amt
|
||||||
|
|
||||||
|
settings=get_model("settings").browse(1)
|
||||||
|
if obj.type=="in":
|
||||||
|
journal_id=obj.journal_id.id or settings.pay_in_journal_id.id
|
||||||
|
if not journal_id:
|
||||||
|
raise Exception("Receipts journal not found")
|
||||||
|
elif obj.type=="out":
|
||||||
|
journal_id=obj.journal_id.id or settings.pay_out_journal_id.id
|
||||||
|
if not journal_id:
|
||||||
|
raise Exception("Disbursements journal not found")
|
||||||
|
if not obj.number:
|
||||||
|
raise Exception("Missing payment number")
|
||||||
|
move_vals={
|
||||||
|
"journal_id": journal_id,
|
||||||
|
"number": obj.number,
|
||||||
|
"date": obj.date,
|
||||||
|
"narration": desc,
|
||||||
|
"related_id": "account.payment,%s"%obj.id,
|
||||||
|
"company_id": obj.company_id.id,
|
||||||
|
}
|
||||||
|
move_id=get_model("account.move").create(move_vals)
|
||||||
|
track_id=None
|
||||||
|
for line in obj.lines: # XXX
|
||||||
|
if line.track_id:
|
||||||
|
if track_id:
|
||||||
|
track_id=None
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
track_id=line.track_id.id
|
||||||
|
lines1=[]
|
||||||
|
lines1.append(('create',{
|
||||||
|
"move_id": move_id,
|
||||||
|
"account_id": obj.account_id.id,
|
||||||
|
"description": desc,
|
||||||
|
"track_id": track_id,
|
||||||
|
'debit': 0,
|
||||||
|
'credit':0,
|
||||||
|
}))
|
||||||
|
lines2=[]
|
||||||
|
for account_id, rvals in res.items():
|
||||||
|
amt=rvals['credit'] or 0
|
||||||
|
lines1[0][1]['debit']+=amt #XXX
|
||||||
|
lines2.append(('create',{
|
||||||
|
"move_id": move_id,
|
||||||
|
"account_id": account_id,
|
||||||
|
"description": rvals['description'],
|
||||||
|
'partner_id': rvals['partner_id'],
|
||||||
|
'debit': rvals['debit'],
|
||||||
|
'credit': rvals['credit'],
|
||||||
|
"track_id": track_id,
|
||||||
|
}))
|
||||||
|
lines=lines1+lines2
|
||||||
|
move=get_model("account.move").browse(move_id)
|
||||||
|
move.write({
|
||||||
|
'lines': lines,
|
||||||
|
})
|
||||||
|
move.post()
|
||||||
|
obj.write({
|
||||||
|
'move_id': move.id,
|
||||||
|
'state': 'posted',
|
||||||
|
})
|
||||||
|
print("Done!")
|
||||||
|
else:
|
||||||
|
res=super().post(ids,context=context)
|
||||||
|
return res
|
||||||
|
|
||||||
AccountPayment.register()
|
AccountPayment.register()
|
||||||
|
|
|
@ -333,13 +333,39 @@ class HDCase(Model):
|
||||||
'ref': obj.number,
|
'ref': obj.number,
|
||||||
'direct_lines': [],
|
'direct_lines': [],
|
||||||
}
|
}
|
||||||
vals['direct_lines'].append(('create',{
|
|
||||||
'description': 'Payment; %s'%obj.number,
|
patient=obj.patient_id
|
||||||
'account_id': income_account_id,
|
ptype=patient.type_id
|
||||||
'qty': 1,
|
prod_acc=st.get_product_account
|
||||||
'unit_price': pay_amount,
|
for line in obj.lines:
|
||||||
'amount': pay_amount,
|
if line.reimbursable=='no':
|
||||||
}))
|
if line.amount < 1:
|
||||||
|
continue
|
||||||
|
prod=line.product_id
|
||||||
|
acc=prod_acc(prod.id,ptype.id,'cash')
|
||||||
|
account_id=acc.get("ar_credit_id",None)
|
||||||
|
ar_debit_id=acc.get("ar_debit_id",None)
|
||||||
|
if not account_id:
|
||||||
|
raise Exception("No Income Credit Account for product [%s] %s"%(prod.code, prod.name))
|
||||||
|
if not ar_debit_id:
|
||||||
|
raise Exception("No Ar Debit Account for product [%s] %s"%(prod.code, prod.name))
|
||||||
|
desc=line.description or ""
|
||||||
|
if prod:
|
||||||
|
desc="[%s] %s"%(prod.code, line.description or "")
|
||||||
|
vals['direct_lines'].append(('create',{
|
||||||
|
"description": desc,
|
||||||
|
"qty": line.qty,
|
||||||
|
"unit_price": line.price or 0,
|
||||||
|
"amount": line.amount or 0,
|
||||||
|
'account_id': account_id,
|
||||||
|
}))
|
||||||
|
#vals['direct_lines'].append(('create',{
|
||||||
|
#'description': 'Payment; %s'%obj.number,
|
||||||
|
#'account_id': income_account_id,
|
||||||
|
#'qty': 1,
|
||||||
|
#'unit_price': pay_amount,
|
||||||
|
#'amount': pay_amount,
|
||||||
|
#}))
|
||||||
|
|
||||||
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
||||||
obj.write({
|
obj.write({
|
||||||
|
@ -351,6 +377,11 @@ class HDCase(Model):
|
||||||
})
|
})
|
||||||
payment=get_model('account.payment').browse(payment_id)
|
payment=get_model('account.payment').browse(payment_id)
|
||||||
payment.post()
|
payment.post()
|
||||||
|
if payment.move_id:
|
||||||
|
for mline in payment.move_id.lines:
|
||||||
|
mline.write({
|
||||||
|
'partner_id': partner.id,
|
||||||
|
})
|
||||||
return {
|
return {
|
||||||
'next': {
|
'next': {
|
||||||
'name': 'clinic_hd_case',
|
'name': 'clinic_hd_case',
|
||||||
|
@ -401,7 +432,10 @@ class HDCase(Model):
|
||||||
if line.reimbursable=='yes':
|
if line.reimbursable=='yes':
|
||||||
acc=prod_acc(prod.id,obj.patient_type_id.id)
|
acc=prod_acc(prod.id,obj.patient_type_id.id)
|
||||||
else:
|
else:
|
||||||
acc=prod_acc(prod.id,obj.patient_type_id.id,'cash')
|
if is_credit:
|
||||||
|
acc=prod_acc(prod.id,obj.patient_type_id.id,'credit')
|
||||||
|
else:
|
||||||
|
acc=prod_acc(prod.id,obj.patient_type_id.id,'cash')
|
||||||
account_id=acc.get("ar_credit_id",None)
|
account_id=acc.get("ar_credit_id",None)
|
||||||
ar_debit_id=acc.get("ar_debit_id",None)
|
ar_debit_id=acc.get("ar_debit_id",None)
|
||||||
if not account_id:
|
if not account_id:
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
|
import time
|
||||||
|
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 . import utils
|
||||||
|
|
||||||
class MatchingPayment(Model):
|
class MatchingPayment(Model):
|
||||||
_name="clinic.matching.payment"
|
_name="clinic.matching.payment"
|
||||||
_transient=True
|
_transient=True
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
|
"date": fields.Date("Month"),
|
||||||
|
"date_from": fields.Date("From", required=True),
|
||||||
|
"date_to": fields.Date("To", required=True),
|
||||||
'file': fields.File("File"),
|
'file': fields.File("File"),
|
||||||
'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
|
'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
|
||||||
'hcode_id': fields.Many2One("clinic.hospital","HCode",required=True),
|
'pcode': fields.Char("Code",required=True),
|
||||||
|
'hcode_id': fields.Many2One("clinic.hospital","HCode"),
|
||||||
'expenes': fields.Many2Many("clinic.hd.case.expense","Expenses"),
|
'expenes': fields.Many2Many("clinic.hd.case.expense","Expenses"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,18 +28,110 @@ class MatchingPayment(Model):
|
||||||
tid=tids[0]
|
tid=tids[0]
|
||||||
return tid
|
return tid
|
||||||
|
|
||||||
|
def _get_pcode(self,context={}):
|
||||||
|
types=get_model('clinic.patient.type').search_browse([['default','=',True]])
|
||||||
|
if types:
|
||||||
|
return types[0].code
|
||||||
|
|
||||||
|
def _get_date_from(self,context={}):
|
||||||
|
year,month=time.strftime("%Y-%m").split("-")
|
||||||
|
return '%s-%s-01'%(year,month)
|
||||||
|
|
||||||
|
def _get_date_to(self,context={}):
|
||||||
|
year,month,day=time.strftime("%Y-%m-%d").split("-")
|
||||||
|
weekday, total_day=monthrange(int(year), int(month))
|
||||||
|
return "%s-%s-%s"%(year,month,total_day)
|
||||||
|
|
||||||
_defaults={
|
_defaults={
|
||||||
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||||||
|
'date_from': _get_date_from,
|
||||||
|
'date_to': _get_date_to,
|
||||||
'patient_type_id': _get_ptype,
|
'patient_type_id': _get_ptype,
|
||||||
|
'pcode': _get_pcode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_line(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
if not obj.file:
|
||||||
|
raise Exception("File not found!")
|
||||||
|
fname=obj.file
|
||||||
|
if obj.pcode=='SSO':
|
||||||
|
hcode=obj.hcode_id.code or ""
|
||||||
|
if not hcode:
|
||||||
|
raise Exception("Please input hcode")
|
||||||
|
n,sf=fname.split(".")
|
||||||
|
if sf not in ('xls','xlsx'):
|
||||||
|
raise Exception("File should be xls or xlsx")
|
||||||
|
fpath=get_file_path(fname)
|
||||||
|
lines=utils.read_excel(fpath,show_datetime=True)
|
||||||
|
|
||||||
|
elif obj.pcode=='UC':
|
||||||
|
fpath=get_file_path(fname)
|
||||||
|
node='HDBills'
|
||||||
|
lines=utils.read_xml(fpath,node=node)
|
||||||
|
hcode=fname.split("_")[0]
|
||||||
|
else:
|
||||||
|
raise Exception("Type %s is not support"%obj.pcode or "")
|
||||||
|
|
||||||
|
if not lines:
|
||||||
|
raise Exception("No data to match")
|
||||||
|
return lines
|
||||||
|
|
||||||
def match(self,ids,context={}):
|
def match(self,ids,context={}):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
for exp in obj.expenes:
|
lines=obj.get_line()
|
||||||
exp.delete()
|
matches1={}
|
||||||
|
matches2={}
|
||||||
|
if obj.pcode=='SSO':
|
||||||
|
for line in lines:
|
||||||
|
hcode=line.get('hcode18')
|
||||||
|
if not hcode:
|
||||||
|
hcode='0'
|
||||||
|
hcode=int(hcode)
|
||||||
|
hcode=str(hcode)
|
||||||
|
if obj.hcode==hcode:
|
||||||
|
lsrv_amt=line.get('epoadm29') or 0
|
||||||
|
lfee_amt=line.get('amount23') or 0
|
||||||
|
lmdc_amt=line.get('allow37') or 0
|
||||||
|
dttran=line.get("dttran")
|
||||||
|
name=line.get("name14")
|
||||||
|
date=dttran[0:10]
|
||||||
|
time=dttran[11:] #XXX
|
||||||
|
if not time:
|
||||||
|
print("wrong format")
|
||||||
|
continue
|
||||||
|
hn=line.get('hn')
|
||||||
|
hn=''.join([x for x in hn if x.isdigit()])
|
||||||
|
key1='%s:%s:%s:%s:%s'%(
|
||||||
|
hn,
|
||||||
|
date,
|
||||||
|
lfee_amt,
|
||||||
|
lsrv_amt,
|
||||||
|
lmdc_amt,
|
||||||
|
)
|
||||||
|
key2='%s:%s:%s:%s:%s'%(
|
||||||
|
name,
|
||||||
|
date,
|
||||||
|
lfee_amt,
|
||||||
|
lsrv_amt,
|
||||||
|
lmdc_amt,
|
||||||
|
)
|
||||||
|
if not matches1.get(key1):
|
||||||
|
matches1[key1]=0
|
||||||
|
if not matches2.get(key2):
|
||||||
|
matches2[key2]=0
|
||||||
|
elif obj.pcode=='UC':
|
||||||
|
pass
|
||||||
|
|
||||||
exp_ids=[]
|
exp_ids=[]
|
||||||
for exp in get_model('clinic.hd.case.expense').search_browse([]):
|
dom=[]
|
||||||
|
dom.append(['date',">=",obj.date_from])
|
||||||
|
dom.append(['date',"<=",obj.date_to])
|
||||||
|
|
||||||
|
return
|
||||||
|
for exp in get_model('clinic.hd.case.expense').search_browse(dom):
|
||||||
exp_ids.append(exp.id)
|
exp_ids.append(exp.id)
|
||||||
#TODO Checking
|
#TODO Checking
|
||||||
obj.write({
|
obj.write({
|
||||||
'expenes': [('add',exp_ids)]
|
'expenes': [('add',exp_ids)]
|
||||||
})
|
})
|
||||||
|
@ -42,4 +144,21 @@ class MatchingPayment(Model):
|
||||||
'flash': 'Succesfully',
|
'flash': 'Succesfully',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def onchange_date(self,context={}):
|
||||||
|
data=context['data']
|
||||||
|
date=data['date']
|
||||||
|
year,month,day=date.split("-")
|
||||||
|
weekday, total_day=monthrange(int(year), int(month))
|
||||||
|
data['date_from']="%s-%s-01"%(year,month)
|
||||||
|
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def onchange_ptype(self,context={}):
|
||||||
|
data=context['data']
|
||||||
|
type_id=data['patient_type_id']
|
||||||
|
if type_id:
|
||||||
|
t=get_model('clinic.patient.type').browse(type_id)
|
||||||
|
data['pcode']=t.code or ""
|
||||||
|
return data
|
||||||
|
|
||||||
MatchingPayment.register()
|
MatchingPayment.register()
|
||||||
|
|
|
@ -67,14 +67,14 @@ class ReportPaymentMatching(Model):
|
||||||
|
|
||||||
fname=obj.file
|
fname=obj.file
|
||||||
#pks
|
#pks
|
||||||
if obj.type_id.code=='S':
|
if obj.type_id.code=='SSO':
|
||||||
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")
|
||||||
fpath=get_file_path(fname)
|
fpath=get_file_path(fname)
|
||||||
lines=utils.read_excel(fpath,show_datetime=True)
|
lines=utils.read_excel(fpath,show_datetime=True)
|
||||||
|
|
||||||
elif obj.type_id.code=='U':
|
elif obj.type_id.code=='UC':
|
||||||
fpath=get_file_path(fname)
|
fpath=get_file_path(fname)
|
||||||
node='HDBills'
|
node='HDBills'
|
||||||
lines=utils.read_xml(fpath,node=node)
|
lines=utils.read_xml(fpath,node=node)
|
||||||
|
@ -99,7 +99,7 @@ class ReportPaymentMatching(Model):
|
||||||
})
|
})
|
||||||
if not matches.get(exp.date):
|
if not matches.get(exp.date):
|
||||||
patient=exp.patient_id
|
patient=exp.patient_id
|
||||||
if obj.type_id.code=='S':
|
if obj.type_id.code=='SSO':
|
||||||
key='%s:%s:%s:%s:%s'%(
|
key='%s:%s:%s:%s:%s'%(
|
||||||
patient.hn_no,
|
patient.hn_no,
|
||||||
exp.date,
|
exp.date,
|
||||||
|
|
Loading…
Reference in New Issue