lambda-erp 1.4.27__tar.gz → 1.4.29__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/PKG-INFO +2 -1
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/chat.py +90 -40
- lambda_erp-1.4.29/api/list_columns.py +178 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/main.py +2 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/pdf_templates.py +5 -2
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/providers.py +1 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/documents.py +4 -1
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/mcp.py +1 -1
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/services.py +72 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/frontend/src/api/client.ts +5 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/database.py +5 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/pyproject.toml +2 -1
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/.gitignore +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/LICENSE +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/README.md +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/attachments.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/auth.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/chat_links.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/deps.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/erp_context.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/errors.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/list_values.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/mentions.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/oauth.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/pdf.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/record_attachments.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/record_notes.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/masters.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/reports.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/templates/document.html +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/templates/record.html +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/time_filters.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/tool_results.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/api/write_context.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/frontend/README.md +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/addresses.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/bundles.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/tax_defaults.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/delivery_note.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/units.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/lambda_erp/workflow.py +0 -0
- {lambda_erp-1.4.27 → lambda_erp-1.4.29}/terraform/README.md +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: lambda-erp
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.29
|
|
4
4
|
Summary: Core ERP logic - accounting, sales, purchasing, inventory
|
|
5
5
|
Author: TORUS INVESTMENTS AG
|
|
6
6
|
License-Expression: Apache-2.0
|
|
7
7
|
License-File: LICENSE
|
|
8
8
|
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: av<18,>=16
|
|
9
10
|
Requires-Dist: bcrypt>=5
|
|
10
11
|
Requires-Dist: defusedxml>=0.7
|
|
11
12
|
Requires-Dist: fastapi>=0.115
|
|
@@ -22,6 +22,7 @@ import traceback
|
|
|
22
22
|
import uuid
|
|
23
23
|
from datetime import date
|
|
24
24
|
|
|
25
|
+
import av
|
|
25
26
|
import httpx
|
|
26
27
|
from dotenv import load_dotenv
|
|
27
28
|
from fastapi import APIRouter, Depends as _Depends, HTTPException, WebSocket, WebSocketDisconnect
|
|
@@ -242,6 +243,20 @@ async def drain_turns(timeout: float) -> None:
|
|
|
242
243
|
await asyncio.wait(pending, timeout=timeout)
|
|
243
244
|
|
|
244
245
|
|
|
246
|
+
def delete_empty_session(session_id: str) -> bool:
|
|
247
|
+
# History in the sidebar can be stale when another tab adds content.
|
|
248
|
+
db = get_db()
|
|
249
|
+
with db.atomic():
|
|
250
|
+
cursor = db.conn.execute(
|
|
251
|
+
'''DELETE FROM "Chat Session" WHERE id = ?
|
|
252
|
+
AND (active_turn IS NULL OR active_turn_until IS NULL OR active_turn_until < ?)
|
|
253
|
+
AND NOT EXISTS (SELECT 1 FROM "Chat Message" WHERE session_id = ?)
|
|
254
|
+
AND NOT EXISTS (SELECT 1 FROM "Chat Attachment" WHERE session_id = ?)''',
|
|
255
|
+
[session_id, _utc_iso(), session_id, session_id],
|
|
256
|
+
)
|
|
257
|
+
return cursor.rowcount == 1
|
|
258
|
+
|
|
259
|
+
|
|
245
260
|
def delete_session(session_id: str):
|
|
246
261
|
"""Delete a chat session, its messages, and its attachments."""
|
|
247
262
|
try:
|
|
@@ -255,9 +270,15 @@ def delete_session(session_id: str):
|
|
|
255
270
|
db.conn.commit()
|
|
256
271
|
|
|
257
272
|
|
|
258
|
-
def update_session_title(session_id: str, title: str):
|
|
273
|
+
def update_session_title(session_id: str, title: str, *, generated: bool = False):
|
|
259
274
|
db = get_db()
|
|
260
|
-
|
|
275
|
+
if generated:
|
|
276
|
+
# A first-turn title can finish after an operator has already renamed the chat.
|
|
277
|
+
db.sql('''UPDATE "Chat Session" SET title = ?, updated_at = CURRENT_TIMESTAMP
|
|
278
|
+
WHERE id = ? AND title_is_manual = 0 AND title = ?''', [title, session_id, "New Chat"])
|
|
279
|
+
else:
|
|
280
|
+
db.sql('''UPDATE "Chat Session" SET title = ?, title_is_manual = 1, updated_at = CURRENT_TIMESTAMP
|
|
281
|
+
WHERE id = ?''', [title, session_id])
|
|
261
282
|
db.conn.commit()
|
|
262
283
|
|
|
263
284
|
|
|
@@ -557,9 +578,10 @@ def api_rename_session(session_id: str, data: dict, user: dict = _Depends(get_cu
|
|
|
557
578
|
session = get_session(session_id)
|
|
558
579
|
if not can_access_session(session, user):
|
|
559
580
|
return {"detail": "Session not found"}
|
|
560
|
-
title = data.get("title"
|
|
561
|
-
if title:
|
|
562
|
-
|
|
581
|
+
title = data.get("title")
|
|
582
|
+
if not isinstance(title, str) or not title.strip():
|
|
583
|
+
raise HTTPException(status_code=422, detail="A chat name is required.")
|
|
584
|
+
update_session_title(session_id, title.strip())
|
|
563
585
|
return {"ok": True}
|
|
564
586
|
|
|
565
587
|
|
|
@@ -3090,27 +3112,35 @@ Purchase Order → Purchase Receipt (receiving) / Purchase Invoice (billing) →
|
|
|
3090
3112
|
|
|
3091
3113
|
### Items vs. charges on an invoice
|
|
3092
3114
|
|
|
3093
|
-
|
|
3115
|
+
An invoice has **two kinds of lines**:
|
|
3094
3116
|
|
|
3095
|
-
- **Items** (`items[]`):
|
|
3096
|
-
- **Charges** (`taxes[]`):
|
|
3117
|
+
- **Items** (`items[]`): goods or services with an Item master record and a qty × rate shape ("10 × Bolt Pack M8", "1 × Engineering Consultation").
|
|
3118
|
+
- **Charges** (`taxes[]`): rows that point at a GL account directly, with no Item: **freight, shipping, postage, handling, customs, import duties, insurance**, and the actual taxes (VAT, GST, sales tax).
|
|
3097
3119
|
|
|
3098
|
-
|
|
3120
|
+
**Defaults, not prohibitions.** These are the defaults when nobody says otherwise. When the user asks for a charge as a line item ("Versand als normale Position", "the shipping should be a line"), do that: an explicit instruction of the user beats these defaults. Never refuse such a request by pointing to this section.
|
|
3099
3121
|
|
|
3100
|
-
|
|
3101
|
-
- `charge_type`: `"Actual"` for a fixed amount (freight, shipping, handling, customs), `"On Net Total"` for a percentage (most VAT/GST), `"On Previous Row Total"` for a percentage applied on top of earlier charges (EU VAT that includes freight in its base).
|
|
3102
|
-
- `account_head`: the GL account to debit. Use the company's defaults:
|
|
3122
|
+
**Purchase invoices (parsing a supplier's invoice):** by default products go into `items[]` and shipping or customs into `taxes[]` with `charge_type="Actual"`, the amount, and the company's account:
|
|
3103
3123
|
- Freight / shipping / postage → `default_freight_in_account` on the Company record
|
|
3104
3124
|
- Customs / duty / tariff → `default_customs_account`
|
|
3105
|
-
|
|
3106
|
-
|
|
3125
|
+
Do not create a new Item master just for a supplier's "Shipping" or "Customs duty" line.
|
|
3126
|
+
|
|
3127
|
+
**Sales documents (quotation, sales order, sales invoice):** re-billed shipping or handling can be either
|
|
3128
|
+
- a **line item** (common in Switzerland, and what most customers expect to see): use a non-stock service item for it (search for one such as "Versand" first; create it once if none exists, is_stock_item=0). It counts into the net total, VAT applies to it like to any line, and it is booked to that item's income account; or
|
|
3129
|
+
- a **charge row** with `charge_type="Actual"`. Then name an income account for it (ask which, if none is known). Do NOT use `default_freight_in_account` on a sales document: that is the purchase freight expense, and re-billed shipping would then reduce costs instead of showing as revenue. VAT that must include it goes after it as `On Previous Row Total`.
|
|
3130
|
+
If the user does not say which, use the line item for a fixed shipping amount and say so.
|
|
3131
|
+
To turn an existing shipping charge row into a line: add the line with the same amount, remove the charge row, and check that net total, VAT and grand total come out as intended (VAT on the new net total).
|
|
3132
|
+
|
|
3133
|
+
Each charge row has:
|
|
3134
|
+
- `charge_type`: `"Actual"` for a fixed amount, `"On Net Total"` for a percentage (most VAT/GST), `"On Previous Row Total"` for a percentage applied on top of earlier charges (VAT that includes freight in its base).
|
|
3135
|
+
- `account_head`: the GL account (see above for which).
|
|
3136
|
+
- `description`: the label as it should print ("Versand", "Customs duty", "MWST 8.1 %").
|
|
3107
3137
|
- `rate` (for percentage charges) or `tax_amount` (for `Actual` charges).
|
|
3108
3138
|
- `add_deduct_tax`: `"Add"` for most charges; `"Deduct"` for discounts/rebates on the bill.
|
|
3109
3139
|
|
|
3110
|
-
When you parse a supplier invoice PDF that has both products and a shipping line, create ONE Purchase Invoice with the items in `items[]` and the shipping as a row in `taxes[]` with `charge_type="Actual"`, the freight amount, and the freight account. Same structure for customs duties.
|
|
3111
|
-
|
|
3112
3140
|
If multiple charges stack (freight + VAT on total incl. freight), put freight first as `Actual`, then VAT second as `On Previous Row Total` referencing the freight row's `idx`.
|
|
3113
3141
|
|
|
3142
|
+
**The PDF shows the document as stored.** A charge row prints in the totals block, an item line in the item list. Never make a PDF layout print a charge as if it were an item or a numbered position, or print totals the document does not hold: the PDF would then disagree with the books (and the PDF check refuses a layout that leaves out the stored net total). If the user wants the structure changed, change the document, not the layout.
|
|
3143
|
+
|
|
3114
3144
|
### Adding VAT to a SALES document (quotation / sales order / sales invoice)
|
|
3115
3145
|
|
|
3116
3146
|
"Add 8.1% VAT / MwSt" needs exactly ONE `taxes[]` row — do it directly with update_document:
|
|
@@ -3811,7 +3841,7 @@ async def generate_title(
|
|
|
3811
3841
|
|
|
3812
3842
|
title = (response.output_text or "").strip().strip('"\'')[:120]
|
|
3813
3843
|
if title:
|
|
3814
|
-
update_session_title(session_id, title)
|
|
3844
|
+
update_session_title(session_id, title, generated=True)
|
|
3815
3845
|
print(f"[chat_title] model={title_model} session_id={session_id} "
|
|
3816
3846
|
f"ms={int((time.monotonic() - started) * 1000)}", flush=True)
|
|
3817
3847
|
else:
|
|
@@ -4441,6 +4471,8 @@ async def run_thinking_loop(
|
|
|
4441
4471
|
# Speech-to-text (voice → text)
|
|
4442
4472
|
# ---------------------------------------------------------------------------
|
|
4443
4473
|
|
|
4474
|
+
TRANSCRIPTION_MODEL = "gpt-transcribe"
|
|
4475
|
+
|
|
4444
4476
|
# Domain-vocabulary biasing for the transcription `prompt`. A bare term list,
|
|
4445
4477
|
# NO language constraint — the spoken language is auto-detected, and a
|
|
4446
4478
|
# locale-derived hint would mis-transcribe users who speak another language
|
|
@@ -4456,31 +4488,50 @@ VOICE_TRANSCRIBE_PROMPT = (
|
|
|
4456
4488
|
|
|
4457
4489
|
# Below this the API rejects the clip as "too short"; we treat it as a no-op
|
|
4458
4490
|
# (the user tapped the mic by accident) rather than an error.
|
|
4459
|
-
_MIN_TRANSCRIBE_BYTES = 1500
|
|
4491
|
+
_MIN_TRANSCRIBE_BYTES = 1500
|
|
4460
4492
|
|
|
4461
4493
|
|
|
4462
|
-
def
|
|
4463
|
-
"""
|
|
4494
|
+
def recorded_audio_seconds(file) -> float | None:
|
|
4495
|
+
"""Read a voice clip locally. Streaming WebM may omit the duration header."""
|
|
4496
|
+
try:
|
|
4497
|
+
with av.open(file, mode="r", options={
|
|
4498
|
+
"format_whitelist": "matroska,webm,mov,mp4,m4a,3gp,3g2,mj2,ogg,wav,mp3,flac,aac,mpeg",
|
|
4499
|
+
"protocol_whitelist": "",
|
|
4500
|
+
}) as container:
|
|
4501
|
+
stream = container.streams.audio[0]
|
|
4502
|
+
if stream.duration is not None and stream.duration > 0:
|
|
4503
|
+
return float(stream.duration * stream.time_base)
|
|
4504
|
+
# Count samples when the recorder left the stream length unknown.
|
|
4505
|
+
return sum(frame.samples / frame.sample_rate for frame in container.decode(stream)) or None
|
|
4506
|
+
except (av.FFmpegError, IndexError, ValueError, OSError, ZeroDivisionError):
|
|
4507
|
+
return None
|
|
4508
|
+
|
|
4464
4509
|
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
Raises on an actual API error so the caller can surface it.
|
|
4468
|
-
"""
|
|
4510
|
+
def transcribe_audio(audio_bytes: bytes, audio_format: str, erp_user: str | None = None) -> tuple[str, float]:
|
|
4511
|
+
"""Return the transcript and the audio seconds to record for this paid call."""
|
|
4469
4512
|
client = OpenAI(**client_kwargs(httpx.Timeout(60.0, connect=10.0), erp_user=erp_user))
|
|
4470
4513
|
|
|
4471
4514
|
audio_file = io.BytesIO(audio_bytes)
|
|
4472
4515
|
audio_file.name = f"voice.{audio_format or 'webm'}"
|
|
4473
4516
|
|
|
4474
4517
|
transcription = client.audio.transcriptions.create(
|
|
4475
|
-
model=
|
|
4518
|
+
model=TRANSCRIPTION_MODEL,
|
|
4476
4519
|
file=audio_file,
|
|
4477
|
-
response_format="json",
|
|
4478
4520
|
prompt=VOICE_TRANSCRIBE_PROMPT,
|
|
4479
4521
|
)
|
|
4480
4522
|
|
|
4523
|
+
seconds = getattr(getattr(transcription, "usage", None), "seconds", None)
|
|
4524
|
+
if seconds is None:
|
|
4525
|
+
seconds = getattr(transcription, "duration", None)
|
|
4526
|
+
if seconds is None:
|
|
4527
|
+
seconds = recorded_audio_seconds(io.BytesIO(audio_bytes))
|
|
4528
|
+
if seconds is None:
|
|
4529
|
+
logger.warning("Using estimated duration for an unreadable %s voice clip", audio_format)
|
|
4530
|
+
seconds = len(audio_bytes) / 2000 # Same legacy fallback as the Lambda gateway.
|
|
4531
|
+
|
|
4481
4532
|
text = (getattr(transcription, "text", "") or "").strip()
|
|
4482
4533
|
if len(text) < 2:
|
|
4483
|
-
return ""
|
|
4534
|
+
return "", seconds
|
|
4484
4535
|
|
|
4485
4536
|
# Prompt-echo guard: on silent/noise audio, prompt-biased transcription
|
|
4486
4537
|
# tends to hallucinate the biasing vocabulary back. If (nearly) every word
|
|
@@ -4491,9 +4542,9 @@ def transcribe_audio(audio_bytes: bytes, audio_format: str, erp_user: str | None
|
|
|
4491
4542
|
if text_tokens:
|
|
4492
4543
|
coverage = sum(1 for tok in text_tokens if tok in prompt_tokens) / len(text_tokens)
|
|
4493
4544
|
if coverage >= 0.8:
|
|
4494
|
-
return ""
|
|
4545
|
+
return "", seconds
|
|
4495
4546
|
|
|
4496
|
-
return text
|
|
4547
|
+
return text, seconds
|
|
4497
4548
|
|
|
4498
4549
|
|
|
4499
4550
|
# ---------------------------------------------------------------------------
|
|
@@ -4837,7 +4888,7 @@ async def chat_websocket(
|
|
|
4837
4888
|
)
|
|
4838
4889
|
continue
|
|
4839
4890
|
|
|
4840
|
-
if msg_type
|
|
4891
|
+
if msg_type in ("delete_empty_session", "delete_session"):
|
|
4841
4892
|
session_id = data.get("session_id")
|
|
4842
4893
|
if not session_id:
|
|
4843
4894
|
await send_error("No session_id provided", request_id=request_id)
|
|
@@ -4856,8 +4907,12 @@ async def chat_websocket(
|
|
|
4856
4907
|
)
|
|
4857
4908
|
continue
|
|
4858
4909
|
|
|
4859
|
-
|
|
4860
|
-
|
|
4910
|
+
if msg_type == "delete_empty_session":
|
|
4911
|
+
deleted = delete_empty_session(session_id)
|
|
4912
|
+
await send_event("empty_session_delete_result", request_id=request_id, session_id=session_id, deleted=deleted)
|
|
4913
|
+
else:
|
|
4914
|
+
delete_session(session_id)
|
|
4915
|
+
await send_event("session_deleted", request_id=request_id, session_id=session_id)
|
|
4861
4916
|
continue
|
|
4862
4917
|
|
|
4863
4918
|
if msg_type == "clear_history":
|
|
@@ -4998,7 +5053,7 @@ async def chat_websocket(
|
|
|
4998
5053
|
continue
|
|
4999
5054
|
|
|
5000
5055
|
try:
|
|
5001
|
-
text = await asyncio.to_thread(
|
|
5056
|
+
text, audio_seconds = await asyncio.to_thread(
|
|
5002
5057
|
transcribe_audio, audio_bytes, audio_format, ws_user_id,
|
|
5003
5058
|
)
|
|
5004
5059
|
except Exception as e:
|
|
@@ -5009,17 +5064,12 @@ async def chat_websocket(
|
|
|
5009
5064
|
)
|
|
5010
5065
|
continue
|
|
5011
5066
|
|
|
5012
|
-
# Track the spend. Audio duration is estimated from byte size
|
|
5013
|
-
# (~1.5 KB/s for webm/opus); the Demo Spend Log records every
|
|
5014
|
-
# role for the admin dashboard, and counts public_manager rows
|
|
5015
|
-
# against the hourly cap.
|
|
5016
|
-
estimated_seconds = len(audio_bytes) / 1500
|
|
5017
5067
|
demo_limiter.record(
|
|
5018
5068
|
client_ip or "unknown",
|
|
5019
|
-
cost_of_transcription(
|
|
5069
|
+
cost_of_transcription(TRANSCRIPTION_MODEL, audio_seconds),
|
|
5020
5070
|
role=ws_user_role,
|
|
5021
5071
|
provider="openai",
|
|
5022
|
-
model=
|
|
5072
|
+
model=TRANSCRIPTION_MODEL,
|
|
5023
5073
|
session_id=data.get("session_id"),
|
|
5024
5074
|
)
|
|
5025
5075
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""Personal list columns of the document lists, readable and changeable from the chat.
|
|
2
|
+
|
|
3
|
+
The web app keeps each user's columns of a document list as the preference
|
|
4
|
+
`columns.<doctype slug>` (comma-separated, in display order) and the sort
|
|
5
|
+
order as `sort.<doctype slug>` (`column:asc|desc`). The column menu of a list
|
|
6
|
+
writes them; these actions let the assistant do the same for the signed-in
|
|
7
|
+
user, and only for them. Since 1.4.29.
|
|
8
|
+
|
|
9
|
+
Columns a list can show: `name`, the document's own columns the user may see,
|
|
10
|
+
the readable name of a linked record (`<link field>__title`, see
|
|
11
|
+
services.linked_title_fields) and, where the document type prints, the PDF link
|
|
12
|
+
`__pdf`. Unset, a list shows the app's default columns.
|
|
13
|
+
"""
|
|
14
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
15
|
+
|
|
16
|
+
from api import services
|
|
17
|
+
from api.menu_layout import _actor
|
|
18
|
+
from lambda_erp import permissions
|
|
19
|
+
from lambda_erp.database import get_db
|
|
20
|
+
|
|
21
|
+
PDF_COLUMN = "__pdf"
|
|
22
|
+
# Bookkeeping columns no list shows.
|
|
23
|
+
_NOT_SHOWN = {"docstatus", "discarded", "idx", "content_hash", "access_stamp"}
|
|
24
|
+
MAX_COLUMNS = 20
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class GetColumns(BaseModel):
|
|
28
|
+
model_config = ConfigDict(extra="forbid")
|
|
29
|
+
doctype: str = Field(min_length=1, max_length=100, description="Document type slug, e.g. sales-invoice")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class UpdateColumns(BaseModel):
|
|
33
|
+
model_config = ConfigDict(extra="forbid")
|
|
34
|
+
doctype: str = Field(min_length=1, max_length=100, description="Document type slug, e.g. sales-invoice")
|
|
35
|
+
columns: list[str] | None = Field(
|
|
36
|
+
default=None, max_length=MAX_COLUMNS,
|
|
37
|
+
description="All columns of the list in display order (replaces the current set). Use the names "
|
|
38
|
+
"from get_list_columns; `name` is always shown first if left out.")
|
|
39
|
+
add: list[str] = Field(default_factory=list, max_length=MAX_COLUMNS,
|
|
40
|
+
description="Columns to append to the current set.")
|
|
41
|
+
remove: list[str] = Field(default_factory=list, max_length=MAX_COLUMNS,
|
|
42
|
+
description="Columns to take out of the current set.")
|
|
43
|
+
sort_by: str | None = Field(default=None, max_length=100,
|
|
44
|
+
description="Column to sort the list by (a stored column, not a looked-up name or the PDF link).")
|
|
45
|
+
sort_order: str | None = Field(default=None, pattern="^(asc|desc)$")
|
|
46
|
+
reset: bool = Field(default=False, description="Back to the app's default columns and sort order.")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _doctype(slug):
|
|
50
|
+
doctype = services.SLUG_TO_DOCTYPE.get(slug)
|
|
51
|
+
if not doctype:
|
|
52
|
+
raise ValueError(f"Unknown document type {slug!r}; use a slug such as sales-invoice.")
|
|
53
|
+
permissions.require(doctype, "read")
|
|
54
|
+
return doctype
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _catalog(slug, doctype):
|
|
58
|
+
"""{column: what it is} for the columns this user's list of `slug` can show."""
|
|
59
|
+
db = get_db()
|
|
60
|
+
hidden = permissions.hidden_fields(doctype)
|
|
61
|
+
columns = sorted(db._get_table_columns(doctype) - hidden - _NOT_SHOWN)
|
|
62
|
+
catalog = {"name": "the document's id"}
|
|
63
|
+
catalog.update({column: "a column of the document" for column in columns if column != "name"})
|
|
64
|
+
cls = services.DOCUMENT_CLASSES.get(doctype)
|
|
65
|
+
for field in sorted(getattr(cls, "LINK_FIELDS", {}) or {}):
|
|
66
|
+
title = f"{field}{services.TITLE_SUFFIX}"
|
|
67
|
+
if field in catalog and services.linked_title_fields(doctype, [title]):
|
|
68
|
+
catalog[title] = f"the name of the linked {cls.LINK_FIELDS[field]} (looked up, not sortable)"
|
|
69
|
+
try:
|
|
70
|
+
from api.pdf_profiles import pdf_metadata
|
|
71
|
+
if (pdf_metadata(doctype) or {}).get("supported"):
|
|
72
|
+
catalog[PDF_COLUMN] = "a link that opens the document's PDF (not sortable)"
|
|
73
|
+
except Exception: # noqa: BLE001 - no PDF column rather than no columns
|
|
74
|
+
pass
|
|
75
|
+
return catalog
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _read(user_name, key):
|
|
79
|
+
rows = get_db().sql('SELECT value FROM "User Preference" WHERE user_name = ? AND key = ?', [user_name, key])
|
|
80
|
+
return rows[0]["value"] if rows else ""
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _write(user_name, key, value):
|
|
84
|
+
db = get_db()
|
|
85
|
+
with db.atomic():
|
|
86
|
+
if db.sql('SELECT 1 FROM "User Preference" WHERE user_name = ? AND key = ?', [user_name, key]):
|
|
87
|
+
if value:
|
|
88
|
+
db.sql('UPDATE "User Preference" SET value = ? WHERE user_name = ? AND key = ?', [value, user_name, key])
|
|
89
|
+
else:
|
|
90
|
+
db.sql('DELETE FROM "User Preference" WHERE user_name = ? AND key = ?', [user_name, key])
|
|
91
|
+
elif value:
|
|
92
|
+
db.sql('INSERT INTO "User Preference" (user_name, key, value) VALUES (?, ?, ?)', [user_name, key, value])
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _state(user_name, slug, catalog):
|
|
96
|
+
saved = [column.strip() for column in _read(user_name, f"columns.{slug}").split(",") if column.strip()]
|
|
97
|
+
sort = _read(user_name, f"sort.{slug}")
|
|
98
|
+
by, _, order = sort.partition(":")
|
|
99
|
+
return {
|
|
100
|
+
"doctype": slug,
|
|
101
|
+
"columns": saved or None,
|
|
102
|
+
"columns_note": None if saved else "Not set: the list shows the app's default columns.",
|
|
103
|
+
"sort_by": by or None,
|
|
104
|
+
"sort_order": order or None,
|
|
105
|
+
"available": catalog,
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def get_list_columns(args, user):
|
|
110
|
+
data = GetColumns.model_validate(args)
|
|
111
|
+
user_name, doctype = _actor(user), _doctype(data.doctype)
|
|
112
|
+
return _state(user_name, data.doctype, _catalog(data.doctype, doctype))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def update_list_columns(args, user):
|
|
116
|
+
data = UpdateColumns.model_validate(args)
|
|
117
|
+
user_name, doctype = _actor(user), _doctype(data.doctype)
|
|
118
|
+
catalog = _catalog(data.doctype, doctype)
|
|
119
|
+
slug = data.doctype
|
|
120
|
+
|
|
121
|
+
def check(names):
|
|
122
|
+
unknown = [name for name in names if name not in catalog]
|
|
123
|
+
if unknown:
|
|
124
|
+
raise ValueError(f"Unknown column(s) for {slug}: {', '.join(unknown)}. "
|
|
125
|
+
"Call get_list_columns for the columns this list can show.")
|
|
126
|
+
return names
|
|
127
|
+
|
|
128
|
+
if data.reset:
|
|
129
|
+
_write(user_name, f"columns.{slug}", "")
|
|
130
|
+
_write(user_name, f"sort.{slug}", "")
|
|
131
|
+
current = [c.strip() for c in _read(user_name, f"columns.{slug}").split(",") if c.strip()]
|
|
132
|
+
if data.columns is not None:
|
|
133
|
+
columns = check(list(dict.fromkeys(data.columns)))
|
|
134
|
+
elif data.add or data.remove:
|
|
135
|
+
if not current:
|
|
136
|
+
raise ValueError(f"The {slug} list shows its default columns, which are set by the app. "
|
|
137
|
+
"Send the whole set with columns=[...] (see get_list_columns) instead of add/remove.")
|
|
138
|
+
columns = [c for c in current if c not in set(check(data.remove))] + \
|
|
139
|
+
[c for c in check(data.add) if c not in current]
|
|
140
|
+
else:
|
|
141
|
+
columns = None
|
|
142
|
+
if columns is not None:
|
|
143
|
+
if not columns:
|
|
144
|
+
raise ValueError("A list needs at least one column.")
|
|
145
|
+
if "name" not in columns:
|
|
146
|
+
columns = ["name", *columns]
|
|
147
|
+
_write(user_name, f"columns.{slug}", ",".join(columns[:MAX_COLUMNS]))
|
|
148
|
+
if data.sort_by is not None or data.sort_order is not None:
|
|
149
|
+
by = data.sort_by or (_read(user_name, f"sort.{slug}").partition(":")[0] or None)
|
|
150
|
+
if not by:
|
|
151
|
+
raise ValueError("sort_order needs sort_by.")
|
|
152
|
+
if by not in catalog or by == PDF_COLUMN or by.endswith(services.TITLE_SUFFIX):
|
|
153
|
+
raise ValueError(f"{by!r} cannot be sorted by; use a stored column of the document.")
|
|
154
|
+
_write(user_name, f"sort.{slug}", f"{by}:{data.sort_order or 'asc'}")
|
|
155
|
+
result = _state(user_name, slug, catalog)
|
|
156
|
+
result["note"] = "Saved for the signed-in user only. The list shows it on its next load."
|
|
157
|
+
return result
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def initialize_list_columns():
|
|
161
|
+
services.register_action(
|
|
162
|
+
"get_list_columns", get_list_columns, minimum_role="viewer", pass_user=True,
|
|
163
|
+
parameters=GetColumns.model_json_schema(),
|
|
164
|
+
description=(
|
|
165
|
+
"Show the current user's own columns and sort order of a document list (e.g. doctype "
|
|
166
|
+
"'sales-invoice') and the columns that list can show: the document's columns, the names of "
|
|
167
|
+
"linked records (customer__title, item_code__title) and __pdf, a link to each document's "
|
|
168
|
+
"PDF. Call this before update_list_columns."))
|
|
169
|
+
services.register_action(
|
|
170
|
+
"update_list_columns", update_list_columns, minimum_role="viewer", pass_user=True,
|
|
171
|
+
parameters=UpdateColumns.model_json_schema(),
|
|
172
|
+
description=(
|
|
173
|
+
"Change which columns the current user's own list of a document type shows, their order, "
|
|
174
|
+
"and the sort order (no one else's). columns replaces the whole set in display order; "
|
|
175
|
+
"add / remove change the current set; reset=true restores the app's defaults. Use column "
|
|
176
|
+
"names from get_list_columns: e.g. customer_name for the customer's name stored on a sales "
|
|
177
|
+
"invoice, item_code__title for an item's name, __pdf for a PDF link. Only stored columns "
|
|
178
|
+
"can be sorted by. It changes the display only, never data or permissions."))
|
|
@@ -74,6 +74,8 @@ async def lifespan(app: FastAPI):
|
|
|
74
74
|
initialize_pricing_actions()
|
|
75
75
|
from api.menu_layout import initialize_menu_layout
|
|
76
76
|
initialize_menu_layout()
|
|
77
|
+
from api.list_columns import initialize_list_columns
|
|
78
|
+
initialize_list_columns()
|
|
77
79
|
from api.pdf_templates import initialize_pdf_templates
|
|
78
80
|
initialize_pdf_templates()
|
|
79
81
|
from api.pdf_pages import initialize_pdf_pages
|
|
@@ -699,7 +699,7 @@ _REFERENCES = {
|
|
|
699
699
|
- items: list of {idx, item_code, item_name, description, qty, uom, rate, amount, discount_percentage, frequency}
|
|
700
700
|
A line ordered in a further unit of the item (2 Karton of 100) is stored per stock unit: qty 200, uom Stk, rate 2.90. Then item.ordered_in_unit is true and item.order_qty (2), item.order_uom (Karton), item.conversion_factor (100) and item.order_rate (290.00, the price per ordered unit) say what was ordered. Print order_qty + order_uom and order_rate for such a line (the stock quantity may go below); item.amount is the same either way. Never print item.rate with two decimals for it: 12.99 a carton is 0.1299 a piece.
|
|
701
701
|
A line can carry a deduction (e.g. "Abzüglich bereits verrechnet"): then item.discount_total > 0 (the deduction for the whole line), item.discount_label is its text, and item.gross_rate / item.gross_amount are the full price. Print the full price on the line and a sub-line with the label and −discount_total; item.amount is the net (gross_amount − discount_total). A layout that ignores it prints only the net amount (and gets a warning).
|
|
702
|
-
- taxes: list of {description, rate, tax_amount, total}
|
|
702
|
+
- taxes: list of {description, rate, tax_amount, total}. It holds taxes AND other charges such as shipping: print each row's own description (a neutral label only if it has none), never one fixed label such as "MWSt." or "VAT" for every row. Print them in the totals block as they are: never move a charge into the item list or number it as a position, never compute totals the document does not hold (the export refuses a layout that leaves out the stored net total). A layout shows the document as stored; if the user wants shipping as a line item, the document has to change (record it as an item), not the layout.
|
|
703
703
|
<<TEXTS>>- recurring_summary: per billing period [{frequency, label, net_total, grand_total, ...}]; show_frequency: whether any line recurs
|
|
704
704
|
- plus whatever deployment plugins add (e.g. qr_bill_img, the Swiss QR bill, on invoices: <img src="{{ qr_bill_img }}">; print it, usually on its own page at the end)
|
|
705
705
|
Rules: the PDF must show the document number, the customer or supplier, the currency, net and grand total, and every line's name and amount (the export rejects a layout that omits them), plus pdf_state_notice when set.""",
|
|
@@ -1050,7 +1050,10 @@ _ACTIONS = {
|
|
|
1050
1050
|
"Create a PDF template (layout) for a document type, as a copy of that type's 'standard' layout or of "
|
|
1051
1051
|
"another template (based_on; also another type's, e.g. the offer layout to start the invoice layout in "
|
|
1052
1052
|
"the same style, then adapt it to this type's variables), or from complete HTML. It starts "
|
|
1053
|
-
"unpublished; edit it with update_pdf_template, check it with view_pdf_pages, then publish."
|
|
1053
|
+
"unpublished; edit it with update_pdf_template, check it with view_pdf_pages, then publish. "
|
|
1054
|
+
"To change one detail of an existing layout (remove a slogan, move the logo), create it with based_on "
|
|
1055
|
+
"and no html, which copies that layout, then change only that part of its HTML with "
|
|
1056
|
+
"update_pdf_template; do not rewrite the layout, which loses what it gets right."),
|
|
1054
1057
|
"update_pdf_template": (update_pdf_template, UpdateTemplate, "manager",
|
|
1055
1058
|
"Change a PDF template's working copy: complete html (HTML + CSS with Jinja), title or description. "
|
|
1056
1059
|
"Edits overwrite the working copy in place, as often as needed, without creating versions. "
|
|
@@ -70,6 +70,7 @@ OPENAI_PRICING: dict[str, dict[str, Any]] = {
|
|
|
70
70
|
|
|
71
71
|
# Speech-to-text, priced per minute of audio (not per token).
|
|
72
72
|
TRANSCRIBE_PRICING: dict[str, dict[str, float]] = {
|
|
73
|
+
"gpt-transcribe": {"per_minute": 0.0045},
|
|
73
74
|
"gpt-4o-transcribe": {"per_minute": 0.006},
|
|
74
75
|
"gpt-4o-mini-transcribe": {"per_minute": 0.003},
|
|
75
76
|
"whisper-1": {"per_minute": 0.006},
|
|
@@ -131,7 +131,10 @@ def list_docs(
|
|
|
131
131
|
# fields, which affect query correctness and stay strict.)
|
|
132
132
|
projection = None
|
|
133
133
|
if fields:
|
|
134
|
-
|
|
134
|
+
asked = [f.strip() for f in fields.split(",") if f.strip()]
|
|
135
|
+
from api.services import linked_title_fields
|
|
136
|
+
titles = linked_title_fields(doctype, asked)
|
|
137
|
+
projection = [f for f in asked if f in columns or f in titles]
|
|
135
138
|
|
|
136
139
|
try:
|
|
137
140
|
result = list_document_page(
|
|
@@ -52,7 +52,7 @@ _EXCLUDE = {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
_READ_ONLY = {
|
|
55
|
-
'search_mention_users', 'list_my_mentions', 'list_record_notes', 'get_menu_layout',
|
|
55
|
+
'search_mention_users', 'list_my_mentions', 'list_record_notes', 'get_menu_layout', 'get_list_columns',
|
|
56
56
|
'list_pdf_templates', 'get_pdf_template', 'view_pdf_pages', 'get_pdf_text_defaults',
|
|
57
57
|
'get_erp_context',
|
|
58
58
|
'list_documents', 'get_document_fields', 'get_document', 'get_master_fields',
|
|
@@ -1107,6 +1107,69 @@ def _where_from_filters(db_filters: dict):
|
|
|
1107
1107
|
return where_parts, params
|
|
1108
1108
|
|
|
1109
1109
|
|
|
1110
|
+
# A list can show the readable name of a linked record next to its id: the
|
|
1111
|
+
# column `<link field>__title` (item_code__title on a stock reservation is
|
|
1112
|
+
# the item's item_name). The name is looked up when the list is read, under
|
|
1113
|
+
# the reader's access rules for the linked type; nothing is stored. Since
|
|
1114
|
+
# 1.4.29. Register a further type with register_title_column.
|
|
1115
|
+
TITLE_SUFFIX = "__title"
|
|
1116
|
+
TITLE_COLUMNS = {
|
|
1117
|
+
"Item": "item_name", "Customer": "customer_name", "Supplier": "supplier_name",
|
|
1118
|
+
"Warehouse": "warehouse_name", "Account": "account_name", "Cost Center": "cost_center_name",
|
|
1119
|
+
"Company": "company_name", "Price List": "price_list_name", "Asset": "asset_name",
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
def register_title_column(doctype: str, column: str) -> None:
|
|
1124
|
+
"""Plugin seam: the column that names a record of `doctype` in lists of
|
|
1125
|
+
documents that link to it."""
|
|
1126
|
+
TITLE_COLUMNS[doctype] = column
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
def linked_title_fields(doctype: str, fields) -> dict:
|
|
1130
|
+
"""{virtual field: (link field, linked doctype, its title column)} for
|
|
1131
|
+
the `<link>__title` names in `fields` this document type can answer."""
|
|
1132
|
+
cls = DOCUMENT_CLASSES.get(doctype)
|
|
1133
|
+
links = dict(getattr(cls, "LINK_FIELDS", {}) or {}) if cls else {}
|
|
1134
|
+
found = {}
|
|
1135
|
+
for field in fields or ():
|
|
1136
|
+
if not isinstance(field, str) or not field.endswith(TITLE_SUFFIX):
|
|
1137
|
+
continue
|
|
1138
|
+
base = field[: -len(TITLE_SUFFIX)]
|
|
1139
|
+
target = links.get(base)
|
|
1140
|
+
column = TITLE_COLUMNS.get(target) if target else None
|
|
1141
|
+
if column:
|
|
1142
|
+
found[field] = (base, target, column)
|
|
1143
|
+
return found
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
def _fill_linked_titles(db, rows, wanted: dict, drop: set) -> list:
|
|
1147
|
+
"""Add the linked records' names to list rows. A name the reader may not
|
|
1148
|
+
see (the linked type, that record, or the title column is hidden from
|
|
1149
|
+
them) stays empty rather than revealing it."""
|
|
1150
|
+
rows = [dict(row) for row in rows]
|
|
1151
|
+
for field, (base, target, column) in wanted.items():
|
|
1152
|
+
names = {}
|
|
1153
|
+
ids = sorted({row.get(base) for row in rows if row.get(base)})
|
|
1154
|
+
visible = (ids and permissions.can(target, "read")
|
|
1155
|
+
and column not in permissions.hidden_fields(target)
|
|
1156
|
+
and column in db._get_table_columns(target))
|
|
1157
|
+
if visible:
|
|
1158
|
+
conditions = permissions.record_conditions(target)
|
|
1159
|
+
for start in range(0, len(ids), 500):
|
|
1160
|
+
chunk = ids[start:start + 500]
|
|
1161
|
+
where = f'name IN ({", ".join("?" for _ in chunk)})'
|
|
1162
|
+
if conditions:
|
|
1163
|
+
where += " AND " + " AND ".join(f"({c})" for c in conditions)
|
|
1164
|
+
for hit in db.sql(f'SELECT name, "{column}" AS title FROM "{target}" WHERE {where}', chunk):
|
|
1165
|
+
names[hit["name"]] = hit["title"]
|
|
1166
|
+
for row in rows:
|
|
1167
|
+
row[field] = names.get(row.get(base)) or None
|
|
1168
|
+
if drop:
|
|
1169
|
+
rows = [{key: value for key, value in row.items() if key not in drop} for row in rows]
|
|
1170
|
+
return rows
|
|
1171
|
+
|
|
1172
|
+
|
|
1110
1173
|
def _projection_columns(doctype_slug: str, fields) -> set:
|
|
1111
1174
|
"""The set of real columns to keep for a `fields` projection — always
|
|
1112
1175
|
includes 'name'. Unknown field names are dropped (validated against the
|
|
@@ -1132,6 +1195,13 @@ def list_documents(doctype_slug: str, filters: dict = None, limit: int = 50, off
|
|
|
1132
1195
|
columns = db._get_table_columns(doctype)
|
|
1133
1196
|
if order_by and order_by not in columns:
|
|
1134
1197
|
raise ValueError(f"Unknown order_by field: {order_by}")
|
|
1198
|
+
titles = linked_title_fields(doctype, fields)
|
|
1199
|
+
title_drop = set()
|
|
1200
|
+
if titles:
|
|
1201
|
+
# A linked name needs its id; fetched for the lookup, returned only if asked.
|
|
1202
|
+
bases = [base for base, _, _ in titles.values()]
|
|
1203
|
+
title_drop = {base for base in bases if base not in fields} - {"name"}
|
|
1204
|
+
fields = [f for f in fields if f not in titles] + [b for b in bases if b not in fields]
|
|
1135
1205
|
permissions.require_fields_visible(doctype, [order_by] if order_by else [], "sort by")
|
|
1136
1206
|
permissions.require_fields_visible(doctype, fields, "select")
|
|
1137
1207
|
order_clause = _order_clause(order_by, order)
|
|
@@ -1151,6 +1221,8 @@ def list_documents(doctype_slug: str, filters: dict = None, limit: int = 50, off
|
|
|
1151
1221
|
query += " OFFSET ?"
|
|
1152
1222
|
params.append(max(0, int(offset)))
|
|
1153
1223
|
rows = db.sql(query, params)
|
|
1224
|
+
if titles:
|
|
1225
|
+
return _fill_linked_titles(db, rows, titles, title_drop)
|
|
1154
1226
|
return rows if fields else _attach_children(db, doctype_slug, rows) # all columns: redacted there
|
|
1155
1227
|
|
|
1156
1228
|
|
|
@@ -380,6 +380,11 @@ export const api = {
|
|
|
380
380
|
{ method: "POST" },
|
|
381
381
|
),
|
|
382
382
|
|
|
383
|
+
renameChatSession: (id: string, title: string) =>
|
|
384
|
+
request<{ ok?: boolean; detail?: string }>(`/chat/sessions/${encodeURIComponent(id)}/title`, {
|
|
385
|
+
method: "PUT", body: JSON.stringify({ title }),
|
|
386
|
+
}),
|
|
387
|
+
|
|
383
388
|
getChatSession: (id: string) =>
|
|
384
389
|
request<{ id: string; title: string; created_at: string; updated_at: string; last_message_at?: string | null; detail?: string }>(
|
|
385
390
|
`/chat/sessions/${encodeURIComponent(id)}`,
|
|
@@ -3784,6 +3784,10 @@ def _m069_chat_attachment_data(db: "Database") -> None:
|
|
|
3784
3784
|
db._add_column_if_missing("Chat Attachment", "data", "BLOB")
|
|
3785
3785
|
|
|
3786
3786
|
|
|
3787
|
+
def _m070_chat_manual_title(db: "Database") -> None:
|
|
3788
|
+
db.ensure_column("Chat Session", "title_is_manual", "INTEGER NOT NULL DEFAULT 0")
|
|
3789
|
+
|
|
3790
|
+
|
|
3787
3791
|
Database.MIGRATIONS = [
|
|
3788
3792
|
(1, "chat_message_session_id", _m001_chat_message_session_id),
|
|
3789
3793
|
(2, "chat_session_user_id", _m002_chat_session_user_id),
|
|
@@ -3854,6 +3858,7 @@ Database.MIGRATIONS = [
|
|
|
3854
3858
|
(67, "item_units", _m067_item_units),
|
|
3855
3859
|
(68, "units_completed", _m068_units_completed),
|
|
3856
3860
|
(69, "chat_attachment_data", _m069_chat_attachment_data),
|
|
3861
|
+
(70, "chat_manual_title", _m070_chat_manual_title),
|
|
3857
3862
|
]
|
|
3858
3863
|
|
|
3859
3864
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "lambda-erp"
|
|
3
|
-
version = "1.4.
|
|
3
|
+
version = "1.4.29"
|
|
4
4
|
description = "Core ERP logic - accounting, sales, purchasing, inventory"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -12,6 +12,7 @@ dependencies = [
|
|
|
12
12
|
"python-multipart>=0.0.9",
|
|
13
13
|
"pydantic>=2.0",
|
|
14
14
|
"openai>=1.0",
|
|
15
|
+
"av>=16,<18",
|
|
15
16
|
"httpx>=0.27",
|
|
16
17
|
"python-dotenv>=1.0",
|
|
17
18
|
"python-dateutil>=2.8",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|