Hi friends,
I have a new model that aims to extend 'res.partner' model.
Now, I want to set a filter on the 'country_id' field of 'res.partner' model to show just some countries that their's list is set in Config Params(For this, I've also set a new field in the Config Params that the user can choose some countries, so I want the field of Country in the contact page to show just those selected ids).
How can I do that? What is the best solution?
I've done the following:
widly_used_countries=fields.Many2many(
string='Widly Used Countries',
comodel_name="res.country",
compute="_compute_widly_used_countries",
store=True
)
def_compute_widly_used_countries(self):
country_ids=eval(self.env['ir.config_parameter'].sudo().get_param('exchange.widely_used_countries'))
domain=[('id', 'in', country_ids)]
self.widly_used_countries=self.env['res.country'].search(domain)
And my soultion is to override country_id field as follow:
country_id=fields.Many2one(
comodel_name="res.country",
domain="[('id', 'in', widly_used_countries)]"
)
And now when I upgrade the module, Odoo raises the error that the 'widly_used_countries' should be presented in the view.
To do so, I've also defined a new view inheriting the 'base.view_partner_form'.
But in each place I put 'widly_used_countries', the Odoo error still remains.
I don't know why?