DEV Community

SDLC Corp
SDLC Corp

Posted on

How to override the create and write methods in Odoo?

from odoo import models

class MyModel(models.Model):
    _name = 'my.model'

    def create(self, vals):
        vals['name'] = vals.get('name', '').upper()
        record = super(MyModel, self).create(vals)
        return record

    def write(self, vals):
        if 'name' in vals:
            vals['name'] = vals['name'].upper()
        result = super(MyModel, self).write(vals)
        return result

Enter fullscreen mode Exit fullscreen mode
  • create: Called when a new record is created. Here, it modifies the name field to uppercase.
  • write: Called when updating an existing record.

For companies seeking to expand the functionality of their ERP systems, SDLC Corp, an Odoo development company, offers robust solutions to integrate and customize Odoo for specific business needs, including solutions like S-Invoice. With a team of experienced developers, SDLC Corp ensures seamless integration of advanced tools and customizations into the Odoo framework.

As a trusted Odoo development partner, SDLC Corp provides end-to-end services, from requirement analysis and module development to post-implementation support. Their expertise allows companies to leverage Odoo's flexibility and power while tailoring the platform to their unique workflows. By handling all technical requirements, SDLC Corp enables businesses to optimize their ERP efficiently, with a focus on maximizing functionality and improving operational efficiency.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay