diff --git a/netforce_clinic/actions/clinic_hdcase_invoice_print.xml b/netforce_clinic/actions/clinic_hdcase_invoice_print.xml
new file mode 100644
index 0000000..217d76c
--- /dev/null
+++ b/netforce_clinic/actions/clinic_hdcase_invoice_print.xml
@@ -0,0 +1,6 @@
+
+ report_odt2
+ account.invoice
+ get_invoice_data
+ cust_invoice
+
diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml
index 0e95784..0a6e647 100644
--- a/netforce_clinic/layouts/clinic_hd_case_form.xml
+++ b/netforce_clinic/layouts/clinic_hd_case_form.xml
@@ -128,6 +128,9 @@
+
+
+
diff --git a/netforce_clinic/models/account_invoice.py b/netforce_clinic/models/account_invoice.py
index 44d1c39..82bf4e2 100644
--- a/netforce_clinic/models/account_invoice.py
+++ b/netforce_clinic/models/account_invoice.py
@@ -1,6 +1,10 @@
import time
from netforce.model import Model, fields, get_model
+from netforce.utils import get_file_path
+from netforce.access import get_active_company, get_active_user
+
+from . import utils
class AccountInvoice(Model):
_inherit="account.invoice"
@@ -310,4 +314,126 @@ class AccountInvoice(Model):
dt=(t1-t0)*1000
print("invoice.post <<< %d ms"%dt)
+
+
+ def get_invoice_data(self,ids,context={}):
+ settings=get_model('settings').browse(1)
+ pages=[]
+ for obj in self.browse(ids):
+ context['refer_id']=obj.id
+ data=self.get_invoice_page(context=context)
+ limit_item=10
+ if data['state']=='draft':
+ limit_item-=3
+ for i in range(len(data['lines']),limit_item):
+ data['lines'].append({
+ 'no': '',
+ 'product_name': '',
+ 'description': '',
+ 'uom_name': '',
+ 'qty': None,
+ 'price': None,
+ 'amount': None,
+ })
+ pages.append(data)
+ if pages:
+ pages[-1]["is_last_page"]=True
+ return {
+ "pages": pages,
+ "logo": get_file_path(settings.logo),
+ }
+
+ def get_invoice_page(self,context={}):
+ if not context.get('refer_id'):
+ return {}
+ inv_id=int(context['refer_id'])
+ inv=self.browse(inv_id)
+ comp_id=get_active_company()
+ comp=get_model('company').browse(comp_id)
+ context['branch_id']=inv.department_id.branch_id.id
+ st=get_model('settings').browse(1,context=context)
+ cst=get_model('clinic.setting').browse(1)
+ cust=inv.partner_id
+ cust_tax_no=cust.tax_no or ''
+ cust_name=cust.name or ''
+ cust_addr=''
+ if cust.addresses:
+ cust_addr=cust.addresses[0].address_text
+ if 'your' in cust_addr:
+ cust_addr=''
+ no=1
+ sub_total=0
+ amount_total=0
+ lines=[]
+ for line in inv.lines:
+ amt=line.amount or 0
+ prod=line.product_id
+ lines.append({
+ 'no': no,
+ 'product_name': prod.name or '',
+ 'description': line.description or '',
+ 'uom_name': prod.uom_id.name or '',
+ 'qty': line.qty or 0,
+ 'price': line.price or 0,
+ 'amount': amt,
+ })
+ sub_total+=amt
+ no+=1
+ amount_total=sub_total
+ is_draft=inv.state=='draft' and True or False
+ is_cheque=False
+ user_id=get_active_user()
+ user=get_model("base.user").browse(user_id)
+ comp_name=comp.name or ""
+ if st.default_address_id.company:
+ comp_name=st.default_address_id.company or ""
+ payment_terms=''
+ currency_code=''
+ due_date=inv.due_date
+ number=inv.number or ""
+ ref=inv.ref or ""
+ payment_terms=inv.payment_terms or ""
+ currency_code=inv.currency_id.code or ""
+ due_date=inv.due_date
+ add=st.default_address_id
+ data={
+ 'partner_name': cust_name,
+ 'partner_address': cust_addr,
+ 'partner_tax_no': cust_tax_no,
+ 'due_date': due_date,
+ 'currency_code': currency_code,
+ 'payment_terms': payment_terms,
+ 'comp_name': comp_name,
+ 'add_address': add.address or '',
+ 'add_address2': add.address2 or '',
+ 'add_province_name': add.province_id.name or '',
+ 'add_district_name': add.district_id.name or '',
+ 'add_subdistrict_name': add.subdistrict_id.name or '',
+ 'add_city': add.city or '',
+ 'add_postal_code': add.postal_code or '',
+ 'add_phone': add.phone or '',
+ 'add_fax': add.fax or '',
+ 'tax_no': st.tax_no or '',
+ 'number': number,
+ 'ref': ref,
+ 'date': inv.date,
+ 'datenow': inv.date or time.strftime("%d/%m/%Y"),
+ 'dateprint': inv.date or time.strftime("%d/%m/%Y %H:%M:%S"),
+ 'note': inv.note or '',
+ 'lines':lines,
+ 'amount_subtotal': sub_total,
+ 'amount_total': amount_total,
+ 'total_text': utils.num2word(amount_total),
+ 'is_cheque': is_cheque,
+ 'is_draft': is_draft,
+ 'user_name': user.name or "",
+ 'state': inv.state or "",
+ }
+ data['pay_type']='Credit'
+ if st.logo:
+ data['logo']=get_file_path(st.logo)
+ if cst.signature:
+ data['signature']=get_file_path(cst.signature)
+ return data
+
AccountInvoice.register()
diff --git a/netforce_clinic/reports/cust_invoice.odt b/netforce_clinic/reports/cust_invoice.odt
index 5bc494e..17429e7 100644
Binary files a/netforce_clinic/reports/cust_invoice.odt and b/netforce_clinic/reports/cust_invoice.odt differ