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

How to make Function Field with Store parameter?

By
Branimir
on 7/30/13, 6:27 AM 3,751 views

I'm trying to add a searchable field to product.product with the Supplier Reference Code. There is a function already provided to get the default Supplier, so I just had to add the 'seller_product_code' field:

    def _calc_seller(self, cr, uid, ids, fields, arg, context=None):
    result = {}
    for product in self.browse(cr, uid, ids, context=context):
        main_supplier = self._get_main_product_supplier(cr, uid, product, context=context)
        result[product.id] = {
            'seller_info_id': main_supplier and main_supplier.id or False,
            'seller_delay': main_supplier.delay if main_supplier else 1,
            'seller_qty': main_supplier and main_supplier.qty or 0.0,
            'seller_id': main_supplier and main_supplier.name.id or False,
            'seller_product_code': main_supplier and main_supplier.product_code or False
        }
    return result

Then I added this in product.product:

'seller_product_code': fields.function( _calc_seller, type='string',string='Supplier Reference Code',multi="seller_info"),

Until here everything is OK, but now to be able to search it it has to be stored as I understand (or needs fnct_search). I tried putting it as:

store=True

or:

store={'product.supplierinfo': (lambda self, cr, uid, ids, c={}: ids,['product_code'],10)}

But it gives me Error:

AttributeError: 'module' object has no attribute 'string'

What is wrong? How can I make it stored so I can search it, or how the fnct_search must look like?

2

Hello Branimir,

You have provided wrong data-type as "String" which is not supported/provided by odoo, you should either use "Char" or "Text". It should be like type="char" or type="text", in your definition of fields.function.

Regards

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: 7/30/13, 6:27 AM
Seen: 3751 times
Last updated: 3/16/15, 8:10 AM