clinic/netforce_clinic/models/invoice_payment.py

42 lines
1.3 KiB
Python
Raw Permalink Normal View History

2015-08-13 06:27:46 +00:00
from netforce.model import Model, get_model
2015-02-20 13:10:40 +00:00
2015-02-21 13:38:21 +00:00
class InvoicePayment(Model):
2015-08-13 06:27:46 +00:00
_inherit="invoice.payment"
2015-02-21 13:38:21 +00:00
2015-08-13 06:27:46 +00:00
def add_payment(self,ids,context={}):
2015-02-21 13:38:21 +00:00
obj=self.browse(ids)[0]
2015-08-13 06:27:46 +00:00
inv=obj.invoice_id
if inv.inv_type not in ("invoice","debit"):
raise Exception("Wrong invoice type")
if obj.amount>inv.amount_due:
raise Exception("Amount paid exceeds due amount")
2015-02-21 13:38:21 +00:00
vals={
2015-08-13 06:27:46 +00:00
"type": inv.type=="out" and "in" or "out",
2015-02-21 13:38:21 +00:00
"pay_type": "invoice",
2015-08-13 06:27:46 +00:00
"partner_id": inv.partner_id.id,
"date": obj.date,
"ref": obj.ref,
"account_id": obj.account_id.id,
"currency_id": inv.currency_id.id,
"lines": [("create",{
"type": "invoice",
"invoice_id": inv.id,
"account_id": inv.account_id.id,
"amount": obj.amount,
})],
2015-02-21 13:38:21 +00:00
}
2015-08-13 06:27:46 +00:00
pmt_id=get_model("account.payment").create(vals,context={"type":vals["type"]})
# to check when before payment post
ctx={
'hdcase_reconcile':inv.hdcase_reconcile,
2015-02-20 13:10:40 +00:00
}
2015-08-13 06:27:46 +00:00
get_model("account.payment").post([pmt_id],context=ctx)
2015-02-25 15:23:16 +00:00
return {
2015-08-13 06:27:46 +00:00
"next": {
"name": "view_invoice",
"active_id": inv.id,
}
2015-02-25 15:23:16 +00:00
}
2015-02-20 13:10:40 +00:00
2015-02-21 13:38:21 +00:00
InvoicePayment.register()