Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
2508 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Tekijä

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%

Tekijä

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

Just use the code I suggested and it will work.

Tekijä

its working thanks

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
tammik. 22
2336
0
tammik. 22
18
2
heinäk. 22
4744
0
helmik. 22
2668
1
helmik. 22
61