Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

when i use @api.model?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
apionchangemodel
3 Respostes
19631 Vistes
Avatar
Ra_one_1_11

hello i am new in odoo 


i wnat to know about all decoraters i alrady seen all documantation but its very hard to understand for me .

my question is

when i use @api.model?

when i use @api.dependace

 when i use @api.onchange


please ans in easy way to better understand for me


thanks in advance



0
Avatar
Descartar
Ra_one_1_11
Autor

thank you Waleed Mohsen

can u give me information about all of the api in odoo 15
it is possible for you?

Kiran K

https://www.cybrosys.com/blog/common-orm-methods

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

api.model

The model decorator is used with the methods where self is a record set, but only the model is relevant and not its contents. It helps in the code migration since it will convert the old API calls to the new ones, which makes the migration process faster.

Here is an example code for @api.model:

@api.model
def _get_default_currency(self):
''' Get the default currency from either the journal, either the default journal's company. '''
journal = self._get_default_journal()
return journal.currency_id or journal.company_id.currency_id

api.depends

The depends decorator is used to specify the compute dependencies for a computing method. Each argument must be a string of field names, where it can be a simple or a dot-separated sequence of field names. It is possible to pass a single function as an argument, where the dependencies are given by calling the function with the field’s model.

Here is an example code for @api.depends:

complete_name = fields.Char('Complete Name', compute='_compute_complete_name', store=True)
@api.depends('name', 'parent_id.complete_name')
def _compute_complete_name(self):
for department in self:
if department.parent_id:
department.complete_name = '%s / %s' % (
department.parent_id.complete_name, department.name)
else:
department.complete_name = department.name

api.onchange

The onchange method decorator is mostly used with the onchange method for the given fields. The onchange method will be triggered while we change the value of any of the fields specified with the onchange decorator from the form view. The onchange method will be invoked on a pseudo-record that contains all the values of fields present in the form view. Even though we cannot perform the CRUD operations in that record, the field assignments are updated in the form view. The onchange decorator does not support the dotted names(fields of relational fields like product_id.default_code), and those will be ignored. We can only use simple field names.

Here is an example code for @api.onchange:

@api.onchange('analytic_account_id', 'analytic_tag_ids')
def _onchange_mark_recompute_taxes_analytic(self):
''' Trigger tax recomputation only when some taxes with analytics
'''
for line in self:
if not line.tax_repartition_line_id and any(tax.analytic for tax in line.tax_ids):
line.recompute_tax_line = True

Regards

0
Avatar
Descartar
Avatar
Waleed Ali Mohsen
Best Answer

@api.model decorator used on methods for which only the model is important, not the contents of the recordset. so self should be used as a reference for the model, without expecting it to contain actual records.
In another words it's used when you need to do something with model itself and don't need to modify/check some exact model's record/records

@api.depends(fld1,...) is used for computed field functions, to identify on what changes the (re)calculation should be triggered. It must set values on the computed fields, otherwise it will error.

@api.onchange(fld1,...) is used in the user interface, to automatically change some field values when other fields are changed. The self argument is a singleton with the current form data, and the method should set values on it for the changes that should happen in the form. It doesn’t actually write to database records, instead it provides information to change the data in the UI form.

1
Avatar
Descartar
Tri Nanda

What if I don't declare @api.model?
What will happen?
I try to remove it but there is no effect after it.

Avatar
Mukesh Gehlot
Best Answer

When @api.model is not declared, Odoo treats the method as a standard method that operates on a recordset. If you attempt to call this method on a model without a record, it may lead to unexpected behavior or errors, especially if the method is intended to operate on the model level (e.g., creating a record or performing an action that doesn't depend on a specific record).

If your method is not heavily dependent on the differences in behavior that @api.model introduces, removing it might not cause immediate issues. For example, if the method is simple and doesn’t rely on special model-level operations, it might still work without the decorator. However, this can lead to problems in more complex scenarios where the distinction between a model method and a recordset method becomes important



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

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

Registrar-se
Related Posts Respostes Vistes Activitat
API 8.0 onchange() and depends() decorators only work for UI changes and 1 record only?
api onchange
Avatar
Avatar
1
de juny 15
5936
How to create chained selection fields in Odoo using API data?
api selection onchange
Avatar
Avatar
1
d’oct. 25
651
Return multiple domain modification from one onchange()
api onchange domains
Avatar
Avatar
Avatar
2
d’abr. 25
3740
Execute @api.onchange only once?
api onchange odoo
Avatar
Avatar
1
de nov. 22
3970
Display many2many Field data into one2many field
api onchange odoo12
Avatar
Avatar
Avatar
2
de des. 19
8833
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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