Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always call object info adapters with a record #1919

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/bika/lims/browser/analysisrequest/add2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ def get_record_metadata(self, record):
if len(uids) == 1:
extra_fields[field_name] = uids[0]

# Populate metadata with object info from extra fields
# Populate metadata with object info from extra fields (hidden fields)
for field_name, uid in extra_fields.items():
key = "{}_metadata".format(field_name.lower())
if metadata.get(key):
Expand All @@ -1230,7 +1230,7 @@ def get_record_metadata(self, record):
obj = self.get_object_by_uid(uid)
if not obj:
continue
obj_info = self.get_object_info(obj, field_name)
obj_info = self.get_object_info(obj, field_name, record=extra_fields)
if not obj_info or "uid" not in obj_info:
continue
metadata[key] = {obj_info["uid"]: obj_info}
Expand Down Expand Up @@ -1380,16 +1380,17 @@ def get_object_info(self, obj, key, record=None):
func_name = "get_{}_info".format(field_name.lower())
func = getattr(self, func_name, None)

# always ensure we have a record
if record is None:
record = {}

# Get the info for each object
info = callable(func) and func(obj) or self.get_base_info(obj)

# Check if there is any adapter to handle objects for this field
for name, adapter in getAdapters((obj, ), IAddSampleObjectInfo):
logger.info("adapter for '{}': {}".format(field_name, name))
if record is not None:
ad_info = adapter.get_object_info_with_record(record)
else:
ad_info = adapter.get_object_info()
ad_info = adapter.get_object_info_with_record(record)
self.update_object_info(info, ad_info)

return info
Expand Down