dodil/erp-brick-inventory
DODIL ERP brick: inventory
src/brick_inventory/domain/moves.py
"""What a move is: a quantity of one product (and lot) that went from one place to another at a moment. The ledger."""
from dataclasses import dataclass, field
from datetime import date
from decimal import Decimal
from typing import Optional
from brick_inventory.domain.values import NO_LOT, OURS, UNRESTRICTED
@dataclass
class MoveSpec:
"""One move to append. Quantities are in the product's BASE unit; the unit the document used is kept beside them."""
document_id: str
line_no: int
product_id: str
quantity_base: Decimal
from_location: str
to_location: str
moved_on: date
unit_code: str = ""
quantity: Optional[Decimal] = None
unit_numerator: int = 1
unit_denominator: int = 1
lot_code: str = NO_LOT
stock_type_from: str = UNRESTRICTED
stock_type_to: str = UNRESTRICTED
owner_from: str = OURS
owner_to: str = OURS
n: int = 1 # move_id = {document_id}:{line_no}:{n}
move_ref: str = ""
reason: str = ""
reverses_move_id: str = ""
value_in: Optional[Decimal] = None # what a move into our stock brings (a receipt's value, a return's cost)
value_out: Optional[Decimal] = None # what a move out of our stock is worth when it names the cost it reverses
purchase_value: Optional[Decimal] = None # standard cost: what purchasing paid, for the price difference
zero_value: bool = False # consignment stock is not ours: no value
allow_negative: bool = False # the migration's one exception
skip_claim: bool = False
releasing: bool = False # the release of a blocked lot: its stock may become unrestricted (INV-41)
extra: dict = field(default_factory=dict)
@property
def move_id(self) -> str:
return f"{self.document_id}:{self.line_no}:{self.n}"