Odoo Help

0

Update all record

By
Pamungkas Sugihartoko
on 12/17/15, 2:35 AM 1,560 views

Hi all,


i'm new in odoo and python programming. i have a situation. i want to update all record in a table. here's my code

def button_posting(self):

self.write({'state':'active'})

return True

that code only update one record. from 'draft' to 'active' in state field. 

when i clicked a 'Posting' button, i want update all record to 'draft' and only one record become 'active'

how can i do that..?

thanks before.


PS: i'm sorry for my terrible english.. :)


i got this error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\http.py", line 537, in _handle_exception
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\http.py", line 574, in dispatch
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\http.py", line 310, in _call_function
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\service\model.py", line 113, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\http.py", line 307, in checked_call
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\http.py", line 803, in __call__
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\http.py", line 403, in response_wrap
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\openerp\addons\web\controllers\main.py", line 948, in call_button
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\api.py", line 241, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\api.py", line 363, in old_api
  File "D:\koulu\mdi_ta\models.py", line 31, in button_posting
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\api.py", line 239, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\api.py", line 463, in new_api
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\models.py", line 1644, in search
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\api.py", line 241, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\models.py", line 4640, in _search
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\api.py", line 241, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\models.py", line 4463, in _where_calc
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\osv\expression.py", line 646, in __init__
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\osv\expression.py", line 749, in parse
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\osv\expression.py", line 532, in __init__
  File "C:\Program Files (x86)\Odoo 8.0-20150723\server\.\openerp\osv\expression.py", line 588, in check_leaf
ValueError: Invalid leaf id

here is my code:

@api.multi

def button_posting(self):

self.search(['id', '!=', self.id]).write({'state':'draft'})

self.write({'state':'active'})

return True


what should i do? i use win 10

thanks.


Pamungkas Sugihartoko
on 12/17/15, 3:36 AM

Solve it?

Axel Mendoza
on 12/22/15, 3:07 PM
0
Pamungkas Sugihartoko
On 12/23/15, 2:37 AM

un done sir..

i still get error... T__T

0
Axel Mendoza
On 12/17/15, 3:13 AM

You can do it like:

@api.multi

def button_posting(self):

self.search([('id', '!=', self.id)]).write({'state':'draft'})

self.write({'state':'active'})

return True

Hope that helps

Sorry I omit some parenthesis on the domain, I update it on the anwer, copy and check it again

Axel Mendoza
on 12/17/15, 3:44 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 12/17/15, 2:35 AM
Seen: 1560 times
Last updated: 12/23/15, 2:37 AM