Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

OnChange Frontend V12CE

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
portalonchangefrontendV12
1 Răspunde
5627 Vizualizări
Imagine profil
notteccon

Hi!

I know how to use @api.onchange('my_field') in the Model for the backend, but now I am implementing the Controller and the Templates for the portal access and I want a similar behavior, I have searched the documentation but I have not found how to do it.


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

    @api.onchange('name')
    def onchange_name(self):
        if self.name == False
            self.description = False


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


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


Thank you.

1
Imagine profil
Abandonează
Imagine profil
Sudhir Arya (ERP Harbor Consulting Services)
Cel mai bun răspuns

You can always call the onchange method using the recordset.

Try the following code:

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)
mymodel.onchange_name() # This will reflect the changes done by onchange and you will see the update in the record


2
Imagine profil
Abandonează
notteccon
Autor

Hi Sudhir

Thank you for your answer.

I tried this way, and you are right, the record is updated, but the values in the control form does not change, for thant i had to implemente onchange in the JS. I dont know if there is a better way

Thanks again

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Portal Users Apps Access Rights V12CE
portal rights V12
Imagine profil
0
iun. 21
3893
Use Pivot Table into portal frontend
portal frontend pivot odoo11
Imagine profil
Imagine profil
1
apr. 24
5157
Add new records to a many2one field using a website form Rezolvat
form many2one qweb portal frontend
Imagine profil
Imagine profil
1
aug. 24
2691
Element '<xpath expr="//head/link[last()]">' cannot be located in parent view every time trying to extend portal.frontend_layout
portal template xpath frontend v14
Imagine profil
Imagine profil
1
mar. 24
5649
Many2many ir.attachment Portal frontend widget V12
attachment widget portal many2many V12
Imagine profil
Imagine profil
1
mar. 24
8522
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now