Duplicating an _inherits'ed record may link translations to a wrong record or fails with an AccessError
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Odoo Server (MOVED TO GITHUB) |
Fix Released
|
Low
|
OpenERP Publisher's Warranty Team |
Bug Description
Hi,
Concerns:
Duplication of records which are '_inherits' of another model as a product.product.
Does not happen on a database where the IDs of the product.product are synchronized with the IDs of the product.template, so it is probably not reproducible on most of the databases, but as soon as you can have several variants for a template, it will happen.
Steps to reproduce:
I don't know how we can reproduce it on runbot, as we need to have several variants for 1 template.
However, the steps to reproduce it are just to create some templates, and several variants on each of them, then to duplicate a variant.
Actual behavior:
Either the translations are linked with a wrong product.template, either the copy fails with the following error:
AccessError
One of the records you are trying to modify has already been deleted (Document type: Product Template).
Moreover, the source values of a wrong product.template may be replaced by the one of the duplicated product.
Probably related to: https:/
Expected:
It duplicates the product with error with the correct translations.
My analysis:
Say that we are copying the product with the ID 77. This product is related to a template whose ID is 25.
The new ID of the copied product is 78. The new ID of the copied template is 26.
The field name we are translating is 'name'
In copy_translations() at http://
looking at the lines 5001-5002:
elif field_name in self._inherit_
Here, the translation name will be: 'product.
Just below, on the line 5012:
We can already smell the issue: new_id is 78 and the translation is related to 'product.template'. Here, 'res_id' should likely be 26.
Now, there is a direct consequence, when the translation is written, we end up in ir_translation.
def _set_src(self, cr, uid, id, name, value, args, context=None):
''' When changing source term of a translation, change its value in db for
the associated object, and the src field
'''
if context is None:
context = {}
record = self.browse(cr, uid, id, context=context)
if value and record.type == 'model':
model = self.pool.
#We need to take the context without the language information, because we want to write on the
#value store in db and not on the one associate with current language.
#Also not removing lang from context trigger an error when lang is different
return self.write(cr, uid, id, {'src': value}, context=context)
On this specific line:
model is 'product.template'
record.res_id is 78
field is 'name'
The result is the following:
- if a template exists with the ID 78, the values will be written on this one.
- if a template with ID 78 does not exist, we'll have an AccessError.
Related branches
- OpenERP Core Team: Pending requested
-
Diff: 107 lines (+63/-13)2 files modifiedopenerp/addons/base/tests/test_base.py (+42/-0)
openerp/osv/orm.py (+21/-13)
summary: |
- Duplicating an _inherits'ed record may copy random translations or fails - with an AccessError + Duplicating an _inherits'ed record may link translations on a wrong + record or fails with an AccessError |
summary: |
- Duplicating an _inherits'ed record may link translations on a wrong + Duplicating an _inherits'ed record may link translations to a wrong record or fails with an AccessError |
Changed in openobject-server: | |
assignee: | nobody → OpenERP Publisher's Warranty Team (openerp-opw) |
tags: | added: maintenance |
Changed in openobject-server: | |
status: | New → Confirmed |
importance: | Undecided → Low |
Here is a dump to reproduce the steps.
Branches:
server: 5109 / launchpad_ translations_ on_behalf_ of_openerp- 20131026062452- 54qhvc3cru0x8e6 h translations_ on_behalf_ of_openerp- 20131028054233- 15znliqv2eh2jq0 i translations_ on_behalf_ of_openerp- 20131027061322- op6b5ohzf6eiyiu 2 variant_ simple' that I'll attach to this bug report in the addons-path. This module adds the actions for the variant views.
addons: 9546 / launchpad_
web: 4047 / launchpad_
You will also need to put the module 'product_
What I already did on the dump: variant_ simple, sale
- installed a fresh database with modules: product_
- created some product.product on an existing product.template (15" LCD Monitor) so the IDs are not aligned between product.template and product.product
Steps to reproduce:
1. Load the dump
2. Open the menu "Sales / Products / Products"
3. Select a product, for instance "USB Adapter"
4. Use the duplicate function
Result:
AccessError
One of the records you are trying to modify has already been deleted (Document type: Product Template).