diff --git a/netforce_clinic/layouts/clinic_input_data_form.xml b/netforce_clinic/layouts/clinic_input_data_form.xml
new file mode 100644
index 0000000..89d5e99
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_input_data_form.xml
@@ -0,0 +1,6 @@
+
diff --git a/netforce_clinic/layouts/clinic_input_data_list.xml b/netforce_clinic/layouts/clinic_input_data_list.xml
new file mode 100644
index 0000000..e883d03
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_input_data_list.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_je_form.xml b/netforce_clinic/layouts/clinic_je_form.xml
index 8d25b1e..310e89a 100644
--- a/netforce_clinic/layouts/clinic_je_form.xml
+++ b/netforce_clinic/layouts/clinic_je_form.xml
@@ -31,7 +31,13 @@
-
+
+
+
+
+
+
+
@@ -41,10 +47,10 @@
-
-
-
-
+
+
+
+
@@ -61,6 +67,5 @@
-
diff --git a/netforce_clinic/models/input_data.py b/netforce_clinic/models/input_data.py
index fa3a061..c739a0e 100644
--- a/netforce_clinic/models/input_data.py
+++ b/netforce_clinic/models/input_data.py
@@ -4,7 +4,7 @@ class InputData(Model):
_name="clinic.input.data"
_string="Input Data"
_fields={
- 'doc_date': fields.Char("Doc Date"),
+ 'doc_date': fields.Date("Doc Date"),
'name': fields.Char("Name"),
'hn': fields.Char("HN"),
'amount': fields.Float("Amount"),
diff --git a/netforce_clinic/models/je.py b/netforce_clinic/models/je.py
index 1ed389a..af9722d 100644
--- a/netforce_clinic/models/je.py
+++ b/netforce_clinic/models/je.py
@@ -1,7 +1,9 @@
import time
import xlrd
+from datetime import datetime
from netforce.model import Model, fields, get_model
+from netforce.access import get_active_company
from netforce.access import get_active_user, set_active_user
from netforce.utils import get_file_path
from netforce.utils import get_data_path
@@ -110,23 +112,81 @@ class JE(Model):
ws=wb.sheet_by_name(sheet_name)
num_rows = ws.nrows - 1
curr_row = -1
- records=[]
- import pprint
+ input_data=[]
while curr_row < num_rows:
curr_row += 1
+ # skip header
+ if curr_row <=1:
+ continue
#row=ws.row(curr_row)
- record={}
# XXX
- for col in (1,2,3,4):
- record[col]=ws.cell_value(curr_row, col)
- records.append(record)
- pprint.pprint(records)
+ doc_date=ws.cell_value(curr_row, 0)
+ doc_date=datetime(*xlrd.xldate_as_tuple(doc_date, wb.datemode))
+ doc_date=doc_date.strftime("%Y-%m-%d")
+ data={
+ 'doc_date':doc_date,
+ 'name':ws.cell_value(curr_row, 1),
+ 'hn':ws.cell_value(curr_row, 2),
+ 'amount':ws.cell_value(curr_row, 3),
+ }
+ input_data.append(('create',data))
+ data_ids=[data.id for data in obj.input_data]
+ get_model("clinic.input.data").delete(data_ids)
+ obj.write({
+ 'input_data': input_data,
+ 'description': 'see preview',
+ })
+
+
+ def clear_data(self,ids,context={}):
+ obj=self.browse(ids[0])
+ data_ids=[data.id for data in obj.input_data]
+ get_model("clinic.input.data").delete(data_ids)
def find_invoice(self,ids,context={}):
- pass
+ obj=self.browse(ids[0])
+ partner_id=None
+ setting=get_model("clinic.setting").browse(1)
+ if obj.type=='sc':
+ partner_id=setting.sc_partner_id.id
+ elif obj.type=='mg':
+ partner_id=setting.mg_partner_id.id
+ elif obj.type=='nhso':
+ partner_id=setting.nhso_partner_id.id
+ if not partner_id:
+ raise Exception("No partner")
- def import2journal(self,ids,context={}):
- pass
+ # XXX
+ if obj.lines:
+ for line in obj.lines:
+ line.delete()
+ dom=[]
+ dom.append(['state','=','waiting_payment'])
+ dom.append(['partner_id','=',partner_id])
+ lines=[]
+ for invoice in get_model("account.invoice").search_browse(dom):
+ print(invoice.id, " ", invoice.number, " ", invoice.amount_total),
+ line={
+ 'invoice_id': invoice.id,
+ 'amount': invoice.amount_total,
+ }
+ lines.append(('create',line))
+ obj.write({
+ 'lines': lines,
+ })
+ return {
+ 'next': {
+ 'name': 'clinic_je',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },
+ 'flash':'Load invoice OK!',
+ }
+
+ def post_payment(self,ids,context={}):
+ obj=self.browse(ids[0])
+ if not obj.lines:
+ raise Exception("No invoice to post")
def onchange_sheet(self,context={}):
data=context["data"]
@@ -136,5 +196,60 @@ class JE(Model):
if sheet['name']!=line['name']:
sheet['select']=None
return data
+
+ def make_payment(self,ids,context={}):
+ obj=self.browse(ids[0])
+ if obj.payment_id:
+ if obj.lines:
+ if obj.payment_id.invoice_lines:
+ return
+ vals={
+ 'invoice_lines':[],
+ }
+ for line in obj.lines:
+ line={
+ 'invoice_id': line.invoice_id.id,
+ 'amount': line.amount,
+ }
+ vals['invoice_lines'].append(('create',line))
+ obj.payment_id.write(vals)
+ print("add invoice to payment")
+ return
+ company_id=get_active_company()
+ timenow=time.strftime("%Y-%m-%d")
+ setting=get_model("clinic.setting").browse(1)
+ account_id=None
+ partner_id=None
+ if obj.type=='sc':
+ account_id=setting.ar_sc_id.id
+ partner_id=setting.sc_partner_id.id
+ elif obj.type=='mg':
+ account_id=setting.ar_mg_id.id
+ partner_id=setting.mg_partner_id.id
+ elif obj.type=='nhso':
+ account_id=setting.ar_nhso_id.id
+ partner_id=setting.nhso_partner_id.id
+ vals={
+ "partner_id": partner_id,
+ "company_id": company_id,
+ "type": "in",
+ "pay_type": "invoice",
+ "date": timenow,
+ "account_id": account_id,
+ 'lines': [], # TODO find invoice matching
+ }
+ payment_id=get_model("account.payment").create(vals,context={'type': 'in'})
+ obj.write({
+ 'payment_id': payment_id,
+ })
+
+ return {
+ 'next': {
+ 'name': 'clinic_je',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },
+ 'flash': "Make payment ok !",
+ }
JE.register()