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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
1
Reply
815
Views
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.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up