This question has been flagged
1 Reply
2352 Views

I'm on Odoo v14 CE.

I'm currently writing a custom app, so I'm modifying my models / views very often (var names, add and remove, ..) and sometimes with major changes
After all these changes, I ended with a strange behavior with a wizard (Transient model)

This wizard duplicates a "product.template" then set a custom name on it. Sample code could be :

new_product = current_product.copy()
vals = {
'name': "my new name"
}
new_product.write(vals)

The strange behavior is :
- On my existing database (the one with many changes / updates), it does not work, the name keeps being "Current product name (Copy)"
- On a fresh (new) database, everything works as expected : the name of the duplicated product is set to "my new name"

So I guess it's not a code issue by itself, but I was suspecting something wrong in the config hold in the database itself about this app/module, maybe some states, or code that has not been correcly updated / cleaned ?

Maybe I should do something specific (vaccum / cleanup) after important updates ? I also tried :
- duplicating the database, same problem, only a new database solves this issue
- having some other update methods, for example new_product.name = "my new name" but same problem

Any idea ?
Is there a way to force the reinstallation of an app without losing all data ?

Thank you

Avatar
Discard
Author

Some additional information about the models :
- The transient model is only for the wizard itself, it allows to define some important information for creating the new product (by duplicating another one)
- The current_product.copy in the above sample code concerns the default "product.template" model (so it's no Transient)

So I'm not sure if it's related to TransientModel or not..

Author Best Answer

And another information I forgot : other fields are correctly updated ! If I do something like

new_product = current_product.copy()
vals = {
'tracking': 'lot',
'sale_ok': True,
'name': "my new name"
}
new_product.write(vals)

In that case, 'tracking' and 'sale_ok' will be updated, but 'name' will stay on "Current product name (Copy)"

'name' is behaving as if it had a "readonly" attribute set on it, but it's not the case (and I can update it in the edit form with no problem, and it will save with the correct name)

Avatar
Discard