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

Differences in Create Method Between Neutralized and Live Databases

Subscribe

Get notified when there's activity on this post

This question has been flagged
1 Reply
777 Views
Avatar
Luis Garcia

Hi all,

I noticed something a bit curious after shipping a new feature on a customized Odoo 18 instance on Odoo.sh. We built a custom integration with a service, and part of our implementation involved overriding the create​ and write​ methods in the res.partner​ model to make calls to the service (see the example code below).

  def create(self, vals):

    '''

      Override account creation so that a brivo user is

      created along with this user.

    '''

    res = super().create(vals)

    res._create_brivo_user()

    return res


  def write(self, vals):

    '''

      Override account editing so that the brivo user

      is edited along with this user.

    '''

    res = super().write(vals)

    # Update or create the brivo user on write if the user is active

    if not self.env.context.get('skip_brivo_call_on_write', False) and self.active:  

      if self.brivo_id:

        brivo_update_user(self.env, self)

      else:

        self._create_brivo_user()

    # If the user's barcode was updated,

    # update the Brivo user's credential

    if not self.env.context.get('skip_brivo_call_on_write', False) and vals.get('barcode') and self:

      self._update_user_barcode_credential()

    return res

So, when we call create​, we create a corresponding user on the service (Brivo). We then use the context to avoid making extra calls in write​ because we understand that there's an automatic call to it that's made after the call to create​.

This flow worked perfectly fine on a local (neutralized) copy of our database. However, when we tested it in a production database, we were unable to create new contacts on Odoo. Inspecting the logs, I noticed that there were extra, unexpected calls being made to the Brivo service that were causing creation to fail. After a bit of digging, I realized that the write​ method was being called before the new contact record was being written to the database. We fixed the issue by removing our create​ override.

I expected the flow to be like this: create​, then write to database, then write​. This seemed to be how it worked in the local copy of the database. That doesn't seem to be the case in the production copy.

What are the differences in the create/write lifecycle between a production and a neutralized database, if any?

0
Avatar
Discard
Ray Carnes (ray)

Neutralized databases are just "cut off" from integrations such as bank feeds, shipping, email - things that allow them to "contact the outside world".

Think of CREATE as a database SQL INSERT and WRITE as a database SQL UPDATE.

WRITE is not part of CREATE nor is it called before or after it - it is a separate call. Something else is going on.

Ray Carnes (ray)

What may be happening is that your CREATE call is providing data for a field that is used as a dependency for a class method that provides the value for another field, so WRITE is called after your call because of this.

Creating a new res.partner with a value for parent_id will trigger a write to compute the value of commercial_partner_id.

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,


In Odoo, the lifecycle is always the same: create() writes the new record to the database and then returns a recordset; write() is only called explicitly, not as part of create().


If you saw write() being triggered after create() in your local environment, it was likely due to default values, Studio customizations, or another module calling write() right after creation.


A “neutralized” (sanitized) copy of a database doesn’t behave differently at ORM level, but it may have fewer modules, fewer records, or missing automation, which explains why the extra write() never appeared.


In production, you may have additional modules, server actions, automated fields, or integrations that explicitly trigger a write() right after create().


Many standard Odoo features update records immediately after creation (e.g. assigning sequences, computing related fields, creating followers), which results in extra write() calls.


That’s why overriding both create() and write() with external API calls is risky — you can end up with duplicate or premature calls.


A safer pattern is to keep the API call logic in a dedicated method and trigger it via @api.model_create_multi, @api.onchange, or via a post-commit hook depending on your needs.


In short: the ORM lifecycle is identical across environments; the difference is the extra automation/customizations present in production that trigger write() calls you didn’t see locally.


Hope it helps.

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
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