{"action":"created","issue":{"url":"https://api.github.com/repos/OCA/server-tools/issues/305","labels_url":"https://api.github.com/repos/OCA/server-tools/issues/305/labels{/name}","comments_url":"https://api.github.com/repos/OCA/server-tools/issues/305/comments","events_url":"https://api.github.com/repos/OCA/server-tools/issues/305/events","html_url":"https://github.com/OCA/server-tools/issues/305","id":119495581,"number":305,"title":"[AUDITLOG] and property fields","user":{"login":"ritchyteam","id":8818777,"avatar_url":"https://avatars.githubusercontent.com/u/8818777?v=3","gravatar_id":"","url":"https://api.github.com/users/ritchyteam","html_url":"https://github.com/ritchyteam","followers_url":"https://api.github.com/users/ritchyteam/followers","following_url":"https://api.github.com/users/ritchyteam/following{/other_user}","gists_url":"https://api.github.com/users/ritchyteam/gists{/gist_id}","starred_url":"https://api.github.com/users/ritchyteam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ritchyteam/subscriptions","organizations_url":"https://api.github.com/users/ritchyteam/orgs","repos_url":"https://api.github.com/users/ritchyteam/repos","events_url":"https://api.github.com/users/ritchyteam/events{/privacy}","received_events_url":"https://api.github.com/users/ritchyteam/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-30T13:51:05Z","updated_at":"2015-11-30T14:02:18Z","closed_at":null,"body":"AuditLog (branch 8.0 (5f99ef17)) did not log write in property fields in case superuser company is different from user company\r\n\r\nproperty field is company dependent:\r\n\r\nff = fields.Many2one(\r\n        string='Label',\r\n        comodel_name='aaa.bbb',\r\n        company_dependent=True\r\n    )\r\n\r\n----\r\n\r\nyour code:\r\n\r\ndef _make_write(self):\r\n        \"\"\"Instanciate a write method that log its calls.\"\"\"\r\n        @api.multi\r\n        def write(self, vals, **kwargs):\r\n            self = self.with_context(auditlog_disabled=True)\r\n            rule_model = self.env['auditlog.rule']\r\n            old_values = dict(\r\n                (d['id'], d) for d in self.sudo().read(list(self._fields)))\r\n            result = write.origin(self, vals, **kwargs)\r\n            new_values = dict(\r\n                (d['id'], d) for d in self.sudo().read(list(self._fields)))\r\n            rule_model.sudo().create_logs(\r\n                self.env.uid, self._name, self.ids,\r\n                'write', old_values, new_values)\r\n            return result\r\n        return write\r\n\r\nself.sudo().read - it read data for superuser and if current user company is different from superuser company new_values contains the same values for property fields\r\n\r\nhow to fix:\r\n1 way\r\n\r\njust use self.read\r\n\r\n2 way (but i did not sure that this is right way)\r\n\r\ndef _make_write(self):\r\n        \"\"\"Instanciate a write method that log its calls.\"\"\"\r\n        @api.multi\r\n        def write(self, vals, **kwargs):\r\n            self = self.with_context(auditlog_disabled=True)\r\n            rule_model = self.env['auditlog.rule']\r\n            ctx = dict(self._context)\r\n            ctx.update(force_company=self.env.user.company_id.id)\r\n            old_values = dict(\r\n                (d['id'], d) for d in self.sudo().with_context(ctx).read(list(self._fields)))\r\n            result = write.origin(self, vals, **kwargs)\r\n            new_values = dict(\r\n                (d['id'], d) for d in self.sudo().with_context(ctx).read(list(self._fields)))\r\n            print new_values\r\n            rule_model.sudo().create_logs(\r\n                self.env.uid, self._name, self.ids,\r\n                'write', old_values, new_values)\r\n            return result\r\n        return write\r\n\r\n "},"comment":{"url":"https://api.github.com/repos/OCA/server-tools/issues/comments/160638493","html_url":"https://github.com/OCA/server-tools/issues/305#issuecomment-160638493","issue_url":"https://api.github.com/repos/OCA/server-tools/issues/305","id":160638493,"user":{"login":"sebalix","id":5315285,"avatar_url":"https://avatars.githubusercontent.com/u/5315285?v=3","gravatar_id":"","url":"https://api.github.com/users/sebalix","html_url":"https://github.com/sebalix","followers_url":"https://api.github.com/users/sebalix/followers","following_url":"https://api.github.com/users/sebalix/following{/other_user}","gists_url":"https://api.github.com/users/sebalix/gists{/gist_id}","starred_url":"https://api.github.com/users/sebalix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebalix/subscriptions","organizations_url":"https://api.github.com/users/sebalix/orgs","repos_url":"https://api.github.com/users/sebalix/repos","events_url":"https://api.github.com/users/sebalix/events{/privacy}","received_events_url":"https://api.github.com/users/sebalix/received_events","type":"User","site_admin":false},"created_at":"2015-11-30T14:02:18Z","updated_at":"2015-11-30T14:02:18Z","body":"You are right, `sudo` only is not enough in a multi-companies environment.\r\nAbout your fix, I think this should be ok:\r\n\r\n```python\r\ncompany_id = self.env.user.company_id.id\r\nold_values = dict(\r\n    (d['id'], d) for d in self.sudo().with_context(\r\n        force_company=company_id).read(list(self._fields)))\r\n```\r\n\r\nDo you want to make a PR for this? And maybe a unit test on this bug?"}}