I have a model (like purchase.order) and it has a field One2Many to model line (like purchase.order.line) I want to get these lines before saving the model. Can anyone help me please?
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
Hello Mouna Cherrad, for above given scenario, you can use a compute field and calculate the values from the rows, It will be similar like purchase order's Total(amount_total) field.
for example:
quantity_total = fields.Integer(string='Quantity', compute='_quantity_total')
@api.depends('order_line.quantity')
def _quantity_total(self):
for order in self:
order.quantity_total = sum(order.mapped('order_line.quantity'))
Please give more details about what do you want to achieve. You mean before save the record, You can get them in create method from vals. You can override create method and you can get the order_line (one2many) from vals and do what ever you want and then call super method of create/write.
Hello Waleed, thank you for your answer.
Yes, the scenario is as follows:
I have a field quantity in the model that should be the sum of the quantities in the rows , so when adding a new line I want to get all the quantities in the lines above even if they are not saved to propose the next quantity of the new line (the difference between the quantity in the model and the sum of the quantities in the lines). I hope it is more clear
@Atul Patel Give you the write answer.
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