Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

v17: create parent child record in another table on Save

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
v17
1 Svar
1508 Visninger
Avatar
SmithJohn45

in Automation Rules we do not have Triggers like Before Create but there is On Save which work fine for creating record(s) in another table(s),  but if there is no relation field for Action Create Record and also if i want to create parent-child records how it can be done?

i tried using Execute Code as below but it throws error.

Model : Approval Request

Trigger : On Save

Execute Code:

    if record.request_status=='approved' and record.category_id in (8, 9, 13):

        # Create stock.picking record

        picking_data = {

            'picking_type_id': 1,

            'company_id': 1,

            # Add other required fields

        }

        stock_picking = env['stock.picking'].create(picking_data)

    

        for approval_line in record.approval_product_line: 

            # Create stock.move record

            move_data = {

                'picking_id': stock_picking.id,

                'product_id': approval_line.product_id.id,

                'product_uom_qty': approval_line.quantity,

                'company_id': 1,

                'product_uom': 1,

                # Add other required fields

            }

        stock_move = env['stock.move'].create(move_data)


error for stock.move:

ValueError: : "'approval.request' object has no attribute 'approval_product_line'" while evaluating


this is my first attempt to create a parent-child record using python code in Automation Rule, i don't know how to about the child side records in this scenario.

can somebody please help with correction in code for stock.move where i want to create Line records which can be multiple as i am totally blank here.

regards


please note: there is an another Automation Rule exists for On Save trigger for same Model mentioned above.


0
Avatar
Kassér
Avatar
SmithJohn45
Forfatter Bedste svar

it has been done, i am using below code to create Internal Transfer records successfully using below code, the juniors like me can get benefit. request to all juniors please at least respond with counter question(s) if someone misunderstood or approach is wrong like Oracle related forum seniors.

-----

#raise UserError(f'{record.request_status} - {record.category_id.id}')

if record.request_status=='approved' and record.category_id.id in (8, 9, 13):

    new_stock_picking = env['stock.picking'].create({

      'picking_type_id': 1,

      'company_id': 1,

    })


    for approval_line in record.product_line_ids: 

        # Create stock.move record

        move_data = {

            'picking_id': new_stock_picking.id,

            'picking_type_id': 5,

            'product_id': approval_line.product_id.id,

            'product_uom_qty': approval_line.quantity,

            'name': approval_line.product_id.name,

            'company_id': 1,

            'product_uom': 1,

            'location_id': 1,

            'location_dest_id': 1,

            # Add other required fields

        }

        stock_move = env['stock.move'].create(move_data)

the 'picking_type_id': 5  it means picking type is Internal Transfer, system will use INT sequences for this type of entries.

regards

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Avatar
Avatar
1
okt. 25
1520
How to add a new Many2one field in res.config.settings? Løst
v17
Avatar
Avatar
Avatar
Avatar
4
okt. 25
4151
Add field to ALL models in Odoo
v17
Avatar
Avatar
Avatar
2
sep. 25
2703
How to disable Email notification - You have been assigned to Løst
v17
Avatar
Avatar
Avatar
Avatar
4
sep. 25
8245
Selection Field Options Disappear from Database (PostgreSQL enum) on Module Upgrade
v17
Avatar
0
aug. 25
1463
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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