{"action":"closed","issue":{"url":"https://api.github.com/repos/odoo/odoo/issues/10799","repository_url":"https://api.github.com/repos/odoo/odoo","labels_url":"https://api.github.com/repos/odoo/odoo/issues/10799/labels{/name}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/10799/comments","events_url":"https://api.github.com/repos/odoo/odoo/issues/10799/events","html_url":"https://github.com/odoo/odoo/issues/10799","id":131699732,"number":10799,"title":"[8.0] Error when overwriting a field in v8 api that had multi in v7","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":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-02-05T17:17:20Z","updated_at":"2016-08-23T07:52:53Z","closed_at":"2016-08-23T07:52:53Z","body":"For example, [`product.template` has fields `image_small` and `image_medium` defined with `multi` and `store` attributes set](https://github.com/odoo/odoo/blob/8.0/addons/product/product.py#L566):\r\n\r\n        'image_medium': fields.function(_get_image, fnct_inv=_set_image,\r\n            string=\"Medium-sized image\", type=\"binary\", multi=\"_get_image\", \r\n            store={\r\n                'product.template': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),\r\n            },\r\n            help=\"Medium-sized image of the product. It is automatically \"\\\r\n                 \"resized as a 128x128px image, with aspect ratio preserved, \"\\\r\n                 \"only when the image exceeds one of those sizes. Use this field in form views or some kanban views.\"),\r\n        'image_small': fields.function(_get_image, fnct_inv=_set_image,\r\n            string=\"Small-sized image\", type=\"binary\", multi=\"_get_image\",\r\n            store={\r\n                'product.template': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),\r\n            },\r\n            help=\"Small-sized image of the product. It is automatically \"\\\r\n                 \"resized as a 64x64px image, with aspect ratio preserved. \"\\\r\n                 \"Use this field anywhere a small image is required.\")\r\n\r\n[Now I need an addon to replace that and add an image gallery](https://github.com/OCA/product-attribute/pull/112), with this code:\r\n\r\n```\r\nclass ProductTemplate(models.Model):\r\n    _name = \"product.template\"\r\n    _inherit = [_name, \"multi_image_base.owner\"]\r\n\r\n    image = fields.Binary(related=\"image_main\", store=False)\r\n    image_medium = fields.Binary(related=\"image_main_medium\", store=False)\r\n    image_small = fields.Binary(related=\"image_main_small\", store=False)\r\n```\r\n\r\nBut since there is no equivalent in v8 for `multi`, installing it and testing the `sale` module would fail with:\r\n\r\n```\r\nERROR: test_create_from_product eatePriceItemCase)\r\n Check if price item created from product template has:\r\nraceback (most recent call last):\r\n   File \"/home/travis/build/OCA/product-attribute/pricelist_per_product/tests/test_create.py\", line 23,in test_create_from_product\r\n     product = self.env['product.template'].create(vals)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 266, in wrapper\r\n     return new_api(self, *args, **kwargs)\r\n   File \"/home/travis/build/OCA/product-attribute/pricelist_per_product/product.py\", line 45, in create\r\n     return super(ProductTemplate, self).create(vals)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 266, in wrapper\r\n     return new_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 508, in new_api\r\n     result = method(self._model, cr, uid, *args, **old_kwargs)\r\n   File \"/home/travis/odoo-8.0/addons/product/product.py\", line 741, in create\r\n     product_template_id = super(product_template, self).create(cr, uid, vals, context=context)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 268, in wrapper\r\n     return old_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/addons/mail/mail_thread.py\", line 381, in create\r\n     thread_id = super(mail_thread, self).create(cr, uid, values, context=context)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 268, in wrapper\r\n     return old_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 372, in old_api\r\n     result = method(recs, *args, **kwargs)\r\n   File \"/home/travis/build/OCA/product-attribute/product_profile/product.py\", line 111, in create\r\n     {k: v for k, v in vals.items() if 'profile_default_' not in k})\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 266, in wrapper\r\n     return new_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/models.py\", line 4093, in create\r\n     record = self.browse(self._create(old_vals))\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 266, in wrapper\r\n     return new_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 508, in new_api\r\n     result = method(self._model, cr, uid, *args, **old_kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/models.py\", line 4278, in _create\r\n     result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or []\r\n   File \"/home/travis/odoo-8.0/openerp/osv/fields.py\", line 1483, in set\r\n     self._fnct_inv(obj, cr, user, id, name, value, self._fnct_inv_arg, context)\r\n   File \"/home/travis/odoo-8.0/addons/mail/mail_thread.py\", line 282, in _set_followers\r\n     self.message_subscribe(cr, uid, [id], list(new-old), context=context)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 268, in wrapper\r\n     return old_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/addons/mail/mail_thread.py\", line 1799, in message_subscribe\r\n     }, context=context)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 268, in wrapper\r\n     return old_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/addons/mail/mail_followers.py\", line 59, in create\r\n     res = super(mail_followers, self).create(cr, uid, vals, context=context)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 268, in wrapper\r\n     return old_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 372, in old_api\r\n     result = method(recs, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/models.py\", line 4093, in create\r\n     record = self.browse(self._create(old_vals))\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 266, in wrapper\r\n     return new_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 508, in new_api\r\n     result = method(self._model, cr, uid, *args, **old_kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/models.py\", line 4303, in _create\r\n     recs.recompute()\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 266, in wrapper\r\n     return new_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/models.py\", line 5759, in recompute\r\n     rec._write(values)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 266, in wrapper\r\n     return new_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 592, in new_api\r\n     result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/models.py\", line 4036, in _write\r\n     cr, user, todo, fields_to_recompute, context)\r\n   File \"/home/travis/odoo-8.0/openerp/api.py\", line 268, in wrapper\r\n     return old_api(self, *args, **kwargs)\r\n   File \"/home/travis/odoo-8.0/openerp/models.py\", line 4401, in _store_set_values\r\n     if self._columns[f]._multi not in keys:\r\n KeyError: 'image_small'\r\n```\r\n\r\nHad to fall back to v7 api, so either:\r\n\r\n- There is a fix without docs, please say.\r\n- The fix is use v7.\r\n- The fix is migrate those modules to v8.\r\n- We need a new fix for this."}}
{"actor":{"display_login":"Yajo"}}