Added pricing field for single spool

This commit is contained in:
pdsccode
2023-12-30 07:29:27 +01:00
parent cf4add2753
commit 1eb78f01df
10 changed files with 55 additions and 1 deletions

View File

@@ -134,6 +134,7 @@
"id": "ID",
"filament_name": "Filament",
"filament": "Filament",
"price": "Price",
"material": "Material",
"weight_to_use": "Weight",
"used_weight": "Used Weight",
@@ -150,6 +151,7 @@
"archived": "Archived"
},
"fields_help": {
"price": "Price of a full spool in the system configured currency.",
"weight_to_use": "Select what weight value to enter. Measured weight is only available if the spool weight is set for the selected filament.",
"used_weight": "How much filament has been used from the spool. A new spool should have 0g used.",
"remaining_weight": "How much filament is left on the spool. For a new spool this should match the spool weight.",

View File

@@ -201,7 +201,20 @@ export const SpoolCreate: React.FC<IResourceComponentsProps & CreateOrCloneProps
}}
/>
</Form.Item>
<Form.Item
label={t("filament.fields.price")}
help={t("filament.fields_help.price")}
name={["price"]}
rules={[
{
required: false,
type: "number",
min: 0,
},
]}
>
<InputNumber precision={2} formatter={numberFormatter} parser={numberParser} />
</Form.Item>
<Form.Item hidden={true} name={["used_weight"]} initialValue={0}>
<InputNumber value={usedWeight} />
</Form.Item>

View File

@@ -181,6 +181,20 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
}}
/>
</Form.Item>
<Form.Item
label={t("spool.fields.price")}
help={t("spool.fields_help.price")}
name={["price"]}
rules={[
{
required: false,
type: "number",
min: 0,
},
]}
>
<InputNumber precision={2} formatter={numberFormatter} parser={numberParser} />
</Form.Item>
<Form.Item hidden={true} name={["used_weight"]} initialValue={0}>
<InputNumber value={usedWeight} />
</Form.Item>

View File

@@ -73,6 +73,7 @@ const allColumns: (keyof ISpoolCollapsed & string)[] = [
"id",
"combined_name",
"filament.material",
"price",
"used_weight",
"remaining_weight",
"used_length",
@@ -312,6 +313,14 @@ export const SpoolList: React.FC<IResourceComponentsProps> = () => {
filterValueQuery: useSpoolmanMaterials(),
width: 120,
}),
SortedColumn({
id: "price",
i18ncat: "spool",
actions,
dataSource,
tableState,
width: 80,
}),
NumberColumn({
id: "used_weight",
i18ncat: "spool",

View File

@@ -6,6 +6,7 @@ export interface ISpool {
first_used?: string;
last_used?: string;
filament: IFilament;
price?: number;
remaining_weight?: number;
used_weight: number;
remaining_length?: number;

View File

@@ -58,6 +58,8 @@ export const SpoolShow: React.FC<IResourceComponentsProps> = () => {
<NumberField value={record?.id ?? ""} />
<Title level={5}>{t("spool.fields.filament")}</Title>
<TextField value={record ? filamentURL(record?.filament) : ""} />
<Title level={5}>{t("spool.fields.price")}</Title>
<NumberField value={record?.price ?? ""} />
<Title level={5}>{t("spool.fields.registered")}</Title>
<DateField
value={dayjs.utc(record?.registered).local()}

View File

@@ -133,6 +133,11 @@ class Spool(BaseModel):
first_used: Optional[datetime] = Field(description="First logged occurence of spool usage. UTC Timezone.")
last_used: Optional[datetime] = Field(description="Last logged occurence of spool usage. UTC Timezone.")
filament: Filament = Field(description="The filament type of this spool.")
price: Optional[float] = Field(
ge=0,
description="The price of this spool in the system configured currency.",
example=20.0,
)
remaining_weight: Optional[float] = Field(
default=None,
ge=0,

View File

@@ -34,6 +34,11 @@ class SpoolParameters(BaseModel):
first_used: Optional[datetime] = Field(description="First logged occurence of spool usage.")
last_used: Optional[datetime] = Field(description="Last logged occurence of spool usage.")
filament_id: int = Field(description="The ID of the filament type of this spool.")
price: Optional[float] = Field(
ge=0,
description="The price of this filament in the system configured currency.",
example=20.0,
)
remaining_weight: Optional[float] = Field(
ge=0,
description=(
@@ -336,6 +341,7 @@ async def create( # noqa: ANN201
db_item = await spool.create(
db=db,
filament_id=body.filament_id,
price=body.price,
remaining_weight=body.remaining_weight,
used_weight=body.used_weight,
first_used=body.first_used,

View File

@@ -50,6 +50,7 @@ class Spool(Base):
registered: Mapped[datetime] = mapped_column()
first_used: Mapped[Optional[datetime]] = mapped_column()
last_used: Mapped[Optional[datetime]] = mapped_column()
price: Mapped[Optional[float]] = mapped_column()
filament_id: Mapped[int] = mapped_column(ForeignKey("filament.id"))
filament: Mapped["Filament"] = relationship(back_populates="spools")
used_weight: Mapped[float] = mapped_column()

View File

@@ -38,6 +38,7 @@ async def create(
used_weight: Optional[float] = None,
first_used: Optional[datetime] = None,
last_used: Optional[datetime] = None,
price: Optional[float] = None,
location: Optional[str] = None,
lot_nr: Optional[str] = None,
comment: Optional[str] = None,