matching payment
parent
7c63f06d96
commit
77bca62fcc
|
@ -1,17 +1,21 @@
|
|||
<form model="clinic.invoice.payment" attrs='{"readonly":[["state","=","approved"]]}'>
|
||||
<form model="clinic.invoice.payment" attrs='{"readonly":[["state","!=","draft"]]}'>
|
||||
<head>
|
||||
<field name="state"/>
|
||||
<!--<button string="Print" action="print" icon="print"/>-->
|
||||
<button string="Options" dropdown="2">
|
||||
<item string="To Draft" method="to_draft" states="approved"/>
|
||||
<item string="To Draft" method="to_draft" states="approved,done"/>
|
||||
<item string="View Payment" method="view_payment" states="done"/>
|
||||
</button>
|
||||
</head>
|
||||
<field name="name" span="3"/>
|
||||
<group form_layout="stacked">
|
||||
<field name="name" span="3"/>
|
||||
<field name="partner_id" span="4" required="1"/>
|
||||
</group>
|
||||
<tabs>
|
||||
<tab string="General">
|
||||
<field name="lines" nolabel="1" count="0" attrs='{"readonly":[["state","in",["waiting_approve","approved"]]]}'>
|
||||
<field name="lines" nolabel="1" count="0">
|
||||
<list>
|
||||
<field name="matching_id" domain='[["state","=","approved"]]' onchange="onchange_matching"/>
|
||||
<field name="matching_id" domain='[["state","=","approved"],["partner_id","=",parent.partner_id]]' onchange="onchange_matching"/>
|
||||
<field name="epo"/>
|
||||
<field name="srv"/>
|
||||
<field name="fee"/>
|
||||
|
@ -33,7 +37,8 @@
|
|||
</tabs>
|
||||
<foot>
|
||||
<button string="Submit To Approve" method="submit" states="draft" type="default" icon="arrow-right"/>
|
||||
<button string="Approve" method="approve" states="waiting_approve" type="success"/>
|
||||
<button string="Approve" method="approve" states="waiting_approve" type="success" icon="ok"/>
|
||||
<button string="Reject" method="reject" states="waiting_approve" type="danger" icon="remove"/>
|
||||
<button string="Send To Payment" method="send_to_payment" states="approved" type="default" icon="arrow-right"/>
|
||||
</foot>
|
||||
</form>
|
||||
|
|
|
@ -18,6 +18,8 @@ class InvoicePayment(Model):
|
|||
for line in obj.lines:
|
||||
matching=line.matching_id
|
||||
for mline in matching.lines:
|
||||
if mline.state!='match':
|
||||
continue
|
||||
fee=mline.fee or 0
|
||||
total+=fee
|
||||
total_fee+=fee
|
||||
|
@ -45,6 +47,8 @@ class InvoicePayment(Model):
|
|||
'state': fields.Selection([['draft','Draft'],['waiting_approve','Waiting Approval'],['approved','Approved'],['done','Done']],'State'),
|
||||
'date': fields.Date("Date"),
|
||||
'user_id': fields.Many2One("base.user","Approver"),
|
||||
'partner_id': fields.Many2One("partner","Contact"),
|
||||
'payment_id': fields.Many2One("account.payment","Payment"),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
|
@ -57,38 +61,43 @@ class InvoicePayment(Model):
|
|||
for obj in self.browse(ids):
|
||||
res=obj.make_payment()
|
||||
count+=1
|
||||
if res<=1:
|
||||
obj.write({
|
||||
'state': 'done',
|
||||
})
|
||||
# support list view
|
||||
if count<=1:
|
||||
return res
|
||||
|
||||
def approve(self,ids,context={}):
|
||||
for obj in self.browse(ids):
|
||||
obj.write({
|
||||
'state': 'approve',
|
||||
'state': 'approved',
|
||||
'user_id': get_active_user(),
|
||||
})
|
||||
|
||||
def make_payment(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
lines=[]
|
||||
invoice_lines=[]
|
||||
for line in obj.lines:
|
||||
matches=line.matching_id
|
||||
for match in matches:
|
||||
invoice=match.invoice_id
|
||||
if invoice:
|
||||
for mline in line.matching_id.lines:
|
||||
invoice=mline.invoice_id
|
||||
state=mline.state
|
||||
if invoice and state=='match':
|
||||
vals={
|
||||
'invoice_id': invoice.id,
|
||||
'amount': invoice.amount_due or 0,
|
||||
}
|
||||
lines.append(('create', vals))
|
||||
if not lines:
|
||||
invoice_lines.append(('create', vals))
|
||||
if not invoice_lines:
|
||||
raise Exception("Nothing to approve")
|
||||
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]
|
||||
partner=obj.patient_type_id.contact_id
|
||||
partner=obj.partner_id
|
||||
company_id=get_active_company()
|
||||
datenow=obj.date or time.strftime("%Y-%m-%d")
|
||||
memo='Payment; %s'%(partner.name)
|
||||
vals={
|
||||
"partner_id": partner.id,
|
||||
"company_id": company_id,
|
||||
|
@ -96,10 +105,14 @@ class InvoicePayment(Model):
|
|||
"pay_type": "invoice",
|
||||
'date': datenow,
|
||||
"account_id": st.import_account_id.id,
|
||||
'invoice_lines': [],
|
||||
'invoice_lines': invoice_lines,
|
||||
'rd_cust': True, #XXX
|
||||
'memo': memo,
|
||||
}
|
||||
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
||||
obj.write({
|
||||
'payment_id': payment_id,
|
||||
})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'payment',
|
||||
|
@ -160,4 +173,24 @@ class InvoicePayment(Model):
|
|||
def post_invoice(self,ids,context={}):
|
||||
print("post_invoice")
|
||||
|
||||
def reject(self,ids,context={}):
|
||||
# send msg to user
|
||||
for obj in self.browse(ids):
|
||||
obj.write({
|
||||
'state': 'draft',
|
||||
})
|
||||
|
||||
def view_payment(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
payment_id=None
|
||||
if obj.payment_id:
|
||||
payment_id=obj.payment_id.id
|
||||
return {
|
||||
'next': {
|
||||
'name': 'payment',
|
||||
'mode': 'form',
|
||||
'active_id': payment_id,
|
||||
},
|
||||
}
|
||||
|
||||
InvoicePayment.register()
|
||||
|
|
|
@ -11,6 +11,14 @@ class MatchingPayment(Model):
|
|||
_name="clinic.matching.payment"
|
||||
_transient=True
|
||||
|
||||
def _get_store(self,ids,context={}):
|
||||
res={}
|
||||
for obj in self.browse(ids):
|
||||
partner=obj.patient_type_id.contact_id
|
||||
res[obj.id]={
|
||||
'partner_id': partner.id,
|
||||
}
|
||||
return res
|
||||
|
||||
def _get_all(self,ids,context={}):
|
||||
res={}
|
||||
|
@ -20,6 +28,8 @@ class MatchingPayment(Model):
|
|||
total_srv=0
|
||||
total_epo=0
|
||||
for line in obj.lines:
|
||||
if line.state!='match':
|
||||
continue
|
||||
total_fee+=line.fee or 0
|
||||
total_srv+=line.srv or 0
|
||||
total_epo+=line.epo or 0
|
||||
|
@ -43,6 +53,7 @@ class MatchingPayment(Model):
|
|||
"date_to": fields.Date("To", required=True),
|
||||
'file': fields.File("File"),
|
||||
'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
|
||||
'partner_id': fields.Many2One("partner","Contact", function="_get_store", function_multi=True, store=True),
|
||||
'pcode': fields.Char("Code",required=True),
|
||||
'hcode_id': fields.Many2One("clinic.hospital","HCode"),
|
||||
'lines': fields.One2Many("clinic.matching.payment.line","match_id", "Lines"),
|
||||
|
@ -493,5 +504,13 @@ class MatchingPayment(Model):
|
|||
'state': 'draft',
|
||||
})
|
||||
|
||||
def create(self,vals,**kw):
|
||||
new_id=super().create(vals,**kw)
|
||||
self.function_store([new_id])
|
||||
return new_id
|
||||
|
||||
def write(self,ids,vals,**kw):
|
||||
super().write(ids,vals,**kw)
|
||||
self.function_store(ids)
|
||||
|
||||
MatchingPayment.register()
|
||||
|
|
Loading…
Reference in New Issue