Pregunta

I installed the product_brand module for OpenERP 6.1.

Through web client, I managed to show the product brand in the product list page by inherited the product.product.tree view through debug (developer) mode by inserting the product_brand_id field.

Now I want the product brand name to show in the sale.order.line.tree view of a sales order.

I noticed they are different models, one is product.product, and the other is sale.order.line. Is it possible to show fields of other models in OpenERP?

How to reference a field name across related (different) models?

¿Fue útil?

Solución

Its possible using related fields. First you need to inherit the sale order model and add a related field for product brand id For example:

from osv import osv, fields
class sale_order_line(osv.osv):
    _inherit = 'sale.order.line'
    _columns = {
        'brand_id': fields.related('product_id','product_brand_id',string='Brand',type='many2one',relation='product.brand')
    }
sale_order_line()

Then need to inherit the sale order view. Sale order line tree and form view is specified inside the sale order view. SO inherit the sale order form view using xpath.For example:

<?xml version="1.0" encoding="utf-8"?>
  <openerp>
    <data>
      <record model="ir.ui.view" id="view_order_inherited_brand">
        <field name="name">sale.order.brand</field>
        <field name="type">form</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form" />
        <field name="arch" type="xml">
          <xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="after">
              <field name='brand_id'/>
          </xpath>
        </field>
      </record>
  </data>
</openerp>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top