This question has been flagged

Hello All,

I created a master table for estimated weight. For this master table i have two float fields 'min' and 'max'. Now i have 10 records and in every record there is 'min' and 'max' value. Now i want to show all 'min' and 'max' values from table to another place. For this i use search method, but not reached upto the mark. So, How can i do that?

Python Code:

Master Table code --

class est_weight(models.Model):
    _name = "est.weight"
    _rec_name = 'est_weight_pet'

    min = fields.Float("Min. Weight")
    max = fields.Float("Max. Weight")
    est_weight_price = fields.Integer(string="Price")


Here i want to search all min. and max. value:--

class RentalPackWizard(models.TransientModel):
    _name = "rental.pack.wizard"
    _description = "Rental Pack Wizard"
   
    @api.model
    def _get_min_max(self):
        mini = self.env['est.weight'].search([('min', '=', '')], limit=1)
        maxi = self.env['est.weight'].search([('max', '=', '')], limit=1)


Thanks in advance.

Avatar
Discard
Best Answer

Hi,

To get the field value in all records of a table, you can try like this. This will return a list of the values in all fields

mini_rec = self.env['est.weight'].search([])
mini = mini_rec.mapped('min')
maxi_rec = self.env['est.weight'].search([])

maxi = maxi_rec.mapped('max')

Thanks

Avatar
Discard
Author

Thanks Niyas...!!

Author

And also how to get 'min' and 'max' combinations id-wise??

Author

Because i have i float value field(weight) in sale order and i want to apply condition that if that field value is greater than min value than it show related price. That's why i need to check all the min value one by one by that field. So, How apply condition between 'mini' list values?