Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
one2manyonchange
1 Odpoveď
13241 Zobrazenia
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
Zrušiť
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
Zrušiť
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!

Registrácia
Related Posts Replies Zobrazenia Aktivita
How to update two levels o2m fileds relation
one2many onchange
Avatar
0
sep 20
3710
Several levels of One2many
one2many onchange
Avatar
0
apr 16
3834
One2many onchange in ODOO Solved
one2many onchange
Avatar
Avatar
3
mar 16
14880
How to return domain on one2many field so that seleted values are not shown in next line
domain one2many onchange
Avatar
1
apr 23
5930
onchange return domain for one2many product ID Field Solved
domain one2many onchange
Avatar
Avatar
Avatar
Avatar
7
apr 23
19879
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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