diff --git a/netforce_clinic/actions/create_invoice_payment.xml b/netforce_clinic/actions/create_invoice_payment.xml
new file mode 100644
index 0000000..fdc68e6
--- /dev/null
+++ b/netforce_clinic/actions/create_invoice_payment.xml
@@ -0,0 +1,6 @@
+
+ form_view
+ create.invoice.payment
+ create_invoice_payment_form
+ account_menu
+
diff --git a/netforce_clinic/layouts/clinic_hdcase_payment_form.xml b/netforce_clinic/layouts/clinic_hdcase_payment_form.xml
new file mode 100644
index 0000000..398842b
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_hdcase_payment_form.xml
@@ -0,0 +1,16 @@
+
diff --git a/netforce_clinic/layouts/clinic_import_payment_form.xml b/netforce_clinic/layouts/clinic_import_payment_form.xml
deleted file mode 100644
index 3b0f39d..0000000
--- a/netforce_clinic/layouts/clinic_import_payment_form.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
- -
-
-
-
diff --git a/netforce_clinic/layouts/clinic_payment_form.xml b/netforce_clinic/layouts/clinic_payment_form.xml
index 398842b..5ccf627 100644
--- a/netforce_clinic/layouts/clinic_payment_form.xml
+++ b/netforce_clinic/layouts/clinic_payment_form.xml
@@ -1,16 +1,5 @@
-
+
+ -
+
+
+
diff --git a/netforce_clinic/layouts/create_invoice_payment_form.xml b/netforce_clinic/layouts/create_invoice_payment_form.xml
new file mode 100644
index 0000000..fea299a
--- /dev/null
+++ b/netforce_clinic/layouts/create_invoice_payment_form.xml
@@ -0,0 +1,18 @@
+
diff --git a/netforce_clinic/layouts/payment_list.xml b/netforce_clinic/layouts/payment_list.xml
new file mode 100644
index 0000000..740a2e0
--- /dev/null
+++ b/netforce_clinic/layouts/payment_list.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index a12468c..749868c 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -144,3 +144,4 @@ from . import account_move_line
from . import invoice_payment
from . import document
from . import payment_matching
+from . import create_invoice_payment
diff --git a/netforce_clinic/models/account_invoice.py b/netforce_clinic/models/account_invoice.py
index 37613aa..fccc873 100644
--- a/netforce_clinic/models/account_invoice.py
+++ b/netforce_clinic/models/account_invoice.py
@@ -30,6 +30,7 @@ class AccountInvoice(Model):
'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_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={}):
diff --git a/netforce_clinic/models/account_payment.py b/netforce_clinic/models/account_payment.py
index 18e13af..329f0a2 100644
--- a/netforce_clinic/models/account_payment.py
+++ b/netforce_clinic/models/account_payment.py
@@ -31,7 +31,7 @@ class AccountPayment(Model):
'number': _get_number,
}
-
+
def run_report(self,ids,context={}):
obj=self.browse(ids)[0]
hd_case_id=obj.related_id.id
diff --git a/netforce_clinic/models/create_invoice_payment.py b/netforce_clinic/models/create_invoice_payment.py
new file mode 100644
index 0000000..1dd284c
--- /dev/null
+++ b/netforce_clinic/models/create_invoice_payment.py
@@ -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()
diff --git a/netforce_clinic/models/partner.py b/netforce_clinic/models/partner.py
index 4d8cf32..844da35 100644
--- a/netforce_clinic/models/partner.py
+++ b/netforce_clinic/models/partner.py
@@ -24,7 +24,7 @@ class Partner(Model):
vals.append((obj.id,name))
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+"%"]]
if domain:
dom=[dom,domain]