This question has been flagged
2 Replies
9040 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?

Avatar
Discard
Best Answer

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

Avatar
Discard