This question has been flagged

hi!!! I have added the “origen” attribute to the sale_order class, as I mentioned above this field is linked using a many2one relation to a product attribute value.


This is the class definition:


class sale_order(osv.osv):

_name = "sale.order"

_inherit = 'sale.order'


_columns = {

'fecha_entrega_cliente': fields.datetime('Entrega Solicitada'),

'turno_id': fields.many2one('calendar.event','Turno'),

'obra_id': fields.many2one('sale.obra','Obra', domain="[('name','=',partner_id)]"),

'ubicacion': fields.char('Ubicacion'),

'zona': fields.many2one('sale.zona' ,string='Zona'),

'origen': fields.many2one('product.attribute.value' ,string='Origen'),

}


I want to filter the products shown in a sales order line using the 'origen' attribute . I tried using .xml:


<xpath expr="//tree[@string='Sales Order Lines']/field[@name='product_id']" position="attributes">

<attribute name="domain">[('attribute_line_ids', '=', origen)]</attribute>

</xpath>


But it doesn’t work…


Also tried this in the .py:


class sale_order_line(osv.osv):

_inherit="sale.order.line"

_name="sale.order.line"

_columns={

'origen':fields.related('order_id','origen','id',type="integer"

,string="Origen"),

'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True),('product_variant_ids.attribute_value_ids.attribute_id.id', '=', 'origen')], change_default=True, readonly=True, states={'draft': [('readonly', False)]}, ondelete='restrict'),



But it doesn’t show any product.


I would be really grateful if somebody can help me…!


Avatar
Discard

 I am not getting. will you elaborate more using one example?

Hi guys!!  many thanks for replying. The attribute_line_ids is defined in product.template and the view is in the Variants tab

2015-12-29 7:10 GMT-03:00 Axel Mendoza <portaltemplate12973@mail.odoo.com>:

A new answer for How can I filter products in a sales orders line using a value linked to a variant attribute value of a product? I'm using odoo8 has been posted. Click here to access the post.

--
Axel Mendoza


Best Answer

The thing is that you defined the origen field as a related field.

Related fields only get a value when you save the sale.order.line that will be saved when the sale.order object is saved. So you need to provide a default value for the origen field and change it if necessary using onchange

Or

You could use the sale.order origen field directly in the domain like

<attribute name="domain">[('attribute_line_ids', '=', parent.origen)]</attribute>

Avatar
Discard