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

Value of field is not being set during unit test

By
Rui Coelho
on 12/2/15, 1:02 PM 387 views

I'm developing some unit tests for a some methods I added to the product model. In order to make the tests more lean I'm trying to avoid hitting the database and so I'm creating the objects on the fly like this:


class TestModelProduct(common.SingleTransactionCase):
...

   def my_test(self):
object_being_tested = self.env['product.product'].create({'field_something': 'value_something' }) 
child_product = self.env['product.product'].create({'parent_id': object_being_tested.product.id})
...
child_product.write({'field_I_want_to_change': 4.0})
_logger.warning("VALUE: %s", child_product.field_I_want_to_change)
#
#WARNING qa openerp.addons.my_module.tests.test_product:VALUE: 0.0

object_being_tested.method_being_tested(arg1,arg2,arg3)
...
#assertions


The problem I'm having is that when I set the value of 'field_I_want_to_change', that value is not set in the object for some reason.

Am I missing something about the objects that are created inside these tests?


EDIT: after further investigation I found the field is a function field so that may be the root of the problem. Is there a way to override that function?

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)

Stats

Asked: 12/2/15, 1:02 PM
Seen: 387 times
Last updated: 12/2/15, 1:43 PM