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

Odoo17 Community edition - Error on saving new survey question type.

Abonare

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

Această întrebare a fost marcată
667 Vizualizări
Imagine profil
Steve Rice

I have written an addon that creates a new dropdown question type (Vehicle Registration) in Survey. When the user runs the survey, they are presented with a dropdown to select a vehicle from a dynamically created list of the currently registered vehicles in the Fleet module. This bit works. However, when the user submits the survey, it crashes with the error:

File "/opt/odoo17/odoo17/addons/survey/controllers/main.py", line 536, in survey_submit
    answer_sudo._save_lines(question, answer, comment, overwrite_existing=survey_sudo.users_can_go_back or question.save_as_nickname or question.save_as_email)
  File "/opt/odoo17/odoo17/addons/survey/models/survey_user_input.py", line 301, in _save_lines
    raise AttributeError(question.question_type + ": This type of question has no saving function")
AttributeError: vehicle_dropdown: This type of question has no saving function

This is my survey_question.py:

from odoo import models, fields, api

import logging


_logger = logging.getLogger(__name__)


class SurveyQuestion(models.Model):

_inherit = 'survey.question'

question_type = fields.Selection(selection_add=[('vehicle_dropdown', 'Vehicle Dropdown')])

fleet_vehicles = fields.Many2many('fleet.vehicle', string='Fleet Vehicles')


class SurveyUserInputLine(models.Model):

_inherit = 'survey.user_input.line'


@api.model

def get_options(self):

self.ensure_one()

if self.question_id.question_type == 'vehicle_dropdown':

return [(vehicle.id, vehicle.license_plate) for vehicle in self.question_id.fleet_vehicles]

return super().get_options()


def _save_lines(self, question, answer, comment=None, overwrite_existing=False):

_logger.info(f"Saving lines for question: {question.id} ({question.question_type})")

_logger.info(f"Answer: {answer}, Type: {type(answer)}")


if question.question_type == 'vehicle_dropdown':

if answer:

try:

answer = int(answer)

_logger.info(f"Answer after int conversion: {answer}, Type: {type(answer)}")

existing_line = self.search([

('user_input_id', '=', self.user_input_id.id),

('question_id', '=', question.id)

], limit=1)


if existing_line and overwrite_existing:

existing_line.write({'value_reference': answer})

_logger.info(f"Updated existing line {existing_line.id} with value_reference {answer}")

else:

self.create({

'user_input_id': self.user_input_id.id,

'question_id': question.id,

'answer_type': 'selection',

'value_reference': answer,

})

_logger.info(f"Created new line with value_reference {answer}")

return True

except ValueError as e:

_logger.error(f"Could not convert answer to integer: {e}")

except Exception as e:

_logger.exception(f"Error in _save_lines: {e}")

else:

_logger.info("No answer provided for vehicle dropdown")

return super()._save_lines(question, answer, comment, overwrite_existing)



And this is my survey_question_views.xml:

<?xml version="1.0" encoding="UTF-8"?>

<odoo>

<!-- Inherit the survey.question form view -->

<record id="view_survey_question_form_inherit" model="ir.ui.view">

<field name="name">survey.question.form.inherit</field>

<field name="model">survey.question</field>

<field name="inherit_id" ref="survey.survey_question_form"/>

<field name="arch" type="xml">

<!-- Add the Fleet Vehicles field after the question type field -->

<xpath expr="//field[@name='question_type']" position="after">

<field name="fleet_vehicles" widget="many2many_tags" options="{'no_create': True}" placeholder="Select vehicles"/>

</xpath>

</field>

</record>

<!-- Inherit the survey.question_container template -->

<template id="survey_vehicle_dropdown" inherit_id="survey.question_container">

<!-- Target the inner div after the <h3> question title -->

<xpath expr="//div[h3]" position="after">

<t t-if="question.question_type == 'vehicle_dropdown'">

<div class="form-group">

<label t-esc="question.title" class="form-label"/>

<select name="answer" class="form-control" required="1">

<option value="">Select a Vehicle</option>

<!-- Dynamically load only vehicles with 'Registered' status -->

<t t-foreach="env['fleet.vehicle'].search([('state_id', '=', 3)])" t-as="vehicle">

<option t-att-value="vehicle.id" t-esc="vehicle.license_plate"/>

</t>

</select>

</div>

</t>

</xpath>

</template>

</odoo>


Can anyone help where I'm going wrong?



0
Imagine profil
Abandonează
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
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