Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo inherit error when try to use mail_thread

I am trying to make a notification app in odoo which will send mail to the user. I have found documentation https://www.odoo.com/documentation/12.0/reference/mixins.html, but when I trying to start odoo I receive error non-existing model 'mail.thread'. How can I resolve this problem?

models.py:

class skype_bot(models.Model):
    _name = 'my.skype'
    _inherit = ['mail.thread']
    _description = 'My Skype'

    # class MySkype(skpy.SkypeEventLoop):
    #     def onEvent(self, event):
    #         if isinstance(event, skpy.SkypeNewMessageEvent):
    #             print(repr(event))
    #             message = ('New message from user {} at {}: \'{} \''.format(event.msg.userId,
    #                                                                         event.msg.time.strftime(
    #                                                                             '%H:%M dd. %d.%m.%Y'),
    #                                                                         event.msg.content))

    @api.one
    def SentMail(self, message):
        print('called function sentmail')
        self.env['mail.message'].create({'message_type': 'notification',
                                         'subtype': self.env.ref('mail.mt_comment').id, 
                                         'body': message,
                                         'subject': 'Message subject',
                                         'needaction_partner_ids': [(4, 3)],

                                         })


        self.message_post(
            subject='Skype message',
            body=message,
            partner_ids=[(4, 3)]
        )

log

сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 417, in load_modules
сту 19 16:20:46 PK odoo[20993]: force, status, report, loaded_modules, update_module, models_to_check)
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 313, in load_marked_modules
сту 19 16:20:46 PK odoo[20993]: perform_checks=perform_checks, models_to_check=models_to_check
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/loading.py", line 188, in load_module_graph сту 19 16:20:46 PK odoo[20993]: model_names = registry.load(cr, package) сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/modules/registry.py", line 240, in load
сту 19 16:20:46 PK odoo[20993]: model = cls._build_model(self, cr)
сту 19 16:20:46 PK odoo[20993]: File "/opt/odoo/odoo/odoo/models.py", line 458, in _build_model
сту 19 16:20:46 PK odoo[20993]: raise TypeError("Model %r inherits from non-existing model %r." % (name, parent))
сту 19 16:20:46 PK odoo[20993]: TypeError: Model 'my.skype' inherits from non-existing model 'mail.thread'. - - -

like image 920
Sabr Avatar asked Dec 14 '22 13:12

Sabr


1 Answers

You need to add in your module, at the manifest.py, the following dependency: 'depends' : ['mail'], Because you are trying to inherit from 'mail' module from addons (mail.thread is found on this module). Basic this module it is not installed. So you are trying to inherit from a non-existing model until you install this module. I recomand you to use depends on all modules that are using another models (inherit model/views). In that case, you will no longer get any errors like this. Good luck!

like image 158
Arcas Gabriel Avatar answered Dec 28 '22 11:12

Arcas Gabriel