This question has been flagged
1 Reply
1306 Views

I have many2one field called  uom_id= fields.Many2one ("Units of Measure", 'product.uom')

I would like to see records at the top which is the most used in that field. I don't know how to use _order method in odoo. Please anyone help how to use order_method . Thank you.

Avatar
Discard
Author Best Answer

Now, I've solved it.

class UnitOfMeaure (models.Model):
	_inherit = 'product.uom'
	_order = 'rating desc'
	
	@ api.multi
	def get_rating (self):
		product = self.env ['product.template']. search ([])
		uom_ids = [i.uom_id.id for i in product]
		neck = Counter (uom_ids)

		for rec in neck:
			uom = self.search ([('id', '=', rec)])
			uom.rating = neck [rec]

	rating = fields.Integer (null = True, compute = "get_rating", store = True, string = "Products")
Avatar
Discard