Odoo Help


Bug which occurs with computed Fields in models.py when having _inherits models

Stefan Wild
on 1/30/15, 10:25 AM 1,039 views

Hello everybody,

I have got a problem that when I create a record which inhertis form a record which has got computed fields, that the computed fields in the parent record don't get computed.

Here is an example:






Following Model Sturcture With Inheritance:

sale.order -> subclass.sale.order (with _inherits)

sale.order.line -> subclass.sale.order.line (with _inherits)

subclass.sale.order -> subclass.sale.order.line (1:n relation) 1-filed in subclass.sale.order: "subclass_order_line_ids"

Here is the relevant part of my python code:

class subclass_sale_order(orm.Model): 

 _inherits = {'sale.order': 'openerp_id'}

_columns = { 'openerp_id': fields.many2one('sale.order', string='Sale Order', required=True, ondelete='cascade'),

'subclass_order_line_ids': fields.one2many('subclass.sale.order.line', 'subclass_order_id', 'Subclass Order Lines'), }

class sale_order(orm.Model):

_inherit = 'sale.order'

_columns = { 'subclass_bind_ids': fields.one2many( 'subclass.sale.order', 'openerp_id', string="Subclass Bindings"), } 

class subclass_sale_order_line(orm.Model):

_inherits = {'sale.order.line': 'openerp_id'}

_columns = { 'openerp_id': fields.many2one('sale.order.line', string='Sale Order Line', required=True, ondelete='cascade'), 'subclass_order_id': fields.many2one('subclass.sale.order', 'Subclass Sale Order', required=True, ondelete='cascade', select=True), }

def create(self, cr, uid, vals, context=None):

subclass_order_id = vals['subclass_order_id']

info = self.pool['subclass.sale.order'].read(cr, uid, [subclass_order_id], ['openerp_id'], context=context)

order_id = info[0]['openerp_id']

vals['order_id'] = order_id[0]

return super(subclass_sale_order_line, self).create(cr, uid, vals, context=context)

class sale_order_line(orm.Model):

_inherit = 'sale.order.line'

_columns = { 'subclass_bind_ids': fields.one2many( 'subclass.sale.order.line', 'openerp_id', string="Subclass Bindings"), }


For creating a record i have got follwing data:

record = { 

'user_id': False, 

'pricelist_id': 1L, 'name': u'20002', 

'partner_id': 5, 

'partner_invoice_id': 5, 

'partner_shipping_id': 5, 

        (0, 0, { 
            'product_uos_qty': 3, 
            'name': u'MyArtikel2_OhneVariante',             
            'price_unit': 10, 
            'product_uom_qty': 3, 
            'product_id': 1}), 
          (0, 0, { 
            'product_uos_qty': 2, 
            'name': u'MyArtikel_OhneVariante', 
            'price_unit': 10, 
            'product_uom_qty': 2, 
            'product_id': 1}) ] 

The Problem:

Here is a link for a picture:


When i create a record, with the given data, and put the order_lines in the inherited class (subclass_sale_line_ids) then the computed fields of the sale_order class(_amount_all_wrapper) is not called. 

The Problem is in the models.py / fields.py class:

odoo want to prevent that computed fields ar calculated in the many part of a one2many relation.

Therfore they set in fields.py context['recomputed'] = false (ca. line 739)

The Problem now is following:

  • First the models.py class creates a subclass.sale.order
  • Then a the inherited class sale.order is created "recompute = TRUE, but nothing to compute because there are no lines yet"
  • Then the related class subclass.sale.order.line (many - part) of the one2many relation is created "recomputed = FALSE, because of that is the many-part"
  • Then the inherited class sale.order is created "recompute is still FALSE"
  • Now everything is created and the create method of subclass.sale.order gets finished. "Recompute is TRUE" now
  • But the class has no computed fields, and result = NONE (models.py @line about (4227)) 
  • So the amount of my sale order doesn't get computed

The solution in odoo 7 was in line ca. 4503 of orm.py

# When linking/creating parent records, force context without 'no_store_function' key that
# defers stored functions computing, as these won't be computed in batch at the end of create(). 
parent_context = dict(context)
parent_context.pop('no_store_function', None)

They created a new Context where "recompute" = TRUE ('no_store_function' = NONE) when they create a parent class
So the Compution is done when I create a sale.order.line

I hope that a part of you is able to understand my explation of the problem :)

Is that a real Bug of odoo 8?

What could be the solution for my problem ?




About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 1/30/15, 10:25 AM
Seen: 1039 times
Last updated: 3/16/15, 8:10 AM