0
在一個視圖中,我將字段「default_code」替換爲具有相同名稱的字段。當我將此字段設置爲只讀時,當我單擊按鈕「保存」時它不會被保存。它應該被保存。這裏是整個視圖代碼:OpenERP - 當按下「保存」按鈕時,不會保存只讀字段
<?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>
這裏是我重寫創建()和write(),但它仍然不能正常工作:
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)
可能對您有所幫助。 http://stackoverflow.com/questions/20880422/readonly-field-saved-with-null-value – 2014-11-24 14:34:52
已閱讀帖子之前,它不能解決我的問題。謝謝。 – Nebojsa 2014-11-24 14:53:34
不,我沒有,因爲我不知道在哪裏輸入那段代碼。 – Nebojsa 2014-11-24 15:19:41