diff --git a/conservancy_beancount/reports/core.py b/conservancy_beancount/reports/core.py index c583c4297b2742e2192c0fb38945626136af9752..3fae1583dc32cbe1df40cf73d7cd7c7cdfa76817 100644 --- a/conservancy_beancount/reports/core.py +++ b/conservancy_beancount/reports/core.py @@ -1052,6 +1052,37 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta): ### Properties + def set_custom_property(self, + name: str, + value: Any, + valuetype: Optional[str]=None, + ) -> odf.meta.UserDefined: + if valuetype is None: + if isinstance(value, bool): + valuetype = 'boolean' + elif isinstance(value, (datetime.date, datetime.datetime)): + valuetype = 'date' + elif isinstance(value, (int, float, Decimal)): + valuetype = 'float' + if not isinstance(value, str): + if valuetype == 'boolean': + value = 'true' if value else 'false' + elif valuetype == 'date': + value = value.isoformat() + else: + value = str(value) + retval = self.ensure_child(self.document.meta, odf.meta.UserDefined, name=name) + if valuetype is None: + try: + retval.removeAttribute('valuetype') + except KeyError: + pass + else: + retval.setAttribute('valuetype', valuetype) + retval.childNodes.clear() + retval.addText(value) + return retval + def set_properties(self, *, created: Optional[datetime.datetime]=None, generator: str='conservancy_beancount',