Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7428 Lượt xem

Hi,

In model "mail.message" , I want to set the value 'Employee Only' by default True , if the Type is a comment.

So , I inherited the method create from "mail.message" I added the condition in the function , but I still having errors , what's wrong? Any help please?

class MessageExtend(models.Model):
    _inherit = "mail.message"
     
    def create(self, values_list):
        tracking_values_list = []
        for values in values_list:

               if 'message_type' in ['comment']:
                self.is_internal = True

            if 'email_from' not in values:  # needed to compute reply_to
                author_id, email_from = self.env['mail.thread']._message_compute_author(values.get('author_id'),
                                                                                        email_from=None,
                                                                                        raise_exception=False)
                values['email_from'] = email_from


   .....

Thanks.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Christina, 

I would suggest using this code, I have tested and works well for me:

class MailClass(models.Model):
    _inherit = "mail.message"
    @api.model_create_multi
    def create(self, vals):
        records = super(MailClass, self).create(vals)
        for record in records:
            # if the message type of the mail.message is a comment, mark as internal
            if record.message_type == "comment":
                record.is_internal = True
        return records
              When overriding a function it is best practice to call the base function using super instead of copy and pasting the code, this will help when migrating Odoo versions. Meaning if the base function changes it should be an issue as you are still supplying code with the correct parameters it needs. 

              I hope this solves your issue,

              Thanks, 
              Ảnh đại diện
              Huỷ bỏ
              Câu trả lời hay nhất

              Hi,

              Update the function like this and see:

                if 'message_type' in ['comment']:
                              values_list['is_internal'] = True


              Thanks

              Ảnh đại diện
              Huỷ bỏ

              Hello Niyas,

              Would it be:

              if 'message_type' in values_list['comment'] ? This is a good idea to change before supplying into the function.

              Thanks,

              Sorry more like

              "if values_list['message_type'] == "comment"'

              Bài viết liên quan Trả lời Lượt xem Hoạt động
              0
              thg 9 23
              41
              4
              thg 3 23
              16858
              2
              thg 7 22
              3749
              0
              thg 5 22
              2042
              1
              thg 11 21
              18439