add action to create invoice payment
parent
5b75d5fda0
commit
421ec99363
|
@ -0,0 +1,6 @@
|
||||||
|
<action>
|
||||||
|
<field name="view_cls">form_view</field>
|
||||||
|
<field name="model">create.invoice.payment</field>
|
||||||
|
<field name="view_xml">create_invoice_payment_form</field>
|
||||||
|
<field name="menu">account_menu</field>
|
||||||
|
</action>
|
|
@ -0,0 +1,16 @@
|
||||||
|
<form model="clinic.hd.case.payment">
|
||||||
|
<field name="hd_case_id" invisible="1"/>
|
||||||
|
<field name="bill_no"/>
|
||||||
|
<field name="pay_amount" onchange="onchange_amount"/>
|
||||||
|
<newline/>
|
||||||
|
<field name="to_pay" readonly="1"/>
|
||||||
|
<newline/>
|
||||||
|
<group attrs='{"invisible":[["pay_amount","=",0]]}'>
|
||||||
|
<field name="complete" help="Mark as complete"/>
|
||||||
|
</group>
|
||||||
|
<foot>
|
||||||
|
<button attrs='{"invisible":[["pay_amount","=",0]]}' string="Cash" type="success" icon="ok" method="cash" confirm="Are you sure?"/>
|
||||||
|
<button attrs='{"invisible":[["pay_amount","=",0]]}' string="Credit" type="default" icon="check" method="credit"/>
|
||||||
|
<button attrs='{"invisible":[["pay_amount","!=",0]]}' string="OK" type="success" icon="ok" method="credit"/>
|
||||||
|
</foot>
|
||||||
|
</form>
|
|
@ -1,5 +0,0 @@
|
||||||
<inherit model="account.payment" inherit="payment_form">
|
|
||||||
<item string="Copy" position="after">
|
|
||||||
<item string="Import Payment (UC)" method="import_payment"/>
|
|
||||||
</item>
|
|
||||||
</inherit>
|
|
|
@ -1,16 +1,5 @@
|
||||||
<form model="clinic.hd.case.payment">
|
<inherit inherit="payment_form">
|
||||||
<field name="hd_case_id" invisible="1"/>
|
<item string="Copy" position="after">
|
||||||
<field name="bill_no"/>
|
<item string="Import Payment (UC)" method="import_payment"/>
|
||||||
<field name="pay_amount" onchange="onchange_amount"/>
|
</item>
|
||||||
<newline/>
|
</inherit>
|
||||||
<field name="to_pay" readonly="1"/>
|
|
||||||
<newline/>
|
|
||||||
<group attrs='{"invisible":[["pay_amount","=",0]]}'>
|
|
||||||
<field name="complete" help="Mark as complete"/>
|
|
||||||
</group>
|
|
||||||
<foot>
|
|
||||||
<button attrs='{"invisible":[["pay_amount","=",0]]}' string="Cash" type="success" icon="ok" method="cash" confirm="Are you sure?"/>
|
|
||||||
<button attrs='{"invisible":[["pay_amount","=",0]]}' string="Credit" type="default" icon="check" method="credit"/>
|
|
||||||
<button attrs='{"invisible":[["pay_amount","!=",0]]}' string="OK" type="success" icon="ok" method="credit"/>
|
|
||||||
</foot>
|
|
||||||
</form>
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<form model="create.invoice.payment">
|
||||||
|
<head>
|
||||||
|
<field name="state"/>
|
||||||
|
</head>
|
||||||
|
<field name="date" mode="month" onchange="onchange_date" span="3"/>
|
||||||
|
<field name="date_from" span="3"/>
|
||||||
|
<field name="date_to" span="3"/>
|
||||||
|
<newline/>
|
||||||
|
<field name="partner_id" span="3"/>
|
||||||
|
<field name="account_id" domain='[["type","!=","view"]]' states="ready_payment" span="3"/>
|
||||||
|
<related>
|
||||||
|
<field name="invoices"/>
|
||||||
|
</related>
|
||||||
|
<foot replace="1">
|
||||||
|
<button string="Back" states="ready_payment" method="back_step" type="default" icon="arrow-left"/>
|
||||||
|
<button string="Next" method="do_next" type="primary" icon="arrow-right"/>
|
||||||
|
</foot>
|
||||||
|
</form>
|
|
@ -0,0 +1,14 @@
|
||||||
|
<list model="account.payment">
|
||||||
|
<top>
|
||||||
|
<button string="Create Invoice Payment" action="create_invoice_payment"/>
|
||||||
|
</top>
|
||||||
|
<field name="number"/>
|
||||||
|
<field name="date"/>
|
||||||
|
<field name="partner_id"/>
|
||||||
|
<field name="type"/>
|
||||||
|
<field name="pay_type"/>
|
||||||
|
<field name="account_id"/>
|
||||||
|
<field name="ref"/>
|
||||||
|
<field name="amount_total"/>
|
||||||
|
<field name="state"/>
|
||||||
|
</list>
|
|
@ -144,3 +144,4 @@ from . import account_move_line
|
||||||
from . import invoice_payment
|
from . import invoice_payment
|
||||||
from . import document
|
from . import document
|
||||||
from . import payment_matching
|
from . import payment_matching
|
||||||
|
from . import create_invoice_payment
|
||||||
|
|
|
@ -30,6 +30,7 @@ class AccountInvoice(Model):
|
||||||
'patient_partner_id': fields.Many2One("partner","Partner Patient",search=True),
|
'patient_partner_id': fields.Many2One("partner","Partner Patient",search=True),
|
||||||
'patient_id': fields.Many2One("clinic.patient","Patient",function="_get_patient", function_multi=True,store=True,search=True),
|
'patient_id': fields.Many2One("clinic.patient","Patient",function="_get_patient", function_multi=True,store=True,search=True),
|
||||||
'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",function="_get_patient", function_multi=True,store=True,search=True),
|
'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",function="_get_patient", function_multi=True,store=True,search=True),
|
||||||
|
'create_invoice_id': fields.Many2One("create.invoice.payment","Create Invoice Payment"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_number(self,context={}):
|
def _get_number(self,context={}):
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
import time
|
||||||
|
from calendar import monthrange
|
||||||
|
|
||||||
|
from netforce.model import Model, fields , get_model
|
||||||
|
from netforce.database import get_connection
|
||||||
|
|
||||||
|
class CreateInvoicePayment(Model):
|
||||||
|
_name="create.invoice.payment"
|
||||||
|
_transient=True
|
||||||
|
|
||||||
|
_fields={
|
||||||
|
"date": fields.Date("Month", required=True),
|
||||||
|
'date_from': fields.Date("From",required=True),
|
||||||
|
'date_to': fields.Date("To",required=True),
|
||||||
|
'partner_id': fields.Many2One("partner","Contact",required=True),
|
||||||
|
'invoices': fields.One2Many("account.invoice","create_invoice_id","Invoices"),
|
||||||
|
'state': fields.Selection([["find_invoice","Find Invoice"],["ready_payment","Ready Payment"]],'State'),
|
||||||
|
'account_id': fields.Many2One("account.account","Account"),
|
||||||
|
}
|
||||||
|
|
||||||
|
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={
|
||||||
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||||||
|
'date_from': _get_date_from,
|
||||||
|
'date_to': _get_date_to,
|
||||||
|
'state': 'find_invoice',
|
||||||
|
}
|
||||||
|
|
||||||
|
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 back_step(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
state='find_invoice'
|
||||||
|
if obj.state=='ready_payment':
|
||||||
|
db=get_connection()
|
||||||
|
res=db.query("""
|
||||||
|
select id from account_invoice where create_invoice_id=%s
|
||||||
|
""",obj.id)
|
||||||
|
if res:
|
||||||
|
inv_ids=[r['id'] for r in res]
|
||||||
|
db.execute("update account_invoice set create_invoice_id=null where id in %s",tuple(inv_ids))
|
||||||
|
|
||||||
|
obj.write({
|
||||||
|
'state': state,
|
||||||
|
})
|
||||||
|
|
||||||
|
def find_invoice(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
obj.write({
|
||||||
|
'state': 'ready_payment',
|
||||||
|
})
|
||||||
|
db=get_connection()
|
||||||
|
res=db.query("""
|
||||||
|
select id from account_invoice where create_invoice_id=%s
|
||||||
|
""",obj.id)
|
||||||
|
if res:
|
||||||
|
inv_ids=[r['id'] for r in res]
|
||||||
|
db.execute("update account_invoice set create_invoice_id=null where id in %s",tuple(inv_ids))
|
||||||
|
|
||||||
|
res=db.query("""
|
||||||
|
select id from account_invoice where date>=%s and date <=%s and state='waiting_payment'
|
||||||
|
and partner_id=%s
|
||||||
|
""",obj.date_from, obj.date_to,obj.partner_id.id)
|
||||||
|
if res:
|
||||||
|
inv_ids=[r['id'] for r in res]
|
||||||
|
db.execute("update account_invoice set create_invoice_id=%s where id in %s",obj.id,tuple(inv_ids))
|
||||||
|
|
||||||
|
|
||||||
|
def create_payment(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
if not obj.account_id:
|
||||||
|
raise Exception("Missing account")
|
||||||
|
if not obj.invoices:
|
||||||
|
raise Exception("Nothing to pay!")
|
||||||
|
partner=obj.partner_id
|
||||||
|
type="in"
|
||||||
|
vals={
|
||||||
|
'type': type, # receivable
|
||||||
|
'account_id': obj.account_id.id,
|
||||||
|
'partner_id': partner.id,
|
||||||
|
'pay_type': 'invoice',
|
||||||
|
'invoice_lines': [],
|
||||||
|
}
|
||||||
|
datenow=time.strftime("%Y-%m-%d")
|
||||||
|
rate_type="sell" # receivable
|
||||||
|
settings=get_model("settings").browse(1)
|
||||||
|
currency=settings.currency_id
|
||||||
|
if not currency:
|
||||||
|
raise Exception("Missing setting.currency")
|
||||||
|
for inv in obj.invoices:
|
||||||
|
vals['invoice_lines'].append(('create',{
|
||||||
|
'invoice_id': inv.id,
|
||||||
|
"amount": get_model("currency").convert(inv.amount_due,inv.currency_id.id,currency.id,date=datenow,rate_type=rate_type),
|
||||||
|
}))
|
||||||
|
ctx={
|
||||||
|
'type': type,
|
||||||
|
}
|
||||||
|
payment_id=get_model("account.payment").create(vals,context=ctx)
|
||||||
|
return {
|
||||||
|
'next': {
|
||||||
|
'name': 'payment',
|
||||||
|
'mode': 'form',
|
||||||
|
'active_id': payment_id,
|
||||||
|
},
|
||||||
|
'flash': 'Create Payment Successfull',
|
||||||
|
}
|
||||||
|
|
||||||
|
def do_next(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
if obj.state=='find_invoice':
|
||||||
|
obj.find_invoice()
|
||||||
|
elif obj.state=='ready_payment':
|
||||||
|
res=obj.create_payment()
|
||||||
|
return res
|
||||||
|
|
||||||
|
CreateInvoicePayment.register()
|
|
@ -24,7 +24,7 @@ class Partner(Model):
|
||||||
vals.append((obj.id,name))
|
vals.append((obj.id,name))
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
def name_search(self,name,domain=None,condition=[],context={},**kw):
|
def _name_search(self,name,domain=None,condition=[],context={},**kw):
|
||||||
dom=[["name","ilike","%"+name+"%"]]
|
dom=[["name","ilike","%"+name+"%"]]
|
||||||
if domain:
|
if domain:
|
||||||
dom=[dom,domain]
|
dom=[dom,domain]
|
||||||
|
|
Loading…
Reference in New Issue