Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
665 Prikazi
Avatar
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
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

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

Prijavi
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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