feat: printer duplicate copies setting (Feature 1)
- Add `duplicates` column (0-9) to printers table via migration - Print loop repeats job 1+duplicates times per printer zone - PrinterForm in Settings > Print now has ΑΝΤΙΓΡΑΦΑ (0-9) field - PrinterRow shows amber badge when duplicates > 0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -406,6 +406,8 @@ def _run_migrations():
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
priority VARCHAR NOT NULL DEFAULT 'normal'
|
||||
)""",
|
||||
# Printer duplicate copies (0 = print once, 1 = print twice, etc.)
|
||||
"ALTER TABLE printers ADD COLUMN duplicates INTEGER NOT NULL DEFAULT 0",
|
||||
]
|
||||
for sql in migrations:
|
||||
try:
|
||||
|
||||
@@ -13,6 +13,7 @@ class Printer(Base):
|
||||
is_active = Column(Boolean, default=True, nullable=False)
|
||||
protocol = Column(String, default="escpos_tcp", nullable=False)
|
||||
line_width = Column(Integer, default=48, nullable=False)
|
||||
duplicates = Column(Integer, default=0, nullable=False)
|
||||
|
||||
products = relationship("Product", back_populates="printer_zone")
|
||||
print_logs = relationship("PrintLog", back_populates="printer")
|
||||
|
||||
@@ -12,6 +12,7 @@ class PrinterBase(BaseModel):
|
||||
is_active: bool = True
|
||||
protocol: str = "escpos_tcp"
|
||||
line_width: int = 48
|
||||
duplicates: int = 0
|
||||
|
||||
|
||||
class PrinterCreate(PrinterBase):
|
||||
@@ -25,6 +26,7 @@ class PrinterUpdate(BaseModel):
|
||||
is_active: Optional[bool] = None
|
||||
protocol: Optional[str] = None
|
||||
line_width: Optional[int] = None
|
||||
duplicates: Optional[int] = None
|
||||
|
||||
|
||||
class PrinterOut(PrinterBase):
|
||||
|
||||
@@ -1256,7 +1256,9 @@ def _do_route_and_print(order_id: int, item_ids: List[int], db: Session) -> List
|
||||
|
||||
success = False
|
||||
error_msg = None
|
||||
copies = 1 + max(0, printer.duplicates or 0)
|
||||
try:
|
||||
for _ in range(copies):
|
||||
p = _get_printer(printer.ip_address, printer.port)
|
||||
_print_kitchen_ticket(p, order, zone_items, db, printer.line_width)
|
||||
p.close()
|
||||
|
||||
@@ -637,7 +637,7 @@ function BeepSection({ beepEnabled, beepPattern, onChange, isPending, printers }
|
||||
// ── Printers section ───────────────────────────────────────────────────────
|
||||
|
||||
const PROTOCOLS = [{ value: 'escpos_tcp', label: 'ESC/POS TCP (standard)' }]
|
||||
const EMPTY_FORM = { name: '', ip_address: '', port: 9100, protocol: 'escpos_tcp', line_width: 48, is_active: true }
|
||||
const EMPTY_FORM = { name: '', ip_address: '', port: 9100, protocol: 'escpos_tcp', line_width: 48, is_active: true, duplicates: 0 }
|
||||
|
||||
function PrinterForm({ initial, onSave, onCancel, isPending }) {
|
||||
const [form, setForm] = useState(initial ?? EMPTY_FORM)
|
||||
@@ -674,6 +674,11 @@ function PrinterForm({ initial, onSave, onCancel, isPending }) {
|
||||
<input value={form.line_width} onChange={e => set('line_width', parseInt(e.target.value) || 48)}
|
||||
type="number" min={20} max={80} style={inputStyle} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, flex: '0 0 90px' }}>
|
||||
<label style={{ fontSize: 11, fontWeight: 600, color: '#6b7280' }}>ΑΝΤΙΓΡΑΦΑ</label>
|
||||
<input value={form.duplicates ?? 0} onChange={e => set('duplicates', Math.max(0, Math.min(9, parseInt(e.target.value) || 0)))}
|
||||
type="number" min={0} max={9} style={inputStyle} title="0 = μία εκτύπωση, 1 = δύο κ.ο.κ." />
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8, alignItems: 'center', paddingBottom: 2 }}>
|
||||
<button onClick={() => onSave(form)} disabled={isPending || !form.name.trim() || !form.ip_address.trim()}
|
||||
style={btnPrimary}>Αποθήκευση</button>
|
||||
@@ -739,6 +744,11 @@ function PrinterRow({ printer, onEdit, onDelete, onTest, onToggle, testPending }
|
||||
</span>
|
||||
<span style={{ fontSize: 11, color: '#9ca3af', marginLeft: 6 }}>— {printer.protocol}</span>
|
||||
<span style={{ fontSize: 11, color: '#9ca3af', marginLeft: 6 }}>— {printer.line_width ?? 48} χαρ.</span>
|
||||
{(printer.duplicates ?? 0) > 0 && (
|
||||
<span style={{ fontSize: 11, color: '#f59e0b', fontWeight: 700, marginLeft: 6 }}>
|
||||
— x{(printer.duplicates ?? 0) + 1} αντ.
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<span style={{
|
||||
|
||||
Reference in New Issue
Block a user