matching payment

conv_bal
watcha.h 2015-02-25 22:23:16 +07:00
parent 7c63f06d96
commit 77bca62fcc
3 changed files with 74 additions and 17 deletions

View File

@ -1,17 +1,21 @@
<form model="clinic.invoice.payment" attrs='{"readonly":[["state","=","approved"]]}'> <form model="clinic.invoice.payment" attrs='{"readonly":[["state","!=","draft"]]}'>
<head> <head>
<field name="state"/> <field name="state"/>
<!--<button string="Print" action="print" icon="print"/>--> <!--<button string="Print" action="print" icon="print"/>-->
<button string="Options" dropdown="2"> <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> </button>
</head> </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> <tabs>
<tab string="General"> <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> <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="epo"/>
<field name="srv"/> <field name="srv"/>
<field name="fee"/> <field name="fee"/>
@ -33,7 +37,8 @@
</tabs> </tabs>
<foot> <foot>
<button string="Submit To Approve" method="submit" states="draft" type="default" icon="arrow-right"/> <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"/> <button string="Send To Payment" method="send_to_payment" states="approved" type="default" icon="arrow-right"/>
</foot> </foot>
</form> </form>

View File

@ -18,6 +18,8 @@ class InvoicePayment(Model):
for line in obj.lines: for line in obj.lines:
matching=line.matching_id matching=line.matching_id
for mline in matching.lines: for mline in matching.lines:
if mline.state!='match':
continue
fee=mline.fee or 0 fee=mline.fee or 0
total+=fee total+=fee
total_fee+=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'), 'state': fields.Selection([['draft','Draft'],['waiting_approve','Waiting Approval'],['approved','Approved'],['done','Done']],'State'),
'date': fields.Date("Date"), 'date': fields.Date("Date"),
'user_id': fields.Many2One("base.user","Approver"), 'user_id': fields.Many2One("base.user","Approver"),
'partner_id': fields.Many2One("partner","Contact"),
'payment_id': fields.Many2One("account.payment","Payment"),
} }
_defaults={ _defaults={
@ -57,38 +61,43 @@ class InvoicePayment(Model):
for obj in self.browse(ids): for obj in self.browse(ids):
res=obj.make_payment() res=obj.make_payment()
count+=1 count+=1
if res<=1: obj.write({
'state': 'done',
})
# support list view
if count<=1:
return res return res
def approve(self,ids,context={}): def approve(self,ids,context={}):
for obj in self.browse(ids): for obj in self.browse(ids):
obj.write({ obj.write({
'state': 'approve', 'state': 'approved',
'user_id': get_active_user(), 'user_id': get_active_user(),
}) })
def make_payment(self,ids,context={}): def make_payment(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
lines=[] invoice_lines=[]
for line in obj.lines: for line in obj.lines:
matches=line.matching_id for mline in line.matching_id.lines:
for match in matches: invoice=mline.invoice_id
invoice=match.invoice_id state=mline.state
if invoice: if invoice and state=='match':
vals={ vals={
'invoice_id': invoice.id, 'invoice_id': invoice.id,
'amount': invoice.amount_due or 0, 'amount': invoice.amount_due or 0,
} }
lines.append(('create', vals)) invoice_lines.append(('create', vals))
if not lines: if not invoice_lines:
raise Exception("Nothing to approve") raise Exception("Nothing to approve")
st=get_model("clinic.setting").browse(1) st=get_model("clinic.setting").browse(1)
if not st.import_account_id: if not st.import_account_id:
raise Exception("Import account not found (Ratchawat Setting -> Accounting)") raise Exception("Import account not found (Ratchawat Setting -> Accounting)")
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
partner=obj.patient_type_id.contact_id partner=obj.partner_id
company_id=get_active_company() company_id=get_active_company()
datenow=obj.date or time.strftime("%Y-%m-%d") datenow=obj.date or time.strftime("%Y-%m-%d")
memo='Payment; %s'%(partner.name)
vals={ vals={
"partner_id": partner.id, "partner_id": partner.id,
"company_id": company_id, "company_id": company_id,
@ -96,10 +105,14 @@ class InvoicePayment(Model):
"pay_type": "invoice", "pay_type": "invoice",
'date': datenow, 'date': datenow,
"account_id": st.import_account_id.id, "account_id": st.import_account_id.id,
'invoice_lines': [], 'invoice_lines': invoice_lines,
'rd_cust': True, #XXX 'rd_cust': True, #XXX
'memo': memo,
} }
payment_id=get_model("account.payment").create(vals,context={"type":"in"}) payment_id=get_model("account.payment").create(vals,context={"type":"in"})
obj.write({
'payment_id': payment_id,
})
return { return {
'next': { 'next': {
'name': 'payment', 'name': 'payment',
@ -159,5 +172,25 @@ class InvoicePayment(Model):
def post_invoice(self,ids,context={}): def post_invoice(self,ids,context={}):
print("post_invoice") 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() InvoicePayment.register()

View File

@ -11,6 +11,14 @@ class MatchingPayment(Model):
_name="clinic.matching.payment" _name="clinic.matching.payment"
_transient=True _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={}): def _get_all(self,ids,context={}):
res={} res={}
@ -20,6 +28,8 @@ class MatchingPayment(Model):
total_srv=0 total_srv=0
total_epo=0 total_epo=0
for line in obj.lines: for line in obj.lines:
if line.state!='match':
continue
total_fee+=line.fee or 0 total_fee+=line.fee or 0
total_srv+=line.srv or 0 total_srv+=line.srv or 0
total_epo+=line.epo or 0 total_epo+=line.epo or 0
@ -43,6 +53,7 @@ class MatchingPayment(Model):
"date_to": fields.Date("To", 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),
'partner_id': fields.Many2One("partner","Contact", function="_get_store", function_multi=True, store=True),
'pcode': fields.Char("Code",required=True), 'pcode': fields.Char("Code",required=True),
'hcode_id': fields.Many2One("clinic.hospital","HCode"), 'hcode_id': fields.Many2One("clinic.hospital","HCode"),
'lines': fields.One2Many("clinic.matching.payment.line","match_id", "Lines"), 'lines': fields.One2Many("clinic.matching.payment.line","match_id", "Lines"),
@ -493,5 +504,13 @@ class MatchingPayment(Model):
'state': 'draft', '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() MatchingPayment.register()