print invoice from hd case
							parent
							
								
									8409fc1db7
								
							
						
					
					
						commit
						4fe5529c83
					
				| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
<action>
 | 
			
		||||
    <field name="type">report_odt2</field>
 | 
			
		||||
    <field name="model">account.invoice</field>
 | 
			
		||||
    <field name="method">get_invoice_data</field>
 | 
			
		||||
    <field name="template">cust_invoice</field>
 | 
			
		||||
</action>
 | 
			
		||||
| 
						 | 
				
			
			@ -128,6 +128,9 @@
 | 
			
		|||
    <related>
 | 
			
		||||
        <field name="invoices" click_action="view_invoice">
 | 
			
		||||
        <list colors='{"#9f9":[["state","=","paid"]]}'>
 | 
			
		||||
            <head>
 | 
			
		||||
                <button string="Print" action="clinic_hdcase_invoice_print" action_options="convert=pdf" icon="print"/>
 | 
			
		||||
            </head>
 | 
			
		||||
                <field name="number"/>
 | 
			
		||||
                <field name="ref"/>
 | 
			
		||||
                <field name="inv_type"/>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue