Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Odoo v12 Sending survey results to employee, Singleton error

Subscribe

Get notified when there's activity on this post

This question has been flagged
mailsurveyappraisalsingletonodooV12
3539 Views
Avatar
Abdullah

Hey i am trying to send the result of survey to employee but i am getting the singleton error but i am already using for loops. Kindly have a look at my code

def _prepare_result_receivers(self):
"""
@return: returns a list of tuple (survey, list of employees).
"""
appraisal_send_to = []
if self.emp_appr:
appraisal_send_to.append((self.survey_id, self.emp_appr))
return appraisal_send_to

@api.multi
def throw_appraisal(self):
ComposeMessage = self.env['survey.mail.compose.message']
for appraisal in self:
appraisal_send_to = appraisal._prepare_result_receivers()
for survey,receivers in appraisal_send_to:
for employee in receivers:
email = employee.related_partner_id.email or employee.work_email
if not email:
continue
render_template = appraisal.result_template_id.with_context(email=email, survey=survey, employee=employee).generate_email([appraisal.id])
values = {
'survey_id': survey.id,
'public': 'email_private',
'partner_ids': employee.related_partner_id and [(4, employee.related_partner_id.id)] or False,
'multi_email': email,
'subject': '%s appraisal: %s' % (appraisal.employee_id.name, survey.title),
'body': render_template[appraisal.id]['body'],
'date_deadline': appraisal.date_close,
'model': appraisal._name,
'res_id': appraisal.id,
}
compose_message_wizard = ComposeMessage.with_context(active_id=appraisal.id, active_model=appraisal._name, notif_layout="mail.mail_notification_light").create(values)
compose_message_wizard.send_mail() # Sends a mail and creates a survey.user_input
if employee.user_id:
user_input = survey.user_input_ids.filtered(
lambda user_input: user_input.partner_id == employee.user_id.partner_id and user_input.appraisal_id == appraisal and user_input.state != 'done'
)
if user_input:
form_url = survey.print_url + '/' + user_input[0].token
else:
form_url = survey.print_url
appraisal.activity_schedule(
'hr_appraisal.mail_act_appraisal_form', appraisal.date_close,
note=_('Fill form <a href="%s">%s</a> for <a href="#" data-oe-model="%s" data-oe-id="%s">%s\'s</a> appraisal') % (
form_url, survey.display_name,
appraisal.employee_id._name, appraisal.employee_id.id, appraisal.employee_id.display_name),
user_id=employee.user_id.id)
appraisal.message_post(body=_("Appraisal form(s) have been sent"))
return True

And here is the error i am getting
File "/opt/odoo12/odoo-custom-addons/dos_appraisal_send/models/send_appr.py", line 33, in throw_appraisal render_template = appraisal.result_template_id.with_context(email=email, survey=survey, employee=employee).generate_email([]) File "/opt/odoo12/odoo/addons/mail/models/mail_template.py", line 422, in generate_email self.ensure_one() File "/opt/odoo12/odoo/odoo/models.py", line 4764, in ensure_one raise ValueError("Expected singleton: %s" % self) ValueError: Expected singleton: mail.template()

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

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

Sign up
Related Posts Replies Views Activity
How to install free appraisal module in odoo 12 ? Solved
appraisal odooV12
Avatar
Avatar
Avatar
Avatar
4
Dec 19
5674
Send Mail Error
mail sendmail odooV12
Avatar
0
Nov 21
3452
Odoo not creating leads from emails Solved
mail crm odooV12
Avatar
1
Jun 21
3190
How to change the name of the odoo to the company name XYZ Inc?
mail quotation odooV12
Avatar
Avatar
1
Dec 19
5335
Images in emails not visible when using localhost
mail
Avatar
Avatar
1
Dec 25
472
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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