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

[V8] Update other form using onchange

By
Aurélien Rivet
on 6/23/16, 6:33 AM 144 views

Hi all,

I want to implement a default_adress boolean for child partner of company.

I made a boolean field which I added on the contact form (the windows that appears when you click on a kanban item, at the bottom of the parent partner's form)

I defined a onchange function to watch when this field is edited and then if it is set to True I want to set all others at false.

But it does not work. If I write the value on the record, then they are updated only in the database, and not in the UI.

I think I have to deal with the return value of the on change function but I don't know how to reach others childs of the parent.

Hope someone could help.

Here is my code:

    default_address = fields.Boolean('Default address')
    @api.onchange('default_address')
    def onchange_default_address(self):
        if self.type in ['delivery', 'invoice']:
            if self.default_address is True:
                partners = self.search([('type', '=', self.type),
                                        ('default_address', '=', True)]) - self
                if partners:
                    res = {
                        'value': {
                            'parent_id.child_ids': []
                        }
                    }
                    for partner in partners:
                        res['value']['parent_id.child_ids'] += (1, partner.id,
                                                      {'default_address':
                                                       False})
                    _logger.critical(res)
                    return res
0
Aurélien Rivet
On 6/23/16, 8:04 AM

Thanks for your response Ahmed.

I don't need to add the domain to my search, because search is done on a set of transient model that are displayed in the kanban view. If I display the partner record obtained, I can see they are those I expected. I did try to directly set using dot notation but it does nothing. However, if I write on the partners the value of default_address, they are updated in the database only, not in the UI. What I want to achieve is to update them on the UI and save when I click on Save.

Also, I tried to return True, but it raises an error

"Type Error argument of type bool is not iterable"

Code:

@api.onchange('default_address')

    def onchange_default_address(self):
        if self.type in ['delivery', 'invoice']:
            if self.default_address is True:
                partners = self.search([('type', '=', self.type),
                                        ('default_address', '=', True)]) - self
                if partners:
                    for partner in partners:
                        partner.default_address = False
                        _logger.critical(partner.id) #The ids are those of partners I want to edit
              
 


0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 6/23/16, 7:33 AM

Hello,

With the new API you don't need to return a dict with 'value' key. You can simply use the dot [.] to write the value as:

partner.default_address = False ...


I didn't get what you're trying to achieve but I'll try to modify your code, and I believe you'll get the idea ;)


    @api.onchange('default_address')

def onchange_default_address(self):

if self.type in ['delivery', 'invoice']:

if self.default_address is True:

partners = self.search([('type', '=', self.type),

('default_address', '=', True)]) - self

                                         #I think you need to add to the domain parent_id or something ...

if partners:

                    partners.default_address = False

_logger.critical(res)

return True



Hope this could help a little bit ...


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: 6/23/16, 6:33 AM
Seen: 144 times
Last updated: 6/23/16, 8:04 AM