コンテンツへスキップ
メニュー
この質問にフラグが付けられました

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?


アバター
破棄
最善の回答

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

アバター
破棄
最善の回答

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

アバター
破棄
最善の回答

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



アバター
破棄
著作者

As I said, I did what you offered

関連投稿 返信 ビュー 活動
1
7月 23
2252
1
1月 24
1911
1
10月 23
2124
1
9月 23
1856
2
3月 23
3067