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

Get single object

Subscriure's

Get notified when there's activity on this post

This question has been flagged
many2oneodoo
3 Respostes
12445 Vistes
Avatar
Sylwester Zalewski

Hi, sorry Iam new to odoo and python, so I have tree view with product history in the product equipment class which works fine but I want to also get first element value (product.history.customer) from the tree view but I have following error "ValueError: dictionary update sequence element #0 has length 1; 2 is required"

class product_history(osv.osv):

_name = 'product.history'

_description = 'product History'

_columns = {

'equipment_id': fields.many2one('product.equipment','Unit of work ref', required=True),

'customer': fields.many2one('res.partner', 'Customer',required=True),

'start_date': fields.date("Start Date"),

'end_date': fields.date("End Date"),

}

product_history()

class product_equipment(osv.osv):

_name = "product.equipment"

_description = "equipment"

_inherit = ['mail.thread','ir.needaction_mixin','product.history']

_columns = {

'main_location': fields.function(_last_name,type='many2one', string='Location', readonly = True),

}

def last_location(self, cr, uid, ids, field_name, arg, context=None):

return self.pool.get('product.history').browse(cr, uid, ids)

product_equipment()




0
Avatar
Descartar
Avatar
Temur
Best Answer

from your question I do not see how to identify last location for particular product, but here is how to get last location

class product_equipment(osv.osv):
_name = "product.equipment"
_description = "equipment"
_inherit = ['mail.thread','ir.needaction_mixin','product.history']

_columns = {
'main_location': fields.function(_last_name,type='many2one',obj='product.history', string='Location',readonly=True),
}

def _last_name(self, cr, uid, ids, field_name, arg, context=None): res = {}
      for id in ids: res[id] =
self.pool.get('product.history').search(cr, uid, [ ], limit=1, order="create_date desc")
return res
product_equipment()

it'll find the latest location from all locations... but you'll need to add search domain inside [ ] of search function, in order to get last location for a particular product if you're going to track multiple products (for a single product it should work as is)...

0
Avatar
Descartar
Temur

please try above code first and check if it works in general with empty [ ] -search domain... then we'll need to implement correct domain, it should be something like:

[ ( 'id', 'in', location_ids) ]
where location_ids is variable containing all location ids related to current product. it may be retrieved from one2many field you use for display location list...
Temur

suggestion of search domain:

class product_equipment(osv.osv):
    _name = "product.equipment"
    _description = "equipment"
    _inherit = ['mail.thread','ir.needaction_mixin','product.history']

    _columns = {
        'main_location': fields.function(_last_name,type='many2one',obj='product.history', string='Location',readonly=True),
        'location_ids': fields.one2many('product.history', 'equipment_id', 'Location History'), 
# I think you have already "location_ids" field(maybe with different name), but it's not included in the question.... if so, please adapt field name to your case, otherwise add this field...
    }

    def _last_name(self, cr, uid, ids, field_name, arg, context=None):
        res = {}
        for id in ids:
            location_ids = self.browse(cr, uid, id, context).location_ids.ids
            res[id] = self.pool.get('product.history').search(cr, uid, [( 'id', 'in', location_ids) ], limit=1, order="create_date desc")
        return res
product_equipment()
Sylwester Zalewski
Autor

hi, Thanks for your help!! but I still have some problems, because I cant see the result but if I change the type in "main_location" from many2one to e.g char (which shows the ID) I can see the correct ID so I dont know how to fix that. Also I would like to know if I can show the customer not the name from class history.

Temur

either:

'main_location': fields.function(_last_name,type='many2one',obj='product.history', string='Location',readonly=True),
OR
'main_location': fields.function(_last_name,type='many2one', relation='product.history', string='Location',readonly=True),
should work.. make sure you add obj='product.history' (or relation=) part to the field definition.
Sylwester Zalewski
Autor

That's what I did but it doesn't work, I don't know why, it looks like empty space... any suggestions ?

Temur

to 'product.history' object definition add the following line:

_rec_name = "customer"
-it'll show customer instead of name of product.history record... and try with obj='product.history' in 'main_location' field definition, without relation='product.history', do not forget to restart odoo and then update/upgrade module from "Settings/Modules/Local Modules" page as you make changes.
Avatar
Axel Mendoza
Best Answer

It's not clear what you are trying to do, but here are some corrections in bold:

class product_equipment(osv.osv):
_name = "product.equipment"
    _description = "equipment"
    _inherit = ['mail.thread','ir.needaction_mixin','product.history']

    _columns = {
        'main_location': fields.function(_last_name,type='many2one',relation='product.history', string='Location',readonly=True),
    }

    def _last_name(self, cr, uid, ids, field_name, arg, context=None):
        return self.pool.get('product.history').browse(cr, uid, ids[0])
product_equipment()
0
Avatar
Descartar
Sylwester Zalewski
Autor

unfortunately its not working and same error appears. I will try to explain it better so - I have history list at the bottom in the equipment class and I want to show the last added element outside the list (in the form to show current customer )

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
ver=Any: field meny2one the recommended way...
many2one odoo
Avatar
Avatar
Avatar
2
de març 24
2408
ODOO9: How to correct this condition?
many2one odoo
Avatar
Avatar
1
d’abr. 16
3922
many2one field search for by multiple criteria (name, phone number, etc)?
many2one search odoo
Avatar
Avatar
Avatar
2
de febr. 25
9434
many2one unlink without delete (v16)
many2one odoo odoo16features
Avatar
Avatar
1
d’abr. 24
2480
many2one options=no_open in tree view not working in odoo
invoice many2one odoo
Avatar
Avatar
1
d’oct. 23
9763
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