Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
2315 Widoki

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'


Awatar
Odrzuć

Maybe you could post the error message ? 

Najlepsza odpowiedź

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'))))
Awatar
Odrzuć
Autor

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

Najlepsza odpowiedź

Just make it same type e.g float

Awatar
Odrzuć
Autor

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

Powiązane posty Odpowiedzi Widoki Czynność
0
sty 22
18
1
sty 22
2491
2
lip 22
4731
0
lut 22
2652
1
lut 22
61