odoo添加多个弹框表单2018-07-24

很多时候,我们想为同一个model添加多个form表单,这时候可以为不同的表单添加不同的优先级,默认的优先级是16,优先级的数字越小,表示优先级越高。

如下,我设该表单的优先级为15

  <record id="view_loan_after_form" model="ir.ui.view">
        <field name="name">loan.count.view.from</field>
        <field name="model">loan.record</field>
        <field name="priority">15</field>
        <field name="arch" type="xml">

在该表单中,添加几个button,通过点击button弹出制定的表单,这些表单同时对应loan.record,编辑后保存即可,其作用在于使view_loan_after_form只具有显示作用,view_loan_after_form中的字段全部设置为readonly="1",编辑的表单与显示的表单分开。如下

<form string="贷后基础数据">
                <header>
                </header>
                <sheet>
                    <div class="oe_title" style="float: left;">
                            <label for="apply_id" class="oe_edit_only"/>
                            <h3>
                                <field name="customer_name" readonly="1"/>
                                <!--<field name="name" invisible="1"/>-->
                            </h3>
                            <field name="order" readonly="1"/>
                    </div>
                    <div class="oe_button_box" name="button_box" style="float: right;">
                        <button name="action_edit_finance" type="object"
                                    class="oe_stat_button" icon="fa-archive" string="财务资料补充"/>
                        <button name="action_edit_bank_num" type="object"
                                    class="oe_stat_button" icon="fa-archive" string="银行卡信息补录"/>
                        <button name="action_edit_pledge_case" type="object"
                                    class="oe_stat_button" icon="fa-archive" string="抵押确认"/>
                        <button name="action_edit_original_record" type="object"
                                    class="oe_stat_button" icon="fa-archive" string="原件记录"/>
                        <button name="action_edit_copies_record" type="object"
                                    class="oe_stat_button" icon="fa-archive" string="扫描件记录"/>
                        <button class="oe_stat_button" name="attachment_tree_view" type="object" icon="fa-archive">
                            <div class="o_stat_info">
                                <span class="o_stat_text">附件数量</span>
                                <field name="doc_count" />
                            </div>
                         </button>
                    </div>
                    <group >
                        <group name="left">
                            <field name="credit_id" readonly="1"/>
                            <field name="loan_id"/>
                            <field name="borrower_id" invisible="1"/>
                        </group>
                        <group name="right">
                            <field name="partner_id"  readonly="1"/>
                            <field name="product_id" readonly="1"/>
                            <field name="finance_name" readonly="1" invisible="1"/>
                            <field name="finance_id" readonly="1"/>

例如name="action_edit_finance"的按钮,点击该按钮时触发model中对应的函数,这里只做简单的演示,没有传入上下文及其他参数,这里选择multi装饰器,这里不解释装饰器的作用,self.ensure_one()保证是一个单条记录,有防止连续点击的影响(个人猜测),这里可不用src_model属性,当改变前后model不一致时,需要使用src_model属性,指向操作前的model,view_id属性指定视图,后面为视图id,可以为form视图,也可以为列表视图,这里指向form视图,target=new为弹框显示,其原理和HTML中a标签target=_blank类似,封装解释不同,效果也不同。id为当前操作任务id,这里没有多条id操作,以后应该会补。

    @api.multi
    def action_edit_finance(self):
        self.ensure_one()
        return {
            'name': '财务资料补充',
            'res_model': 'loan.record',
            'type': 'ir.actions.act_window',
            'src_model' :'loan.record',
            'res_id': self.id,
            'view_id': self.env.ref('loan_after.edit_loan_record_finance_form').id,
            'view_mode': 'form',
            'view_type': 'form',
            'target': 'new',
        }

在loan_after目录下创建form表单

  <record id="edit_loan_record_finance_form" model="ir.ui.view">
        <field name="name">Loan Edit Finance</field>
        <field name="model">loan.record</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <group>
                        <group>
                            <field name="order" readonly="1"/>
                            <field name="apply_id"/>
                            <field name="identity"/>
                        </group>
                        <group>
                            <field name="saler_id"/>
                            <field name="product_id"/>
                            <field name="finance_id" readonly="1"/>
                            <field name="finance_name"/>
                        </group>
                        <!--<group>-->
                            <!--<field name="cardholder"/>-->
                            <!--<field name="pay_account"/>-->
                            <!--<field name="bank_card" widget="image" class="oe_avatar"/>-->
                        <!--</group>-->
                    </group>
                    <group>
                        <group>
                            <!--<field name="total_amount" readonly="1"/>-->
                            <!--<field name="loans" />-->
                            <!--<field name="contract_euribor"/>-->
                            <!--<field name="or_loansinterest"/>-->
                            <field name="loansinterest"/>
                            <field name="bank_date"/>
                            <field name="pay_client"/>
                        </group>
                        <group>

                            <field name="advance_payment"/>
                            <field name="advance_date"/>
                            <field name="security_cost"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,991评论 19 139
  • Spring Web MVC Spring Web MVC 是包含在 Spring 框架中的 Web 框架,建立于...
    Hsinwong阅读 22,590评论 1 92
  • 今天去常平,幺姨家看了小弟弟,马上一岁了,真的好可爱哦!每个小生命来到我们的面前,让人不得不喜欢!终于有一点点明白...
    成长路上的幸运儿阅读 237评论 0 0
  • 维修x5的问题还没有维修完,还需要好好检查检查,把故障点找到,加油
    88e94d537f85阅读 145评论 0 0
  • 地铁车厢里空气浑浊密闭,燥热压抑。 几个身背双肩包的陌生人正粗暴的从我身边挤过, 人群喧嚣,嘈杂。 我低头从手机里...
    李清澄阅读 361评论 0 1