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

Write to Record in Related Field of Many2One Relationship

Subscriure's

Get notified when there's activity on this post

This question has been flagged
many2onerelated_fields
7243 Vistes
Avatar
Michael Thomas

I have an object that, when it completes it's workflow, needs to update the state for a different class, specifically manufacturing orders. I have tried everything I can think of to try to update that field. Code is thus:

class mrp_partsorder(osv.Model):
...

_columns = {
'sourceorder_id': fields.many2one('mrp.production', string='Manufacturing Order'
'primarystate': fields.selection ( [..states...], related='sourceorder_id.state'
}

def partsorder_complete(self, cr, uid, ids, context=None):
prod_obj = self.pool.get('mrp.production')
prod_ids = [self.sourceorder_id]
prods = prod_obj.search(cr, uid, prod_ids, context=context)
proc_obj.action_fitting(cr, uid, prods, context=context)
res = self.write(cr, uid, ids, {'state': 'complete'}, context=context)

class mrp_production(osv.osv)
def action_fitting(self, cr, uid, ids, context=None):
res = self.write(cr, uid, ids, {'state': 'fitting'}, context=context) return res
 


At the moment I'm getting the following error:

ValueError: "'mrp.partsorder' object has no attribute '_ids'" while evaluating
u'partsorder_complete()

This is not the only error I've seen, as I've tried quite a few different ideas of solving this problem. Basically, i just want to update the value in the related field (primarystate), but if I write to that field it updates the mrp.partsorder table but not the mrp.production table. So, I figured I needed to use self.pool.get to get the singleton instance of mrp.production and then use the the write method for mrp.production or use the action_fitting() method for mrp.production. 

What is the best way to solve this problem?

Edit: After further consideration I realized that I need to use the function on mrp.production to change the state, rather than just writing to it. I want to do this because of all the functionality built into the manufacturing order. All I need now is to figure out how to call the function from my mrp.partsorder.partsorder_complete() function. 

0
Avatar
Descartar
Michael Thomas
Autor

So I have now tried doing something like: mrp_order = self.pool.get('mrp.production') order_ids = self.sourceorder_id for order in mrp_order.browse(cr, uid, order_ids): order.action_fitting() I think that fixes some syntax issues I have, but I'm still getting the same error. The worst part is it is saying mrp.partsorder has no attribute _ids, which is odd since the function I'm calling is from the mrp.production object.

Michael Thomas
Autor

As a follow up, mrp.partsorder shouldn't be called until the end of the partsorder_complete() function. So, the should be no problem running the action_fitting() function, unless the error is happening when I try to pass the sourceorder_ids (the m2o relationship between mrp.partsorders and mrp.production) to prod_ids.

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
Send a value from context one2many
many2one related_fields odoo15
Avatar
0
de maig 24
1782
Related field not found while trying to set up a One2many field. Solved
many2one one2many related_fields
Avatar
Avatar
Avatar
2
d’oct. 23
3098
Product variant is also product (odoo 14) Solved
product many2one related_fields
Avatar
Avatar
1
de març 21
2786
v17: Module upgrade fails due to Many2one-related field Solved
many2one upgrade related_fields v17
Avatar
Avatar
1
d’oct. 25
476
value not pass from many2one field to form
many2one
Avatar
Avatar
Avatar
Avatar
3
de set. 25
2297
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