Skip to Content
Menu
This question has been flagged
1 Reply
1646 Views

I am stuck in a simple if condition for the below 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 invoice.invoice_line_ids.mapped('tax_ids.name') == 'Sales VAT':
worksheet.write(row, 6, '15%')
else:
worksheet.write(row, 6, '0%')
row += 1
key = u'_'.join((invoice.partner_id.name, invoice.currency_id.name)).encode('utf-8')
key = str(key, 'utf-8')

I just want to fetch the value of one excel field and use in if condition

If tax_ids.name == 'Sales VAT'

it should print 15%

else 

0%

but for all the lines its taking only the else condition i.e 0%








Invoice Date Invoice Number Customer Invoice Description Tax Name Total before VAT VAT %
2022-01-17 INV/2022/0001 Administrator Betrillix Sales VAT 2173.91 0%
2022-01-05 INV/2022/0003 My Company Betrillix, Sample Sales VAT 60.0, 30.0 0%
2022-01-03 INV/2022/0004 My Company Betrillix Sales VAT 2500.0 0%
2022-01-03 INV/2022/0002 Administrator Betrillix Sales VAT 500.0 0%









Avatar
Discard
Best Answer

There is an issue with your condition.

invoice.invoice_line_ids.mapped('tax_ids.name')
# This will give you the tax names in a list. Ex: ['15%', '25%', '18%']

So, you should use the condition as follow:

if 'Sales VAT' in invoice.invoice_line_ids.mapped('tax_ids.name'):
# This will be evaluated like this: 'Sales VAT' in ['15%', '25%', '18%']


Avatar
Discard
Author

I don't want tax names, as the tax names are different, I just want to show the tax percentages as label as there are only 1 tax percent in saudi arabia either 15% or 0%

Author

By the way, thank you and let me check with this code

Just use the code I suggested and it will work.

Author

its working thanks

Related Posts Replies Views Activity
2
Jan 22
1412
0
Jan 22
18
2
Jul 22
3563
0
Feb 22
1817
1
Feb 22
61