简体   繁体   中英

Odoo `sudo` correct log

I am having problem using sudo in Odoo version 11. Checking doc, I think the same problem exists in version 12. Using sudo generate log with wrong(?) user. For eg I override confirm_sale to use sudo .

from odoo import api, fields, models


class SaleOrder(models.Model):
    _inherit = 'sale.order'

    def action_confirm(self):
        return super(SaleOrder, self.sudo()).action_confirm()

Then let say when "Sale User" confirm sale order, log is shown as if "Administrator" approved sale order. Information is lost on who really confirmed sale order.

在此处输入图像描述

Question: So, my question is I want to use sudo but still record correctly who made changes.

Clarification/Use Case: Removing sudo and adding necessary permissions for user can solve the problem. But my very often use case is one group of users can only create/edit data and one or more groups can only confirm/approve data without edit permission. So, sudo is necessary.

Fixes: Currently I am using the below fixes for this problem.

You can use this OCA module https://apps.odoo.com/apps/modules/11.0/base_suspend_security/

Just install the module and use suspend_security() instead of sudo(), it will bypass access rights but keep the current user on log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM