Read valid locations from the context
Sometimes when a context evaluates to a record as None, '' or -1 (see examples in Search product or lot that the context has valid locations), we currently not have control that location is record.
Request:
<class 'trytond.pool.stock.move'>.on_change_with_unit_price_required(*({'from_location': 3, 'id': 26109, 'to_location': -1}, {'client': '4ee12ffe-c848-4c98-aa4a-252b7833489e', 'company_filter': 'one', 'employee': 2, 'employee.rec_name': 'CM', 'company': 1, 'company.rec_name': 'xxxxx', 'language': 'ca', 'language_direction': 'ltr', 'groups': [1, 29, 4, 16, 6, 9, 2, 12, 7, 3, 8, 19, 23, 22, 27, 25, 24, 15, 30, 17, 5, 28, 11, 21, 10, 14, 13, 20, 26, 18], 'locale': {'date': '%d/%m/%Y', 'grouping': [3, 3, 0], 'decimal_point': ',', 'thousands_sep': ' .'}}), **{}) from xxxx@xxxx/xxx/
Traceback:
Traceback (most recent call last):
File "/tryton/trytond/trytond/model/model.py", line 291, in __getattr__
return self._values[name]
~~~~~~~~~~~~^^^^^^
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tryton/trytond/trytond/protocols/dispatcher.py", line 185, in _dispatch
result = rpc.result(meth(inst, *c_args, **c_kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/fields/field.py", line 123, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/modules/stock/move.py", line 467, in on_change_with_unit_price_required
to_type = self.to_location.type if self.to_location else None
^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/modelstorage.py", line 1484, in __getattr__
return super(ModelStorage, self).__getattr__(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tryton/trytond/trytond/model/model.py", line 293, in __getattr__
raise AttributeError("'%s' Model has no attribute '%s': %s"
AttributeError: 'stock.location' Model has no attribute 'type': None