Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to open a view from onchange event (v8.0)

By
Michael Berg
on 12/12/14, 7:24 AM 488 views

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

 

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/12/14, 7:33 AM

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?

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

Michael Berg
on 12/12/14, 10:02 AM

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

Ivan
on 12/14/14, 8:42 PM

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

Michael Berg
on 12/15/14, 3:32 AM
0
Michael Berg
On 12/12/14, 8:34 AM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/12/14, 7:24 AM
Seen: 488 times
Last updated: 3/16/15, 8:10 AM