0
votes

I have an inherited model from res.partner.bank which i added a custom field called location to, this is how the model looks like.

class SalesPartnerBankInherit(models.Model):
    _inherit = 'res.partner.bank'

    location = fields.Char()

I have another inherited model from sale.order with a field that has a many2one relationship to res.partner.bank I want to show only 1 record on the many2one dropdown if there are more than 1 records in res.partner.bank that has the same location field value? This is my inherited sale.order model with the many2one location_id field

location_id = fields.Many2one('res.partner.bank',
                               string='Bank Account Location')

So if there are duplicate res.partner.bank records with the same location, I want to show only 1 record on the dropdown.

1
Make it compute field and in compute method assign only one record to it.Adam Strauss

1 Answers

0
votes

First, make your field compute then in compute method search all record from specific model and assign as per your requirement.

location_id = fields.Many2one('res.partner.bank', string='Meters', compute="_get_value")

def _get_value(self):
    for i in self:
        records = self.env['res.partner.bank'].search([], limit=1) # search with one record only from whole search and assign it.
        i.location_id = records and records.id