Skip to content

Commit 5d1bb21

Browse files
authored
Fix Lab Information setup data import after Laboratory migration to Dexterity (#2918)
The Laboratory content type was migrated to Dexterity in #2810, where it became folderish and inherited edit(title, description) from CMFCore's PortalFolder. The Lab_Information setup data importer still called laboratory.edit() with the old Archetypes field names (Name, LabURL, Confidence, ...), which raised: TypeError: edit() got an unexpected keyword argument 'Name' Update the importer to use api.edit() with the Dexterity schema field names, matching the pattern already used for the migrated SampleType and AnalysisProfile importers. Convert Confidence to int (now schema.Int), wrap the accreditation logo in a NamedBlobImage (now a NamedBlobImage field), and drop the obsolete AccreditationBodyLong value, which never mapped to a field on the Archetypes type either.
1 parent 1298beb commit 5d1bb21

2 files changed

Lines changed: 36 additions & 27 deletions

File tree

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
2.7.0 (unreleased)
55
------------------
66

7+
- #2918 Fix Lab Information setup data import after Laboratory migration to Dexterity
78
- #2917 Fix `ClientID` is not displayed in samples listing, but client name
89
- #2916 Fix msgid collision on `description_calculation_imports` in Calculation content type
910
- #2915 Rename 'Duplicate' sample transition to 'Duplicate Sample' to avoid translation collision with the worksheet duplicate-analysis label

src/senaite/core/exportimport/setupdata/__init__.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from bika.lims.utils import to_utf8
3535
from bika.lims.utils.analysis import create_analysis
3636
from pkg_resources import resource_filename
37+
from plone.namedfile.file import NamedBlobImage
3738
from Products.Archetypes.event import ObjectInitializedEvent
3839
from Products.CMFCore.utils import getToolByName
3940
from Products.CMFPlone.utils import _createObjectByType
@@ -357,37 +358,44 @@ def Import(self):
357358

358359
class Lab_Information(WorksheetImporter):
359360

361+
def get_logo(self, filename):
362+
"""Read a setup data image and return it as a NamedBlobImage
363+
"""
364+
if not filename:
365+
return None
366+
path = resource_filename(
367+
self.dataset_project,
368+
"setupdata/%s/%s" % (self.dataset_name, filename))
369+
try:
370+
file_data = read_file(path)
371+
except IOError as msg:
372+
logger.warning("%s. Error on sheet: %s" % (msg, self.sheetname))
373+
return None
374+
return NamedBlobImage(
375+
data=file_data, filename=api.safe_unicode(filename))
376+
360377
def Import(self):
361378
laboratory = self.context.setup.laboratory
362379
values = {}
363380
for row in self.get_rows(3):
364-
values[row['Field']] = row['Value']
365-
366-
if values['AccreditationBodyLogo']:
367-
path = resource_filename(
368-
self.dataset_project,
369-
"setupdata/%s/%s" % (self.dataset_name,
370-
values['AccreditationBodyLogo']))
371-
try:
372-
file_data = read_file(path)
373-
except Exception as msg:
374-
file_data = None
375-
logger.warning(msg[0] + " Error on sheet: " + self.sheetname)
376-
else:
377-
file_data = None
378-
379-
laboratory.edit(
380-
Name=values['Name'],
381-
LabURL=values['LabURL'],
382-
Confidence=values['Confidence'],
383-
LaboratoryAccredited=self.to_bool(values['LaboratoryAccredited']),
384-
AccreditationBodyLong=values['AccreditationBodyLong'],
385-
AccreditationBody=values['AccreditationBody'],
386-
AccreditationBodyURL=values['AccreditationBodyURL'],
387-
Accreditation=values['Accreditation'],
388-
AccreditationReference=values['AccreditationReference'],
389-
AccreditationBodyLogo=file_data,
390-
TaxNumber=values['TaxNumber'],
381+
values[row["Field"]] = row["Value"]
382+
383+
api.edit(
384+
laboratory,
385+
title=api.safe_unicode(values["Name"]),
386+
lab_url=api.safe_unicode(values["LabURL"]),
387+
confidence=api.to_int(values["Confidence"], default=None),
388+
laboratory_accredited=self.to_bool(
389+
values["LaboratoryAccredited"]),
390+
accreditation_body=api.safe_unicode(values["AccreditationBody"]),
391+
accreditation_body_url=api.safe_unicode(
392+
values["AccreditationBodyURL"]),
393+
accreditation=api.safe_unicode(values["Accreditation"]),
394+
accreditation_reference=api.safe_unicode(
395+
values["AccreditationReference"]),
396+
accreditation_body_logo=self.get_logo(
397+
values["AccreditationBodyLogo"]),
398+
tax_number=api.safe_unicode(values["TaxNumber"]),
391399
)
392400
self.fill_contactfields(values, laboratory)
393401
self.fill_addressfields(values, laboratory)

0 commit comments

Comments
 (0)