Skip to Content
Menu
This question has been flagged
5 Replies
12266 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.. :)


Avatar
Discard

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.


Solve it?

Author Best Answer

un done sir..

i still get error... T__T

Avatar
Discard
Best Answer

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

Avatar
Discard

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

Related Posts Replies Views Activity
2
May 24
4959
1
Sep 23
1074
2
Aug 23
1712
1
Jan 21
2972
1
Jan 20
4850