Pomoc

1

How to select pet name in drop down from sales customer form in Odoov10

Avatar
Pawan Kumar Sharma

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

1 Komentár
Avatar
Discard
Avatar
Pawan Kumar Sharma
-

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

1 Odpoveď
0
Avatar
Rishan Malaka
Best Answer

Hi,

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

6 Komentáre
Avatar
Discard
Avatar
Pawan Kumar Sharma
-

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

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

Avatar
Rishan Malaka
-

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

Avatar
Pawan Kumar Sharma
-

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

Avatar
Pawan Kumar Sharma
-

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

Avatar
Rishan Malaka
-

what is your purpose?

Avatar
Pawan Kumar Sharma
-

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