Odoo Help

Welcome!

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.

0

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

By
Stefan Wild
on 1/30/15, 10:25 AM 739 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, 

'subclass_order_line_ids': 
    [ 
        (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:

http://www.plantuml.com/plantuml/png/fPDTJy8m58Rl-HNdabrO3I4XUc54hKg2cs4ZnYjIjeCqwTgbBIB_taE7J9BXHxnRs_FnlEUyAqs1oh5g0oUNKEuF5v1R51wxRZNFbN2EEQ6G6LkWZJeYz_ADNfk4JjbQfodpVROsTBJoTUa_Cy0l4IfXKNi8060Mq09pjB75t9JLokD1yVqjh9Ue8JVQuxjdpRLqa4sc7BfYRbOUbDG8_Lwl5p5uG1lUc-0GEQSmWgKteWLj8725J0SRz9q2VvhNGg8gTdCt6dkbq1lcq7SZcF2RvF5fcd6uvraATyDnoWyKnMOTPjKo6rOpRB7geHQaMkRBS2CrY7qpqgI4bqRlL4xs4b_HE_2cRjo0NeN13FfddORzvB9bxqUe_kIX1pxXC8eXkKsI0JmFqozJINa6MRBRMIuOZ4SnXtx_VB0rZB4bLOZWz1Ik-SrmIXAIEof55KTP-dlJripm3v-62dyHtRYicyJZbrfyT42mC8H0wmoxs7BCH4ccdGcbPcihgefiI7xDwOm5WqIhpM5E-0TgxrBSJ6hwbBJlONnRzpj6XxfejtNRvGS0

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 ?

 

 

 

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

2 follower(s)

Stats

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