0

我想使用我编写的以下代码在销售订单的 sale.order.line.tree 视图中显示产品类别。它显示了 group by 按钮下的类别按钮,但是单击它时,出现以下错误,我不知道如何解决该错误:assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True" AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True

这是我的代码:

from osv import fields, osv<code>
class sales_order_line_category(osv.osv):
_name='sale.order.line'
_inherit='sale.order.line'
_columns={'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.categ_id'),

}

sales_order_line_category()

我的观点:

`<?xml version="1.0" encoding="utf-8"?>

<record id="view_sale_orderlinecategory" model="ir.ui.view">
        <field name="name">sale.order.line.categoryinherit</field>
        <field name="model">sale.order.line</field>
        <field name="type">tree</field>
        <field name="inherit_id" ref="sale.view_order_line_tree"/>
        <field name="arch" type="xml">
            <field name="name" position="after">
                        <field name="categ_id" string="Category"/>
            </field>            
        </field>    

    </record>



    <record id="view_sale_orderlinecategory2" model="ir.ui.view">
        <field name="name">sale.order.line.categoryinherit2</field>
        <field name="model">sale.order.line</field>
        <field name="type">search</field>
        <field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
        <field name="arch" type="xml">

    <group expand="0" string="Group By..." >
                <filter string="Category of Product" icon="terp-stock_symbol-selection" name="Category"                     context="{'group_by':'categ_id'}"/>
            </group>


        </field> 
    </record>

     <record id="view_sale_orderlinecategory3" model="ir.ui.view">
        <field name="name">sale.order.line.categoryinherit3</field>
        <field name="model">sale.order,line</field>
        <field name="type">search</field>
        <field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
        <field name="arch" type="xml">


            <field name="name" position="before">
                        <field name="categ_id" string="Category"/>
                        </field>


        </field> 
    </record>

</data>

`

4

1 回答 1

0

请您尝试使用以下代码替换吗?

'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.category', store=True),

检查您的字段 categ_id 是否必须出现在您尝试按 categ_id 分组的 sale.order.line 的树视图中

希望这有帮助

于 2013-03-21T05:26:29.110 回答