Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenERP-只读字段在“打开”时不保存;“保存”;按钮按下了_Openerp - Fatal编程技术网

OpenERP-只读字段在“打开”时不保存;“保存”;按钮按下了

OpenERP-只读字段在“打开”时不保存;“保存”;按钮按下了,openerp,Openerp,在一个视图中,我将字段“default_code”替换为同名字段。当我将此字段设置为只读时,单击“保存”按钮时不会保存该字段。它应该被保存。以下是整个视图的代码: <?xml version="1.0" encoding="utf-8"?> <openerp> <data> <record id="product_config_form_view" model="ir.ui.view"> <fi

在一个视图中,我将字段“default_code”替换为同名字段。当我将此字段设置为只读时,单击“保存”按钮时不会保存该字段。它应该被保存。以下是整个视图的代码:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="product_config_form_view" model="ir.ui.view">
            <field name="name">product.config.form.view</field>
            <field name="model">product.template</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="mrp.product_template_form_view_bom_button" />
            <field name="arch" type="xml">
                <label for="name" position="replace">
                    <label for="name" invisible="1"/>
                </label>
                <field name="name" position="replace">                      

                    <div style="font-size:10pt;">
                        <label for="class_id" string="Item Class" />
                    </div>
                    <div style="font-size:10pt;">
                        <field name="class_id" colspan="3" nolabel="1" on_change="onchange_class_id(class_id)"
                        /> </div> 
                    <div style="font-size:10pt;">
                        <label for="name" string="Item Description"/>
                    </div>
                    <div style="font-size:10pt;" >
                        <field name="name" colspan="3" nolabel="1"/>
                    </div>

                </field>

                <field name="default_code" position="replace" >
                    <field name="default_code" string="Item Number" /> 
                </field>

                <xpath expr="//notebook/page[@string='Accounting']/group" position="replace">
                </xpath>
            </field>        
        </record>

        <record id="product_config_tree_view" model="ir.ui.view">
            <field name="name">product.config.tree.view</field>
            <field name="model">product.class</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Product">
                    <field name="default_code" string="Class ID" colspan="3" nolabel="1" />                         
                    <field name="name" string="Class Description" colspan="3" nolabel="1"/>                     
                </tree>
            </field>          
        </record>    

        <record id="class_search_view" model="ir.ui.view">
            <field name="name">class.search.view</field>
            <field name="model">product.class</field>
            <field name="arch" type="xml">
                <search string="Class">
                    <field name="name" string="Class Description" filter_domain="['|',('default_code','ilike',self),
                    ('name','ilike',self)]" />                                
                </search>
            </field>
        </record>

    </data>
</openerp>

变通办法。我已经通过使用一个函数字段(invisible=False,readonly=True)解决了这个问题,该字段使用默认的\u代码(并模仿视图中的项目编号)进行了更新,我将原始的默认\u代码设置为readonly True和invisible True,以便将其保存在数据库中

也许对你有帮助。我以前读过这篇文章,它不能解决我的问题。谢谢。不,我没有,因为我不确定在哪里输入那段代码。好的,我找到了插入补丁的地方,它成功了。但是,修补程序代码将被新的OpenERP版本代码覆盖。我说的对吗?还有其他方法吗,比如过度隐藏write()或create()函数?
class product_product(osv.Model):
    _inherit = 'product.product'

    def create(self, cr, uid, vals, context=None):
        # raise osv.except_osv(_(u'TitleMessage'), _(u'Inside Create'))
        code = vals.get('default_code')
        vals.update({'default_code': code})
        print "\n\nCreate Value=> ",vals
        return super(product_product, self).create(cr, uid, vals, context)


    def write(self, cr, uid, ids, vals, context=None):
        # raise osv.except_osv(_(u'TitleMessage'), _(u'Inside Write'))
        print "\n\n\nCurrent Values =>", valswrite
        code = vals.get('default_code')
        print "\n\nWrite Value=> ",vals
        vals.update({'default_code': code}) 
        return super(product_product, self).write(cr, uid, ids, vals, context)