Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

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?


Avatar
Buang
Jawaban Terbai

Hi

The error that you are getting is because the widly_used_countries field is not defined in the view that you are inheriting. To fix this, you need to add the widly_used_countries field to the view.
 You can do this by adding the following code to the view:
 <field name="widly_used_countries" widget="many2many_list" />

Hope it helps

Avatar
Buang
Jawaban Terbai

Hello 

i have checked your exising code. i would suggest you to inherit res.partner form view and add domain in view for country_id field as below instead of writing in python code.

domain="[('id', 'in', widly_used_countries)]"

Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat

Avatar
Buang
Jawaban Terbai

Hi,

It looks like the error that you are facing is due to the view inheritance.

please make sure that , you have the widly_used_countries field available in the res.partner model to avoid any issues during view inheritance.


Define a new view in your custom module that inherits the base.view_partner_form view and add your field in this view



Hope this will help you

thanks



Avatar
Buang
Penulis

As I said, I did what you offered

Post Terkait Replies Tampilan Aktivitas
1
Jul 23
2241
1
Jan 24
1903
1
Okt 23
2117
1
Sep 23
1847
2
Mar 23
3066