I'm using context from the model for 2 Many2one fields. Both link to the same model, but context should be different depending on a search result.
These are the relevant parts of the code:
class SomeModel(models.Model):
_inherits = ...
_name = ...
#...
def _search_function(self):
# some logic here
return self.env['related.model'].search_read(...)[0]['id']
# ...
first_relational_field = fields.Many2one(
string="...",
help="...",
comodel_name="other.model",
domain="[('this_same_model_id','=',id)]",
context="{'default_related_model_id': "+ str(self._search_function()) +"}",
)
But the next error raises when upgrading the module:
...
context="{'default_price_version_id': "+ str(self._search_function()) +"}"
NameError: name 'self' is not defined
Can methods be defined inside a model and then called to generate parameters in the fields?
Why is self not available for the model?
try to make a print to your self._search_function() and let me know please