This question has been flagged

Hello all,

I want to access res.partner form in my module. But i want that instead of customer(partner_id) it 'pet_name' in drop-down for only particular class. I applied a function and it's work. But, it work for complete res.partner. But i don't want this. So, any one can provide solution or condition for this problem?

My Code is Here:

class customer_information(models.Model):

    _inherit = "res.partner"

 @api.multi

    def name_get(self):

        result = []

        for record in self:

            name = '['

            if record.pet_name:

                name += record.pet_name + ']' + ' ' + record.name

            else:

                name += '] ' + record.name

            result.append((record.id, name))

        return result

  

 pet_name = fields.Char("Pet Name")

    dog_cat = fields.Selection([('dog', 'Dog'), ('cat', 'Cat')], string="Dog/Cat")

    species = fields.Many2one('species.pet', string="Species")

    pet_size = fields.Selection([('large', 'Large'), ('medium', 'Medium'), ('small', 'Small')], string="Size")

    

class machine_weight(models.Model):

    _name = 'machine.weight'

    machine_id = fields.Many2one('sale.pet', string='Machine Weight', ondelete='cascade', index=True,

                                 copy=False)

    pet = fields.Many2one('res.partner')

    weight = fields.Integer()

    price = fields.Integer()

Avatar
Discard
Best Answer

Hi Pawan,
 

You can pass context from xml and in the name get method you can check in if condition , if you get your flag here only then apply a pet name instead of res partner default name.


 @api.multi

    def name_get(self):

        result = []

        if self._context.get('flag'):   #flag = value that you have passed from the xml

            for record in self:

                name = '['

                if record.pet_name:

                    name += record.pet_name + ']' + ' ' + record.name

                else:

                    name += '] ' + record.name

                result.append((record.id, name))

        return result

\


Avatar
Discard
Author

Where is the class, For which we want to implement? and it show error like: "list index out of range".