Skip to Content
Menu
This question has been flagged
2 Replies
3584 Views

I have a website where i need send a message by WhatsApp to my user.


But this error is throwing.

"Traceback (most recent call last):\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\http.py\", line 656, in _handle_exception\n    return super(JsonRequest, self)._handle_exception(exception)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\http.py\", line 314, in _handle_exception\n    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\tools\\pycompat.py\", line 87, in reraise\n    raise value\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\http.py\", line 698, in dispatch\n    result = self._call_function(**self.params)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\http.py\", line 346, in _call_function\n    return checked_call(self.db, *args, **kwargs)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\service\\model.py\", line 97, in wrapper\n    return f(dbname, *args, **kwargs)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\http.py\", line 339, in checked_call\n    result = self.endpoint(*a, **kw)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\http.py\", line 941, in __call__\n    return self.method(*args, **kw)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\http.py\", line 519, in response_wrap\n    response = f(*args, **kw)\n  File \"c:\\program files (x86)\\odoo 12.0\\server\\odoo\\addons\\website\\controllers\\backend.py\", line 182, in website_grava_acordo\n    status = self.website_send_wpp(contato,acordo)\n  File \"c:\\program files (x86)\\odoo 12.0\\server\\odoo\\addons\\website\\controllers\\backend.py\", line 296, in website_send_wpp\n    msg_id = Website.enviar_wpp(msg, proposta)\n  File \"c:\\program files (x86)\\odoo 12.0\\server\\odoo\\addons\\website\\models\\website.py\", line 929, in enviar_wpp\n    'partner_ids':63,\n  File \"<decorator-gen-3>\", line 2, in create\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\api.py\", line 461, in _model_create_multi\n    return create(self, [arg])\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\models.py\", line 3525, in create\n    vals = self._add_missing_default_values(vals)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\models.py\", line 1691, in _add_missing_default_values\n    defaults = self.default_get(list(missing_defaults))\n  File \"c:\\program files (x86)\\odoo 12.0\\server\\odoo\\addons\\whatsapp_integration\\wizard\\send_msg.py\", line 129, in default_get\n    rec = self.env[active_model].browse(res_id)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\api.py\", line 831, in __getitem__\n    return self.registry[model_name]._browse((), self)\n  File \"C:\\Program Files (x86)\\Odoo 12.0\\server\\odoo\\modules\\registry.py\", line 176, in __getitem__\n    return self.models[model_name]\nKeyError: None\n


My class:

class SendWAMessage(models.TransientModel):
    _name = 'whatsapp.msg'
    _description = 'Send WhatsApp Message'

    def _default_unique_user(self):
        IPC = self.env['ir.config_parameter'].sudo()
        dbuuid = IPC.get_param('database.uuid')
        return dbuuid + '_' + str(self.env.uid)

    partner_ids = fields.Many2many(
        'res.partner''whatsapp_msg_res_partner_rel',
        'wizard_id''partner_id''Recipients')
    message = fields.Text('Message'required=True)
    attachment_ids = fields.Many2many(
        'ir.attachment''whatsapp_msg_ir_attachments_rel',
        'wizard_id''attachment_id''Attachments')
    unique_user = fields.Char(default=_default_unique_user)
    number = fields.Char()

## My method called into website class

def enviar_wpp(selfmsgproposta):
        contato = self.env['res.partner'].browse(proposta.x_id_contato)
        try:
            result = self.env['whatsapp.msg'].create({
                'number':'+5511979876697',
                'message':'message',
                'partner_ids':63,
            })
        except Exception as e:
            return (e)
    
    return result


Avatar
Discard

Hope these tips will helps: https://goo.gl/8HgnCF

Best Answer

The problem is with the "'partner_ids':63,". The partner_ids field is a M2m field. Try following code:

 'partner_ids':[(6, 0, [63])],

There are some rules to pass the value to M2m / O2m fields.

Avatar
Discard