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

Update all record

By
Pamungkas Sugihartoko
on 12/17/15, 2:35 AM 829 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

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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

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/17/15, 2:35 AM
Seen: 829 times
Last updated: 12/23/15, 2:37 AM