# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

### Changed

### Deprecated

### Removed

### Fixed

### Security


## [4.3] - 2026-05-12

### Fixed
- Migration `185_MAIN.py` now patches `taxdocument.customer_record_id` via `PRAGMA writable_schema` instead of `migrator.drop_not_null`. The default helper rebuilds the table (`DROP`/`CREATE`/`INSERT`/`RENAME`), which fails with "attempt to write a readonly database" on plants running the PyInstaller-built dispatch.exe on Windows. The new in-place schema patch is a single small write.


## [4.2] - 2026-05-12

### Changed
- `TaxDocument.customer_record` is now optional — Czech VAT rules don't require an identified customer on receipts below the small-amount threshold. The create form, `/add/TaxDocument` endpoint, the post-expedition Flow A and the atxd300 legacy importer all accept a missing customer; the printout hides the customer block when none is set. Migration `185_MAIN.py` drops `NOT NULL` from the column. The single-customer-per-document constraint still holds: a doc without a customer can only group orders that also have no customer.
- Migration `182_MAIN.py` (the 4.0 invoice → tax document backfill) now creates the `customer_record_id` column nullable from the start and no longer skips legacy orders that have an `invoice_number` but no customer — those orphans become TaxDocuments with `customer_record=NULL` instead of being silently dropped. Plants upgrading from ≤3.26 will preserve their orphan invoices automatically. Plants already on 4.0 had their orphan `invoice_number` data dropped at the time of the original 182 run and need to recover from a pre-migration backup if those records are wanted back.
- State migration from `/atx300/state/dispatch.json` is now strictly one-way: after the JSON contents are imported into the `State` table, the file is renamed to `dispatch.json.bak`. File presence is the sole signal that migration is still pending, replacing the previous "State row already exists" check.


## [4.1] - 2026-05-12 [YANKED]

**Yanked:** ships the broken migration `182_MAIN.py` introduced in 4.0 — see the 4.0 yank note.

### Changed
- The expedition form's tax-document checkbox is now checked by default and the Czech caption is clarified to "Vystavit daňový doklad" — almost every dispatched order produces a tax document, so users no longer have to tick the box for each one.


## [4.0] - 2026-05-12 [YANKED]

**Yanked:** the `invoice → TaxDocument` backfill in migration `182_MAIN.py` silently drops legacy orders that have an `invoice_number` but no `customer_record_id`, because the new `taxdocument.customer_record_id` column is created `NOT NULL`. After the migration completes, `order.invoice_number` is dropped and the data is unrecoverable without a pre-migration backup. Plants that have already upgraded need a one-off recovery script run against their backup; plants still on ≤3.26 should skip 4.0/4.1 and upgrade directly to a later release where migration 182 creates the column nullable from the start and preserves orphan invoices.

### Added
- New `State` singleton table (DB migration `184_MAIN.py`) holding the auto-number counters (`order_num_counter`, `taxdocument_num_counter`, `pumporder_num_counter`) and the "last value typed by the user" form defaults (`temperature_air_by_user`, `temperature_concrete_by_user`, `weather_by_user`, `without_water_by_user`). On first startup after upgrade, any existing `/atx300/state/dispatch.json` is read once and its contents (including the legacy `invoice_num_counter` → `taxdocument_num_counter` rename) are imported into the new table; the leftover JSON file is then ignored.

### Changed
- Counter increments for Order, TaxDocument and PumpOrder now share a transaction with the rows they number, eliminating the race where the JSON state file and the DB could disagree if one half of the write failed.

### Removed
- **Irreversible:** `/atx300/state/dispatch.json` is no longer read or written at runtime — all values now live in the new `State` table. The file may be deleted after the first upgraded startup has completed. Downgrading after upgrade will lose any counter increments made under 4.0.


## [3.26] - 2026-05-11

### Added
- Tax documents (daňové doklady) are now first-class records: a new `TaxDocument` table covers one or more orders with a single payment type, VAT rate, currency, and issue/VAT date. The expedition form gained a "Vystavit doklad" checkbox; the payment type selectbox is shown only when ticked. The previous `Order.invoice_number` / `Order.payment_type` fields are migrated into the new table.

### Changed
- Expedition page: the "recently produced orders" list now auto-refreshes every 10 seconds, like other listings.
- Internal naming: the "invoice" terminology has been retired everywhere except the `PaymentType.INVOICE` enum value (which is still a payment type). UI labels in English/German/Slovak now say "Tax document" instead of "Invoice"/"VAT invoice"/"Rechnung"/"faktura"; the Czech text was already "Daňový doklad" and is unchanged. The print URL changed from `/print/invoice/<id>` to `/print/taxdocument/<id>`. The Setup template field was renamed from `invoice_fn` to `taxdocument_fn`, and the default template file from `invoice.html` to `taxdocument.html` (DB migration `183_MAIN.py`).
- Production overview printout: when a tax document's payment type is "Invoice" (external invoicing system), our internal tax-document number is hidden — preserving the prior `invoice_number`-hiding behaviour now that the number lives on `TaxDocument`.

### Removed
- `Order.invoice_number` and `Order.payment_type` (moved to `TaxDocument`). Existing data is migrated automatically.

### Fixed
- Auto-refresh in `viewOnly` listings (e.g. the expeditions "recently produced" list) no longer triggers a 1 Hz redraw of the surrounding page, which was firing the test-synchronisation signal every second and causing intermittent frontend test failures. The visible 10-second data reload is unchanged.


## [3.25] - 2026-05-05

### Added
- New "Export recipes" page under the Misc menu, with a "decimal comma" checkbox so the user can pick whether numeric values use a comma or a period in the exported CSV/TSV.

### Changed
- Recipe listing no longer has the inline CSV/TSV export button; use Misc → Export recipes instead.

### Fixed
- Recipe CSV/TSV export now honours the "decimal comma" preference instead of always emitting raw float values with a period.


## [3.24] - 2026-05-05

### Added
- Setup form: each numeric-series counter shows the highest value already used in the database, so the user can avoid setting a sequence below already-issued numbers.
- Contract listing: a column showing the volume produced so far for each contract.

### Changed
- Order copy count is no longer stored on the order itself; it is taken from Setup at print time. Pump orders have their own separate copy count setting in Setup.

### Fixed
- Invoice printout: surcharges of type "% of concrete price" no longer cause column misalignment and missing VAT/total cells.
- Invoice, `delivery_sheet_bezedos`, and `production_overview` printouts now render currency values with exactly the configured number of decimals (`currency_rounding_precision`).
- Setup form: order/invoice/pump-order numeric series counters can no longer be corrupted. Editing a counter no longer reverts on focus-out. Counters the user did not touch are left alone on save, so editing other fields no longer rewinds a counter that production bumped in the meantime. If the user edits a counter and it has drifted since the form was opened, the save is refused.
- atxd300 importer: customer names from `nazev` and `nazev2` are now joined into a single name (instead of stashing `nazev2` in the comment field), and imported recipe prices are stored in `PricelistRecipe` so the application actually uses them.


## [3.23] - 2026-04-24

### Added
- Recipe edit form shows warning infoboxes when `mixing_duration`, `mixer_semi_opening_duration`, or `mixer_opening_duration` is not filled in (does not block saving).
- Containerfile and Justfile targets (`image-build`, `image-push`, `image-run`) for building and running the application as a dual-arch (amd64+arm64) OCI image.

### Security
- Bumped `lxml` from 6.0.4 to 6.1.0 to address CVE-2026-41066.


## [3.22] - 2026-04-15

### Fixed
- Use write-then-rename (atomic) pattern for all file writes to prevent readers from seeing partially-written files.

## [3.21] - 2026-04-14

### Added
- Continuous mode: vehicle and driver fields are now visible (optional) in the Expeditions form. If selected, they apply to the first delivery only.
- New `distance_rounding_precision` config setting for controlling decimal places on distance in km (default 0).
- Option to display dosed material weights in tonnes instead of kilograms in consumption, stock, and production printouts and exports (checkbox in the report form).

### Changed
- Changed default rounding precision for tonnes to 2.
- Move value/currency formatting from frontend to backend.
- Only allow .ord files to create/update order and recipe in standby mode.

### Fixed
- Fix distance override showing 0 and not accepting zero value.

## [3.20] - 2026-04-10

### Changed
- Tabular printout: don't title-ize translated headers.
- Decimal comma handling for Metrostav exports (work in progress).

### Fixed
- Display names instead of IDs in production printout filter headers.

## [3.19] - 2026-04-08

### Fixed
- Fixed UNIQUE constraint error on construction site name when processing .ord files with the same site name but different site numbers (e.g. "Olomouc" used for multiple ConstructionSiteNumber values). Duplicate names are now disambiguated with the site number suffix.

## [3.18] - 2026-04-07

### Added
- Changelog is now included in the atxpkg package.

## [3.17] - 2026-04-05

### Added
- New `tonnes_rounding_precision` config setting for controlling decimal places on delivery sheet total tonnes (default 3).
- New `volume_rounding_precision` config setting for controlling decimal places on volume in m³ (default 2).
- Show last paired driver in vehicle listing and last paired vehicle in driver listing (mj195).
- Decimal comma toggle for CSV/TSV export.

### Changed
- Renamed `rounding_precision` config setting to `currency_rounding_precision` for clarity. Old name is still supported for backward compatibility.

### Fixed
- Fix vehicle-driver pairings not being saved for new pairs (broken since 3.15), causing driver/pump auto-fill to not work for first-time pairings.
- Fix 0 tonnes on delivery sheets caused by print event firing before DB transaction commits.
- Hide continuous mode auto-print setting on batch plants.

## [3.16] - 2026-04-01

### Fixed
 - Added missing migration

## [3.15] - 2026-04-01

### Added
- Add configurable invoice template.
- Add form to modify car-driver cache.
- Show vehicle volume in select box.
- Add sub-headers to setup form.

### Changed
- Reorder vehicle form fields to be consistent with column order in listing.

### Fixed
- Add missing LockedTable caption translation.

### Security

## [3.14] - 2026-03-30

### Added
- Add recipe pricelists with price matrix UI, replacing single per-recipe price.
- Add per-user can_produce permission.

### Changed
- Show x2/x3/x4 repeated print buttons only on delivery sheets and invoices.
- Filter pump order selectbox to active orders from last 30 days.
- Internally rename CompanySurcharge to Surcharge.
- Internally rename Price to SpecialPrice.

### Fixed
- Persist without_water setting across program restarts.

## [3.13] - 2026-03-22

### Added
- Show tonnes in production printout and export.
- "Group by delivery" option for production printout and export.

### Fixed
- Bind test server to localhost.

## [3.12] - 2026-03-19

### Added
- Email fields for Setup (company and facility/provozovna) and ConstructionSite models.

### Changed
- Upgrade peewee to 4.0.2 and peewee-migrate to 1.15.0.

### Fixed
- Only set k_value/k_ratio on Addition-type OrderMaterials.

## [3.11] - 2026-03-13

### Fixed
- Fix database migrations not found when running PyInstaller-packaged binary.
- Fix populate_db using old 'customer' kwarg instead of renamed 'customer_name'.

## [3.10] - 2026-03-12 [YANKED]

### Added
- Add suppress_print flag to Recipe model.
- Add production enable feature with challenge-based manual override.

### Changed
- Use AtxWSGIServer/AtxWSGIRequestHandler from atxpylib.web and update atxpylib.

### Fixed
- Fix SmartSelectBox losing selection on redraw.
- Fix SmartSelectBox double-click bug when focus changes.
- Fix frontend tests failing when run from non-Prague timezone.

## [3.9] - 2026-03-05 [YANKED]

### Fixed
- Fix compilation.

## [3.8] - 2026-03-04 [YANKED]

### Added
- Add support for weather display.
- Add ConstructionSiteNumber field (for KDX).
- Add facility code to order communication file.
- Add vehicle registration (SPZ) filter to production printout.
- Add operator to zapa delivery sheet.
- Write operator to order file.
- Add bes and miroads logos.
- Parse DistanceJobSite from KDX .ord files and save to ConstructionSite.distance.

### Changed
- Modernize compilation.
- Update zapa delivery sheet templates.
- Update dependencies and atxpylib.
- Make INI file tests case-sensitive.

### Fixed
- Prevent InputField from losing user input on external redraw.
- Fix setMithrilQueryString losing params due to stale route.
- Fix frontend tests failing when system timezone differs from app timezone.
- Fix socket leak in test server port discovery.
- Fix obsolete atxd300 import parameter in manual.

## [3.7] - 2026-01-14

### Added
- Add DriverName and ContractID to Order communication file section.

### Changed
- Update dependencies.
- Move audit from Makefile to Justfile.

## [3.6] - 2025-11-25

### Added
- Optionally show produced volume for contract in expedition form.

### Fixed
- Fix production in non-standby mode.

## [3.5] - 2025-11-17

### Added
- Add initial code to enable production in standby mode.

### Changed
- Add mypy to Justfile.

## [3.4] - 2025-10-27

### Fixed
- Fix crash on continuous delivery handling when deleting order before production.

## [3.3] - 2025-10-23

### Added
- Add separate print event setting for continuous mode.

### Changed
- Unify/simplify production overview selection form.
- Auto-print code cleanups.
- Update dependencies.

## [3.2] - 2025-10-20

### Changed
- Standby mode: ignore temporary files.
- Minor auto-print sequence optimization.

## [3.1] - 2025-10-16

### Fixed
- Fixes after merging bridges refactoring.

### Removed
- Remove orphaned bridges.py file after refactoring to package structure.

## [3.0] - 2025-10-16

### Added
- Add Baris bridge integration with exponential backoff.
- Add standby (listen) mode replacing most of KDX bridge logic.
- Add density field to Material and OrderMaterial.
- Add delivery sheet templates: bezedos, staving, more eurovia variants.
- Add pre-computed date/time human-readable fields to delivery sheets.
- Add preferred table ordering.
- Add better error messages to templates.

### Changed
- Rename material amount to weight, remove unit field.
- Rename listen mode to standby mode.
- Refactor bridges.py into a package.
- Migrate from quitfile to filesig.
- Move .coveragerc into pyproject.toml.
- Change density unit to kg/l.
- Disallow returned_volume for continuous orders.
- Round volume of continuous orders when duplicating.
- Better listing of materials with rounding in batch listing.
- Update dependencies.

### Fixed
- Fix keystroke loss in filter input when typing fast.
- Fix automatic printing error when in continuous mode.
- Fix order._distance_driven_extra and KVD distance_driven in printout.
- Fix grand_total in batch protocol.

### Removed
- Remove RegistrationNumberField.
- Remove reload_config.

## [2.7] - 2025-08-23

### Added
- Add BATCH_COMPLETED printer event, allow selecting for continuous_mode.

### Changed
- Refactor order status change code and input file processing.
- Always have a delivery prepared, not just for batch production.
- Use calc_water_cement_contact_t for all delivery sheets.
- Update dependencies.

### Fixed
- Fix payment type cash displaying as not_set.
- Fix delivery creation in minidisp import.

## [2.6] - 2025-08-18

### Added
- Add grand total to batch protocol.
- Split importer.py into modules, finish import from atxd300.

### Changed
- More logging when importing customers from atxd300.
- Raise if not all DBF fields were used.

### Fixed
- Fix batch_protocol.html layout.

## [2.5] - 2025-08-15

### Changed
- Use calc_water_cement_contact_t for KVD delivery sheets.

## [2.4] - 2025-08-13

### Fixed
- Fix automatic print of single-batch orders.
- Do not send useless requests to atxdispatchprint.

## [2.3] - 2025-08-11

### Added
- Add concrete price percentage multiplier surcharge.
- Translate tabular export headers.

### Changed
- Duplicate driver on order duplication.
- Add actual workability time to eurovia delivery sheets.
- Reorder fields in production overview form.
- Don't show total batch count when continuous_mode.
- Eurovia delivery sheet updates.
- Update dependencies and atxpylib.

### Fixed
- Fix misleading title in Recipe.copy.

## [2.2] - 2025-07-30

### Changed
- Add stamp to eurovia delivery sheet templates.

## [2.1] - 2025-07-30

### Added
- Add prefetch mechanism.
- Add volume to deliveries listing.
- Show continuous_mode in listing if enabled.

### Changed
- Refactor PaymentType and OrderStatus enums.
- Generalize car_driver/pump_driver handling.
- Allow to "forget" car_driver and pump_driver association by selecting "none" driver.
- Order material groups in material selectbox.
- Let user partially control delivery sheet printing for continuous mode.
- Split eurovia delivery sheet templates to half-a4 and landscape-a4 versions.
- Properly format delivery volume column.
- Do not create .ord files for fully recycled orders.

### Fixed
- Fix Delivery.Driver history fields not saving new data.
- Fix wrong names and types for car_driver/pump_driver tables.
- Fix order_delivery form header, show auto_number explicitly.

## [2.0] - 2025-07-25

### Added
- Add remote printing functionality with event stream for print queue.
- Add optional local print mode.
- Add remote printing to pump order.
- Read Production_Start section from .std file to determine actual continuous mode.

### Changed
- Refactor comms files processing.
- Use Manager-provided ContinuousMode.
- Use lang='cs' in printouts when no language provided.
- Improve Enums.
- Update dependencies.

## [1.73] - 2025-07-23

### Changed
- Small fixups for KVD overlay sheet.

## [1.72] - 2025-07-21

### Fixed
- Fix crash on order cancellation with non-zero returned volume.

## [1.71] - 2025-07-09

### Added
- Add Recalc form button to EditOrder form.
- Allow Order unit_price and transport editing.

### Changed
- Make uv the implicit Python and venv runner.
- Remove unused dev dependencies and endpoint.
- Update dependencies.

### Fixed
- Fix edit order tests sometimes failing.

## [1.70] - 2025-06-30

### Added
- Add Order recycled volume field.
- Add 3min +/-10s to water-cement contact time for batch-less deliveries.

### Changed
- Export CSV in cs locale.
- Updates for faked cement-water contact value for eurovia delivery sheets.
- Update dependencies.

### Fixed
- Fix no-break space issue.
- Fix CSV tests.
- Fix KeyboardInterrupt handling in main loop.

## [1.69] - 2025-06-25

### Added
- Add customer logo images.

### Changed
- Move delivery sheet and logo setting from config file to Setup.
- Change phone from company to facility for eurovia delivery sheet.
- Reorder menu.
- Update dependencies.

## [1.68] - 2025-06-09

### Added
- Add User.phone field.

### Changed
- Shrink listings.
- Improve search text normalization.
- Disable auth for /print endpoint.
- Fit eurovia a5 sheet onto one paper.
- Update dependencies.

### Fixed
- Fix material longname extra having space as prefix.
- Fix cache hit ignore.
- Fix typing errors for new mypy.

## [1.67] - 2025-06-09

### Added
- Add tabular export to production overview.
- Print grouped info on all rows in production overview.

## [1.66] - 2025-06-06

### Changed
- Update delivery sheet template for eurovia SBM4000.

## [1.65] - 2025-06-05

### Added
- Pre-fill comment when contract is selected in expedition.

## [1.64] - 2025-05-19

### Added
- Add missing tests for Delivery.driver.

### Changed
- Update dependencies.
- More KVD delivery sheet updates.
- Hide Expeditions temperature if not module delivery sheets.
- Merge KVD printout branch.

### Fixed
- Fix wrong default for Order.payment_type.

## [1.63] - 2025-05-16

### Added
- Add driver field to order+delivery edit form.
- Add VehicleDriver tests.
- Add driver pre-fill to expeditions and new pump order.

### Changed
- Update KVD delivery sheet to new layout.
- Refactor Field locators in tests.
- Update types.
- Uncouple driver from vehicle.
- Show/hide driver details in listings.

### Fixed
- Fix invalid attribute access in templates.
- Small Expeditions cache refactor.
- Optimize lookups in cache code.
- Make cache behave less surprisingly.
- Use list where appropriate.

## [1.62] - 2025-05-15

### Added
- Add a way to import Order.customer and Order.construction_site from minidisp.
- Add Justfile vendor task.

### Changed
- Update dependencies.
- Update vendored JS libraries.
- Update pre-commit hooks.
- Properly size Plus buttons.

### Fixed
- Minidisp importer: be more verbose with errors, use unix style paths, unify naming.
- Minor optimization for importer.
- Prevent input of modified keys to SlimSelect.

### Security
- Update vulnerable flask version.

## [1.61] - 2025-05-07

### Changed
- Order Materials listing by name.

## [1.60] - 2025-05-06

### Added
- Add contract to Order edit if the Order was created via contract.

### Changed
- Reorder Order listing columns.
- Properly hide payment type in Order listing if module prices is not enabled.

## [1.59] - 2025-05-06

### Changed
- Raise eurovia continuous delivery sheet print margin.
- Decouple /prices from module_contract in menu.
- Resolve payment_type todos.

## [1.58] - 2025-05-06

### Changed
- Unbold ufi code.

### Fixed
- Implement delivery_sheet_eurovia_continuous_a5.html changes requested by certification.
- Minor fixes for delivery_sheet_eurovia_continuous_a5.html.

## [1.57] - 2025-04-30

### Fixed
- Be more strict when checking for special URL.
- Fix flaky test.
- Fix Loader count falling below 0.
- Correct super call.
- Use new delivery sheet setup name.

## [1.56] - 2025-04-29

### Changed
- Do not show Prices listing if not module_prices.
- Do not show recipe.price in selectbox if not module_prices.

### Fixed
- Show error when unable to delete an instance.

## [1.55] - 2025-04-29

### Changed
- Add hover effect on tables (listings).
- Move Recipe.price to a different spot in form.
- Merge volume-weight branch.
- Merge fast-cached-spinner branch.

---

**Note:** This changelog records all notable changes made to the project. Earlier versions are not included in this initial changelog but may be added in future updates.
