Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7905 Lượt xem

Hi!

I have a model with a Many2Many 'ir.attachment' field. The implementation in BackEnd is working as expected and the widget in the form is perfect. Now i need to implement a Portal form view and a Portal detail view (FrontEnd), it is implemented for all the fields but 'file_ids', i can not find the widget docu for the portal.

I checked the docu :

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

Also checked:

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

But just found "contact" template


Model
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')
View
<?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>

          <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>


Controller
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>'], type='http', auth='user', website=True)
    def mymodel_portal_view(self, mymodel, **post):
        response = http.request.render("mymodule.mymodel_portal_view", {'mymodel': mymodel})
        return response


Template
<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>


Thanks!


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You have managed to solve this problem. If yes, please share the final code

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 12 24
1108
4
thg 7 25
24081
2
thg 1 23
4776
1
thg 3 15
11306
0
thg 8 23
1454