Hi there fellow developers
in Odoo 8's product.py I see the name_search method concatenates the product name and variant as the product name. I however have hundreds of attributes to my product.
Height: 500mm, 505mm, ... 3000mm
Width: 500mm, 505mm, ... 4000mm
So it makes it impossible to search the desired variant
So i need first select the product, Then the Height attribute, Then the Width attribute
In Theory I need to override the search method
remove the variant in product name
create a search method to select first attribute
create another search method to select second attribute
then it needs to return the product name + att1 + att2 to main search method
Can anyone point me in the right direction?
I really need some serious assistance. Speak to me about cash for code if really neccesary :)
My .py
from openerp import models, fields, api
class product_template(models.Model):
_inherit = 'product.template'
palepoint = fields.Char("Pale Point", size=20)
materialoptions_id = fields.Many2one("product.category","Material Options")
class Sale_order(models.Model):
_inherit = 'sale.order'
material_id= fields.Many2one("product.template","Material",domain=[('categ_id.name','=','Raw Material')])
class product_product(models.Model):
_inherit = 'product.product'
#This search filter the products by selected product category which works fine
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
if context is None:
context = {}
if context.get('material_id'):
productobj = self.pool.get('product.product').read(cr, uid, context['material_id'],['materialoptions_id'])
args = [('categ_id','=',productobj['materialoptions_id'][0])] + args
return super(product_product, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
My view
<openerp>
<data>
<record model="ir.ui.view" id="partner_palepoint_form_view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<field name="list_price" position="after">
<field name="materialoptions_id"/>
</field>
<notebook position="inside">
<page string="Pale Point">
<group>
<field name="palepoint"/>
</group>
</page>
</notebook>
</field>
</record>
<record model="ir.ui.view" id="sale_view_form_view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale_stock.view_order_form_inherit"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="material_id"/>
</field>
<xpath expr="//field[@name='product_id']" position="attributes">
<attribute name="context">{'material_id': parent.material_id}</attribute>
</xpath>
</field>
</record>
</data>
</openerp>
And good old Odoo 8's product.py nam_search method
def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):
# Only use the product.product heuristics if there is a search term and the domain
# does not specify a match on `product.template` IDs.
if not name or any(term[0] == 'id' for term in (args or [])):
return super(product_template, self).name_search(
cr, user, name=name, args=args, operator=operator, context=context, limit=limit)
product_product = self.pool['product.product']
results = product_product.name_search(
cr, user, name, args, operator=operator, context=context, limit=limit)
product_ids = [p[0] for p in results]
template_ids = [p.product_tmpl_id.id
for p in product_product.browse(
cr, user, product_ids, context=context)]
# re-apply product.template order + name_get
return super(product_template, self).name_search(
cr, user, '', args=[('id', 'in', template_ids)],
operator='ilike', context=context, limit=limit)