Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


"Write" called twice on update, once on creation, and "Create" never called?

on 3/4/15, 9:44 AM 420 views


I'm overriding the Create and Write methods for Project.Task model, using following code on Odoo v8.0-20150224:

from openerp import models, fields
import logging

_logger = logging.getLogger(__name__)

class project_task(models.Model):

    _inherit = "project.task"

    has_event = fields.Boolean('Has associated event')

    def create(self, cr, uid, values, context=None):
        if context is None:
            context = {}
        _logger.log(logging.INFO, ' ****** CREATE CALLED AT ' + datetime.datetime.now().strftime("%H:%M:%S.%f"))
        res = super(project_task, self).create(cr, uid, values, context)
        return res

    def write(self, cr, uid, ids, values, context=None):
        if context is None:
            context = {}
        _logger.log(logging.INFO, '##### WRITE CALLED AT ' + datetime.datetime.now().strftime("%H:%M:%S.%f"))
        res = super(project_task, self).write(cr, uid, ids, values, context)

The log shows that:

  • upon creation, Write is called twice or more UPDATE: at least one time, write is called without any editing but "message_last_post" field only
  • upon editing, Write is called once
  • Create is never called

Is this a normal behaviour?

On 3/4/15, 11:33 AM
  1. the task creation involves some nested updates ("message_last_post", "date_deadline" computation)
  2. in order to solve my issue I set a context entry in Create, and in Write I check that entry: if present, do not proceed with override actions.


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 3/4/15, 9:44 AM
Seen: 420 times
Last updated: 3/16/15, 8:10 AM