Skip to Content
मेन्यू
This question has been flagged
2 Replies
2320 Views

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
Discard

Maybe you could post the error message ? 

Best Answer

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
Discard
Author

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'))))

Best Answer

Just make it same type e.g float

Avatar
Discard
Author

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

Related Posts Replies Views Activity
0
जन॰ 22
18
1
जन॰ 22
2492
2
जुल॰ 22
4735
0
फ़र॰ 22
2652
1
फ़र॰ 22
61