Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3801 Widoki

Hello,

I try to open a view from an onchange event. If the user selecting a country i want to check if there is set an information on this record. if this information is not set i want to open the view to enter them.

My model is this:

class e_template(models.Model):

    ......

     Country = fields.Many2one('res.country', string="Location of the Item", default=58)
    @api.onchange('Country')
    def _onchange_Country(self):
        if self.Country.EbayShortCut == False:
            res = {
                "type": "ir.actions.act_window",
                "res_model": "res_country",
                "views": [[False, "form"]],
                "res_id": self.Country,
                "target": "new",
            }
            logging.info(res)
            return res

.....

How to i open the form view in an onchange event. It would be nice to get some help.

thx michael

 

Awatar
Odrzuć
Najlepsza odpowiedź

onchange cannot return action.  If you use many2one field for country (which I believe is available, user can type in the country the choose, the widget will propose which country matches the string that the user enter and if there are no country that matches that string, the user can create the country, as long as they have the access.  Would you care to share why you don't use many2one field to res.country?

Awatar
Odrzuć
Autor

If u will look in my code u can see that the Country is an many2one field. My Problem that i created a new field within the res.country model. I want to check if this field is set or not set. If not set, i want the user to edit the choosen country. But thx for the information that i not can return an action. So i need to look for another solution for my problem. I will return a warning. The user need to open the country by his self. best regards Michael

Just a suggestion, you can domain the country field on EbayShortCut value so that user cannot select country with EbayShortCut == False.

Autor

ok, good idea... I can explain the behavior as a label of the field.... i will think about it. thx

Autor Najlepsza odpowiedź

If u will look in my code u can see that the Country is an many2one field. My Problem that i created a new field within the res.country model. I want to check if this field is set or not set. If not set, i want the user to edit the choosen country.

But thx for the information that i not can return an action. So i need to look for another solution for my problem.

I will return a warning. The user need to open the country by his self.

best regards

Michael

Awatar
Odrzuć