Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Odoo 10: call a method with the new api from server action

Odebírat

Get notified when there's activity on this post

This question has been flagged
methodserver_actionsapi.multiodoo10ir.actions.server
1 Odpovědět
13580 Zobrazení
Avatar
FEDERICO LEONI

I have inherited pos.order model adding some extra fields and my definitions via custom module:

class PosOrderDV(models.Model):
_inherit = "pos.order"
 
profit = fields.Float('Lucro', store=True, index=True, digits=(5,2))
costs = fields.Float('Custos', store=True, index=True, digits=(5,2))

    @api.multi 
  def cost_elab(self):
    ### do stuff ###

Odoo has his personal way to interact with fields trough definition, and I'm seeing a lack of good docs to archive that. Perhaps is better stay with my daemon, but I'm curious to know how people are managing the conversion.

For now, all I got were a series of errors, the most common are

ValueError: <type 'exceptions.AttributeError'>: "'pos.order' object has no attribute 'cost_elab'"

if I call my def with env['pos.order'].cost_elab()

or

NameError: name 'self' is not defined

if I use self.env['pos.order'].cost_elab()




0
Avatar
Zrušit
Avatar
Hilar Andikkadavath
Nejlepší odpověď

Hi,

check whether your object is browsable, and you can call function by

env['pos.order'].cost_elab() like self.env['product.uom']._compute_price(line.product_id.uom_id.id, purchase_price, to_uom_id=line.product_uom.id)


class x(Object):

     def y():

         return "teste"

class y(models.Model, x):

     """ here I can access function y as self.y() """

     print self.y()

if still probs, then please give me your example code

In case of odoo lets take an example.


class res_partner(models.Model):
_inherit = "res.partner"
    @api.multi
def google_map_img(zoom=17, width=298, height=298):
partner = self.browse([partner_id])
        params = {
  'center': '%s, %s %s, %s' % (partner.street or '',
        partner.city or '',
        partner.zip or '',
        partner.country_id and partner.country_id.name_get()[0][1] or ''),
        'size': "%sx%s" % (height, width),
  'zoom': zoom,
        'maptype': 'hybrid',
  'sensor': 'false',
  }
        return urlplus('//maps.googleapis.com/maps/api/staticmap', params)

class test(models.Model):
     _name = 'your.name'

     @api.multi
     def test(self):
partner = self.sudo().partner_id
    return partner and partner.google_map_img(zoom, width, height) or None

In case you have no record set try @api.model instead of multi



     

2
Avatar
Zrušit
FEDERICO LEONI
Autor

Can you please elaborate more?

In pure python with the help of psycopg2 is quite easy trigger an action (I'm using a daemon now) but the more I dig into Odoo the more I realize perhaps is better stay with my own setup.

If you think is important I'll update the OP with a draft of my python code.

FEDERICO LEONI
Autor

And just for let you know, your example give me an error of invalid syntax after 'like'.

Hilar Andikkadavath

like is not an operator here , i just used to explain an example.

eg: self.env['product.uom']._compute_price(line.product_id.uom_id.id,purchase_price,to_uom_id=line.product_uom.id)

FEDERICO LEONI
Autor

Ok, I'll have a look more deeply using your sample code.

But somehow 'self' doesn't works well with pos.order/server action.

See my previous thread here:

https://www.odoo.com/forum/help-1/question/solved-server-actions-how-to-replace-self-write-command-with-new-api-for-odoo-10-113549

Hilar Andikkadavath

I see try @api.model instead of @api.multi

FEDERICO LEONI
Autor

Hilar, thank you for your time.

I prefer not to use @api.model, since I would like to use just the new API.

Let me assimilate the concept and Í'll write some lines of code. But again, coding under Odoo should be more simple... Or probably I'm just getting old!

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

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
[SOLVED] Server actions: how to replace self.write command with new API for Odoo 10? Vyřešeno
server_actions odoo10 ir.actions.server
Avatar
Avatar
Avatar
9
pro 17
16100
Check Action Rules works only once
scheduler server_actions automatic-action odoo10
Avatar
Avatar
2
úno 17
6296
How can I extend " crm_lead_opportunities " action in my custom module Vyřešeno
view actions override odoo10 ir.actions.server
Avatar
Avatar
1
úno 18
5809
[Odoo 10] Override method in pos.config
python inheritance method override odoo10
Avatar
0
úno 17
5
Create schedule action For sending emails
odoo10
Avatar
Avatar
Avatar
2
čvc 25
6556
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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