Odoo 11 ValueError:预期的单例:%s" % 记录 [英] Odoo 11 ValueError: Expected singleton: %s" % record

查看:150
本文介绍了Odoo 11 ValueError:预期的单例:%s" % 记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个自定义模块,我希望在该模块中获取工资单中所有选定的员工并向他们发送默认电子邮件.为此,我正在这样做

I am creating a custom module where I want to get all the selected employee in the Payroll and send them a default email. For that I am doing this

显示操作按钮

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
      <record id="action_email_payslip" model="ir.actions.server">
      <field name="name">Email</field>
      <field eval="2" name="sequence"/>
      <field name="view_mode">form</field>
      <field name="multi" eval="False"/>
            <field name="model_id" ref="hr_payroll.model_hr_payslip"/> 
            <field name="binding_model_id" ref="hr_payroll.model_hr_payslip"/>
            <field name="state">code</field> 
            <field name="code"> 
            action = records.action_send_email() 
            </field>
    </record>
    </data>
</odoo>

在模型中,我的代码是这样的

In the model my code is like this

从odoo导入模型,字段,api,_

from odoo import models, fields, api, _

class EmailPayslip(models.Model):
    _inherit = 'hr.payslip'

    @api.multi
    def action_send_email(self):

        selected_employess = []
        not_selected_employees = []

        for payslip in self:
          try:
            lang = payslip.employee_id.user_id.lang
            template.with_context(lang=lang).send_mail(
                self.env.user.id, force_send=True, raise_exception=True
            )
            selected_employess.append(payslip.name)
          except Exception as e:
            not_selected_employees.append(payslip.name)

        print(selected_employess)

但显示错误类似

ValueError: Expected singleton: %s" % record

ValueError:预期的单例:hr.payslip(1、3、4)

ValueError: Expected singleton: hr.payslip(1, 3, 4)

有人可以告诉我我在这里做错了什么以及如何解决这个问题? 任何帮助和建议都将非常可观.

Can someone tell me what I a doing wrong here and how to fix this? Any help and suggestions will be really appreciable.

此致

推荐答案

也尝试像下面那样循环工资单"

Try to loop the 'payslip' also , like below

 for payslip in self:
    for slip in payslip:
         try:
           lang = payslip.employee_id.user_id.lang
           template.with_context(lang=lang).send_mail(
               self.env.user.id, force_send=True, raise_exception=True
           )
           selected_employess.append(slip.name)
         except Exception as e:
           not_selected_employees.append(slip.name)

这篇关于Odoo 11 ValueError:预期的单例:%s&quot; % 记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆