Vauxoo / odoo

Fork of Odoo (formerly OpenERP). [This project is not publically mantained just born for internal usage with some little patches] go to official repository on github.com/odoo/odoo
https://www.odoo.com
Other
9 stars 9 forks source link

[IMP] portal: allow configure partner_ids in notification of portal - i#2901 #605

Open fernandahf opened 1 week ago

fernandahf commented 1 week ago

When an order is reviewed by the partner and when an order is cancelled from the portal, a notification is sent to the followers of the order, which allows to configure that from a context.

Related: #https://gitlab.com/ircanada/ircodoo/-/issues/2901


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

fernandahf commented 1 week ago

FYI @moylop260

moylop260 commented 6 days ago

IMHO it could be apply without patches but inherit

I mean,

You can use

    def _message_post_helper(res_model, res_id, message, token='', _hash=False, pid=False, nosubscribe=True, **kw):
        if request.env.context.get("skip_partner_ids") and kw.get("partner_ids"):
            kw.pop("partner_ids")

        if request.env.context.get("force_only_note"):
            kw["message_type"] = "notification"
            kw["subtype_xmlid"] = "mail.mt_note"
        return super()._message_post_helper(res_model, res_id, message, token=token, _hash=_hash, pid=pid, nosubscribe=nosubscribe, **kw)
fernandahf commented 6 days ago

@moylop260

The method is not inheritable because it's not under a class:

https://github.com/Vauxoo/odoo/pull/605/files#diff-d43c34911f97d4d6b8963b41c1419a4c55b36f645bafaf627d2890f0faf44d35R26

moylop260 commented 5 days ago

I got it

What about monkey patch using hooks.py?

I mean,

from odoo.addons.portal.controllers import mail

_original_message_post_helper = mail._message_post_helper

def _custom_message_post_helper(self, res_model, res_id, message, token='', _hash=False, pid=False, nosubscribe=True, **kw):
    if request.env.context.get("skip_partner_ids") and kw.get("partner_ids"):
        kw.pop("partner_ids")

    if request.env.context.get("force_only_note"):
        kw["message_type"] = "notification"
        kw["subtype_xmlid"] = "mail.mt_note"
    return _original_message_post_helper(self, res_model, res_id, message, token=token, _hash=_hash, pid=pid, nosubscribe=nosubscribe, **kw)

mail._message_post_helper = _custom_message_post_helper