Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

[SOLVED] Server actions: how to replace self.write command with new API for Odoo 10?

Naroči se

Get notified when there's activity on this post

This question has been flagged
server_actionsodoo10ir.actions.server
9 Odgovori
16087 Prikazi
Avatar
FEDERICO LEONI

I've started a migration to Odoo 10 from Odoo 8 and I didn't figured out how to replace a simple self.write with the new API.

For example, on one of my custom module I have

self.write(cr, uid, context['active_ids'], {'to_wait':'No'})

but when I fire the server action in my view I get

NameError: name 'self' is not defined

This is my working code for the server action on V8:

<record id="rest_order_send" model="ir.actions.server">
<field name="sequence" eval="5"/>
 <field name="name">rest_order_send</field>
 <field name="model_id" ref="model_rest_order"/>
 <field name="condition">True</field>
<field name="type">ir.actions.server</field>
 <field name="state">code</field>
 <field name="code">self.write(cr, uid, context['active_ids'],{'status':'Pronto'})
self.write(cr, uid, context['active_ids'], {'to_floor':'2'})
self.write(cr, uid, context['active_ids'], {'end_date':datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
</field>
</record>

Looking on Odoo10 doc I found I can't use self.write  anymore and I have to use another syntax now, but sadly I didn't figured out how to use the new object_write command.


Partially solved with the help of Raaj with:

pos_obj = env['pos.order'].browse(context.get('active_id'))
pos_obj.write({'costs': '1.45'})
0
Avatar
Opusti
Avatar
Raaj Mishra
Best Answer

Hi Federico, as per new API you can use like,

self.env['object_name']

for more information you can go through these document.

1.https://media.readthedocs.org/pdf/odoo-new-api-guide-line/latest/odoo-new-api-guide-line.pdf

2.https://www.odoo.com/documentation/8.0/reference/orm.html

0
Avatar
Opusti
FEDERICO LEONI
Avtor

Raaj thanks for your reply. However the first link you gave me doesn't works. I had a look again on the doc, but self still raising the same error.

self.env['pos.order']

object.write({'field': 'value'})

At this point I don't know if is possible to use self without a def on my Python code (now the action is called trough xml).

FEDERICO LEONI
Avtor

Same thing with

self.env['pos.order'].write({'field': 'value'})

Raaj Mishra

Hi Federico,if you are calling the method from the pos.order object then self is enough for the operation like,

self.write({'to_wait':'No'})

But if its from different object then you need to get the id of the pos.order object,as i can see at your code in the question you are having them in context.

so in that case you need to perform like this,

pos_obj = self.env['pos.order'].browse(self._context.get('active_id'))

pos_obj.write({'field': 'value'})

if the length of active_ids is more than 1 then you can loop through the statements.

FEDERICO LEONI
Avtor

Raaj, on both my module and pos.order I get always the same error for self:

ValueError: <type 'exceptions.NameError'>: "name 'self' is not defined" while evaluating

u"pos_obj = self.env['pos.order'].browse(self._context.get('active_id'))\n\npos_obj.write({'costs': '1.35'})"

Raaj Mishra

Can you pls post your method for more details and the object name under which its defined.

FEDERICO LEONI
Avtor

I've updated my original post with the xml pulled from one of my modules on V8.

Speaking truly, I've inherited the pos.order and pos.order.line, where I've added 2 more fields because the next step, when I'll understand how this API works, is calling a def.

That because I'm migrating part of my python scripts from my daemon inside Odoo but frankly the lack of documentation (with good examples) is discouraging. I mean a simple sql query and an update with psycopg2 took me 5 minutes of works. On Odoo I'm stuck since yesterday.

FEDERICO LEONI
Avtor

Raaj,

the issue was solved after a complete remove of 'self' from the line:

pos_obj = env['pos.order'].browse(context.get('active_id'))

pos_obj.write({'costs': '1.45'})

Anyway I'm still not understanding the logic.

Avatar
Agile
Best Answer

In odoo10 for write  function only needed this self.write({'field name':'value'}).

0
Avatar
Opusti
FEDERICO LEONI
Avtor

In this specific example (see comments) self will rise an error and the solution I've write on the OP works fine without. So no, it's not always working.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Odoo 10: call a method with the new api from server action Solved
method server_actions api.multi odoo10 ir.actions.server
Avatar
Avatar
1
feb. 17
13567
Check Action Rules works only once
scheduler server_actions automatic-action odoo10
Avatar
Avatar
2
feb. 17
6276
Create schedule action For sending emails
odoo10
Avatar
Avatar
Avatar
2
jul. 25
6541
How to send messages that are not shown in chatter? Solved
odoo10
Avatar
Avatar
Avatar
2
okt. 25
8851
How to ORDER BY? [Odoo 10] Solved
odoo10
Avatar
Avatar
2
nov. 24
29773
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now