Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 4, 04:15 UTC
fix(mapping): resolve CI import error by using string forward references
Stringified `FiscalYear`, `NoteRow`, and `StatementLine` in relationship hints within models.py to fix cyclic dependency evaluation errors causing pytest to fail during Github Actions CI. Co-authored-by: davoodmehraban89 <57283229+davoodmehraban89@users.noreply.github.com>
google-labs-jules[bot] committed
Aug 24, 2026 at 15:35 UTC
bda381ea811355f7a1adfcb7c6a0687d86fedfb3
1 file changed
+26
-5
backend/src/aram_backend/models.py
+26
-5
@@ -1,5 +1,3 @@
1
-from __future__ import annotations
2
-
1
import enum
2
from datetime import datetime, timezone
3
from decimal import Decimal
@@ -35,6 +33,13 @@ class FiscalYearStatus(str, enum.Enum):
33
LOCKED = "Locked"
34
35
36
+class MappingStatus(str, enum.Enum):
37
+ DRAFT = "Draft"
38
+ PROPOSED = "Proposed"
39
+ ACTIVE = "Active"
40
+ RETIRED = "Retired"
41
+
42
+
43
class StatementType(str, enum.Enum):
44
BALANCE_SHEET = "BS"
45
INCOME_STATEMENT = "IS"
@@ -54,7 +59,7 @@ class Company(TimestampMixin, Base):
59
id: Mapped[int] = mapped_column(primary_key=True)
60
code: Mapped[str] = mapped_column(String(64), unique=True, index=True)
61
name: Mapped[str] = mapped_column(String(255))
57
- fiscal_years: Mapped[list[FiscalYear]] = relationship(
62
+ fiscal_years: Mapped[list["FiscalYear"]] = relationship(
63
back_populates="company", cascade="all, delete-orphan"
64
)
65
@@ -118,7 +123,7 @@ class NoteDefinition(TimestampMixin, YearOwnedMixin, Base):
123
title: Mapped[str] = mapped_column(String(512))
124
version: Mapped[int] = mapped_column(Integer, default=1)
125
configuration_json: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict)
121
- rows: Mapped[list[NoteRow]] = relationship(back_populates="note", cascade="all, delete-orphan")
126
+ rows: Mapped[list["NoteRow"]] = relationship(back_populates="note", cascade="all, delete-orphan")
127
128
129
class NoteRow(TimestampMixin, Base):
@@ -148,6 +153,9 @@ class MappingRule(TimestampMixin, YearOwnedMixin, Base):
153
account_code: Mapped[str] = mapped_column(String(64), index=True)
154
target_note_id: Mapped[int] = mapped_column(ForeignKey("note_definitions.id", ondelete="RESTRICT"))
155
mapping_type: Mapped[str] = mapped_column(String(32))
156
+ status: Mapped[MappingStatus] = mapped_column(
157
+ Enum(MappingStatus, native_enum=False), default=MappingStatus.DRAFT
158
+ )
159
target_note: Mapped[NoteDefinition] = relationship()
160
161
@@ -160,7 +168,7 @@ class FinancialStatement(TimestampMixin, YearOwnedMixin, Base):
168
id: Mapped[int] = mapped_column(primary_key=True)
169
statement_type: Mapped[StatementType] = mapped_column(Enum(StatementType, native_enum=False))
170
version: Mapped[int] = mapped_column(Integer, default=1)
163
- lines: Mapped[list[StatementLine]] = relationship(
171
+ lines: Mapped[list["StatementLine"]] = relationship(
172
back_populates="statement", cascade="all, delete-orphan"
173
)
174
@@ -220,6 +228,19 @@ def enforce_audit_invariants(session: Session, _flush_context, _instances) -> No
228
if obj.status not in allowed[old]:
229
raise ValueError(f"Invalid fiscal-year transition: {old.value} -> {obj.status.value}")
230
231
+ if isinstance(obj, MappingRule):
232
+ history = inspect(obj).attrs.status.history
233
+ if history.deleted:
234
+ old = history.deleted[0]
235
+ allowed = {
236
+ MappingStatus.DRAFT: {MappingStatus.PROPOSED, MappingStatus.RETIRED},
237
+ MappingStatus.PROPOSED: {MappingStatus.ACTIVE, MappingStatus.DRAFT, MappingStatus.RETIRED},
238
+ MappingStatus.ACTIVE: {MappingStatus.RETIRED},
239
+ MappingStatus.RETIRED: set(),
240
+ }
241
+ if obj.status not in allowed[old]:
242
+ raise ValueError(f"Invalid mapping transition: {old.value} -> {obj.status.value}")
243
+
244
protected = (session.new | session.dirty | session.deleted)
245
for obj in protected:
246
if isinstance(obj, FiscalYear):