Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • 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 Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & 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
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Write method called in the create method

Subscribe

Get notified when there's activity on this post

This question has been flagged
createv7write
1 Reply
8828 Views
Avatar
N

I have created a custom module and i am redefining the create and write methods. When i create a new sale order, the method create is called, but also the write method.. How it is possible ? Thanks

def create(self, cr, uid, vals, context=None):
    # creation du devis par heritage(et des lignes de commandes du devis) // obligatoire de creer le devis pour acceder aux lignes du devis
    id = super(sale_order, self).create(cr, uid, vals, context)
    # creation d'une liste vide qui contiendra tous les numeros de sections saisis dans la vue
liste_numeros_section = []
    # recuperation des id de chaque ligne du devis (qui ne sont pas des options)
    order_line_ids = self.pool.get('sale.order.line').search(cr, uid, [('order_id', '=', id), ('is_option', '=', False)], context=context)
    #recuperation de l'objet section
    section_pool = self.pool.get('sale.order.section') 
    for i in self.pool.get('sale.order.line').browse(cr,uid,order_line_ids, context=context): # pour chaque ligne du devis
        # si nouveau numero de section, alors creation section + lien avec ligne de devis actuelle
        if not(i.number_section in liste_numeros_section):
            liste_numeros_section.append(i.number_section)
            dict_section = {
                'order_id': id,
                'order_line': [(4, i.id)], # lier ligne du devis actuelle a la section (creation d'une relation)
                'number': i.number_section,
             }
             section_pool.create(cr,uid,dict_section, context=context)
        else:
            # si le numero de section existe deja, alors creation lien ligne du devis actuelle /section
            id_section = self.pool.get('sale.order.section').search(cr,uid, [('number', '=', i.number_section), ('order_id', '=', id)], context=context) #recupere section qui correspond a la ligne du devis
            dict_section = {
                'order_line': [(4, i.id)], # lier ligne du devis actuelle a la section (creation d'une relation)
            }
            section_pool.write(cr,uid,id_section,dict_section, context=context)
        return id

    def write(self, cr, user, ids, vals, context=None):
        raise osv.except_osv(_('Erreur!'),_('Vous ne pouvez pas confirmer une commande qui contient une ou des options'))
        # mise a jour du devis par heritage
        super(sale_order, self).write(cr, user, ids, vals, context)
        order_id = ids[0] # recuperation de l'id du devis courant
        # recuperation de l'objet ligne de devis
        order_line_pool = self.pool.get('sale.order.line')
        # recuperation de l'objet section
        section_pool = self.pool.get('sale.order.section')
# recuperation des id de chaque ligne du devis (qui ne sont pas des options)
        order_line_ids = order_line_pool.search(cr, user, [('order_id', '=', order_id), ('is_option', '=', False)], context=context)
        # recuperation des id de chaque section du devis
        section_ids = section_pool.search(cr, user, [('order_id', '=', order_id)], context=context)
# creation d'une liste vide qui contiendra tous les numeros de sections saisis dans la vue
            liste_numeros_section = []
        # pour chaque ligne du devis
        for i in self.pool.get('sale.order.line').browse(cr,user,order_line_ids, context=context):
            if not (i.section_id in section_ids): # si nouvelle section
                dict_section = {
                    'order_id': order_id,
    # lier ligne du devis actuelle a la section (creation d'une relation)
                    'order_line': [(4, i.id)],
                    'number': i.number_section,
                }
                section_pool.create(cr,user,dict_section, context=context)
            else:
                dict_section = {
                # mise a jour de la relation entre la section et la ligne du devis
                    'order_line': [(6, 0, i.id)],
                    'number': i.number_section,
                }
                section_pool.write(cr,user,i.section_id,dict_section, context=context)
        return True
2
Avatar
Discard
Avatar
patrick
Best Answer

In order to create a new record, you have to write it to the database. I think that the call to super(sale.order).create(..) will do a call to write (or self.write(..)). At the moment I do not have the code of openERP with me to check this.

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
update fields on write() method Solved
create write
Avatar
Avatar
Avatar
2
Jan 16
36690
launch a wizard before saving a record
wizard create write
Avatar
Avatar
1
Aug 20
5583
Odoo 13 Create() Write() stores old values
create write 13.0
Avatar
Avatar
1
Apr 20
6089
How to create and write multiple records by overriding create and write method of odoo12 Solved
create write odoo12
Avatar
Avatar
1
Sep 19
9765
Creating a record or editing an existing record? How to know?
create write odoo12.0
Avatar
Avatar
Avatar
Avatar
3
Feb 19
10219
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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