评分来自项目

huangapple go评论51阅读模式
英文:

Rating from projects

问题

我了解project.task的功能流程,当您将状态更改为completed状态时,会在rating.rating模型中创建一个评级记录。但我无法找到负责在该模型中创建记录的方法。

我还尝试使用一个函数在状态更改为complete状态后从rating.rating模型中获取访问令牌,但也无法获得它:

rating_rec = self.env["rating.rating"].sudo().search([('partner_id', '=', self.partner_id.id), ('res_id', '=', self.id)], order='id desc', limit=1)

我仍然找不到创建评级记录的方法,也无法获取该记录的访问令牌。

我想在rating.rating模型中为特定任务创建记录后添加一个功能。

英文:

i know the functional flow of project.task which is when you change the state to completed state a rating record is created in rating.rating model. But I am unable to find out which method is responsible for creating the record in that model.

I tried to get the access token from the rating.rating model after the state change to complete state too by using a function but unable to get it too:

rating_rec = self.env["rating.rating"].sudo().search([('partner_id', '=', self.partner_id.id), ('res_id', '=', self.id)], order='id desc', limit=1)

still I dont find the method which creates a rating record or nighter get the access token for that record,

I want to add a functionality just after the record is created in the rating.rating model for that particular task.

答案1

得分: 1

在邮件模板中使用了xml id为rating_project_request_email_template。在第一行调用了object.rating_get_access_token(),如果还没有评分,它将创建一个评分。邮件本身将根据项目/阶段中的设置发送。

<div>
    <t t-set="access_token" t-value="object.rating_get_access_token()"/>
<!-- ... -->
</div>

令牌方法位于rating.mixin中:

def rating_get_access_token(self, partner=None):
    """ 返回与现有评分关联的访问令牌或创建一个新的评分
    该评分将创建所请求的令牌随后使用sudo执行显式调用权限
    此方法可以从不同来源使用特别是模板 """
    self.check_access_rights('read')
    self.check_access_rule('read')
    if not partner:
        partner = self.rating_get_partner_id()
    rated_partner = self.rating_get_rated_partner_id()
    ratings = self.rating_ids.sudo().filtered(lambda x: x.partner_id.id == partner.id and not x.consumed)
    if not ratings:
        rating = self.env['rating.rating'].sudo().create({
            'partner_id': partner.id,
            'rated_partner_id': rated_partner.id,
            'res_model_id': self.env['ir.model']._get_id(self._name),
            'res_id': self.id,
            'is_internal': False,
        })
    else:
        rating = ratings[0]
    return rating.access_token
英文:

It's done on the mail template with xml id rating_project_request_email_template. On the first line there is a call of object.rating_get_access_token() which will create a rating, if there is none yet. The mail itself will be send depending on the settings in your projects/stages.

<div>
    <t t-set="access_token" t-value="object.rating_get_access_token()"/>
<!-- ... -->
</div>

The token method is on the rating.mixin:

def rating_get_access_token(self, partner=None):
    """ Return access token linked to existing ratings, or create a new rating
    that will create the asked token. An explicit call to access rights is
    performed as sudo is used afterwards as this method could be used from
    different sources, notably templates. """
    self.check_access_rights('read')
    self.check_access_rule('read')
    if not partner:
        partner = self.rating_get_partner_id()
    rated_partner = self.rating_get_rated_partner_id()
    ratings = self.rating_ids.sudo().filtered(lambda x: x.partner_id.id == partner.id and not x.consumed)
    if not ratings:
        rating = self.env['rating.rating'].sudo().create({
            'partner_id': partner.id,
            'rated_partner_id': rated_partner.id,
            'res_model_id': self.env['ir.model']._get_id(self._name),
            'res_id': self.id,
            'is_internal': False,
        })
    else:
        rating = ratings[0]
    return rating.access_token

huangapple
  • 本文由 发表于 2023年2月24日 14:51:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定