Skip to Content
Menu
This question has been flagged
3 Replies
6041 Views


    i want to add new column in tree view of  Product Variant Values(product --> configure variants) 

from the 'product.template' class  through Many2one 'product_tmpl_id' field , 

 needed this filed list_price(sale price of product)



thanks and regards

shaneeb


Avatar
Discard
Author

am attaching tree view

<record id="product_template_attribute_value_view_tree" model="ir.ui.view">

<field name="name">product.template.attribute.value.view.tree</field>

<field name="model">product.template.attribute.value</field>

<field name="type">tree</field>

<field name="arch" type="xml">

<tree string="Attributes" create="0" delete="0" >

<field name="attribute_id"/>

<field name="name"/>

<field name="price_extra" />

<field name="product_tmpl_id" /> # it display name of 'product.template'

<field name="product_tmpl_id.list_price" /> # it not working

</tree>

</field>

</record>.

is there any chance to get 'product_tmpl_id.list_price' from 'product.template' ?

relation between 'product.template' and "product.template.attribute.value"

class ProductTemplateAttributeValue(models.Model):

"""Materialized relationship between attribute values

and product template generated by the product.template.attribute.line"""

_name = "product.template.attribute.value"

_order = 'sequence, attribute_id, id'

_description = 'Product Attribute Value'

name = fields.Char('Value', related="product_attribute_value_id.name")

product_attribute_value_id = fields.Many2one( 'product.attribute.value', string='Attribute Value', required=True, ondelete='cascade', index=True)

product_tmpl_id = fields.Many2one( 'product.template', string='Product Template', required=True, ondelete='cascade', index=True)

list_price = fields.Many2one( 'product.template', string='list_price', required=True, ondelete='cascade', index=True)

attribute_id = fields.Many2one( 'product.attribute', string='Attribute', related="product_attribute_value_id.attribute_id")

sequence = fields.Integer('Sequence', related="product_attribute_value_id.sequence")

price_extra = fields.Float( string='Attribute Price Extra', default=0.0, digits=dp.get_precision('Product Price'),

help="""Price Extra: Extra price for the variant with this attribute value on sale price. eg. 200 price extra, 1000 + 200 = 1200.""")

exclude_for = fields.One2many( 'product.template.attribute.exclusion', 'product_template_attribute_value_id', string="Exclude for",

relation="product_template_attribute_exclusion", help="""Make this attribute value not compatible with other values of the product or some attribute values of optional and accessory products.""")

Author

how can show one more field from many2one class in tree view?

Author Best Answer

class ProductTemplate(models.Model):
_inherit = "product.template"

@api.multi
def name_get(self):
print("yesy yes .....",self._context.get('template_list_price'))
if self._context.get('template_list_price'):
print([(template.id, '%s' % template.list_price)
for template in self])
return [(template.id, '%s' % template.list_price)
for template in self]
else :
print([(template.id, '%s%s' % (template.default_code and '[%s] ' % template.default_code or '', template.name))
for template in self])
return [(template.id, '%s%s' % (template.default_code and '[%s] ' % template.default_code or '', template.name))
for template in self]
return ''

<record id="product_template_attribute_value_view_tree_inherit" model="ir.ui.view">
<field name="name">product.template.attribute.value.view.tree</field>
<field name="model">product.template.attribute.value</field>
<field name="inherit_id" ref="product.product_template_attribute_value_view_tree"/>
<field name="arch" type="xml">
<field name="price_extra" position="after">
<field name="product_tmpl_id" context="{'template_list_price': True}" />
<field name="price_attribute" on_change="onchange_price_attribute(price_attribute)" />
</field>
</field>
</record>


<record id="product_attribute_value_action_inherit" model="ir.actions.act_window">
<field name="name">Product Variant Values</field>
<field name="res_model">product.template.attribute.value</field>
<field name="inherit_id" ref="product.product_attribute_value_action"/>
<field name="view_mode">tree,form</field>
<field name="domain">[('product_tmpl_id', '=', active_id)]</field>
<field name="view_ids"
eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('product.product_template_attribute_value_view_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('product.product_template_attribute_value_view_form')})]" />
<field name="context">{
'default_product_tmpl_id': active_id,'template_list_price': True
}</field>
</record>

Avatar
Discard