{"action":"created","issue":{"url":"https://api.github.com/repos/OCA/partner-contact/issues/454","repository_url":"https://api.github.com/repos/OCA/partner-contact","labels_url":"https://api.github.com/repos/OCA/partner-contact/issues/454/labels{/name}","comments_url":"https://api.github.com/repos/OCA/partner-contact/issues/454/comments","events_url":"https://api.github.com/repos/OCA/partner-contact/issues/454/events","html_url":"https://github.com/OCA/partner-contact/issues/454","id":247040222,"number":454,"title":"partner_relations module / left and right partners mismatch/  - corrupting relations and throws \"Partners cannot have a relation with themselves\"","user":{"login":"christophe-hanon","id":763767,"avatar_url":"https://avatars0.githubusercontent.com/u/763767?v=4","gravatar_id":"","url":"https://api.github.com/users/christophe-hanon","html_url":"https://github.com/christophe-hanon","followers_url":"https://api.github.com/users/christophe-hanon/followers","following_url":"https://api.github.com/users/christophe-hanon/following{/other_user}","gists_url":"https://api.github.com/users/christophe-hanon/gists{/gist_id}","starred_url":"https://api.github.com/users/christophe-hanon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christophe-hanon/subscriptions","organizations_url":"https://api.github.com/users/christophe-hanon/orgs","repos_url":"https://api.github.com/users/christophe-hanon/repos","events_url":"https://api.github.com/users/christophe-hanon/events{/privacy}","received_events_url":"https://api.github.com/users/christophe-hanon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-08-01T11:35:56Z","updated_at":"2018-04-10T06:40:41Z","closed_at":null,"author_association":"NONE","body":"The partner_relations module exhibits a series of incorrect behaviors.ra\r\n\r\nThis problem is reported for version 8, but as far as I can see, the next generation module has changed its name but not its behavior....\r\n\r\nIn my case we have defined the relation 'tta_member' with the inverse 'has_tta_member'.\r\n\r\n# Case \r\nA has_tta_member B1\r\nA has_tta_member B2\r\n\r\n# Problem 1\r\n\r\nFrom the record A / click on 'relations' and you see both relations. Attempting to edit record B1 or B2 - for example updating the phone number of B1 -\r\nwill generate an exception : \"Partners cannot have a relation with themselves\"\r\n\r\nLooking inside the code, indeed the comparisons is done between the 2 same ids.... strange\r\n\r\n# Problem 2\r\n\r\nTry to change the relation with B2 and put B3 instead results in the following incorrect relation :+1: \r\n\r\nB3 has_tta_member A\r\n\r\nInstead of A has_tta_member B3\r\n\r\n# Some code remarks\r\n\r\nFirst the code convert this / other into left /right partners. But in most cases only one partner is modified. That's the main reason for my first problem.\r\n\r\nSecond problem I think is :     \r\n\r\n```\r\n if 'type_selection_id' not in vals:\r\n            return vals \r\n```\r\n\r\nIn most cases the the type is not changed and because of the return the inversion code is not reachable.\r\n\r\nSorry to say, but as such the code looks dangerous to me, resulting in data corruption....\r\n\r\nI did a quick fix - not very clean but I don't know enough  the module and I am short on time\r\n\r\n````\r\n\r\n    @api.model\r\n    def _correct_vals(self, vals):\r\n        \"\"\"Fill left and right partner from this and other partner.\"\"\"\r\n        vals = vals.copy()\r\n        if 'this_partner_id' in vals:\r\n            vals['left_partner_id'] = vals['this_partner_id']\r\n            del vals['this_partner_id']\r\n        if 'other_partner_id' in vals:\r\n            vals['right_partner_id'] = vals['other_partner_id']\r\n            del vals['other_partner_id']\r\n        # in most cases type_selection_id is not in the vals....\r\n        if 'type_selection_id'  in vals:  \r\n            selection = self.type_selection_id.browse(vals['type_selection_id'])\r\n            type_id = selection.type_id.id\r\n            del vals['type_selection_id']\r\n        else:\r\n            selection = self.type_selection_id\r\n            type_id = selection.type_id.id\r\n        is_inverse = selection.is_inverse\r\n        vals['type_id'] = type_id\r\n        # Need to switch right and left partner if we are in reverse id:\r\n        if 'left_partner_id' in vals or 'right_partner_id' in vals:\r\n            # print \"Inversing\"\r\n            if is_inverse:\r\n                left_partner_id = False\r\n                right_partner_id = False\r\n                if 'left_partner_id' in vals:\r\n                    right_partner_id = vals['left_partner_id']\r\n                    del vals['left_partner_id']\r\n                if 'right_partner_id' in vals:\r\n                    left_partner_id = vals['right_partner_id']\r\n                    del vals['right_partner_id']\r\n                if left_partner_id:\r\n                    vals['left_partner_id'] = left_partner_id\r\n                if right_partner_id:\r\n                    vals['right_partner_id'] = right_partner_id\r\n              \r\n        return vals\r\n\r\n    @api.multi\r\n    def write(self, vals):\r\n        \"\"\"divert non-problematic writes to underlying table\"\"\"\r\n        print \"res_partner_relation_all BEFORE %s\" %vals\r\n     \r\n        for rec in self:\r\n            cvals = vals.copy()\r\n            # need to take the other side of the relation in case we need \r\n            # exchanging the side....\r\n            if 'this_partner_id' in cvals and \\\r\n               'other_partner_id' not in cvals :\r\n                   cvals['other_partner_id'] = rec.other_partner_id.id\r\n            elif 'other_partner_id' and 'this_partner_id' not in cvals :\r\n                   cvals['this_partner_id'] = rec.this_partner_id.id\r\n            fvals = self._correct_vals(cvals)\r\n            print \"res_partner_relation_all AFTER %s\" %fvals\r\n        \r\n            rec.relation_id.write(fvals)\r\n        \r\n        return True\r\n``"},"comment":{"url":"https://api.github.com/repos/OCA/partner-contact/issues/comments/379991069","html_url":"https://github.com/OCA/partner-contact/issues/454#issuecomment-379991069","issue_url":"https://api.github.com/repos/OCA/partner-contact/issues/454","id":379991069,"user":{"login":"hbrunn","id":2563186,"avatar_url":"https://avatars2.githubusercontent.com/u/2563186?v=4","gravatar_id":"","url":"https://api.github.com/users/hbrunn","html_url":"https://github.com/hbrunn","followers_url":"https://api.github.com/users/hbrunn/followers","following_url":"https://api.github.com/users/hbrunn/following{/other_user}","gists_url":"https://api.github.com/users/hbrunn/gists{/gist_id}","starred_url":"https://api.github.com/users/hbrunn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hbrunn/subscriptions","organizations_url":"https://api.github.com/users/hbrunn/orgs","repos_url":"https://api.github.com/users/hbrunn/repos","events_url":"https://api.github.com/users/hbrunn/events{/privacy}","received_events_url":"https://api.github.com/users/hbrunn/received_events","type":"User","site_admin":false},"created_at":"2018-04-10T06:40:41Z","updated_at":"2018-04-10T06:40:41Z","author_association":"MEMBER","body":"no, I'm not. there are a couple of [PRs on this module](https://github.com/OCA/partner-contact/pulls/NL66278) by @NL66278, did you encounter said issue there?"}}
{"actor":{"display_login":"hbrunn"}}