我继承了crm视图,并在该表单上添加了一个按钮。并应用了功能从crm表单打开该客户表单。但是单击该按钮后,我收到错误消息“ ValueError:字段'padding'不存在”。
我分享了我的python和xml代码以及错误屏幕截图:
class CustomCRM(models.Model):
_inherit = 'crm.lead'
@api.multi
def open_customer_view(self):
ir_model_data = self.env['ir.model.data']
view_id = ir_model_data.get_object_reference('base', 'action_partner_form')[1]
partner = self.env['res.partner'].browse(self.partner_id.id)
print("PARTNERS", partner, view_id)
if partner:
res = {
'view_type': 'form',
'view_mode': 'tree',
'views': [(view_id, 'form')],
'res_model': 'res.partner',
'view_id': view_id,
'type': 'ir.actions.act_window',
'res_id': partner.id,
'target': 'fullscreen',
# 'context': ctx,
}
return res
<record id="view_custom_crm_lead_form" model="ir.ui.view">
<field name="name">CustomCrmLead</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<data>
<xpath expr="//header//button[@name='action_set_won']" position="after">
<button name="open_customer_view" string="Customer Form" type="object"
class="btn-primary"/>
</xpath>
</data>
</field>
</record>
答案 0 :(得分:1)
问题解决了。我犯了一个愚蠢的错误,该错误称为操作而不是表单视图ID。然后视图ID应该是 view_id = ir_model_data.get_object_reference('base','view_partner_form')[1] 而不是 view_id = ir_model_data.get_object_reference('base','action_partner_form')[1]