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č

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
methodserver_actionsapi.multiodoo10ir.actions.server
1 Odgovori
13569 Prikazi
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
Opusti
Avatar
Hilar Andikkadavath
Best Answer

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
Opusti
FEDERICO LEONI
Avtor

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
Avtor

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
Avtor

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
Avtor

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!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
[SOLVED] Server actions: how to replace self.write command with new API for Odoo 10? Solved
server_actions odoo10 ir.actions.server
Avatar
Avatar
Avatar
9
dec. 17
16089
Check Action Rules works only once
scheduler server_actions automatic-action odoo10
Avatar
Avatar
2
feb. 17
6276
How can I extend " crm_lead_opportunities " action in my custom module Solved
view actions override odoo10 ir.actions.server
Avatar
Avatar
1
feb. 18
5795
[Odoo 10] Override method in pos.config
python inheritance method override odoo10
Avatar
0
feb. 17
5
Create schedule action For sending emails
odoo10
Avatar
Avatar
Avatar
2
jul. 25
6541
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