Adding up total Quantity

total_amount_final = 0

for item in doc.items:
    item.amount = item.number_of_item * item.rate
    
    total_amount_final = total_amount_final + item.amount

doc.total_amount = total_amount_final

Iwant the number of item in each row to add up and be shown in the total_quantity field . Please help , am new to programming

Ask chatgpt. It will give working code

Example:

total_amount_final = 0
total_quantity = 0

for item in doc.items:
    item.amount = item.number_of_item * item.rate
    total_amount_final += item.amount
    total_quantity += item.number_of_item

doc.total_amount = total_amount_final
doc.total_quantity = total_quantity

Now check the fieldname and set it according to the scenario.