This question has been flagged
2 Replies
2869 Views

Hello All,

I inherite(res.partner) sales customer form. And make changes with adding some addition fields. Now when call this form another place in Many2one type then only customer name shown in drop down. How to show pet name in drop-down?

My code is here:

Python Code:

class customer_information(models.Model):
    _inherit = "res.partner"

    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")

Module Where i want pet name:

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.pet_name')
    weight = fields.Integer()
    price = fields.Integer()

Avatar
Discard
Author

I Applied name_get method but it is not work for me.

@api.multi

def name_get(self):

result = []

print "R::", result

for record in self:

print"r:", record

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

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

return result

Best Answer

Hi,

For that you have to inherit res.partner  in your "
machine_weight" class

Avatar
Discard
Author

For this i added below field in "machine_weight" class:

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

i noted that.but you have to inherit that res.partner on your machine_weight class to build relationship.

Author

Now, I also try this. But, getting 'False' value for this field on terminal by printing "print "r:", record.name"

Author

Hello Rishan,

Now, My function work well. But, Can u tell me how to call this function for particular class only, not global. My class name is "body_processing" where i want to call this 'name_get' function. My code is here:

@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

what is your purpose?

Author

Want to show other field(pet_name) in drop-down form res.partner except partner_id.