lambda-erp 1.4.16__tar.gz → 1.4.18__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.16 → lambda_erp-1.4.18}/PKG-INFO +1 -1
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/chat.py +11 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/pdf.py +16 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/pdf_profiles.py +4 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/masters.py +19 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/services.py +6 -1
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/templates/delivery_note.html +11 -1
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/templates/document.html +11 -1
- lambda_erp-1.4.18/lambda_erp/addresses.py +191 -0
- lambda_erp-1.4.18/lambda_erp/bundles.py +167 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/database.py +77 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/model.py +10 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/permissions.py +4 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/pyproject.toml +1 -1
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/.gitignore +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/LICENSE +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/README.md +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/attachments.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/auth.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/chat_links.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/deps.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/erp_context.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/errors.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/list_values.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/main.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/mentions.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/oauth.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/providers.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/record_notes.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/reports.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/templates/record.html +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/time_filters.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/api/write_context.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/frontend/README.md +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/delivery_note.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/lambda_erp/workflow.py +0 -0
- {lambda_erp-1.4.16 → lambda_erp-1.4.18}/terraform/README.md +0 -0
|
@@ -3034,6 +3034,17 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
3034
3034
|
- Never invent or guess a serial number. If the user has not given them, ask; to see what is in stock use search_masters master_type="serial-no" (filter item_code, warehouse) or the serial-trace report for one number.
|
|
3035
3035
|
- Units from before the item was serial-tracked have no number: give them one with a Stock Entry of type "Serial Assignment" (item_code, qty, t_warehouse, serial_no).
|
|
3036
3036
|
|
|
3037
|
+
### Item bundles
|
|
3038
|
+
- An **Item Bundle** (doctype `item-bundle`: item_code = the bundle, items = rows of item_code and qty per bundle) makes one item code stand for several items. The bundle's own item is not a stock item.
|
|
3039
|
+
- On quotations, sales orders, delivery notes and sales / POS invoices, put the bundle's item_code and qty on a line and save: the line is replaced by one line per item of the bundle, which are then ordinary lines. Do not give a bundle line a rate, discount or batch; do not expand a bundle by hand.
|
|
3040
|
+
- When the user names a set, look for it with list_documents doctype="item-bundle" (or the item) before listing single items yourself.
|
|
3041
|
+
|
|
3042
|
+
### Addresses
|
|
3043
|
+
- A customer can have several addresses (master_type="address": customer, label, is_billing, is_shipping, is_default_billing, is_default_shipping, recipient_name, contact_person, address, zip_code, city, country, instructions). Search them with search_masters master_type="address" and the customer's name.
|
|
3044
|
+
- Quotation, Sales Order, Delivery Note and Sales Invoice carry `billing_address` and `shipping_address` (address record ids of that customer) and `billing_address_display` / `shipping_address_display` (the text that prints). Leave them out to get the customer's defaults; documents made from an order follow the order.
|
|
3045
|
+
- When an order names where the goods must go and that address is not on record, put the text in `shipping_address_display` (recipient first, one line per row) without a link: what the document says takes precedence. Do not create an address record for a one-off address unless the user asks.
|
|
3046
|
+
- Never guess between several addresses of a customer: use the default, or ask.
|
|
3047
|
+
|
|
3037
3048
|
### Storage locations (places inside a warehouse)
|
|
3038
3049
|
- A warehouse with `use_locations=1` has storage locations (master `storage-location`: warehouse + location label, e.g. "A12"). The same label may exist in several warehouses.
|
|
3039
3050
|
- In such a warehouse every stock-moving line names its location: `location` on Delivery Note, Purchase Receipt and invoice lines (with update_stock=1); on Stock Entry lines `s_location` for the source side and `t_location` for the target side. Drafts may be saved without it; submit is refused. A warehouse without storage locations takes no location.
|
|
@@ -311,6 +311,18 @@ def _render_commercial_pdf(doctype, name, doc, contract, layout=None, blocked=No
|
|
|
311
311
|
line.lstrip().startswith(">>") for line in _remarks.splitlines()
|
|
312
312
|
)
|
|
313
313
|
|
|
314
|
+
# The document's own addresses (lambda_erp/addresses.py): a delivery note
|
|
315
|
+
# is addressed to where the goods go, everything else to where the
|
|
316
|
+
# invoice goes, with the delivery address below it when it differs.
|
|
317
|
+
from lambda_erp.addresses import delivery_instructions, document_address_lines
|
|
318
|
+
billing_lines = document_address_lines(doc, "billing")
|
|
319
|
+
shipping_lines = document_address_lines(doc, "shipping")
|
|
320
|
+
if file == "delivery_note.html":
|
|
321
|
+
address_lines, delivery_lines = shipping_lines or billing_lines, []
|
|
322
|
+
else:
|
|
323
|
+
address_lines = billing_lines
|
|
324
|
+
delivery_lines = shipping_lines if shipping_lines and shipping_lines != billing_lines else []
|
|
325
|
+
|
|
314
326
|
context = dict(
|
|
315
327
|
doc=doc,
|
|
316
328
|
pdf_status=contract["status"],
|
|
@@ -322,6 +334,10 @@ def _render_commercial_pdf(doctype, name, doc, contract, layout=None, blocked=No
|
|
|
322
334
|
party_label=party_label,
|
|
323
335
|
party_name=party_name,
|
|
324
336
|
party_info=party_info,
|
|
337
|
+
address_lines=address_lines,
|
|
338
|
+
delivery_lines=delivery_lines,
|
|
339
|
+
delivery_label="Delivery address",
|
|
340
|
+
delivery_instructions=delivery_instructions(doc) if file == "delivery_note.html" else None,
|
|
325
341
|
currency=currency,
|
|
326
342
|
meta_fields=meta_fields,
|
|
327
343
|
items=items,
|
|
@@ -91,6 +91,10 @@ PROFILES.update({
|
|
|
91
91
|
fields=('company', 'customer', 'warehouse', 'posting_date', 'external_reference', 'sales_invoice', 'remarks'),
|
|
92
92
|
required=('customer', 'warehouse', 'posting_date', 'items'),
|
|
93
93
|
tables=(PDFTable('items', ('item_code', 'item_name', 'qty', 'uom', 'batch_no'), ('item_code', 'qty'), True),)),
|
|
94
|
+
'Item Bundle': PDFProfile('record', 'Item bundle',
|
|
95
|
+
fields=('item_code', 'bundle_name', 'description', 'disabled'),
|
|
96
|
+
required=('item_code', 'items'),
|
|
97
|
+
tables=(PDFTable('items', ('item_code', 'item_name', 'qty'), ('item_code', 'qty'), True),)),
|
|
94
98
|
'Stock Reservation': PDFProfile('record', 'Stock reservation overview',
|
|
95
99
|
fields=('item_code', 'warehouse', 'reserved_qty', 'sales_order', 'customer', 'status', 'remarks', 'reserved_by', 'company'),
|
|
96
100
|
required=('item_code', 'warehouse', 'reserved_qty')),
|
|
@@ -67,6 +67,10 @@ DELETE_REFERENCE_CHECKS = {
|
|
|
67
67
|
"serial-no": [
|
|
68
68
|
('SELECT 1 FROM "Serial Movement" WHERE serial = ? LIMIT 1', "stock movement"),
|
|
69
69
|
],
|
|
70
|
+
"address": [
|
|
71
|
+
(f'SELECT 1 FROM "{table}" WHERE billing_address = ? OR shipping_address = ? LIMIT 1', table.lower())
|
|
72
|
+
for table in ("Quotation", "Sales Order", "Delivery Note", "Sales Invoice")
|
|
73
|
+
],
|
|
70
74
|
"storage-location": [
|
|
71
75
|
('SELECT 1 FROM "Stock Ledger Entry" s JOIN "Storage Location" l ON l.warehouse = s.warehouse '
|
|
72
76
|
'AND l.location = s.location WHERE l.name = ? LIMIT 1', "stock ledger entry"),
|
|
@@ -222,6 +226,7 @@ def _normalize_master_data(data: dict) -> dict:
|
|
|
222
226
|
MASTER_LINK_FIELDS = {
|
|
223
227
|
'customer': {'default_price_list': 'Price List'},
|
|
224
228
|
'supplier': {'default_price_list': 'Price List'},
|
|
229
|
+
'address': {'customer': 'Customer'},
|
|
225
230
|
'company': {'default_price_list': 'Price List'},
|
|
226
231
|
'item': {'default_warehouse': 'Warehouse'},
|
|
227
232
|
'warehouse': {'company': 'Company', 'account': 'Account', 'parent_warehouse': 'Warehouse',
|
|
@@ -284,6 +289,11 @@ def _validate_master_input(master_type, doctype, data, name=None):
|
|
|
284
289
|
raise ValidationError('Cannot change master identity; create a new record instead')
|
|
285
290
|
merged = dict(db.get_value(doctype, name, list(allowed)) or {}) if name else {}
|
|
286
291
|
merged.update(data)
|
|
292
|
+
if master_type == 'address':
|
|
293
|
+
# The title is made from customer, label and town, never typed.
|
|
294
|
+
from lambda_erp.addresses import address_title
|
|
295
|
+
merged['address_title'] = data['address_title'] = address_title(
|
|
296
|
+
merged, db.get_value('Customer', merged.get('customer'), 'customer_name') if merged.get('customer') else None)
|
|
287
297
|
for field in master_requirements(master_type)['required']:
|
|
288
298
|
if missing(merged.get(field)):
|
|
289
299
|
raise ValidationError(f'{doctype}: {field} is required')
|
|
@@ -298,6 +308,9 @@ def _validate_master_input(master_type, doctype, data, name=None):
|
|
|
298
308
|
_validate_batch(db, merged, name)
|
|
299
309
|
if master_type == 'serial-no':
|
|
300
310
|
_validate_serial(db, data, name)
|
|
311
|
+
if master_type == 'address':
|
|
312
|
+
from lambda_erp.addresses import validate_address
|
|
313
|
+
validate_address(merged)
|
|
301
314
|
# A user restricted to assigned records cannot write one outside of them
|
|
302
315
|
# (a new customer or warehouse is never one of the assigned).
|
|
303
316
|
permissions.require_record_in_scope(doctype, {**merged, 'name': name})
|
|
@@ -480,6 +493,9 @@ def _create_master_record(master_type: str, data: dict) -> dict:
|
|
|
480
493
|
doc["default_currency"] = companies[0].get("default_currency") or "USD"
|
|
481
494
|
|
|
482
495
|
db.insert(doctype, doc)
|
|
496
|
+
if master_type == 'address':
|
|
497
|
+
from lambda_erp.addresses import finish_address
|
|
498
|
+
finish_address(doc["name"])
|
|
483
499
|
row = db.get_all(doctype, filters={"name": doc["name"]}, fields=["*"])[0]
|
|
484
500
|
return _echo_identity_alias(master_type, row)
|
|
485
501
|
|
|
@@ -538,6 +554,9 @@ def _update_master_record(master_type: str, name: str, data: dict) -> dict:
|
|
|
538
554
|
update_fields["modified"] = now()
|
|
539
555
|
if update_fields:
|
|
540
556
|
db.set_value(doctype, name, update_fields)
|
|
557
|
+
if master_type == 'address':
|
|
558
|
+
from lambda_erp.addresses import finish_address
|
|
559
|
+
finish_address(name)
|
|
541
560
|
if master_type == 'batch':
|
|
542
561
|
# A batch's expiry date and block decide what may be sold: keep the trail.
|
|
543
562
|
from lambda_erp.stock.stock_ledger import log_batch_changes
|
|
@@ -38,6 +38,7 @@ from lambda_erp.assets.reservation import Reservation
|
|
|
38
38
|
from lambda_erp.stock.reservation import StockReservation
|
|
39
39
|
from lambda_erp.stock.consignment import ConsignmentWithdrawal
|
|
40
40
|
from lambda_erp.stock.stock_count import StockCount
|
|
41
|
+
from lambda_erp.bundles import ItemBundle
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
# --- Doctype registries ---
|
|
@@ -73,6 +74,7 @@ DOCUMENT_CLASSES = {
|
|
|
73
74
|
"Consignment Withdrawal": ConsignmentWithdrawal,
|
|
74
75
|
# Counted quantities; submitting books the differences with a reason.
|
|
75
76
|
"Stock Count": StockCount,
|
|
77
|
+
"Item Bundle": ItemBundle,
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
CONVERTERS = {
|
|
@@ -106,6 +108,8 @@ MASTER_TABLES = {
|
|
|
106
108
|
"storage-location": ("Storage Location", "location"),
|
|
107
109
|
# One row per (item, serial number); written by the stock ledger.
|
|
108
110
|
"serial-no": ("Serial No", "serial_no"),
|
|
111
|
+
# Further addresses of a customer (lambda_erp/addresses.py).
|
|
112
|
+
"address": ("Address", "address_title"),
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
# Auto-naming prefixes: masters created without an explicit `name` get a
|
|
@@ -118,11 +122,12 @@ MASTER_NAME_PREFIXES = {
|
|
|
118
122
|
"warehouse": "WH",
|
|
119
123
|
"batch": "BATCH",
|
|
120
124
|
"storage-location": "LOC",
|
|
125
|
+
"address": "ADDR",
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
# Minimum numeric suffix width for sequential plugin master ids. Core masters
|
|
124
129
|
# retain the historical three-digit form; plugins can opt into e.g. FIDX-0001.
|
|
125
|
-
MASTER_NAME_DIGITS: dict[str, int] = {"batch": 5, "storage-location": 5}
|
|
130
|
+
MASTER_NAME_DIGITS: dict[str, int] = {"batch": 5, "storage-location": 5, "address": 5}
|
|
126
131
|
|
|
127
132
|
# High-volume plugin masters can opt out of sequential ids. Sequential naming
|
|
128
133
|
# must inspect existing suffixes after a process restart; opaque random ids keep
|
|
@@ -100,14 +100,24 @@
|
|
|
100
100
|
</div>
|
|
101
101
|
<div class="party-block" style="text-align: right;">
|
|
102
102
|
<h3>{{ party_label }}</h3>
|
|
103
|
-
<div class="name">{{ party_name }}</div>
|
|
103
|
+
<div class="name">{{ address_lines[0] if address_lines else party_name }}</div>
|
|
104
104
|
{% if party_info %}
|
|
105
|
+
{% if address_lines %}
|
|
106
|
+
{# The document's own address (lambda_erp/addresses.py); its first line is the recipient. #}
|
|
107
|
+
{% for line in address_lines[1:] %}<div class="detail">{{ line }}</div>{% endfor %}
|
|
108
|
+
{% else %}
|
|
105
109
|
{% if party_info.get("address") %}<div class="detail">{{ party_info.address }}</div>{% endif %}
|
|
106
110
|
{% if party_info.get("city") or party_info.get("zip_code") or party_info.get("country") %}<div class="detail">{{ party_info.get("city", "") }}{% if party_info.get("zip_code") %} {{ party_info.zip_code }}{% endif %}{% if party_info.get("country") %}, {{ party_info.country }}{% endif %}</div>{% endif %}
|
|
111
|
+
{% endif %}
|
|
107
112
|
{% if party_info.get("email") %}<div class="detail">{{ party_info.email }}</div>{% endif %}
|
|
108
113
|
{% if party_info.get("phone") %}<div class="detail">{{ party_info.phone }}</div>{% endif %}
|
|
109
114
|
{% if party_info.get("tax_id") %}<div class="detail">Tax ID: {{ party_info.tax_id }}</div>{% endif %}
|
|
110
115
|
{% endif %}
|
|
116
|
+
{% if delivery_lines %}
|
|
117
|
+
<div class="detail" style="margin-top: 6px;"><strong>{{ delivery_label }}</strong></div>
|
|
118
|
+
{% for line in delivery_lines %}<div class="detail">{{ line }}</div>{% endfor %}
|
|
119
|
+
{% endif %}
|
|
120
|
+
{% if delivery_instructions %}<div class="detail" style="margin-top: 4px;">{{ delivery_instructions }}</div>{% endif %}
|
|
111
121
|
</div>
|
|
112
122
|
</div>
|
|
113
123
|
|
|
@@ -96,14 +96,24 @@
|
|
|
96
96
|
</div>
|
|
97
97
|
<div class="party-block" style="text-align: right;">
|
|
98
98
|
<h3>{{ party_label }}</h3>
|
|
99
|
-
<div class="name">{{ party_name }}</div>
|
|
99
|
+
<div class="name">{{ address_lines[0] if address_lines else party_name }}</div>
|
|
100
100
|
{% if party_info %}
|
|
101
|
+
{% if address_lines %}
|
|
102
|
+
{# The document's own address (lambda_erp/addresses.py); its first line is the recipient. #}
|
|
103
|
+
{% for line in address_lines[1:] %}<div class="detail">{{ line }}</div>{% endfor %}
|
|
104
|
+
{% else %}
|
|
101
105
|
{% if party_info.get("address") %}<div class="detail">{{ party_info.address }}</div>{% endif %}
|
|
102
106
|
{% if party_info.get("city") or party_info.get("zip_code") or party_info.get("country") %}<div class="detail">{{ party_info.get("city", "") }}{% if party_info.get("zip_code") %} {{ party_info.zip_code }}{% endif %}{% if party_info.get("country") %}, {{ party_info.country }}{% endif %}</div>{% endif %}
|
|
107
|
+
{% endif %}
|
|
103
108
|
{% if party_info.get("email") %}<div class="detail">{{ party_info.email }}</div>{% endif %}
|
|
104
109
|
{% if party_info.get("phone") %}<div class="detail">{{ party_info.phone }}</div>{% endif %}
|
|
105
110
|
{% if party_info.get("tax_id") %}<div class="detail">Tax ID: {{ party_info.tax_id }}</div>{% endif %}
|
|
106
111
|
{% endif %}
|
|
112
|
+
{% if delivery_lines %}
|
|
113
|
+
<div class="detail" style="margin-top: 6px;"><strong>{{ delivery_label }}</strong></div>
|
|
114
|
+
{% for line in delivery_lines %}<div class="detail">{{ line }}</div>{% endfor %}
|
|
115
|
+
{% endif %}
|
|
116
|
+
{% if delivery_instructions %}<div class="detail" style="margin-top: 4px;">{{ delivery_instructions }}</div>{% endif %}
|
|
107
117
|
</div>
|
|
108
118
|
</div>
|
|
109
119
|
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Several addresses per customer, and the two a sales document uses.
|
|
2
|
+
|
|
3
|
+
A customer keeps its main address on the customer record, as before. On top
|
|
4
|
+
of it, any number of Address records: accounting, central store, a ward.
|
|
5
|
+
Each says what it is for (invoices, deliveries or both) and one of each kind
|
|
6
|
+
can be the default.
|
|
7
|
+
|
|
8
|
+
A sales document (quotation, sales order, delivery note, sales invoice)
|
|
9
|
+
carries an invoice address and a delivery address. Each is a link to an
|
|
10
|
+
Address plus the text as it is printed:
|
|
11
|
+
|
|
12
|
+
billing_address / billing_address_display
|
|
13
|
+
shipping_address / shipping_address_display
|
|
14
|
+
|
|
15
|
+
The text is a copy taken when the document is saved, so a document that was
|
|
16
|
+
issued keeps its address when the master changes. It can be edited for one
|
|
17
|
+
document, or typed in without a link when an order names an address that is
|
|
18
|
+
not on record: what the document says takes precedence.
|
|
19
|
+
|
|
20
|
+
Where a document has neither, it inherits from the document it was made
|
|
21
|
+
from (order from quotation, delivery from order, invoice from delivery or
|
|
22
|
+
order); else it takes the customer's default of that kind; else it stays
|
|
23
|
+
empty and the customer's main address is printed.
|
|
24
|
+
|
|
25
|
+
See docs/addresses.md.
|
|
26
|
+
"""
|
|
27
|
+
from lambda_erp.database import get_db
|
|
28
|
+
from lambda_erp.exceptions import ValidationError
|
|
29
|
+
from lambda_erp.utils import flt, now
|
|
30
|
+
|
|
31
|
+
# document type -> where an inherited address comes from: (line field naming
|
|
32
|
+
# the source line or document, table to resolve a line to its document or
|
|
33
|
+
# None, source document type), first match wins.
|
|
34
|
+
SOURCES = {
|
|
35
|
+
"Quotation": (),
|
|
36
|
+
"Sales Order": (("quotation_item", "Quotation Item", "Quotation"),),
|
|
37
|
+
"Delivery Note": (("against_sales_order", None, "Sales Order"),),
|
|
38
|
+
"Sales Invoice": (("delivery_note", None, "Delivery Note"), ("sales_order", None, "Sales Order")),
|
|
39
|
+
}
|
|
40
|
+
KINDS = {"billing": ("is_billing", "is_default_billing", "invoices"),
|
|
41
|
+
"shipping": ("is_shipping", "is_default_shipping", "deliveries")}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def register_address_document(doctype, sources=()):
|
|
45
|
+
"""Plugin seam: a further document type with a customer that carries
|
|
46
|
+
billing_address / shipping_address (and their _display columns, which the
|
|
47
|
+
plugin adds to its table). `sources` as in SOURCES."""
|
|
48
|
+
SOURCES[doctype] = tuple(sources)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def format_address(address, customer_name=None):
|
|
52
|
+
"""An Address record as the lines that are printed."""
|
|
53
|
+
lines = [address.get("recipient_name") or customer_name or "", address.get("contact_person") or "",
|
|
54
|
+
*str(address.get("address") or "").splitlines(),
|
|
55
|
+
" ".join(part for part in (address.get("zip_code"), address.get("city")) if part),
|
|
56
|
+
address.get("country") or ""]
|
|
57
|
+
return "\n".join(line.strip() for line in lines if line and line.strip())
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def address_title(address, customer_name=None):
|
|
61
|
+
"""What an address is called when picking it: customer, label, town."""
|
|
62
|
+
parts = [customer_name or address.get("customer") or "", address.get("label") or "", address.get("city") or ""]
|
|
63
|
+
return ", ".join(part for part in parts if part)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _columns(doctype):
|
|
67
|
+
return get_db()._get_table_columns(doctype)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _source_addresses(doc):
|
|
71
|
+
"""(billing link, billing text, shipping link, shipping text) of the
|
|
72
|
+
document this one was made from, or None."""
|
|
73
|
+
db = get_db()
|
|
74
|
+
for field, line_table, source in SOURCES.get(doc.DOCTYPE, ()):
|
|
75
|
+
if "billing_address" not in _columns(source):
|
|
76
|
+
continue
|
|
77
|
+
for row in doc.get("items") or ():
|
|
78
|
+
reference = row.get(field)
|
|
79
|
+
if not reference:
|
|
80
|
+
continue
|
|
81
|
+
parent = db.get_value(line_table, reference, "parent") if line_table else reference
|
|
82
|
+
found = db.get_value(source, parent, ["customer", "billing_address", "billing_address_display",
|
|
83
|
+
"shipping_address", "shipping_address_display"]) if parent else None
|
|
84
|
+
if found and found.get("customer") == doc.get("customer"):
|
|
85
|
+
return found
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def default_address(customer, kind):
|
|
90
|
+
"""The customer's default Address of a kind ('billing' / 'shipping'), or None."""
|
|
91
|
+
usable, default, _ = KINDS[kind]
|
|
92
|
+
rows = get_db().sql(
|
|
93
|
+
f'SELECT name FROM "Address" WHERE customer = ? AND COALESCE(disabled, 0) = 0 '
|
|
94
|
+
f'AND COALESCE({default}, 0) = 1 AND COALESCE({usable}, 0) = 1 ORDER BY name LIMIT 1', [customer])
|
|
95
|
+
return rows[0]["name"] if rows else None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def resolve_document_addresses(doc):
|
|
99
|
+
"""Fill, check and snapshot a sales document's two addresses. Called
|
|
100
|
+
before the document validates, on every save and on submit."""
|
|
101
|
+
if doc.DOCTYPE not in SOURCES:
|
|
102
|
+
return
|
|
103
|
+
db = get_db()
|
|
104
|
+
if "billing_address" not in _columns(doc.DOCTYPE) or not _columns("Address"):
|
|
105
|
+
return
|
|
106
|
+
customer = doc.get("customer")
|
|
107
|
+
if not customer:
|
|
108
|
+
return
|
|
109
|
+
stored = db.get_value(doc.DOCTYPE, doc.name, [
|
|
110
|
+
"customer", "billing_address", "billing_address_display", "shipping_address",
|
|
111
|
+
"shipping_address_display"]) if getattr(doc, "_persisted", False) and doc.name else None
|
|
112
|
+
customer_name = db.get_value("Customer", customer, "customer_name") or customer
|
|
113
|
+
inherited = None
|
|
114
|
+
for kind, (usable, _, purpose) in KINDS.items():
|
|
115
|
+
link_field, text_field = f"{kind}_address", f"{kind}_address_display"
|
|
116
|
+
link = str(doc._data.get(link_field) or "").strip() or None
|
|
117
|
+
text = str(doc._data.get(text_field) or "").strip() or None
|
|
118
|
+
was_link = (stored or {}).get(link_field) or None
|
|
119
|
+
was_text = str((stored or {}).get(text_field) or "").strip() or None
|
|
120
|
+
if stored and stored.get("customer") != customer and link == was_link:
|
|
121
|
+
# Another customer now: the old customer's address does not follow.
|
|
122
|
+
link = text = was_link = was_text = None
|
|
123
|
+
if not link and not text:
|
|
124
|
+
if inherited is None:
|
|
125
|
+
inherited = _source_addresses(doc) or {}
|
|
126
|
+
link, text = inherited.get(link_field) or None, inherited.get(text_field) or None
|
|
127
|
+
if not link and not text:
|
|
128
|
+
link = default_address(customer, kind)
|
|
129
|
+
if link:
|
|
130
|
+
address = db.get_all("Address", filters={"name": link}, fields=["*"])
|
|
131
|
+
address = address[0] if address else None
|
|
132
|
+
if not address:
|
|
133
|
+
raise ValidationError(f"{doc.DOCTYPE}: {link_field} {link} does not exist")
|
|
134
|
+
if address.get("customer") != customer:
|
|
135
|
+
raise ValidationError(
|
|
136
|
+
f"{doc.DOCTYPE}: address {link} belongs to customer {address.get('customer')}, not {customer}")
|
|
137
|
+
if link != was_link:
|
|
138
|
+
if flt(address.get("disabled")):
|
|
139
|
+
raise ValidationError(f"{doc.DOCTYPE}: address {link} is disabled")
|
|
140
|
+
if not flt(address.get(usable)):
|
|
141
|
+
raise ValidationError(f"{doc.DOCTYPE}: address {link} is not marked for {purpose}")
|
|
142
|
+
if not text or (link != was_link and text == was_text):
|
|
143
|
+
# A newly picked address replaces the text of the previous one,
|
|
144
|
+
# unless the text was changed in the same save.
|
|
145
|
+
text = format_address(address, customer_name)
|
|
146
|
+
doc._data[link_field], doc._data[text_field] = link, text
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def finish_address(name):
|
|
150
|
+
"""After an Address was saved: its title, and one default per customer and kind."""
|
|
151
|
+
db = get_db()
|
|
152
|
+
rows = db.get_all("Address", filters={"name": name}, fields=["*"])
|
|
153
|
+
if not rows:
|
|
154
|
+
return
|
|
155
|
+
address = rows[0]
|
|
156
|
+
customer_name = db.get_value("Customer", address.get("customer"), "customer_name")
|
|
157
|
+
values = {"address_title": address_title(address, customer_name)}
|
|
158
|
+
for usable, default, _ in KINDS.values():
|
|
159
|
+
if flt(address.get(default)):
|
|
160
|
+
if not flt(address.get(usable)) or flt(address.get("disabled")):
|
|
161
|
+
values[default] = 0
|
|
162
|
+
else:
|
|
163
|
+
db.sql(f'UPDATE "Address" SET {default} = 0, modified = ? WHERE customer = ? AND name <> ? '
|
|
164
|
+
f'AND COALESCE({default}, 0) = 1', [now(), address.get("customer"), name])
|
|
165
|
+
db.set_value("Address", name, values)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def validate_address(merged):
|
|
169
|
+
"""Checks on an Address before it is saved."""
|
|
170
|
+
if not str(merged.get("label") or "").strip():
|
|
171
|
+
raise ValidationError("Address: label is required (what the address is: Accounting, Central store, ...)")
|
|
172
|
+
if not any(str(merged.get(field) or "").strip() for field in ("address", "city", "zip_code")):
|
|
173
|
+
raise ValidationError("Address: give at least the street, the zip code or the town")
|
|
174
|
+
# Left out, an address is for both (the column defaults).
|
|
175
|
+
usable = [flt(1 if merged.get(field) in (None, "") else merged.get(field)) for field in ("is_billing", "is_shipping")]
|
|
176
|
+
if not any(usable):
|
|
177
|
+
raise ValidationError("Address: mark it for invoices, for deliveries or both")
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def document_address_lines(doc, kind):
|
|
181
|
+
"""The lines to print for a document's invoice ('billing') or delivery
|
|
182
|
+
('shipping') address, or [] when the document has none."""
|
|
183
|
+
return [line for line in str(doc.get(f"{kind}_address_display") or "").splitlines() if line.strip()]
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def delivery_instructions(doc):
|
|
187
|
+
"""Instructions of the delivery address a document links, for delivery notes."""
|
|
188
|
+
link = doc.get("shipping_address")
|
|
189
|
+
if not link or not _columns("Address"):
|
|
190
|
+
return None
|
|
191
|
+
return get_db().get_value("Address", link, "instructions") or None
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Item bundles: one item code that stands for several items.
|
|
2
|
+
|
|
3
|
+
A bundle is an item that is not stocked, sold or priced itself. Its Item
|
|
4
|
+
Bundle record lists the items it stands for, with a quantity each. Putting
|
|
5
|
+
the bundle on a line of a sales document replaces that line by one line per
|
|
6
|
+
component when the document is saved:
|
|
7
|
+
|
|
8
|
+
line SET-KNEE, qty 2
|
|
9
|
+
becomes IMPLANT-A, qty 2 (1 per set)
|
|
10
|
+
SCREW-4, qty 8 (4 per set)
|
|
11
|
+
|
|
12
|
+
From there the components are ordinary lines: each is priced, reserved,
|
|
13
|
+
picked by batch, delivered and invoiced on its own, and can be changed or
|
|
14
|
+
removed on the draft. What differs per customer (the tool for the left or
|
|
15
|
+
the right hand) is simply not part of the bundle and is added as a line.
|
|
16
|
+
|
|
17
|
+
Each line that came from a bundle keeps `bundle_item` and `bundle_qty` (the
|
|
18
|
+
bundle and how many of it were entered), so documents can say what was
|
|
19
|
+
ordered as a set.
|
|
20
|
+
|
|
21
|
+
See docs/bundles.md.
|
|
22
|
+
"""
|
|
23
|
+
from lambda_erp.database import get_db
|
|
24
|
+
from lambda_erp.exceptions import ValidationError
|
|
25
|
+
from lambda_erp.model import Document
|
|
26
|
+
from lambda_erp.utils import _dict, flt
|
|
27
|
+
|
|
28
|
+
# Document types whose item lines expand bundles.
|
|
29
|
+
EXPANDING = {"Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"}
|
|
30
|
+
MAX_DEPTH = 5
|
|
31
|
+
|
|
32
|
+
# What a component line takes over from the bundle line; everything about the
|
|
33
|
+
# item itself (name, unit, price, batch) is its own.
|
|
34
|
+
CARRIED = ("warehouse", "delivery_date", "cost_center", "income_account", "location")
|
|
35
|
+
# What a bundle line may not carry: it has no price and no stock of its own.
|
|
36
|
+
REFUSED = ("rate", "price_list_rate", "discount_percentage", "discount_amount", "batch_no", "serial_no")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def register_bundle_document(doctype):
|
|
40
|
+
"""Plugin seam: a further document type whose `items` lines expand
|
|
41
|
+
bundles (its line table needs bundle_item TEXT and bundle_qty REAL)."""
|
|
42
|
+
EXPANDING.add(doctype)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def bundle_of(item_code):
|
|
46
|
+
"""The enabled Item Bundle record of an item code, or None."""
|
|
47
|
+
db = get_db()
|
|
48
|
+
if not item_code or not db._get_table_columns("Item Bundle"):
|
|
49
|
+
return None
|
|
50
|
+
rows = db.sql('SELECT name FROM "Item Bundle" WHERE item_code = ? AND COALESCE(disabled, 0) = 0 '
|
|
51
|
+
'AND COALESCE(discarded, 0) = 0 LIMIT 1', [item_code])
|
|
52
|
+
return rows[0]["name"] if rows else None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def components(item_code, qty=1.0, _path=()):
|
|
56
|
+
"""The items a bundle stands for, as [(item_code, qty)], bundles inside
|
|
57
|
+
bundles resolved. `qty` is how many of the bundle."""
|
|
58
|
+
name = bundle_of(item_code)
|
|
59
|
+
if not name:
|
|
60
|
+
return [(item_code, flt(qty))]
|
|
61
|
+
if item_code in _path or len(_path) >= MAX_DEPTH:
|
|
62
|
+
raise ValidationError(f"Item Bundle {item_code} contains itself: {' > '.join((*_path, item_code))}")
|
|
63
|
+
result = []
|
|
64
|
+
for row in get_db().get_all("Item Bundle Item", filters={"parent": name}, fields=["item_code", "qty"],
|
|
65
|
+
order_by="idx"):
|
|
66
|
+
result.extend(components(row["item_code"], flt(qty) * flt(row["qty"]), (*_path, item_code)))
|
|
67
|
+
return result
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def expand_bundle_lines(doc):
|
|
71
|
+
"""Replace every bundle line of a sales document by its component lines.
|
|
72
|
+
Called before the document validates, on every save and on submit; a
|
|
73
|
+
document without bundle lines is left exactly as it is."""
|
|
74
|
+
if doc.DOCTYPE not in EXPANDING:
|
|
75
|
+
return
|
|
76
|
+
lines = doc.get("items") or []
|
|
77
|
+
if not any(bundle_of(row.get("item_code")) for row in lines):
|
|
78
|
+
return
|
|
79
|
+
table = doc.CHILD_TABLES["items"][0]
|
|
80
|
+
stamps = "bundle_item" in get_db()._get_table_columns(table)
|
|
81
|
+
expanded = []
|
|
82
|
+
for position, row in enumerate(lines, 1):
|
|
83
|
+
code = row.get("item_code")
|
|
84
|
+
if not bundle_of(code):
|
|
85
|
+
expanded.append(row)
|
|
86
|
+
continue
|
|
87
|
+
qty = flt(row.get("qty"))
|
|
88
|
+
if not qty:
|
|
89
|
+
raise ValidationError(f"{doc.DOCTYPE} row {position}: bundle {code} needs a quantity")
|
|
90
|
+
priced = [field for field in REFUSED if row.get(field) not in (None, "", 0, 0.0)]
|
|
91
|
+
if priced:
|
|
92
|
+
raise ValidationError(
|
|
93
|
+
f"{doc.DOCTYPE} row {position}: {code} is a bundle and has no {', '.join(priced)} of its own. "
|
|
94
|
+
f"Leave it out; the items of the bundle are priced and picked as their own lines")
|
|
95
|
+
for item_code, item_qty in components(code, qty):
|
|
96
|
+
line = _dict({field: row.get(field) for field in CARRIED if row.get(field) not in (None, "")})
|
|
97
|
+
line.update(item_code=item_code, qty=item_qty)
|
|
98
|
+
if stamps:
|
|
99
|
+
line.update(bundle_item=code, bundle_qty=qty)
|
|
100
|
+
expanded.append(line)
|
|
101
|
+
doc._children["items"] = []
|
|
102
|
+
for line in expanded:
|
|
103
|
+
doc.append("items", line)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class ItemBundle(Document):
|
|
107
|
+
DOCTYPE = "Item Bundle"
|
|
108
|
+
CHILD_TABLES = {"items": ("Item Bundle Item", None)}
|
|
109
|
+
PREFIX = "BNDL"
|
|
110
|
+
REQUIRED_FIELDS = ("item_code", "items")
|
|
111
|
+
CHILD_REQUIREMENTS = {"items": {"required": ["item_code", "qty"]}}
|
|
112
|
+
CONDITIONAL_REQUIREMENTS = (
|
|
113
|
+
"item_code is the bundle: an item that is not a stock item and has no batch or serial tracking. "
|
|
114
|
+
"Create that item first; one bundle per item.",
|
|
115
|
+
"items lists what the bundle stands for, with the quantity per one bundle. A component can itself be a "
|
|
116
|
+
"bundle. The bundle cannot contain itself.",
|
|
117
|
+
"On quotations, sales orders, delivery notes and sales / POS invoices, a line with the bundle's item_code "
|
|
118
|
+
"is replaced by one line per component when the document is saved. A bundle has no price: the components "
|
|
119
|
+
"are priced as usual.",
|
|
120
|
+
"Changing a bundle changes what new lines expand to; lines on existing documents stay as they are.",
|
|
121
|
+
)
|
|
122
|
+
LINK_FIELDS = {"item_code": "Item"}
|
|
123
|
+
CHILD_LINK_FIELDS = {"items": {"item_code": "Item"}}
|
|
124
|
+
|
|
125
|
+
def validate(self):
|
|
126
|
+
db = get_db()
|
|
127
|
+
item = db.get_value("Item", self.item_code, ["item_name", "is_stock_item", "has_batch_no", "has_serial_no"])
|
|
128
|
+
if not item:
|
|
129
|
+
raise ValidationError(f"Item Bundle: item {self.item_code} does not exist")
|
|
130
|
+
if flt(item.get("is_stock_item")) or flt(item.get("has_batch_no")) or flt(item.get("has_serial_no")):
|
|
131
|
+
raise ValidationError(
|
|
132
|
+
f"Item Bundle: {self.item_code} is a stock item. A bundle is an item that is not stocked itself "
|
|
133
|
+
f"(is_stock_item = 0, no batch or serial tracking)")
|
|
134
|
+
if db.sql('SELECT 1 FROM "Stock Ledger Entry" WHERE item_code = ? LIMIT 1', [self.item_code]):
|
|
135
|
+
raise ValidationError(f"Item Bundle: {self.item_code} has stock movements and cannot become a bundle")
|
|
136
|
+
twin = db.sql('SELECT name FROM "Item Bundle" WHERE item_code = ? AND name <> ? '
|
|
137
|
+
'AND COALESCE(discarded, 0) = 0 LIMIT 1', [self.item_code, self.name or ""])
|
|
138
|
+
if twin:
|
|
139
|
+
raise ValidationError(f"Item {self.item_code} already has bundle {twin[0]['name']}; change that one")
|
|
140
|
+
if not self._data.get("bundle_name"):
|
|
141
|
+
self._data["bundle_name"] = item.get("item_name") or self.item_code
|
|
142
|
+
rows = self.get("items") or []
|
|
143
|
+
if not rows:
|
|
144
|
+
raise ValidationError("Item Bundle: at least one item is required")
|
|
145
|
+
seen = set()
|
|
146
|
+
for idx, row in enumerate(rows, 1):
|
|
147
|
+
code = row.get("item_code")
|
|
148
|
+
if not code or not db.exists("Item", code):
|
|
149
|
+
raise ValidationError(f"Item Bundle row {idx}: item {code or ''} does not exist")
|
|
150
|
+
if code == self.item_code:
|
|
151
|
+
raise ValidationError(f"Item Bundle row {idx}: a bundle cannot contain itself")
|
|
152
|
+
if code in seen:
|
|
153
|
+
raise ValidationError(f"Item Bundle row {idx}: {code} is listed twice; give it one line with the total quantity")
|
|
154
|
+
seen.add(code)
|
|
155
|
+
try:
|
|
156
|
+
qty = float(row.get("qty"))
|
|
157
|
+
except (TypeError, ValueError):
|
|
158
|
+
raise ValidationError(f"Item Bundle row {idx}: Qty must be a number")
|
|
159
|
+
if not qty > 0 or qty != qty or qty == float("inf"):
|
|
160
|
+
raise ValidationError(f"Item Bundle row {idx}: Qty must be positive")
|
|
161
|
+
row["qty"] = qty
|
|
162
|
+
row["item_name"] = db.get_value("Item", code, "item_name")
|
|
163
|
+
# A component that is a bundle must not lead back here.
|
|
164
|
+
if bundle_of(code):
|
|
165
|
+
inner = [inner_code for inner_code, _ in components(code, 1, (self.item_code,))]
|
|
166
|
+
if self.item_code in inner:
|
|
167
|
+
raise ValidationError(f"Item Bundle row {idx}: {code} contains {self.item_code}")
|
|
@@ -3586,6 +3586,81 @@ def _m062_stock_document_pricing(db: "Database") -> None:
|
|
|
3586
3586
|
db.ensure_column("Supplier", "default_price_list", "TEXT")
|
|
3587
3587
|
|
|
3588
3588
|
|
|
3589
|
+
def _m063_addresses(db: "Database") -> None:
|
|
3590
|
+
"""Several addresses per customer, and an invoice and a delivery address
|
|
3591
|
+
on sales documents (see docs/addresses.md). No address is created and no
|
|
3592
|
+
document changed: a customer's main address stays where it is and is
|
|
3593
|
+
still what prints when a document has no address of its own."""
|
|
3594
|
+
db.conn.execute(db._ddl(
|
|
3595
|
+
"""CREATE TABLE IF NOT EXISTS "Address" (
|
|
3596
|
+
name TEXT PRIMARY KEY,
|
|
3597
|
+
customer TEXT NOT NULL,
|
|
3598
|
+
label TEXT,
|
|
3599
|
+
address_title TEXT,
|
|
3600
|
+
is_billing INTEGER DEFAULT 1,
|
|
3601
|
+
is_shipping INTEGER DEFAULT 1,
|
|
3602
|
+
is_default_billing INTEGER DEFAULT 0,
|
|
3603
|
+
is_default_shipping INTEGER DEFAULT 0,
|
|
3604
|
+
recipient_name TEXT,
|
|
3605
|
+
address TEXT,
|
|
3606
|
+
zip_code TEXT,
|
|
3607
|
+
city TEXT,
|
|
3608
|
+
country TEXT,
|
|
3609
|
+
contact_person TEXT,
|
|
3610
|
+
email TEXT,
|
|
3611
|
+
phone TEXT,
|
|
3612
|
+
instructions TEXT,
|
|
3613
|
+
disabled INTEGER DEFAULT 0,
|
|
3614
|
+
creation TEXT,
|
|
3615
|
+
modified TEXT
|
|
3616
|
+
)"""))
|
|
3617
|
+
db.conn.execute(db._ddl('CREATE INDEX IF NOT EXISTS "ix_address_customer" ON "Address" (customer)'))
|
|
3618
|
+
db.conn.commit()
|
|
3619
|
+
db._col_cache.pop("Address", None)
|
|
3620
|
+
db._text_col_cache.pop("Address", None)
|
|
3621
|
+
db.ensure_column("Customer", "invoice_email", "TEXT")
|
|
3622
|
+
for table in ("Quotation", "Sales Order", "Delivery Note", "Sales Invoice"):
|
|
3623
|
+
for column in ("billing_address", "billing_address_display", "shipping_address", "shipping_address_display"):
|
|
3624
|
+
db.ensure_column(table, column, "TEXT")
|
|
3625
|
+
|
|
3626
|
+
|
|
3627
|
+
def _m064_item_bundles(db: "Database") -> None:
|
|
3628
|
+
"""Item bundles: an item code that stands for several items and expands
|
|
3629
|
+
into their lines on sales documents (see docs/bundles.md). No item
|
|
3630
|
+
becomes a bundle by this migration."""
|
|
3631
|
+
db.conn.execute(db._ddl(
|
|
3632
|
+
"""CREATE TABLE IF NOT EXISTS "Item Bundle" (
|
|
3633
|
+
name TEXT PRIMARY KEY,
|
|
3634
|
+
item_code TEXT NOT NULL,
|
|
3635
|
+
bundle_name TEXT,
|
|
3636
|
+
description TEXT,
|
|
3637
|
+
disabled INTEGER DEFAULT 0,
|
|
3638
|
+
status TEXT DEFAULT 'Draft',
|
|
3639
|
+
docstatus INTEGER DEFAULT 0,
|
|
3640
|
+
discarded INTEGER DEFAULT 0,
|
|
3641
|
+
creation TEXT,
|
|
3642
|
+
modified TEXT
|
|
3643
|
+
)"""))
|
|
3644
|
+
db.conn.execute(db._ddl(
|
|
3645
|
+
"""CREATE TABLE IF NOT EXISTS "Item Bundle Item" (
|
|
3646
|
+
name TEXT PRIMARY KEY,
|
|
3647
|
+
parent TEXT NOT NULL,
|
|
3648
|
+
idx INTEGER DEFAULT 0,
|
|
3649
|
+
item_code TEXT,
|
|
3650
|
+
item_name TEXT,
|
|
3651
|
+
qty REAL DEFAULT 1
|
|
3652
|
+
)"""))
|
|
3653
|
+
db.conn.execute(db._ddl('CREATE INDEX IF NOT EXISTS "ix_item_bundle_item_code" ON "Item Bundle" (item_code)'))
|
|
3654
|
+
db.conn.execute(db._ddl('CREATE INDEX IF NOT EXISTS "ix_item_bundle_item_parent" ON "Item Bundle Item" (parent)'))
|
|
3655
|
+
db.conn.commit()
|
|
3656
|
+
for table in ("Item Bundle", "Item Bundle Item"):
|
|
3657
|
+
db._col_cache.pop(table, None)
|
|
3658
|
+
db._text_col_cache.pop(table, None)
|
|
3659
|
+
for table in ("Quotation Item", "Sales Order Item", "Delivery Note Item", "Sales Invoice Item", "POS Invoice Item"):
|
|
3660
|
+
db.ensure_column(table, "bundle_item", "TEXT")
|
|
3661
|
+
db.ensure_column(table, "bundle_qty", "REAL")
|
|
3662
|
+
|
|
3663
|
+
|
|
3589
3664
|
def _m052_access_profiles(db: "Database") -> None:
|
|
3590
3665
|
"""Access profiles narrow what a user's role allows (lambda_erp.permissions).
|
|
3591
3666
|
No profile is created and no user is assigned one: nothing changes for
|
|
@@ -3688,6 +3763,8 @@ Database.MIGRATIONS = [
|
|
|
3688
3763
|
(60, "serial_numbers", _m060_serial_numbers),
|
|
3689
3764
|
(61, "record_scope", _m061_record_scope),
|
|
3690
3765
|
(62, "stock_document_pricing", _m062_stock_document_pricing),
|
|
3766
|
+
(63, "addresses", _m063_addresses),
|
|
3767
|
+
(64, "item_bundles", _m064_item_bundles),
|
|
3691
3768
|
]
|
|
3692
3769
|
|
|
3693
3770
|
|
|
@@ -346,6 +346,11 @@ class Document:
|
|
|
346
346
|
from lambda_erp.controllers.item_prices import normalize_item_prices
|
|
347
347
|
normalize_item_prices(self)
|
|
348
348
|
self._normalize_timestamps(before_validate=True)
|
|
349
|
+
# A bundle line becomes the lines of its items before anything is priced.
|
|
350
|
+
from lambda_erp.bundles import expand_bundle_lines
|
|
351
|
+
expand_bundle_lines(self)
|
|
352
|
+
from lambda_erp.addresses import resolve_document_addresses
|
|
353
|
+
resolve_document_addresses(self)
|
|
349
354
|
self.validate()
|
|
350
355
|
normalize_item_prices(self)
|
|
351
356
|
self._require_in_scope()
|
|
@@ -404,6 +409,11 @@ class Document:
|
|
|
404
409
|
from lambda_erp.controllers.item_prices import normalize_item_prices
|
|
405
410
|
normalize_item_prices(self)
|
|
406
411
|
self._normalize_timestamps(before_validate=True)
|
|
412
|
+
# A bundle line becomes the lines of its items before anything is priced.
|
|
413
|
+
from lambda_erp.bundles import expand_bundle_lines
|
|
414
|
+
expand_bundle_lines(self)
|
|
415
|
+
from lambda_erp.addresses import resolve_document_addresses
|
|
416
|
+
resolve_document_addresses(self)
|
|
407
417
|
self.validate()
|
|
408
418
|
normalize_item_prices(self)
|
|
409
419
|
self._require_in_scope()
|
|
@@ -265,6 +265,10 @@ def _core_record_scopes():
|
|
|
265
265
|
register_record_scope(doctype, "customer", "customer")
|
|
266
266
|
for doctype in ("Item Price", "Pricing Rule", "Serial No"):
|
|
267
267
|
register_record_scope(doctype, "customer", "customer", optional=True)
|
|
268
|
+
register_record_scope("Address", "customer", "customer")
|
|
269
|
+
register_record_scope("Address", "warehouse", unrelated=True)
|
|
270
|
+
for dimension in ("customer", "warehouse"):
|
|
271
|
+
register_record_scope("Item Bundle", dimension, unrelated=True)
|
|
268
272
|
for doctype in ("Payment Entry", "Subscription", "Reservation"):
|
|
269
273
|
register_record_scope(doctype, "customer", "party", when=("party_type", "Customer"))
|
|
270
274
|
register_record_scope("Journal Entry", "customer", child="accounts", child_table="Journal Entry Account",
|
|
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
|