feat: add produces_eggs flag for animal, group assets

even if the farmOS instance does not have `farm_eggs` module
installed, we should support the schema
This commit is contained in:
Lance Edgar 2026-02-18 18:56:40 -06:00
parent 2e0ec73317
commit 26a4746898
9 changed files with 85 additions and 4 deletions

View file

@ -0,0 +1,52 @@
"""add produces_eggs via EggMixin
Revision ID: 82a03f4ef1a4
Revises: 11e0e46f48a6
Create Date: 2026-02-18 18:45:36.015144
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import wuttjamaican.db.util
# revision identifiers, used by Alembic.
revision: str = "82a03f4ef1a4"
down_revision: Union[str, None] = "11e0e46f48a6"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# asset_animal
op.add_column(
"asset_animal", sa.Column("produces_eggs", sa.Boolean(), nullable=True)
)
op.add_column(
"asset_animal_version",
sa.Column("produces_eggs", sa.Boolean(), autoincrement=False, nullable=True),
)
# asset_group
op.add_column(
"asset_group", sa.Column("produces_eggs", sa.Boolean(), nullable=True)
)
op.add_column(
"asset_group_version",
sa.Column("produces_eggs", sa.Boolean(), autoincrement=False, nullable=True),
)
def downgrade() -> None:
# asset_group
op.drop_column("asset_group_version", "produces_eggs")
op.drop_column("asset_group", "produces_eggs")
# asset_animal
op.drop_column("asset_animal_version", "produces_eggs")
op.drop_column("asset_animal", "produces_eggs")

View file

@ -215,6 +215,18 @@ def add_asset_proxies(subclass):
Asset.make_proxy(subclass, "asset", "archived")
class EggMixin:
produces_eggs = sa.Column(
sa.Boolean(),
nullable=True,
doc="""
Whether the group asset produces eggs (i.e. it should be
available in the egg harvest form).
""",
)
class AssetParent(model.Base):
"""
Represents an "asset's parent relationship" from farmOS.

View file

@ -28,7 +28,7 @@ from sqlalchemy import orm
from wuttjamaican.db import model
from wuttafarm.db.model.asset import AssetMixin, add_asset_proxies
from wuttafarm.db.model.asset import AssetMixin, add_asset_proxies, EggMixin
class AnimalType(model.Base):
@ -84,7 +84,7 @@ class AnimalType(model.Base):
return self.name or ""
class AnimalAsset(AssetMixin, model.Base):
class AnimalAsset(AssetMixin, EggMixin, model.Base):
"""
Represents an animal asset from farmOS
"""

View file

@ -25,10 +25,10 @@ Model definition for Groups
from wuttjamaican.db import model
from wuttafarm.db.model.asset import AssetMixin, add_asset_proxies
from wuttafarm.db.model.asset import AssetMixin, add_asset_proxies, EggMixin
class GroupAsset(AssetMixin, model.Base):
class GroupAsset(AssetMixin, EggMixin, model.Base):
"""
Represents a group asset from farmOS
"""

View file

@ -125,6 +125,7 @@ class ToFarmOSAsset(ToFarmOS):
"asset_name": asset["attributes"]["name"],
"is_location": asset["attributes"]["is_location"],
"is_fixed": asset["attributes"]["is_fixed"],
"produces_eggs": asset["attributes"].get("produces_eggs"),
"notes": notes,
"archived": asset["attributes"]["archived"],
}
@ -138,6 +139,8 @@ class ToFarmOSAsset(ToFarmOS):
attrs["is_location"] = source_data["is_location"]
if "is_fixed" in self.fields:
attrs["is_fixed"] = source_data["is_fixed"]
if "produces_eggs" in self.fields:
attrs["produces_eggs"] = source_data["produces_eggs"]
if "notes" in self.fields:
attrs["notes"] = {"value": source_data["notes"]}
if "archived" in self.fields:
@ -159,6 +162,7 @@ class AnimalAssetImporter(ToFarmOSAsset):
"animal_type_uuid",
"sex",
"is_sterile",
"produces_eggs",
"birthdate",
"notes",
"archived",
@ -286,6 +290,7 @@ class GroupAssetImporter(ToFarmOSAsset):
supported_fields = [
"uuid",
"asset_name",
"produces_eggs",
"notes",
"archived",
]

View file

@ -140,6 +140,7 @@ class AnimalAssetImporter(FromWuttaFarm, farmos_importing.model.AnimalAssetImpor
"animal_type_uuid",
"sex",
"is_sterile",
"produces_eggs",
"birthdate",
"notes",
"archived",
@ -152,6 +153,7 @@ class AnimalAssetImporter(FromWuttaFarm, farmos_importing.model.AnimalAssetImpor
"animal_type_uuid": animal.animal_type.farmos_uuid,
"sex": animal.sex,
"is_sterile": animal.is_sterile,
"produces_eggs": animal.produces_eggs,
"birthdate": animal.birthdate,
"notes": animal.notes,
"archived": animal.archived,
@ -191,6 +193,7 @@ class GroupAssetImporter(FromWuttaFarm, farmos_importing.model.GroupAssetImporte
supported_fields = [
"uuid",
"asset_name",
"produces_eggs",
"notes",
"archived",
]
@ -199,6 +202,7 @@ class GroupAssetImporter(FromWuttaFarm, farmos_importing.model.GroupAssetImporte
return {
"uuid": group.farmos_uuid or self.app.make_true_uuid(),
"asset_name": group.asset_name,
"produces_eggs": group.produces_eggs,
"notes": group.notes,
"archived": group.archived,
"_src_object": group,

View file

@ -312,6 +312,7 @@ class AnimalAssetImporter(AssetImporterBase):
"animal_type_uuid",
"sex",
"is_sterile",
"produces_eggs",
"birthdate",
"notes",
"archived",
@ -371,6 +372,7 @@ class AnimalAssetImporter(AssetImporterBase):
"animal_type_uuid": animal_type_uuid,
"sex": animal["attributes"]["sex"],
"is_sterile": sterile,
"produces_eggs": animal["attributes"]["produces_eggs"],
"birthdate": birthdate,
}
)
@ -449,6 +451,7 @@ class GroupAssetImporter(AssetImporterBase):
"asset_name",
"is_location",
"is_fixed",
"produces_eggs",
"notes",
"archived",
"image_url",
@ -467,6 +470,7 @@ class GroupAssetImporter(AssetImporterBase):
data.update(
{
"asset_type": "group",
"produces_eggs": group["attributes"]["produces_eggs"],
}
)
return data

View file

@ -157,6 +157,7 @@ class AnimalAssetView(AssetMasterView):
"birthdate",
"is_sterile",
"sex",
"produces_eggs",
"archived",
]
@ -166,6 +167,7 @@ class AnimalAssetView(AssetMasterView):
"birthdate",
"sex",
"is_sterile",
"produces_eggs",
"notes",
"asset_type",
"archived",

View file

@ -42,6 +42,7 @@ class GroupView(AssetMasterView):
"thumbnail",
"drupal_id",
"asset_name",
"produces_eggs",
"archived",
]
@ -49,6 +50,7 @@ class GroupView(AssetMasterView):
"asset_name",
"notes",
"asset_type",
"produces_eggs",
"archived",
"farmos_uuid",
"drupal_id",