Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
2360 Visualizzazioni

I am trying to compute VAT field in my customized excel report, based on a total before vat field and multiplying it by 0.15 but everytime I execute the code I get errors like type error

below is the code

for invoice in invoice_objs:
invoice_date = invoice.invoice_date.strftime('%Y-%m-%d')
worksheet.write(row, 0, invoice_date)
worksheet.write(row, 1, invoice.name)
worksheet.write(row, 2, invoice.partner_id.name)
worksheet.write(row, 3, ', '.join(invoice.invoice_line_ids.mapped('product_id.name')))
worksheet.write(row, 4, ', '.join(invoice.invoice_line_ids.mapped('tax_ids.name')))
worksheet.write(row, 5, ', '.join(str(i) for i in invoice.invoice_line_ids.mapped('price_subtotal')))
if 'Sales VAT' in invoice.invoice_line_ids.mapped('tax_ids.name'):
worksheet.write(row, 6, '15%')
else:
worksheet.write(row, 6, '0%')
if 'Sales VAT' in invoice.invoice_line_ids.mapped('tax_ids.name'):
%%--> worksheet.write(row, 7, (', '.join(str(i) for i in invoice.invoice_line_ids.mapped('price_subtotal')))* 0.15)

Please check the last line might be there is issue in that 


--------UPDATE-----------

Error Message: 

File "/home/suhaib/odoo/odoo/addons/invoice_summary_report/wizard/invoice_summary_report_wizard.py", line 93, in action_print_invoice_summary
    worksheet.write(row, 7, (', '.join(str(i) for i in invoice.invoice_line_ids.mapped('price_subtotal')))* 0.15)
TypeError: can't multiply sequence by non-int of type 'float'


Avatar
Abbandona

Maybe you could post the error message ? 

Risposta migliore

You cannot multiply with the list. 

Ex: [2, 5, 7] * 0.15

When invoice.invoice_line_ids.mapped('price_subtotal') is executed, it will return the list.

Try the following code:

worksheet.write(row, 7, (', '.join(str(i * 0.15) for i in invoice.invoice_line_ids.mapped('price_subtotal'))))
Avatar
Abbandona
Autore

That worked thanks,
I have one more concern
that how can I add the value of two fields in the same report
worksheet.write(row, 5, ', '.join(str(i) for i in invoice.invoice_line_ids.mapped('price_subtotal'))) ( + ) worksheet.write(row, 7, (', '.join(str(i * 0.15) for i in invoice.invoice_line_ids.mapped('price_subtotal'))))

Risposta migliore

Just make it same type e.g float

Avatar
Abbandona
Autore

can you please write the code cuz I am new to this

Post correlati Risposte Visualizzazioni Attività
0
gen 22
18
1
gen 22
2526
2
lug 22
4760
0
feb 22
2680
1
feb 22
61