简体   繁体   中英

How to put product brand in sale order line?

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM