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

How to Import one2many field record from one model to one2many field in another model

Subscriure's

Get notified when there's activity on this post

This question has been flagged
one2manyonchange
1 Respondre
13238 Vistes
Avatar
Nanda Kanoko

I need to import record saved from my o2m field to another o2m field in different model

class notebook_project(osv.osv):
    _name = "notebook.project"
    _description = "Notebook Project ID"

    def onchange_project_id(self, cr, uid, ids, project_id, arg, context=None):
        if project_id :
            prod = self.pool.get('project.project').browse(cr, uid, project_id, context=context)
            return {'value': {'name': prod.name}}
        return {}   

    _columns = {
        'name' : fields.char('Name', size=64),
        'project_id' : fields.many2one('project.project', 'Project'),
        'notebook_project_lines' : fields.one2many('notebook.project', 'notebook_project_id', 'Members Lines'),
        'notebook_project_id': fields.many2one('notebook.project', ondelete='cascade', select=True),
        'project_member' : fields.many2one('hr.employee', 'Members'),

        }

notebook_project()

Explanation :

I assigned some employee to certain project . When i see in my PostgreSQL , the notebook_project_id already record the ID that shows some employee already assigned to the project ID they assigned to . How can I call those record on different model ?

Ex : In first model , Project A have employee 1 , 2 , 3 . And on second model , when i choose project A and save , the field shows employee 1 , 2 , 3 on project A The models is somehow like mrp.bom and mrp.production . first model is mrp.bom and second model is mrp.production Please help !

0
Avatar
Descartar
Avatar
ainur rofiq
Best Answer

I am not expert in python, there may be a better solution then this stupid code :)

class main_model(osv.osv)
    _name = "your.main.model"
    _columns = {
        'main_o2m':fields.one2many('some.model', 'field_id', 'Label', required=False),
        ......
    }

    def create(self, cr, user, vals, context={}):
        #first model
        first_obj = self.pool.get('your.first.model')
        #browse and get o2m fields, according to your selected project(id)
        first_o2m = first_obj.browse(cr, user, [SELECTED_ID]).lines

        #copy first o2m model to second o2m model
        for line in first_o2m:
            vals['main_o2m'].append([0, False, {'employe_id':line.employe_id.id,}])

        return super(main_model, self).create(cr, user, vals, context)

hope this help. thanks

0
Avatar
Descartar
Nanda Kanoko
Autor

Here is the newest code i made , with error explanation in it . Please kindly check it , thanks . Link :http://stackoverflow.com/questions/17714692/copy-one2many-field-snafu

Nanda Kanoko
Autor

can u explain what is the selected ID ?

ainur rofiq

SELECTED_ID is 'id' of yout first model. this 'id' can be a field value in XML or a result of search condition as you want

Nanda Kanoko
Autor

well , according to my code posted in : http://stackoverflow.com/questions/17714692/copy-one2many-field-snafu ,, which one is the SELECTED_ID one ? because when i tried using notebook_project , it give Attribute Error

ainur rofiq

'project_id', but I get confused about your relation model. Is that work?

Nanda Kanoko
Autor

the truth is , i'm not really sure the relation is perfect , but ppl opinion said it's not wrong .. Actuallu it works , since it able to show the employee from first model ... but the problem is , the employee showed is not according to chosen project ,, the rest you can see at the web . Thanks anyway

Nanda Kanoko
Autor

tried it , it give an attribute error AttributeError: 'browse_record_list' object has no attribute 'lines'

ainur rofiq

that indicate method browse return a list.... try browse(cr, uid,......)[0].lines or if you use search method : project_id = obj.search(.....) then use project_id[0] as parameter in browse method. obj.browse(cr, uid, project_id[0])

Nanda Kanoko
Autor

added that , still got same error

ainur rofiq

I'm sory... I have no idea

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
How to update two levels o2m fileds relation
one2many onchange
Avatar
0
de set. 20
3701
Several levels of One2many
one2many onchange
Avatar
0
d’abr. 16
3830
One2many onchange in ODOO Solved
one2many onchange
Avatar
Avatar
3
de març 16
14874
How to return domain on one2many field so that seleted values are not shown in next line
domain one2many onchange
Avatar
1
d’abr. 23
5926
onchange return domain for one2many product ID Field Solved
domain one2many onchange
Avatar
Avatar
Avatar
Avatar
7
d’abr. 23
19874
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