rechu.models package¶
Submodules¶
rechu.models.base module¶
Base model for receipt cataloging.
rechu.models.product module¶
Models for product metadata.
- final class rechu.models.product.DiscountMatch(**kwargs)[source]¶
-
Discount label model for a product matching string.
- id: MappedColumn[int]¶
- is_pattern: MappedColumn[bool]¶
- label: MappedColumn[str]¶
- product: Relationship[Product]¶
- product_id: MappedColumn[int]¶
- class rechu.models.product.Indicator(*values)[source]¶
-
Price matcher indicators that are not dates or units.
- MAXIMUM = 'maximum'¶
- MINIMUM = 'minimum'¶
- final class rechu.models.product.LabelMatch(**kwargs)[source]¶
-
Label model for a product matching string.
- id: MappedColumn[int]¶
- is_pattern: MappedColumn[bool]¶
- name: MappedColumn[str]¶
- product: Relationship[Product]¶
- product_id: MappedColumn[int]¶
- final class rechu.models.product.PriceMatch(**kwargs)[source]¶
-
Price model for a product matching value, which may be part of a value range or time interval.
- id: MappedColumn[int]¶
- indicator: MappedColumn[str | None]¶
- product: Relationship[Product]¶
- product_id: MappedColumn[int]¶
- value: MappedColumn[Price]¶
- final class rechu.models.product.Product(**kwargs)[source]¶
Bases:
BaseProduct model for metadata.
- alcohol: MappedColumn[str | None]¶
- brand: MappedColumn[str | None]¶
- category: MappedColumn[str | None]¶
- check_merge(other: Product) None[source]¶
Check if the other product is compatible with merging into this product.
- clear() None[source]¶
Remove all matchers, properties, identifiers and range products, but not the generic product or its properties that we inherit now.
- description: MappedColumn[str | None]¶
- discounts: Relationship[list[DiscountMatch]]¶
- generic: Relationship[Product | None]¶
- generic_id: MappedColumn[int | None]¶
- gtin: MappedColumn[GTIN | None]¶
- property has_patterns: bool¶
Determine whether any of the label or discount matchers have regular expressions to match receipt product and discount labels against, rather than plain strings.
- id: MappedColumn[int]¶
- labels: Relationship[list[LabelMatch]]¶
- merge(other: Product, replace: bool = True) bool[source]¶
Merge attributes of the other product into this one.
This replaces values and the primary key in this product, except for the shop identifier (which must be the same) and the matchers (where unique matchers from the other product are added).
This is similar to a session merge except no database changes are done and the matchers are more deeply merged.
If replace is disabled, then simple property fields that already have a value are not changed. Matchers are always updated.
Returns whether the product has changed, with new matchers or different values.
- portions: MappedColumn[int | None]¶
- prices: Relationship[list[PriceMatch]]¶
- range: Relationship[list[Product]]¶
- replace(new: Product) bool[source]¶
Replace all matchers, properties, identifiers and range products with those defined in the new product, or with the generic product’s inherited properties; the original generic product is kept.
Returns whether the new product is not empty.
- shop: MappedColumn[str]¶
- shop_meta: Relationship[Shop]¶
- sku: MappedColumn[str | None]¶
- type: MappedColumn[str | None]¶
- volume: MappedColumn[Quantity | None]¶
- weight: MappedColumn[Quantity | None]¶
rechu.models.receipt module¶
Models for receipt data.
- final class rechu.models.receipt.Discount(**kwargs)[source]¶
Bases:
BaseDiscount model for a discount action mentioned on a receipt.
- id: MappedColumn[int]¶
- items: Relationship[list[ProductItem]]¶
- label: MappedColumn[str]¶
- position: MappedColumn[int]¶
- price_decrease: MappedColumn[Price]¶
- receipt: Relationship[Receipt]¶
- receipt_key: MappedColumn[str]¶
- final class rechu.models.receipt.DiscountItems(**kwargs)[source]¶
Bases:
BaseAssociation table for products involved in discounts.
- discount_id: MappedColumn[int]¶
- product_id: MappedColumn[int]¶
- final class rechu.models.receipt.ProductItem(**kwargs)[source]¶
Bases:
BaseProduct model for a product item mentioned on a receipt.
- amount: MappedColumn[float]¶
- discount_indicator: MappedColumn[str | None]¶
- property discount_indicators: list[str]¶
Retrieve a list of discrete portions of the discount indicator.
- discounts: Relationship[list[Discount]]¶
- id: MappedColumn[int]¶
- label: MappedColumn[str]¶
- position: MappedColumn[int]¶
- price: MappedColumn[Price]¶
- product: Relationship[Product | None]¶
- product_id: MappedColumn[int | None]¶
- quantity: MappedColumn[Quantity]¶
- receipt: Relationship[Receipt]¶
- receipt_key: MappedColumn[str]¶
- unit: MappedColumn[Unit | None]¶
- final class rechu.models.receipt.Receipt(**kwargs)[source]¶
Bases:
BaseReceipt model for a receipt from a certain date at a shop with products and possibly discounts.
- date: MappedColumn[date]¶
- discounts: Relationship[list[Discount]]¶
- filename: MappedColumn[str]¶
- products: Relationship[list[ProductItem]]¶
- shop: MappedColumn[str]¶
- shop_meta: Relationship[Shop]¶
- updated: MappedColumn[datetime]¶
rechu.models.shop module¶
Models for shop metadata.
- final class rechu.models.shop.DiscountIndicator(**kwargs)[source]¶
Bases:
BaseIndicator model for a substring or regular expression that matches a receipt item’s discount indicator.
- id: MappedColumn[int]¶
- pattern: MappedColumn[str]¶
- shop: Relationship[Shop]¶
- shop_id: MappedColumn[int]¶
- final class rechu.models.shop.Shop(**kwargs)[source]¶
Bases:
BaseShop metadata model.
- discount_indicators: Relationship[list[DiscountIndicator]]¶
- key: MappedColumn[str]¶
- merge(other: Shop, replace: bool = True) bool[source]¶
Merge attributes of the other shop into this one.
This replaces values in this shop, except for the key which must be the same in order for .
This is similar to a session merge except no database changes are done.
If replace is disabled, then simple property fields that already have a value are not changed.
Returns whether the shop has changed with different values.
- name: MappedColumn[str | None]¶
- products: MappedColumn[str | None]¶
- website: MappedColumn[str | None]¶
- wikidata: MappedColumn[str | None]¶
Module contents¶
Models for receipt cataloging.
- class rechu.models.Base(**kwargs: Any)[source]¶
Bases:
DeclarativeBaseBase ORM model class for receipt models.
- class rechu.models.Product(**kwargs)[source]¶
Bases:
BaseProduct model for metadata.
- alcohol: MappedColumn[str | None]¶
- brand: MappedColumn[str | None]¶
- category: MappedColumn[str | None]¶
- check_merge(other: Product) None[source]¶
Check if the other product is compatible with merging into this product.
- clear() None[source]¶
Remove all matchers, properties, identifiers and range products, but not the generic product or its properties that we inherit now.
- description: MappedColumn[str | None]¶
- discounts: Relationship[list[DiscountMatch]]¶
- generic: Relationship[Product | None]¶
- generic_id: MappedColumn[int | None]¶
- gtin: MappedColumn[GTIN | None]¶
- property has_patterns: bool¶
Determine whether any of the label or discount matchers have regular expressions to match receipt product and discount labels against, rather than plain strings.
- id: MappedColumn[int]¶
- labels: Relationship[list[LabelMatch]]¶
- merge(other: Product, replace: bool = True) bool[source]¶
Merge attributes of the other product into this one.
This replaces values and the primary key in this product, except for the shop identifier (which must be the same) and the matchers (where unique matchers from the other product are added).
This is similar to a session merge except no database changes are done and the matchers are more deeply merged.
If replace is disabled, then simple property fields that already have a value are not changed. Matchers are always updated.
Returns whether the product has changed, with new matchers or different values.
- portions: MappedColumn[int | None]¶
- prices: Relationship[list[PriceMatch]]¶
- range: Relationship[list[Product]]¶
- replace(new: Product) bool[source]¶
Replace all matchers, properties, identifiers and range products with those defined in the new product, or with the generic product’s inherited properties; the original generic product is kept.
Returns whether the new product is not empty.
- shop: MappedColumn[str]¶
- shop_meta: Relationship[Shop]¶
- sku: MappedColumn[str | None]¶
- type: MappedColumn[str | None]¶
- volume: MappedColumn[Quantity | None]¶
- weight: MappedColumn[Quantity | None]¶
- class rechu.models.Receipt(**kwargs)[source]¶
Bases:
BaseReceipt model for a receipt from a certain date at a shop with products and possibly discounts.
- date: MappedColumn[date]¶
- discounts: Relationship[list[Discount]]¶
- filename: MappedColumn[str]¶
- products: Relationship[list[ProductItem]]¶
- shop: MappedColumn[str]¶
- shop_meta: Relationship[Shop]¶
- updated: MappedColumn[datetime]¶
- class rechu.models.Shop(**kwargs)[source]¶
Bases:
BaseShop metadata model.
- discount_indicators: Relationship[list[DiscountIndicator]]¶
- key: MappedColumn[str]¶
- merge(other: Shop, replace: bool = True) bool[source]¶
Merge attributes of the other shop into this one.
This replaces values in this shop, except for the key which must be the same in order for .
This is similar to a session merge except no database changes are done.
If replace is disabled, then simple property fields that already have a value are not changed.
Returns whether the shop has changed with different values.
- name: MappedColumn[str | None]¶
- products: MappedColumn[str | None]¶
- website: MappedColumn[str | None]¶
- wikidata: MappedColumn[str | None]¶