diff --git a/netforce_clinic/layouts/clinic_invoice_payment_form.xml b/netforce_clinic/layouts/clinic_invoice_payment_form.xml index c8f4f17..60305fe 100644 --- a/netforce_clinic/layouts/clinic_invoice_payment_form.xml +++ b/netforce_clinic/layouts/clinic_invoice_payment_form.xml @@ -1,17 +1,21 @@ -
diff --git a/netforce_clinic/models/invoice_payment.py b/netforce_clinic/models/invoice_payment.py index 5504c21..7210130 100644 --- a/netforce_clinic/models/invoice_payment.py +++ b/netforce_clinic/models/invoice_payment.py @@ -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', @@ -159,5 +172,25 @@ 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() diff --git a/netforce_clinic/models/matching_payment.py b/netforce_clinic/models/matching_payment.py index 8aeba9e..f243608 100644 --- a/netforce_clinic/models/matching_payment.py +++ b/netforce_clinic/models/matching_payment.py @@ -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()