Yes these are the same, the status is changed in a .py when i fetch some data. The status is displayed correct, according to the current value, but not in the vals. There are only in vals when the user touch the field. So all writes will not recognise when the change by a program. The fields needs deforced to update. Think need to write a work around, with a cache / buffer to updater the vals.
her is a slimline example of the problem, also with the workaround to get it working with an bi=uffer to store the value.
import logging
from odoo import api, fields, models
from odoo.addons.bag_ep_api.utils.buffer_manager import BufferManager
from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__)
# Odoo version 18
class ResPartner(models.Model):
_inherit = 'res.partner'
ep_lookup_status = fields.Integer(
string = "EP Lookup status",
tracking = True,
readonly = True,
default = 0
)
@api.model_create_multi
def create(self, vals_list):
partners = super().create(vals_list)
return partners
def write(self, vals):
# if buffer is not active, this will do nothing, also no message the api.constrains will also not work
# when activate in the _onchange it wil preform exact as expected, workaround
buffer = BufferManager.get(self.env.user.id)
if buffer:
for key in buffer:
if key not in vals:
vals[key] = buffer[key]
result = super().write(vals)
for record in self:
if record.ep_lookup_status == 0:
raise ValidationError('Lookup status cannot be 0')
return result
@api.constrains('ep_lookup_status')
def _check_ep_lookup_status(self):
for rec in self:
if rec.ep_lookup_status == 0:
raise ValidationError('Lookup status cannot be 0')
@api.onchange('zip')
def _onchange_zip(self):
# some other code with channing the ep_lookup_status
# for demo
if self.zip == '2035 VS':
self.ep_lookup_status = 1;
else:
self.ep_lookup_status = 0;
BufferManager.set(self.env.user.id,'ep_lookup_status', self.ep_lookup_status)
return self._handle_onchange_result(
ep_lookup_status = self.ep_lookup_status,
)
@staticmethod
def _handle_onchange_result(warnings = None, model_name = None, data_model = None, ep_lookup_status = None):
# #
result = {}
warnings = {}
# some other to infor the user(s)
# Show a warning message if needed
if warnings:
result['warning'] = {
'title': " -- Warning -- ",
'message': "\n".join(warnings),
}
return result or None
Is lookup_status and ep_lookup_status meant to be the same? What and how is it even changed?
Thanks for this :)