Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Qweb templating (Python side) : Access survey_user_input model on survey template using t-field ?

Odoberať

Get notified when there's activity on this post

This question has been flagged
pythonqwebcontrollerst-field
1 Odpoveď
11446 Zobrazenia
Avatar
TEIMI Yassine

Dears,

As you know t-field gives fields access via browsable record.

For the survey module, it's used on survey qweb template. For example, for the survey_init template (the first page of every started survey, describing survey title, and description) here is the code using t-field :

 <template id="survey_init" name="Survey"> 

<t t-call="website.layout">
<div class="wrap">
<div class="oe_structure" />
<div class="container">
<div groups="base.group_website_publisher" t-ignore="true" class="text-right">
<a href="/web#action=survey.action_survey_form" class="btn btn-default">Go back to su rveys</a>
</div>
<div class='jumbotron mt32'>
<h1 t-field='survey.title' />
<div t-field='survey.description' class="oe_no_empty"/>
<a class="btn btn-primary btn-lg" t-att-href="'/survey/fill/%s/%s' % (slug(survey ), token)">
Start Survey
</a>
</div>
</div>
<div class="oe_structure" />
</div>
</t>
</template>

So how this is can be done ?

Humble answer : After inspecting the controllers code, it's the start_survey() method that is responsible of launching the survey, it takes the variable survey as a parameter, and send it via data dictionnary trough : website.request.render, wich allows access survey fields value using t-field.

Here is the code part (For one page rendering case "test survey" among others) explainig that :

 @http.route(['/survey/start/<model("survey.survey"):survey>', 
'/survey/start/<model("survey.survey"):survey>/<string:token>'],

type='http', auth='public', website=True)
def start_survey(self, survey, token=None, **post):
cr, uid, context = request.cr, request.uid, request.context
    survey_obj = request.registry['survey.survey']
    user_input_obj = request.registry['survey.user_input']
    # Test mode
    if token and token == "phantom":
        _logger.info("[survey] Phantom mode")
        user_input_id = user_input_obj.create(cr, uid, {'survey_id': survey.id, 'test_entry': True}, context=context)
        user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0]
        data = {'survey': survey, 'page': None, 'token': user_input.token}
    return request.website.render('survey.survey_init', data)

My question here is how survey is passed as a parameter ? is it by using @route ?

If I know how to pass more parameters to start_survey(), then maybe I can pass a parameter named like "survey_user_input" trough data dictionnary, allowing me to use it on t-field.

NB:

I'm calling my survey from hr_evaluation_interview model from the hr_evaluation module.

Here is the method calling survey from hr_evaluation module (maybe I can use it to pass a parameter to start survey via context) :

 def action_start_survey(self, cr, uid, ids, context=None): 
''' Open the website page with the survey form '''
    trail = ""
    context = dict(context or {}, relative_url=True)
    if 'survey_token' in context:
        trail = "/" + context['survey_token']
    return {
        'type': 'ir.actions.act_url',
        'name': "Start Survey",
        'target': 'self',
        'url': self.read(cr, uid, ids, ['public_url'], context=context)[0]['public_url'] + trail
        }

I hope my question is clear, if not, I'm here for further explainations.

Many thanks for your help.

0
Avatar
Zrušiť
Avatar
Axel Mendoza
Best Answer

The argument survey is converted and passed by the @route decorator, converting the positional param of the url to a model object using a model argument pattern converter declared in the url param of the @route decorator and passed to the handle method of the url. 

See more here about that:

https://www.odoo.com/documentation/8.0/howtos/website.html#urls-and-routing

Specifically:

Odoo provides an additional converter called model which provides records directly when given their id. Let's use this to create a generic page for teacher biographies:

So you need to redefine the method and the @route url pattern and the method arguments to match the url pattern.

The url returned on the method action_start_survey need to match the @route url pattern so add the id value of the survey_user_input param to the url obtained from the field public_url or to the trail var, the thing is that the result url need to match the url for the @route overrided

1
Avatar
Zrušiť
TEIMI Yassine
Autor

Thanks a lot Axel for your explainations, I'm now trying to override : action_start_survey method called from hr_interview (I did'nt included it on my post), it's the first called method, that calls action_start_survey of the survey model. (So functionnaly speaking, it's like using action_start_survey for a human ressources evaluation purpose). Then I'll override action_start_survey of the survey module, and then override @route decorator and start_survey() method. I'll post my code, and further details soon. Thanks for your valuable help.

TEIMI Yassine
Autor

Hi Axel, it worked : On the first action_start_survey (on hr_interview object) I had to pass a browsable record of it, using context, and then on action_start_survey(survey object), modify trail, and add slug(context['interview']) to the url, and finally on the start_survey() method override @route decorator and pass the parameter, then send it via data dictionnary to the qweb view, and it's ready to use. I have to do the same for print_survey() and fill_survey(). Thanks a lot Axel for your help.

Axel Mendoza

Happy to help

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

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
What's the difference between t-esc and t-field in a report ? Solved
qweb t-field
Avatar
Avatar
Avatar
3
júl 23
32681
Issue with a new Product Label Template (102x102) in Odoo V17
development python qweb
Avatar
0
dec 24
1847
passing values to the react using Controller
qweb controllers ReactJs
Avatar
Avatar
Avatar
2
dec 23
2418
Email template - list of followers
python qweb email
Avatar
Avatar
Avatar
2
jún 23
3233
My custom report is changing when user Configured the Document Layout Solved
python qweb v14
Avatar
Avatar
1
jan 23
3395
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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