diff --git a/CHANGES.rst b/CHANGES.rst index 2598a547..5997fe70 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changelog 6.0.21 (unreleased) ------------------- -- Nothing changed yet. +- Handle cost with empty text block in previous upgrade-step. + [cekk] 6.0.20 (2023-10-30) diff --git a/src/design/plone/contenttypes/upgrades/upgrades.py b/src/design/plone/contenttypes/upgrades/upgrades.py index e2b5dc96..85bc0eb2 100644 --- a/src/design/plone/contenttypes/upgrades/upgrades.py +++ b/src/design/plone/contenttypes/upgrades/upgrades.py @@ -1505,6 +1505,17 @@ def to_7011(context): def to_7012(context): + def has_empty_prezzo(value): + if not value: + return True + if value == {"blocks": {}, "blocks_layout": {"items": []}}: + return True + blocks_layout = value.get("blocks_layout", {}).get("items", []) + blocks = list(value.get("blocks", {}).values()) + if len(blocks_layout) == 1 and blocks[0] == {"@type": "text"}: + return True + return False + logger.info("Set default value in prezzo field because now is required.") brains = api.content.find(portal_type=["Event"]) @@ -1518,7 +1529,7 @@ def to_7012(context): logger.info("Progress: {}/{}".format(i, tot)) event = brain.getObject() prezzo = getattr(event, "prezzo", None) - if not prezzo or prezzo == {"blocks": {}, "blocks_layout": {"items": []}}: + if has_empty_prezzo(value=prezzo): fixed.append(brain.getPath()) uid = str(uuid4()) event.prezzo = {