My previous post got broken by adding hyperlinks, here's a hopefully amended version.
Hi alI!
I haven't used this forum before so bear with me if I make any noob mistakes or I seem a bit dense. I'm very new to Odoo, been using it for about a week in an attempt to migrate a clients' database over to it. This has obviously presented quite a steep learning curve but so far I've been more or less able to figure things out as I go along. Or so I thought. Some context: I've been tasked with figuring out some functionality to allow staff in a shop to tare the scale using POS. Obviously, being completely new to this I thought I'd look on the module store. I ended up finding a module called "pos_tare" that's maintained by OCA. The only issue with the module is that it's only updated to Odoo 12. Being naive and completely new to Odoo, I tried to add this module to the SaaS instance of the project that my colleague had been working on for a number of days. There'll be backups, right? Of course, no backups, so uploading the outdated module to the online version of Odoo obviously broke the database.
On my local
server running a restored version of the broken database and on SaaS, I
get this error message upon trying to access the POS configuration
screen.
Odoo Server Error
Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 237, in _dispatch result = request.dispatch() File "/usr/lib/python3/dist-packages/odoo/http.py", line 683, in dispatch result = self._call_function(**self.params) File "/usr/lib/python3/dist-packages/odoo/http.py", line 359, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 347, in checked_call result = self.endpoint(*a, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 912, in __call__ return self.method(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 531, in response_wrap response = f(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1389, in call_kw return self._call_kw(model, method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1381, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 396, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 383, in _call_kw_multi result = method(recs, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/models.py", line 3009, in read raise ValueError("Invalid field %r on model %r" % (name, self._name)) Exception The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/http.py", line 639, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 315, in _handle_exception raise exception.with_traceback(None) from new_cause ValueError: Invalid field 'iface_tare_method' on model 'pos.config'
This
obviously points to the fact that the module hasn't installed properly
from the web version, but the error message is the same after retrying
installation locally. It's also the same if I try to import the module
from a database with just the dependencies installed. My first question
is, is there any way I can recover the data I already have on here from
the database, just excluding (what I assume to be) the bad pos.config
model? Or just the parts of the database that have been affected by the
module. Quite a lot of work has already gone into the website and
importing stock lists and I'll be in a spot of hot water if I'm unable
to recover the data. I tried adding the field manually into pos.config
using pgAdmin but that proved to be well beyond my understanding.
I came to the potentially erroneous conclusion that I could simply update the module and install it in the broken database and my woes would be remedied. I decided to try my hand at updating this module using OCA's guides on updating modules from Odoo \12\ to\ 13\\ and\ then\ \13 to 14. This was essentially all going well, until I got to adding ondelete parameters to the selection fields in some of the config functionality. Before adding these parameters, Odoo threw this error on module installation:
Error:
Odoo Server Error
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/usr/lib/python3/dist-packages/odoo/http.py", line 683, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 359, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 347, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 912, in __call__
return self.method(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 531, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1393, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1381, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 396, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 383, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-71>", line 2, in button_immediate_install
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 73, in check_and_log
return method(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 474, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 592, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 89, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 455, in load_modules
loaded_modules, update_module, models_to_check)
File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 348, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 197, in load_module_graph
registry.setup_models(cr)
File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 273, in setup_models
model._setup_base()
File "/usr/lib/python3/dist-packages/odoo/models.py", line 2791, in _setup_base
self._add_field(name, field.new())
File "/usr/lib/python3/dist-packages/odoo/models.py", line 404, in _add_field
field.setup_base(self, name)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 278, in setup_base
self._setup_attrs(model, name)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 2328, in _setup_attrs
"containing the specified option." % self
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/http.py", line 639, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 315, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: barcode.rule.type: required selection fields must define an ondelete policy that implements the proper cleanup of the corresponding records upon module uninstallation. Please use one or more of the following policies: 'set default' (if the field has a default defined), 'cascade', or a single-argument callable where the argument is the recordset containing the specified option.
This error is identical when installing on to the broken database or a blank database with the dependent modules. This break is obviously due to the selection field in barcode_rule.py being incorrect since Odoo 14 made ondelete a requirement for selection fields. Here's the code in barcode_rule.py:
from odoo import models, fields
class BarcodeRule(models.Model):
_inherit = 'barcode.rule'
type = fields.Selection(selection_add=[
('tare', 'Tare')
])
And now OCA's guideline for ondelete syntax:
"If you add new values in a selection field through selection_add
, you have to define a new ondelete=
attribute setting the value to assign for each previous value in case of uninstallation. More info at [github link breaks my post] Example: selection_field = fields.Selection(selection_add=[("foo", "Foo")], ondelete={"foo": "set null"})
."
Finally Odoo docs example:\
Since Odoo 14.0 you have to specify ondelete
attribute.ondelete provides a fallback mechanism for any overridden field with a selection_add. It is a dict that maps every option from the selection_add to a fallback action. This fallback action will be applied to all records whose selection_add option maps to it. The actions can be any of the following:•'set null'– the default, all records with this option will have their selection value set to False.•'cascade'– all records with this option will be deleted along with the option itself.•'set default'– all records with this option will be set to the default of the field definition•<callable>– a callable whose first and only argument will be the set of records containing the specified Selection option, for custom processing. e.g.:my_selection = fields.Selection(selection_add=[('bacon', "Bacon"),], ondelete={'bacon':lambda records: record.write({'my_selection': 'bar'})})
My programming knowledge is, admittedly, fairly limited. I have no idea how to implement Odoo's explanation of the ondelete rule. However, when editing the code in barcode_rule.py to account for the OCA explanation, which I interpreted as:
from odoo import models, fields
class BarcodeRule(models.Model):
_inherit = 'barcode.rule'
type = fields.Selection(selection_add=[
("tare", "Tare")],
ondelete={"tare": "cascade"})
Apologies for the ugly code, I reformatted it to look just like the documentation example in case I was making a typing error. What confounds me now, and what has led me to seek out help, is that this completely breaks any database it's loaded on. I have to drop the database from pgAdmin, The whole page goes white and outputs this error message:
Error:
Traceback:
Error: QWeb2: Can't clone undefined template PosTicket
exception@http://localhost:8069/web/content/510-9d5c618/web.assets_common.js:4394:7
add_template@http://localhost:8069/web/content/510-9d5c618/web.assets_common.js:4411:361
load_qweb/lock</<@http://localhost:8069/web/content/510-9d5c618/web.assets_common.js:4861:6
mightThrow@http://localhost:8069/web/content/510-9d5c618/web.assets_common.js:1616:18
resolve/</process<@http://localhost:8069/web/content/510-9d5c618/web.assets_common.js:1618:89
Googling this has not yielded any results, and so I'm completely stuck at the moment. My questions are: have I formatted ondelete correctly? If not, how do I format it? And if I haven't, what is up with this really strange error message? My theory at the moment is that Odoo crashes for some mercurial reason when it finds one fixed piece of the module but encounters another piece that is broken in the same way. Either that or the module is more broken than I thought. Odoo ostensibly interprets the ondelete successfully and then gets stuck on another, more difficult, error. I find this unlikely though, because there are other selection_fields that are broken in the same way.
I'm running Odoo 14.0+e-20210512 on a Debian server hosted locally, although this affects both my Debian and Windows servers.
This became somewhat of a novel! I really appreciate any and all help I can get on this, I've tried to provide as much info as possible with this. If I've missed anything I'll be more than willing to provide more. Of course if I've made any errors or this isn't the place to post this then I'll happily accept a point in the right direction.
Thanks again!