I've made a model with a field name Car where users can write a car model, so I want to count the number of each model.
I was looking
self.env['car.model'].search_count(['car_model', '=', 'name_of_model']) So I want to count every data that user write but dinamically
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
1742
Views
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
Have a look at Odoo's models.py:
@api.model
def search_count(self, args):
""" search_count(args) -> int
Returns the number of records in the current model matching :ref:`the
provided domain <reference/orm/domains>`.
"""
res = self.search(args, count=True)
return res if isinstance(res, pycompat.integer_types) else len(res)
You can use the search() method (reference can be found in the same file) with count=True. If you decorate your own method with api.depends('fields_that_trigger_recomputation') or api.onchange('...') the records will be counted every time a user creates a new one.