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

I have multiple sales orders for a project.  I am trying to create a field on the project form card that will total all of the untaxed amounts on the sales orders.  I have created a One2Many field to show the list of all of the sales orders but can't figure out how to get a field on the Project form to total from the sub list.  Can anyone help?

Avatar
Discard
Best Answer

Hi Doug,

You can add computed field in project and the computed method will loop the sale orders and save the total to the the computed field as below:


total_sale_amount_untaxed = fields.Monetary(string='Total Sale Untaxed Amount', store=True, compute='_compute_untaxed_amount')

@api.depends('sale_order_ids') # replace sale_order_ids with the One2many which you created to retrieve sale orders

def _compute_untaxed_amount(self):
for project in self:
total_amount = 0.0
for order in project.sale_order_ids:
total_amount += order.amount_untaxed
project.total_sale_amount_untaxed = total_amount

Note: The above code will work if you are using one currency but if you are using multi currency then you need to convert the sale order with secondary currency to the company currency.

Avatar
Discard