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
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • 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

ODOO 8.0 @api.onchange problem

Subscriure's

Get notified when there's activity on this post

This question has been flagged
onchange8.0
2 Respostes
5054 Vistes
Avatar
Jorge Barcelo Cortes

Hello. Before start some code:

class ExampleModelItem(models.Model):
_name = "example.model.item"
partner_id = fields.Many2one(comodel_name='res.partner')
lines = fields.Many2many(comodel_name='sale.order.line')

@api.onchange("partner_id")
def _compute_sale_lines(self):
ctx_obj = self._context['reglas']

class ExampleModel(models.Model):
_name = "example.model"
reglas = fields.One2many(comodel_name='example.model.item', inverse_name='...', string="...")
lines = fields.Many2many(comodel_name='sale.order.line')

The view in "example.model" looks like :


<field name="reglas" context="{'reglas': reglas}">
<tree>...</tree>
<form>...</form>
</field>

As you can see in the view we set the field in the context, we get the value to ctx_obj variable in the _compute function.

This ctx_obj have a list of the old o2m structure [(0, False, {...}), (1, 1, {...}), (4, 3, False), ..., (type, id, data)]

The problem i facing is, how can i know in the compute method if the record is one of the records in the ctx_obj? Or even better, wich one. When self.id exists its easy, because i can find that id in the ctx_obj. But when self.id is a Newid object, the ctx_obj will be a False. Is there a way to acknowledge is the newid is already in the context object or not??


Thank you in advance

0
Avatar
Descartar
Avatar
Jorge Barcelo Cortes
Autor Best Answer

The problem is not o get values to the function. As you can see the data reach the function.

Let me elaborate it a little more:

Beeing in the main form, i have values {'reglas': [], 'lines': [(6, 0, [100201, 100202])]}

No i create a new subform, and when the function is called i have ctx_obj=[]. The function runs, data is build and back to the main form with values {'reglas': [(0, False, {'partner_id': 38, 'lines': [(6, 0, [100201])]})]}.

Now if i edit again the same item before i save the main form, and change partner_id....ctx_obj=[(0, False, {'partner_id': 38, 'lines': [(6, 0, [100201])]})], and the record doesnt have an ID.

If instead of edit, i create a second one, ctx_obj is the same. The main point of this post is, how can i relate the record to the item inside ctx_obj??

For now a strinct rule of "not edit not saved data" work, but i would like to remove the problem before impose such thing.

0
Avatar
Descartar
Avatar
Deepa Venkatesh
Best Answer

Context must be specified on the source-field of the onchange.

In your case, ensure whether you are passing the necessary context on the field 'partner_id'

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.onchange causes looping page redirect 302 Solved
onchange 8.0
Avatar
Avatar
1
de març 15
6019
@api.onchange strange behavior in Odoo 8.0 Solved
onchange 8.0
Avatar
Avatar
Avatar
3
de març 15
5058
trying to auto correct a wrong users value
onchange
Avatar
Avatar
1
d’oct. 23
2756
"Wrong value for %s: %r" % (self, value) Solved
onchange
Avatar
Avatar
2
d’oct. 23
2974
How to add domain in onchange function for a One2many field Solved
onchange
Avatar
Avatar
Avatar
2
d’ag. 23
5213
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