Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2364 Lượt xem

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'


Ảnh đại diện
Huỷ bỏ

Maybe you could post the error message ? 

Câu trả lời hay nhất

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'))))
Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

Just make it same type e.g float

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 22
18
1
thg 1 22
2529
2
thg 7 22
4768
0
thg 2 22
2683
1
thg 2 22
61