{"action":"created","issue":{"url":"https://api.github.com/repos/OCA/partner-contact/issues/139","labels_url":"https://api.github.com/repos/OCA/partner-contact/issues/139/labels{/name}","comments_url":"https://api.github.com/repos/OCA/partner-contact/issues/139/comments","events_url":"https://api.github.com/repos/OCA/partner-contact/issues/139/events","html_url":"https://github.com/OCA/partner-contact/pull/139","id":93231739,"number":139,"title":"Recursive @onchange misbehavior","user":{"login":"Yajo","id":973709,"avatar_url":"https://avatars.githubusercontent.com/u/973709?v=3","gravatar_id":"","url":"https://api.github.com/users/Yajo","html_url":"https://github.com/Yajo","followers_url":"https://api.github.com/users/Yajo/followers","following_url":"https://api.github.com/users/Yajo/following{/other_user}","gists_url":"https://api.github.com/users/Yajo/gists{/gist_id}","starred_url":"https://api.github.com/users/Yajo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yajo/subscriptions","organizations_url":"https://api.github.com/users/Yajo/orgs","repos_url":"https://api.github.com/users/Yajo/repos","events_url":"https://api.github.com/users/Yajo/events{/privacy}","received_events_url":"https://api.github.com/users/Yajo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-07-06T09:25:30Z","updated_at":"2015-07-30T11:07:26Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/OCA/partner-contact/pulls/139","html_url":"https://github.com/OCA/partner-contact/pull/139","diff_url":"https://github.com/OCA/partner-contact/pull/139.diff","patch_url":"https://github.com/OCA/partner-contact/pull/139.patch"},"body":"@pedrobaeza This is the bug that I discovered from https://github.com/OCA/partner-contact/pull/104.\r\n\r\nThe problem is that I don't know how to fix it, but at least I'm sending the tests to get some help.\r\n\r\nCurrent failure:\r\n\r\n- User creates a new partner.\r\n- User unchecks `is_company`.\r\n- User sets `firstname` to \"John\".\r\n  - This triggers `_compute_name()`.\r\n    - This updates `name`.\r\n      - This triggers `_onchange_name()`.\r\n        - This inverts name.\r\n          - This sets `lastname` to \"John\" and `firstname` to False.\r\n\r\nThe result is that the user writes in `firstname`, and that ends up in `lastname` after triggering all the onchanges.\r\n\r\n**1st idea** tried: Remove `_onchange_name()` function, and let `_inverse_name_after_cleaning_whitespace()` be called only on save, but then:\r\n\r\n- User creates a new partner.\r\n- User checks `is_company`.\r\n- User writes in `name`.\r\n- User saves.\r\n  - Odoo sends the correct `name` value, but also sends `lastname = firstname = False` because hidden fields are sent always too.\r\n    - This triggers `_compute_name()`.\r\n      - This sets `name = False`\r\n        - This makes `_check_name()` fail.\r\n\r\n**2nd idea** was to disable `_onchange_name()` when called from `_compute_name()`, so the code was:\r\n\r\n    @api.one\r\n    @api.depends(\"firstname\", \"lastname\")\r\n    def _compute_name(self):\r\n        \"\"\"Write the 'name' field according to splitted data.\"\"\"\r\n        self.with_context(skip_invert=True).name = u\" \".join(\r\n            filter(None, (self.lastname, self.firstname)))\r\n\r\n    [...]\r\n\r\n    @api.one\r\n    @api.onchange(\"name\")\r\n    def _onchange_name(self):\r\n        \"\"\"Ensure :attr:`~.name` is inverted in the UI.\"\"\"\r\n        if not self.env.context.get(\"skip_invert\"):\r\n            self._inverse_name_after_cleaning_whitespace()\r\n\r\nBut seems like the *onchange magic* does not work when switching the context. `_compute_name()` never changes anything. For some reason if you don't set new values directly to `self`, no record is updated.\r\n\r\nIn fact, that does not even let you install the module, since `_compute_name()` is called from `_install_partner_firstname()`.\r\n\r\n**3rd idea** was same as 2nd but returning the modified record, but I ended up with same result as for the 2nd:\r\n\r\n    @api.one\r\n    @api.depends(\"firstname\", \"lastname\")\r\n    def _compute_name(self):\r\n        \"\"\"Write the 'name' field according to splitted data.\"\"\"\r\n        other = self.with_context(skip_invert=True)\r\n        other.name = u\" \".join(\r\n            filter(None, (self.lastname, self.firstname)))\r\n        return other\r\n\r\nSo **4th idea** was to leave `_compute_name()` uncahnged and add `context=\"{'skip_invert': True}\"` to firstname and lastname `<field/>` in views, but [seems like the `context` attribute is only used in relational fields](https://www.odoo.com/documentation/8.0/reference/views.html#semantic-components). That context was ignored.\r\n\r\nSo, right now I'm on a dead end. I'd appreciate any suggestions."},"comment":{"url":"https://api.github.com/repos/OCA/partner-contact/issues/comments/126274514","html_url":"https://github.com/OCA/partner-contact/pull/139#issuecomment-126274514","issue_url":"https://api.github.com/repos/OCA/partner-contact/issues/139","id":126274514,"user":{"login":"Yajo","id":973709,"avatar_url":"https://avatars.githubusercontent.com/u/973709?v=3","gravatar_id":"","url":"https://api.github.com/users/Yajo","html_url":"https://github.com/Yajo","followers_url":"https://api.github.com/users/Yajo/followers","following_url":"https://api.github.com/users/Yajo/following{/other_user}","gists_url":"https://api.github.com/users/Yajo/gists{/gist_id}","starred_url":"https://api.github.com/users/Yajo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yajo/subscriptions","organizations_url":"https://api.github.com/users/Yajo/orgs","repos_url":"https://api.github.com/users/Yajo/repos","events_url":"https://api.github.com/users/Yajo/events{/privacy}","received_events_url":"https://api.github.com/users/Yajo/received_events","type":"User","site_admin":false},"created_at":"2015-07-30T11:07:26Z","updated_at":"2015-07-30T11:07:26Z","body":"Anything else for merging?"}}