Coverage for opt/mealie/lib/python3.12/site-packages/mealie/repos/repository_meal_plan_rules.py: 88%

13 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-25 15:48 +0000

1from sqlalchemy import or_, select 1o

2 

3from mealie.db.models.household.mealplan import GroupMealPlanRules 1o

4from mealie.schema.meal_plan.plan_rules import PlanRulesDay, PlanRulesOut, PlanRulesType 1o

5 

6from .repository_generic import HouseholdRepositoryGeneric 1o

7 

8 

9class RepositoryMealPlanRules(HouseholdRepositoryGeneric[PlanRulesOut, GroupMealPlanRules]): 1o

10 def get_rules(self, day: PlanRulesDay, entry_type: PlanRulesType) -> list[PlanRulesOut]: 1o

11 stmt = select(GroupMealPlanRules).filter( 1abcdefghijklmn

12 or_( 

13 GroupMealPlanRules.day == day, 

14 GroupMealPlanRules.day.is_(None), 

15 GroupMealPlanRules.day == PlanRulesDay.unset.value, 

16 ), 

17 or_( 

18 GroupMealPlanRules.entry_type == entry_type, 

19 GroupMealPlanRules.entry_type.is_(None), 

20 GroupMealPlanRules.entry_type == PlanRulesType.unset.value, 

21 ), 

22 ) 

23 

24 if self.group_id: 24 ↛ 26line 24 didn't jump to line 26 because the condition on line 24 was always true1abcdefghijklmn

25 stmt = stmt.filter(GroupMealPlanRules.group_id == self.group_id) 1abcdefghijklmn

26 if self.household_id: 26 ↛ 29line 26 didn't jump to line 29 because the condition on line 26 was always true1abcdefghijklmn

27 stmt = stmt.filter(GroupMealPlanRules.household_id == self.household_id) 1abcdefghijklmn

28 

29 rules = self.session.execute(stmt).scalars().all() 1abcdefghijklmn

30 

31 return [self.schema.model_validate(x) for x in rules] 1abcdefghijklmn