Odoo V12 Many2many ir.attachment门户前端小部件

问题描述

我有一个模型,其中有一个 Many2many 'ir.attachment'字段。 BackEnd中的实现按预期工作,并且表单上的小部件非常完美。现在,我需要实现一个Portal表单视图和一个Portal细节视图(前端),它适用于所有字段,但'file_ids'却无法找到该门户的窗口小部件文档。

我检查了文档:

https://www.odoo.com/documentation/12.0/reference/javascript_reference.html#relational-fields

也已选中:

https://github.com/odoo/odoo/blob/12.0/odoo/addons/base/views/ir_qweb_widget_templates.xml

但是刚刚找到了“ contact”模板

模型

from odoo import fields,models,api
class MyModel(models.Model):
    _name = 'mymodule.mymodel'
    _inherit = ['mail.thread','mail.activity.mixin','portal.mixin']
    _description = 'My Model'
    _order = 'create_date desc'
    _rec_name = 'name'

    name = fields.Char()
    description = fields.Char()
    file_ids = fields.Many2many(comodel_name='ir.attachment',string='Files')

查看

<?xml version="1.0"?>
<odoo>
  <record id="view_mymodule_mymodel_form" model="ir.ui.view">
    <field name="name">MyModel Form</field>
    <field name="model">mymodule.mymodel</field>
    <field name="arch" type="xml">
      <form string="MyModel">
        <sheet>

          <field name="id" invisible="1"/>
          <group name="group_data" col="1">
            <group col="4">
              <field name="name"/>
              <field name="description"/>
            </group>
          </group>
<!-- This render a great widget -->
          <field name="file_ids" widget="many2many_binary"/>

          <div class="oe_chatter">
            <field name="message_follower_ids" widget="mail_followers"/>
            <field name="message_ids" widget="mail_thread"/>
          </div>

        </sheet>
      </form>
    </field>
  </record>
</odoo>

控制器

from odoo import http,_
from odoo.addons.portal.controllers.portal import CustomerPortal

class MyModelCustomerPortal(CustomerPortal):
    @http.route(['/mymodule/mymodel/edit/<model("mymodule.mymodel"):mymodel>'],type='http',auth='user',website=True)
    def mymodel_portal_edit(self,mymodel,**post):
        if post:
            mymodel.sudo().write(post)
            return http.request.redirect('/mymodule/mymodel/view/%s' % slug(mymodel))
        response = http.request.render("mymodule.mymodel_portal_edit",{'mymodel': mymodel})
        return response

    @http.route(['/mymodule/mymodel/view/<model("mymodule.mymodel"):mymodel>'],website=True)
    def mymodel_portal_view(self,**post):
        response = http.request.render("mymodule.mymodel_portal_view",{'mymodel': mymodel})
        return response

模板

<odoo>
    <template id="mymodel_portal_edit" name="MyModel Form" >
        <t t-call="portal.portal_layout">
            <t t-set="breadcrumbs_searchbar" t-value="True"/>
            <t t-call="portal.portal_searchbar"> <t t-set="title">MyModel</t> </t>
            <t t-if="not mymodel"><p>There are currently no data for your account.</p></t>
            <h3>My Model</h3>
            <form t-attf-action="/mymodule/mymodel/edit/{{slug(mymodel)}}" method="post">
                <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
                <div class="row o_portal_details">
                    <div class="col-lg-12">
                        <div class="row">
                            <div class="col-lg-12">
                              <div t-if="error_message" class="alert alert-danger" role="alert">
                                  <t t-foreach="error_message" t-as="err"><t t-esc="err"/><br /></t>
                              </div>
                            </div>
                            <div t-attf-class="form-group col-xl-6">
                                <label class="col-form-label" for="name">Name</label>
                                <input type="text" name="name" t-att-value="mymodel.name" t-attf-class="form-control"/>
                            </div>
                            <div t-attf-class="form-group col-xl-6">
                                <label class="col-form-label" for="description">Description</label>
                                <input type="text" name="description" t-att-value="mymodel.description" t-attf-class="form-control"/>
                            </div>
                            <div t-attf-class="form-group col-xl-6">
                                <label class="col-form-label" for="file?ids">Files</label>
                                <input type="file" class="form-control o_website_form_input" name="file_ids" t-options="{'widget': 'many2many_binary'}"/> 
<!-- This render a simple input file selector -->
                            </div>
                        </div>
                        <div class="clearfix">
                            <button type="submit" class="btn btn-primary float-left mb32 ">
                                Save<span class="fa fa-long-arrow-right" />
                            </button>
                            <a t-attf-href="/mymodule/mymodel/view/{{slug(mymodel)}}" class="btn btn-danger float-right mb32 ">
                                Cancel <span class="fa fa-long-arrow-right" />
                            </a>
                        </div>
                    </div>
                </div>
            </form>
            <div class="oe_structure"/>
        </t>
    </template>
</odoo>

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)