handle data without due date
This commit is contained in:
parent
ec60d1ffcd
commit
172cc678d3
1 changed files with 10 additions and 4 deletions
14
app.py
14
app.py
|
|
@ -27,7 +27,7 @@ class PrintRequest(BaseModel):
|
|||
# grocy payload:
|
||||
grocycode: str = Field(..., description="Raw GrocyCode")
|
||||
product: str = Field(..., description="Product name")
|
||||
due_date: str = Field(None, description="Due date from stock entry")
|
||||
due_date: Optional[str] = Field(None, description="Due date from stock entry")
|
||||
|
||||
class Config:
|
||||
# ignore any other fields Grocy might send
|
||||
|
|
@ -35,7 +35,9 @@ class PrintRequest(BaseModel):
|
|||
|
||||
|
||||
@lru_cache(maxsize=256)
|
||||
def make_code128(grocycode: str, product_name: str, due_date: Optional[str]) -> Image.Image:
|
||||
def make_code128(
|
||||
grocycode: str, product_name: str, due_date: Optional[str]
|
||||
) -> Image.Image:
|
||||
# 1) Instantiate the barcode object (checksum auto-added for Code128)
|
||||
code = Code128(grocycode, writer=ImageWriter())
|
||||
|
||||
|
|
@ -49,7 +51,9 @@ def make_code128(grocycode: str, product_name: str, due_date: Optional[str]) ->
|
|||
"text_distance": 5.0, # gap between bars and text
|
||||
# you can also pass 'format': 'PNG' here if needed
|
||||
},
|
||||
text=" | ".join([product_name, due_date]), # explicitly draw your data string under the bars
|
||||
text=(
|
||||
" | ".join([product_name, due_date]) if due_date else product_name
|
||||
), # explicitly draw your data string under the bars
|
||||
)
|
||||
|
||||
# 3) Convert to 1-bit for your Brother QL workflow
|
||||
|
|
@ -128,7 +132,9 @@ async def print_from_grocy(req: PrintRequest):
|
|||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
code_img, dm_img = await asyncio.gather(
|
||||
loop.run_in_executor(None, make_code128, req.grocycode, req.product, req.due_date),
|
||||
loop.run_in_executor(
|
||||
None, make_code128, req.grocycode, req.product, req.due_date
|
||||
),
|
||||
loop.run_in_executor(None, make_datamatrix, req.grocycode),
|
||||
)
|
||||
label_img = compose_label([code_img, dm_img])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue