Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
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
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…!
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>
About This Community
This platform 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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 12/28/15, 2:52 PM |
Seen: 659 times |
Last updated: 12/29/15, 2:02 PM |
I am not getting. will you elaborate more using one example?