【已解决】扩展partner模型,新建partner保存后,country_id的字段无法保存数据,其他字段可以正确保存
-
扩展的partner模型代码:
<br />class youxiang_partner(models.Model):<br /> _inherit = 'res.partner'<br /><br /> name = fields.Char()<br /> province_id = fields.Many2one(comodel_name="youxiang.province", string=u"省份", required=False, )<br /> city_id = fields.Many2one(comodel_name="youxiang.city", string=u"城市", required=False, )<br /> area_id = fields.Many2one(comodel_name="youxiang.area", string=u"区域", required=False, )<br />
修改地址的显示顺序:<br /> <record id="cn_view_partner_form" model="ir.ui.view"><br /> <field name="name">res.partner.form.inherit</field><br /> <field name="model">res.partner</field><br /> <field name="inherit_id" ref="base.view_partner_form"/><br /> <field name="arch" type="xml"><br /> <!--隐藏原来的地址视图--><br /> <xpath expr="//form/sheet/group/group/div/field[@name='country_id']" position="attributes"><br /> <attribute name="invisible">1</attribute><br /> </xpath><br /> <xpath expr="//form/sheet/group/group/div/div[@class='address_format']" position="attributes"><br /> <attribute name="invisible">1</attribute><br /> </xpath><br /> <xpath expr="//form/sheet/group/group/div/field[@name='street']" position="attributes"><br /> <attribute name="invisible">1</attribute><br /> </xpath><br /> <xpath expr="//form/sheet/group/group/div/field[@name='street2']" position="attributes"><br /> <attribute name="invisible">1</attribute><br /> </xpath><br /><br /> <!-- 重编地址格式 --><br /> <xpath expr="//button[@name='open_parent']" position="after"><br /> <div><br /> <field name="country_id" placeholder="国家" class="oe_no_button" style="width: 50%%"<br /> options='{"no_open": True, "no_create": True}'<br /> attrs="{'readonly': [('use_parent_address','=',True)]}"<br /> required="1"<br /> /><br /> <field name="province_id" placeholder="省份" class="oe_no_button" style="width: 50%%"<br /> options='{"no_open": True,}'<br /> attrs="{'readonly': [('use_parent_address','=',True)]}"<br /> required="1"<br /> /><br /> </div><br /> <div><br /> <field name="city_id" placeholder="城市" class="oe_no_button" style="width: 50%%"<br /> options='{"no_open": True,}'<br /> attrs="{'readonly': [('use_parent_address','=',True)]}"<br /> required="1"<br /> /><br /> <field name="area_id" placeholder="区" class="oe_no_button" style="width: 50%%"<br /> options='{"no_open": True,}'<br /> attrs="{'readonly': [('use_parent_address','=',True)]}"<br /> required="1"<br /> /><br /> </div><br /> <field name="street" placeholder="详细地址..."<br /> attrs="{'readonly': [('use_parent_address','=',True)]}"<br /> required="1"<br /> /><br /> </xpath><br /> </record><br /><br /> </data><br /></openerp><br />
保存partner后,页面有显示已选国家的数据,但是查看数据库country_id字段是没有数据的,刷新页面后,country_id显示空白 -
感觉姐夫Jeff和Joshua的回答,问题得到解决。
由于我view中的country_id是使用invisible属性隐藏了该字段,再在后面重新添加country_id,这个做法是错误的,这样每次保存form都是获取第一个隐藏的country_id字段值,所以一直为空,应该修改代码如下:<br /> <xpath expr="//form/sheet/group/group/div/field[@name='country_id']" position="replace"><br /> </xpath><br />