5

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.

Sidharth Panda
  • 404
  • 3
  • 17

1 Answers1

1

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
CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • thanks for the information, I can understand that a template is called and that template is responsible for creating the `rating` record, but I like to know when we click on the `completed` state on a task from which method this template is been redirected, is this the method `_send_task_rating_mail` which is responsible for this action.... If I write my functionality by inheriting this method will i get the id of the `rating.rating` record which is created for that task? – Sidharth Panda Feb 24 '23 at 11:36
  • IIRC that's the "initial" method, which will send a mail, yes. – CZoellner Feb 24 '23 at 12:03