lambda-erp 1.4.22__tar.gz → 1.4.24__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.22 → lambda_erp-1.4.24}/PKG-INFO +1 -1
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/chat.py +3 -1
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/oauth.py +93 -2
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/pdf_profiles.py +2 -2
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/item_price.py +22 -2
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/taxes_and_totals.py +6 -1
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/database.py +17 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/consignment.py +17 -6
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/stock_count.py +11 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/units.py +49 -17
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/workflow.py +6 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/pyproject.toml +1 -1
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/.gitignore +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/LICENSE +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/README.md +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/attachments.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/auth.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/chat_links.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/deps.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/erp_context.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/errors.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/list_values.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/main.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/mentions.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/pdf.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/providers.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/record_attachments.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/record_notes.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/masters.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/reports.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/services.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/templates/document.html +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/templates/record.html +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/time_filters.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/api/write_context.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/frontend/README.md +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/addresses.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/bundles.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/controllers/tax_defaults.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/delivery_note.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.22 → lambda_erp-1.4.24}/terraform/README.md +0 -0
|
@@ -3065,7 +3065,9 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
3065
3065
|
- To enter a line in such a unit, send `qty` and `rate` in that unit and name it in `uom` (qty 2, uom "Karton", rate 290). On save the line is stored per stock unit (qty 200, rate 2.90) and keeps `order_uom`, `conversion_factor` and `order_qty` (2). Amounts are unchanged: 2 x 290 = 200 x 2.90.
|
|
3066
3066
|
- On a stored line `qty`, `rate`, delivered/billed quantities and every stock figure are in the stock unit; `order_qty` + `order_uom` say what was ordered. Tell the user both when they differ ("2 Karton = 200 Stk"). Never multiply or divide by the factor yourself before sending a line: either send the entered unit in `uom`, or send stock units.
|
|
3067
3067
|
- A unit the item does not have is refused. Do not guess a factor from a product name or from "VE"/"Pack": ask, or have an Item Unit created first.
|
|
3068
|
-
- An Item Price with `uom` set is a price per that unit (290 per Karton) and is used for lines entered in it; a price without `uom` is per stock unit.
|
|
3068
|
+
- An Item Price with `uom` set is a price per that unit (290 per Karton) and is used for lines entered in it; a price without `uom` is per stock unit. `per_qty` on an Item Price means the rate buys that many units (12.50 per 100 = 0.125 each); it is not a pack size.
|
|
3069
|
+
- An Item Unit with must_be_whole_number = 1 takes whole quantities only (2 Karton, not 1.5); say so instead of rounding.
|
|
3070
|
+
- Consignment withdrawals (qty + uom) and stock counts (counted_qty + uom) can be entered in a unit the same way; returns too (qty -1, uom "Karton").
|
|
3069
3071
|
|
|
3070
3072
|
### Addresses
|
|
3071
3073
|
- 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.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Social login (Google / Apple) for Lambda ERP.
|
|
1
|
+
"""Social login (Google / Apple / Microsoft) for Lambda ERP.
|
|
2
2
|
|
|
3
3
|
OAuth/OIDC is layered on top of the existing password auth without changing what
|
|
4
4
|
a session *is*: once a provider has proven the user's identity, we mint the very
|
|
@@ -20,6 +20,14 @@ Design notes:
|
|
|
20
20
|
The OIDC nonce is stored with that flow and verified in the ID token.
|
|
21
21
|
- A provider is simply *disabled* (its buttons hidden) whenever its env vars are
|
|
22
22
|
absent, so local/dev runs need no OAuth setup.
|
|
23
|
+
- Microsoft (any Microsoft account by default: personal accounts and the
|
|
24
|
+
users of any organisation) differs in two ways, both handled in
|
|
25
|
+
`_microsoft_identity`: the token's issuer names the user's own tenant, so
|
|
26
|
+
it is checked against the tenant id inside the token instead of one fixed
|
|
27
|
+
string; and the `email` claim is not proof of ownership for organisation
|
|
28
|
+
accounts (their admin can write any address into it, the "nOAuth" attack),
|
|
29
|
+
so the address is only taken when its domain is the one the tenant has
|
|
30
|
+
verified for the user's sign-in name.
|
|
23
31
|
"""
|
|
24
32
|
|
|
25
33
|
import os
|
|
@@ -83,14 +91,47 @@ PROVIDERS = {
|
|
|
83
91
|
"scope": "openid email name",
|
|
84
92
|
"response_mode": "form_post",
|
|
85
93
|
},
|
|
94
|
+
"microsoft": {
|
|
95
|
+
"label": "Microsoft",
|
|
96
|
+
# Per tenant; checked in _microsoft_identity.
|
|
97
|
+
"issuer": None,
|
|
98
|
+
# Built from MICROSOFT_OAUTH_TENANT in _discovery_url.
|
|
99
|
+
"discovery": None,
|
|
100
|
+
"scope": "openid email profile",
|
|
101
|
+
"response_mode": None,
|
|
102
|
+
},
|
|
86
103
|
}
|
|
87
104
|
|
|
105
|
+
# The tenant every personal Microsoft account (outlook.com, hotmail.com, ...)
|
|
106
|
+
# belongs to.
|
|
107
|
+
MICROSOFT_CONSUMER_TENANT = "9188040d-6c67-4c5b-b112-36a304b66dad"
|
|
108
|
+
_GUID = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
|
109
|
+
_EMAIL = re.compile(r"[^@\s]+@[^@\s]+\.[^@\s]+")
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _microsoft_tenant() -> str:
|
|
113
|
+
"""Who may sign in with Microsoft: "common" (default: any Microsoft
|
|
114
|
+
account), "organizations" (work and school accounts only), "consumers"
|
|
115
|
+
(personal accounts only), or one tenant's id for a single organisation."""
|
|
116
|
+
tenant = (os.environ.get("MICROSOFT_OAUTH_TENANT") or "common").strip().lower()
|
|
117
|
+
if tenant in ("common", "organizations", "consumers") or _GUID.fullmatch(tenant):
|
|
118
|
+
return tenant
|
|
119
|
+
raise HTTPException(status_code=500, detail="MICROSOFT_OAUTH_TENANT must be common, organizations, consumers or a tenant id")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _discovery_url(provider: str) -> str:
|
|
123
|
+
if provider == "microsoft":
|
|
124
|
+
return f"https://login.microsoftonline.com/{_microsoft_tenant()}/v2.0/.well-known/openid-configuration"
|
|
125
|
+
return PROVIDERS[provider]["discovery"]
|
|
126
|
+
|
|
88
127
|
|
|
89
128
|
def _client_id(provider: str) -> str | None:
|
|
90
129
|
if provider == "google":
|
|
91
130
|
return os.environ.get("GOOGLE_OAUTH_CLIENT_ID")
|
|
92
131
|
if provider == "apple":
|
|
93
132
|
return os.environ.get("APPLE_OAUTH_CLIENT_ID")
|
|
133
|
+
if provider == "microsoft":
|
|
134
|
+
return os.environ.get("MICROSOFT_OAUTH_CLIENT_ID")
|
|
94
135
|
return None
|
|
95
136
|
|
|
96
137
|
|
|
@@ -103,6 +144,8 @@ def _client_secret(provider: str) -> str | None:
|
|
|
103
144
|
"""
|
|
104
145
|
if provider == "google":
|
|
105
146
|
return os.environ.get("GOOGLE_OAUTH_CLIENT_SECRET")
|
|
147
|
+
if provider == "microsoft":
|
|
148
|
+
return os.environ.get("MICROSOFT_OAUTH_CLIENT_SECRET")
|
|
106
149
|
if provider == "apple":
|
|
107
150
|
team_id = os.environ.get("APPLE_TEAM_ID")
|
|
108
151
|
key_id = os.environ.get("APPLE_KEY_ID")
|
|
@@ -141,7 +184,7 @@ _jwks_cache: dict[str, dict] = {}
|
|
|
141
184
|
|
|
142
185
|
def _discovery(provider: str) -> dict:
|
|
143
186
|
if provider not in _discovery_cache:
|
|
144
|
-
url =
|
|
187
|
+
url = _discovery_url(provider)
|
|
145
188
|
resp = httpx.get(url, timeout=10)
|
|
146
189
|
resp.raise_for_status()
|
|
147
190
|
_discovery_cache[provider] = resp.json()
|
|
@@ -306,6 +349,7 @@ def _verify_id_token(provider: str, id_token: str, nonce: str) -> dict:
|
|
|
306
349
|
key,
|
|
307
350
|
algorithms=[header.get("alg", "RS256")],
|
|
308
351
|
audience=_client_id(provider),
|
|
352
|
+
# None for Microsoft: its issuer is checked in _microsoft_identity.
|
|
309
353
|
issuer=PROVIDERS[provider]["issuer"],
|
|
310
354
|
# Apple omits at_hash; we don't pass the access token, so disable it.
|
|
311
355
|
options={"verify_at_hash": False},
|
|
@@ -314,9 +358,56 @@ def _verify_id_token(provider: str, id_token: str, nonce: str) -> dict:
|
|
|
314
358
|
raise HTTPException(status_code=400, detail=f"Identity token rejected: {exc}")
|
|
315
359
|
if nonce and claims.get("nonce") != nonce:
|
|
316
360
|
raise HTTPException(status_code=400, detail="Sign-in nonce mismatch")
|
|
361
|
+
if provider == "microsoft":
|
|
362
|
+
claims = _microsoft_identity(claims)
|
|
317
363
|
return claims
|
|
318
364
|
|
|
319
365
|
|
|
366
|
+
def _microsoft_identity(claims: dict) -> dict:
|
|
367
|
+
"""Finish verifying a Microsoft ID token (its signature, audience, expiry
|
|
368
|
+
and nonce are already checked) and put it in the shape the callback
|
|
369
|
+
expects: `sub`, `email`, `email_verified`.
|
|
370
|
+
|
|
371
|
+
Issuer: a token from the multi-tenant endpoint is issued by the user's own
|
|
372
|
+
tenant, `https://login.microsoftonline.com/<tid>/v2.0`. It must be exactly
|
|
373
|
+
that for the `tid` it carries, and that tenant must be one this deployment
|
|
374
|
+
admits (MICROSOFT_OAUTH_TENANT).
|
|
375
|
+
|
|
376
|
+
Subject: tenant id + object id, the user's identity at Microsoft that does
|
|
377
|
+
not change with the app registration (`sub` alone is per registration).
|
|
378
|
+
|
|
379
|
+
E-mail: see the module docstring. Personal accounts: the address Microsoft
|
|
380
|
+
holds. Organisation accounts: the `email` claim only when its domain is
|
|
381
|
+
that of the sign-in name (`preferred_username`), which the tenant has
|
|
382
|
+
verified; else the sign-in name; none for a guest of the tenant.
|
|
383
|
+
"""
|
|
384
|
+
tid = str(claims.get("tid") or "").lower()
|
|
385
|
+
if not _GUID.fullmatch(tid):
|
|
386
|
+
raise HTTPException(status_code=400, detail="Identity token rejected: no tenant")
|
|
387
|
+
if claims.get("iss") != f"https://login.microsoftonline.com/{tid}/v2.0":
|
|
388
|
+
raise HTTPException(status_code=400, detail="Identity token rejected: issuer does not match its tenant")
|
|
389
|
+
personal = tid == MICROSOFT_CONSUMER_TENANT
|
|
390
|
+
admitted = _microsoft_tenant()
|
|
391
|
+
if (admitted == "organizations" and personal) or (admitted == "consumers" and not personal) \
|
|
392
|
+
or (_GUID.fullmatch(admitted) and tid != admitted):
|
|
393
|
+
raise HTTPException(status_code=403, detail="This Microsoft account is not from an organisation that may sign in here")
|
|
394
|
+
|
|
395
|
+
oid = str(claims.get("oid") or "").lower()
|
|
396
|
+
subject = f"{tid}:{oid}" if _GUID.fullmatch(oid) else claims.get("sub")
|
|
397
|
+
|
|
398
|
+
mail = str(claims.get("email") or "").strip().lower()
|
|
399
|
+
upn = str(claims.get("preferred_username") or "").strip().lower()
|
|
400
|
+
mail = mail if _EMAIL.fullmatch(mail) else ""
|
|
401
|
+
upn = upn if _EMAIL.fullmatch(upn) and "#ext#" not in upn else ""
|
|
402
|
+
if personal:
|
|
403
|
+
email = mail or upn
|
|
404
|
+
elif mail and upn and mail.rsplit("@", 1)[1] == upn.rsplit("@", 1)[1]:
|
|
405
|
+
email = mail
|
|
406
|
+
else:
|
|
407
|
+
email = upn
|
|
408
|
+
return {**claims, "sub": subject, "email": email or None, "email_verified": bool(email)}
|
|
409
|
+
|
|
410
|
+
|
|
320
411
|
def _email_is_verified(claims: dict) -> bool:
|
|
321
412
|
val = claims.get("email_verified")
|
|
322
413
|
return val is True or str(val).lower() == "true"
|
|
@@ -108,10 +108,10 @@ PROFILES.update({
|
|
|
108
108
|
fields=('price_list_name', 'currency', 'selling', 'buying', 'enabled'),
|
|
109
109
|
required=('price_list_name', 'currency')),
|
|
110
110
|
'Item Unit': PDFProfile('record', 'Item unit',
|
|
111
|
-
fields=('item_code', 'uom', 'conversion_factor', 'enabled'),
|
|
111
|
+
fields=('item_code', 'uom', 'conversion_factor', 'must_be_whole_number', 'enabled'),
|
|
112
112
|
required=('item_code', 'uom', 'conversion_factor')),
|
|
113
113
|
'Item Price': PDFProfile('record', 'Item price overview',
|
|
114
|
-
fields=('item_code', 'price_list', 'customer', 'supplier', 'uom', 'min_qty', 'rate', 'valid_from', 'valid_upto', 'enabled'),
|
|
114
|
+
fields=('item_code', 'price_list', 'customer', 'supplier', 'uom', 'per_qty', 'min_qty', 'rate', 'valid_from', 'valid_upto', 'enabled'),
|
|
115
115
|
required=('item_code', 'price_list', 'rate')),
|
|
116
116
|
'Bank Account': PDFProfile('record', 'Bank account overview',
|
|
117
117
|
fields=('account_name', 'company', 'account', 'iban', 'currency', 'bank_name', 'bic', 'disabled'), required=('account_name', 'company', 'account', 'iban', 'currency')),
|
|
@@ -80,6 +80,8 @@ class ItemPrice(Document):
|
|
|
80
80
|
CONDITIONAL_REQUIREMENTS = (
|
|
81
81
|
'A row without a customer/supplier is the list price for that item. A row naming a party overrides it for that party only.',
|
|
82
82
|
'min_qty sets a volume break: the highest min_qty at or below the line quantity wins.',
|
|
83
|
+
'per_qty: the rate is the price of this many units (rate 12.50, per_qty 100 = 0.125 each). Default 1. '
|
|
84
|
+
'It is not a pack size: for a carton of 100 give the item an Item Unit and set uom on the price.',
|
|
83
85
|
'A customer may only be set on a selling Price List, a supplier only on a buying one.',
|
|
84
86
|
)
|
|
85
87
|
|
|
@@ -96,6 +98,17 @@ class ItemPrice(Document):
|
|
|
96
98
|
raise ValidationError("Min Qty cannot be negative")
|
|
97
99
|
if flt(self.rate) < 0:
|
|
98
100
|
raise ValidationError("Rate cannot be negative")
|
|
101
|
+
per = self._data.get("per_qty")
|
|
102
|
+
if per in (None, ""):
|
|
103
|
+
self._data["per_qty"] = 1
|
|
104
|
+
else:
|
|
105
|
+
try:
|
|
106
|
+
per = float(per)
|
|
107
|
+
except (TypeError, ValueError):
|
|
108
|
+
raise ValidationError("Per Qty must be a number")
|
|
109
|
+
if not math.isfinite(per) or per <= 0:
|
|
110
|
+
raise ValidationError("Per Qty must be positive")
|
|
111
|
+
self._data["per_qty"] = per
|
|
99
112
|
if self.customer and self.supplier:
|
|
100
113
|
raise ValidationError("An Item Price names either a customer or a supplier, not both")
|
|
101
114
|
|
|
@@ -225,7 +238,15 @@ def find_item_price(item_code, price_list, qty=0, party_field=None, party=None,
|
|
|
225
238
|
unit_match = 1 if (uom and row.get("uom") == uom) else 0
|
|
226
239
|
return (party_match, unit_match, flt(row.get("min_qty")), *_validity_rank(row), str(row.get("name")))
|
|
227
240
|
|
|
228
|
-
|
|
241
|
+
best = dict(max(rows, key=rank))
|
|
242
|
+
# A price quoted per several units (12.50 per 100): `rate` of the row
|
|
243
|
+
# that is returned is the price of ONE unit; `quoted_rate` and `per_qty`
|
|
244
|
+
# keep what the price list says.
|
|
245
|
+
per = flt(best.get("per_qty"))
|
|
246
|
+
if per > 0 and per != 1:
|
|
247
|
+
best["quoted_rate"] = flt(best["rate"])
|
|
248
|
+
best["rate"] = flt(best["rate"]) / per
|
|
249
|
+
return best
|
|
229
250
|
|
|
230
251
|
|
|
231
252
|
def set_item_defaults(doc, party_type=None, party_field=None, *, set_description=True):
|
|
@@ -294,7 +315,6 @@ def set_item_defaults(doc, party_type=None, party_field=None, *, set_description
|
|
|
294
315
|
date=date,
|
|
295
316
|
)
|
|
296
317
|
if unit_row is not None:
|
|
297
|
-
row = dict(row)
|
|
298
318
|
row["rate"] = flt(row["rate"]) / factor
|
|
299
319
|
# Where the base price came from is kept on the line
|
|
300
320
|
# (price_source / price_reference), see price_resolution.py.
|
|
@@ -31,7 +31,7 @@ informational: nothing is posted, owed or paid from them.
|
|
|
31
31
|
|
|
32
32
|
import json
|
|
33
33
|
from decimal import Decimal
|
|
34
|
-
from lambda_erp.utils import flt, cint, _dict, dec, money
|
|
34
|
+
from lambda_erp.utils import flt, cint, _dict, dec, money, round_half_up
|
|
35
35
|
from lambda_erp.exceptions import ValidationError
|
|
36
36
|
|
|
37
37
|
HUNDRED = Decimal(100)
|
|
@@ -85,6 +85,11 @@ class TaxCalculator:
|
|
|
85
85
|
# Rounding that to the cent would move the line amount, so the
|
|
86
86
|
# unit rate keeps six places there; amounts round as always.
|
|
87
87
|
places = 6 if flt(item.get("conversion_factor")) not in (0.0, 1.0) else 2
|
|
88
|
+
# The same holds for a list price finer than a cent (12.50 per
|
|
89
|
+
# 100 is 0.125 each): a discount on it is not rounded to the cent.
|
|
90
|
+
list_price = item.get("price_list_rate")
|
|
91
|
+
if places == 2 and list_price not in (None, "") and dec(list_price) != round_half_up(list_price, 2):
|
|
92
|
+
places = 6
|
|
88
93
|
# Apply discount to get rate from price_list_rate
|
|
89
94
|
if item.get('rate') is not None and flt(item['rate']) == 0:
|
|
90
95
|
item['rate'] = 0.0
|
|
@@ -3690,6 +3690,22 @@ def _m067_item_units(db: "Database") -> None:
|
|
|
3690
3690
|
db.ensure_column(table, "order_qty", "REAL")
|
|
3691
3691
|
|
|
3692
3692
|
|
|
3693
|
+
def _m068_units_completed(db: "Database") -> None:
|
|
3694
|
+
"""Units of measure, the rest (see docs/units.md): consignment
|
|
3695
|
+
withdrawals and stock counts can be entered in a further unit, a unit can
|
|
3696
|
+
require whole quantities, and an Item Price can be quoted per several
|
|
3697
|
+
units. Existing rows keep their meaning: per_qty 1, no whole-number rule."""
|
|
3698
|
+
db.ensure_column("Item Unit", "must_be_whole_number", "INTEGER DEFAULT 0")
|
|
3699
|
+
db.ensure_column("Item Price", "per_qty", "REAL DEFAULT 1")
|
|
3700
|
+
for table in ("Consignment Withdrawal Item", "Stock Count Item"):
|
|
3701
|
+
if not db._get_table_columns(table):
|
|
3702
|
+
continue
|
|
3703
|
+
db.ensure_column(table, "uom", "TEXT")
|
|
3704
|
+
db.ensure_column(table, "order_uom", "TEXT")
|
|
3705
|
+
db.ensure_column(table, "conversion_factor", "REAL")
|
|
3706
|
+
db.ensure_column(table, "order_qty", "REAL")
|
|
3707
|
+
|
|
3708
|
+
|
|
3693
3709
|
def _m065_record_attachments(db: "Database") -> None:
|
|
3694
3710
|
"""Files kept with a document or master record, and a tracking reference
|
|
3695
3711
|
on delivery notes (see docs/attachments.md)."""
|
|
@@ -3831,6 +3847,7 @@ Database.MIGRATIONS = [
|
|
|
3831
3847
|
(65, "record_attachments", _m065_record_attachments),
|
|
3832
3848
|
(66, "attachment_sensitivity", _m066_attachment_sensitivity),
|
|
3833
3849
|
(67, "item_units", _m067_item_units),
|
|
3850
|
+
(68, "units_completed", _m068_units_completed),
|
|
3834
3851
|
]
|
|
3835
3852
|
|
|
3836
3853
|
|
|
@@ -60,11 +60,16 @@ def _serials(value):
|
|
|
60
60
|
def content_hash(warehouse, items, replenish=False):
|
|
61
61
|
"""What a withdrawal report says, reduced to what matters: the same
|
|
62
62
|
report gives the same hash whatever the order of its lines."""
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
# In stock units: a report of "1 Karton" and the stored line of 100 pieces
|
|
64
|
+
# are the same report (units.py).
|
|
65
|
+
from lambda_erp import units
|
|
66
|
+
|
|
67
|
+
def line(row):
|
|
68
|
+
qty, rate = units.in_stock_units(row)
|
|
69
|
+
return (str(row.get("item_code") or ""), str(row.get("batch_no") or ""), str(row.get("location") or ""),
|
|
70
|
+
round(qty, 6), None if rate is None else round(rate, 6), sorted(_serials(row.get("serial_no"))))
|
|
71
|
+
|
|
72
|
+
lines = sorted(line(row) for row in items or [])
|
|
68
73
|
payload = json.dumps({"warehouse": warehouse, "lines": lines, "replenish": bool(flt(replenish))},
|
|
69
74
|
sort_keys=True, default=str)
|
|
70
75
|
return hashlib.sha256(payload.encode()).hexdigest()
|
|
@@ -114,6 +119,10 @@ class ConsignmentWithdrawal(Document):
|
|
|
114
119
|
self.posting_date = nowdate()
|
|
115
120
|
if not self.get("items"):
|
|
116
121
|
raise ValidationError("At least one item is required")
|
|
122
|
+
# Reported by the carton: rows in a further unit of the item become
|
|
123
|
+
# stock units before anything reads the quantity (units.py).
|
|
124
|
+
from lambda_erp import units
|
|
125
|
+
units.apply_units(self, rate_fields=("rate",))
|
|
117
126
|
for idx, row in enumerate(self.get("items"), 1):
|
|
118
127
|
if not row.get("item_code"):
|
|
119
128
|
raise ValidationError(f"Consignment Withdrawal row {idx}: Item Code is required")
|
|
@@ -179,7 +188,9 @@ class ConsignmentWithdrawal(Document):
|
|
|
179
188
|
for row in self.get("items"):
|
|
180
189
|
line = _dict(item_code=row["item_code"], qty=flt(row["qty"]), warehouse=self.warehouse,
|
|
181
190
|
batch_no=row.get("batch_no") or None, location=row.get("location") or None,
|
|
182
|
-
serial_no=row.get("serial_no") or None
|
|
191
|
+
serial_no=row.get("serial_no") or None,
|
|
192
|
+
order_uom=row.get("order_uom") or None,
|
|
193
|
+
conversion_factor=row.get("conversion_factor") or None)
|
|
183
194
|
if row.get("rate") is not None:
|
|
184
195
|
line["rate"] = flt(row["rate"])
|
|
185
196
|
invoice.append("items", line)
|
|
@@ -22,6 +22,7 @@ See docs/stock-counts.md.
|
|
|
22
22
|
"""
|
|
23
23
|
from lambda_erp.accounting.general_ledger import make_gl_entries, make_reverse_gl_entries
|
|
24
24
|
from lambda_erp.database import get_db
|
|
25
|
+
from lambda_erp import units
|
|
25
26
|
from lambda_erp.exceptions import ValidationError
|
|
26
27
|
from lambda_erp.model import Document
|
|
27
28
|
from lambda_erp.stock.stock_ledger import (
|
|
@@ -73,6 +74,7 @@ class StockCount(Document):
|
|
|
73
74
|
if not self.get("items"):
|
|
74
75
|
raise ValidationError("At least one item is required")
|
|
75
76
|
system = _system_quantities(self.warehouse)
|
|
77
|
+
unit_columns = units.has_unit_columns(self)
|
|
76
78
|
seen = set()
|
|
77
79
|
counted = differences = 0
|
|
78
80
|
for idx, row in enumerate(self.get("items"), 1):
|
|
@@ -107,6 +109,15 @@ class StockCount(Document):
|
|
|
107
109
|
if quantity < 0 or quantity != quantity or quantity == float("inf"):
|
|
108
110
|
raise ValidationError(f"Stock Count row {idx}: Counted Qty cannot be negative")
|
|
109
111
|
row["counted_qty"] = quantity
|
|
112
|
+
# Counted by the carton: a row whose uom names one of the item's
|
|
113
|
+
# units is converted to stock units like a document line.
|
|
114
|
+
if unit_columns:
|
|
115
|
+
stock_uom = db.get_value("Item", row["item_code"], "stock_uom")
|
|
116
|
+
factor = units.pending_factor(row, stock_uom, f"Stock Count row {idx}", qty_field="counted_qty")
|
|
117
|
+
if factor:
|
|
118
|
+
units.convert_line(row, stock_uom, factor, rate_fields=(), qty_field="counted_qty")
|
|
119
|
+
quantity = row["counted_qty"]
|
|
120
|
+
units.stamp_order_qty(row, "counted_qty")
|
|
110
121
|
row["difference_qty"] = quantity - row["system_qty"]
|
|
111
122
|
counted += 1
|
|
112
123
|
differences += 1 if abs(row["difference_qty"]) > EPSILON else 0
|
|
@@ -55,6 +55,8 @@ class ItemUnit(Document):
|
|
|
55
55
|
"stock_uom, and an item has each unit once.",
|
|
56
56
|
"A document line entered with this uom is converted to the stock unit when saved; the line keeps "
|
|
57
57
|
"order_uom, conversion_factor and order_qty. Changing or disabling a unit does not change stored documents.",
|
|
58
|
+
"must_be_whole_number = 1: a line entered in this unit needs a whole quantity (2 Karton, not 1.5). "
|
|
59
|
+
"Quantities in the stock unit are not affected.",
|
|
58
60
|
)
|
|
59
61
|
|
|
60
62
|
def validate(self):
|
|
@@ -80,6 +82,7 @@ class ItemUnit(Document):
|
|
|
80
82
|
self._data["conversion_factor"] = factor
|
|
81
83
|
enabled = self._data.get("enabled")
|
|
82
84
|
self._data["enabled"] = 1 if enabled in (None, "") else int(flt(enabled) != 0)
|
|
85
|
+
self._data["must_be_whole_number"] = int(flt(self._data.get("must_be_whole_number")) != 0)
|
|
83
86
|
twin = db.sql(
|
|
84
87
|
'SELECT name FROM "Item Unit" WHERE item_code = ? AND uom = ? AND name <> ? '
|
|
85
88
|
'AND COALESCE(discarded, 0) = 0 LIMIT 1',
|
|
@@ -93,16 +96,23 @@ def _table_ready(db):
|
|
|
93
96
|
return bool(db._get_table_columns("Item Unit"))
|
|
94
97
|
|
|
95
98
|
|
|
96
|
-
def
|
|
97
|
-
"""The enabled further units of an item as {uom:
|
|
99
|
+
def unit_records(item_code):
|
|
100
|
+
"""The enabled further units of an item as {uom: {"factor", "whole"}}."""
|
|
98
101
|
db = get_db()
|
|
99
102
|
if not item_code or not _table_ready(db):
|
|
100
103
|
return {}
|
|
104
|
+
whole = "must_be_whole_number" in db._get_table_columns("Item Unit")
|
|
101
105
|
rows = db.sql(
|
|
102
|
-
'SELECT
|
|
106
|
+
'SELECT * FROM "Item Unit" WHERE item_code = ? '
|
|
103
107
|
'AND COALESCE(enabled, 1) = 1 AND COALESCE(discarded, 0) = 0 ORDER BY uom',
|
|
104
108
|
[item_code])
|
|
105
|
-
return {row["uom"]: flt(row["conversion_factor"])
|
|
109
|
+
return {row["uom"]: {"factor": flt(row["conversion_factor"]),
|
|
110
|
+
"whole": bool(whole and flt(row.get("must_be_whole_number")))} for row in rows}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def units_of(item_code):
|
|
114
|
+
"""The enabled further units of an item as {uom: conversion_factor}."""
|
|
115
|
+
return {uom: unit["factor"] for uom, unit in unit_records(item_code).items()}
|
|
106
116
|
|
|
107
117
|
|
|
108
118
|
def conversion_factor(item_code, uom):
|
|
@@ -110,35 +120,42 @@ def conversion_factor(item_code, uom):
|
|
|
110
120
|
return units_of(item_code).get(uom)
|
|
111
121
|
|
|
112
122
|
|
|
113
|
-
def pending_factor(item, stock_uom, label="Row"):
|
|
123
|
+
def pending_factor(item, stock_uom, label="Row", qty_field="qty"):
|
|
114
124
|
"""The factor a line still has to be converted by, or None.
|
|
115
125
|
|
|
116
126
|
A line is converted when its `uom` is one of the item's units. None for
|
|
117
127
|
a line already in the stock unit, and for an item without any Item Unit
|
|
118
|
-
(its `uom` stays free text). Raises for a unit the item does not have
|
|
128
|
+
(its `uom` stays free text). Raises for a unit the item does not have,
|
|
129
|
+
and for a broken quantity of a unit that is only handled whole.
|
|
119
130
|
"""
|
|
120
131
|
uom = str(item.get("uom") or "").strip()
|
|
121
132
|
if not uom or uom == (stock_uom or ""):
|
|
122
133
|
return None
|
|
123
|
-
units =
|
|
134
|
+
units = unit_records(item.get("item_code"))
|
|
124
135
|
if not units:
|
|
125
136
|
return None
|
|
126
|
-
|
|
127
|
-
if not factor:
|
|
128
|
-
known = ", ".join(f"{name} (= {flt(value):g} {stock_uom})" for name, value in units.items())
|
|
137
|
+
unit = units.get(uom)
|
|
138
|
+
if not unit or not unit["factor"]:
|
|
139
|
+
known = ", ".join(f"{name} (= {flt(value['factor']):g} {stock_uom})" for name, value in units.items())
|
|
129
140
|
raise ValidationError(
|
|
130
141
|
f"{label}: {uom} is not a unit of item {item.get('item_code')}. It is stocked in {stock_uom}; "
|
|
131
142
|
f"its further units are {known}. Use one of these, or add an Item Unit for {uom} first")
|
|
132
|
-
|
|
143
|
+
entered = flt(item.get(qty_field))
|
|
144
|
+
if unit["whole"] and abs(entered - round(entered)) > 1e-9:
|
|
145
|
+
raise ValidationError(
|
|
146
|
+
f"{label}: {item.get('item_code')} is handled in whole {uom} only, not {entered:g}. "
|
|
147
|
+
f"Enter a whole number of {uom}, or the quantity in {stock_uom} "
|
|
148
|
+
f"(1 {uom} = {flt(unit['factor']):g} {stock_uom})")
|
|
149
|
+
return unit["factor"]
|
|
133
150
|
|
|
134
151
|
|
|
135
|
-
def convert_line(item, stock_uom, factor, rate_fields=RATE_FIELDS):
|
|
152
|
+
def convert_line(item, stock_uom, factor, rate_fields=RATE_FIELDS, qty_field="qty"):
|
|
136
153
|
"""Convert one line from the unit in `uom` to the stock unit, in place.
|
|
137
154
|
Returns the quantity as it was entered."""
|
|
138
|
-
entered = flt(item.get(
|
|
155
|
+
entered = flt(item.get(qty_field))
|
|
139
156
|
item["order_uom"] = str(item.get("uom")).strip()
|
|
140
157
|
item["conversion_factor"] = factor
|
|
141
|
-
item[
|
|
158
|
+
item[qty_field] = flt(entered * factor, QTY_PLACES)
|
|
142
159
|
for field in rate_fields:
|
|
143
160
|
if item.get(field) not in (None, ""):
|
|
144
161
|
# Not rounded: 10.00 for a pack of 3 is 3.3333... per piece, and
|
|
@@ -148,11 +165,11 @@ def convert_line(item, stock_uom, factor, rate_fields=RATE_FIELDS):
|
|
|
148
165
|
return entered
|
|
149
166
|
|
|
150
167
|
|
|
151
|
-
def stamp_order_qty(item):
|
|
168
|
+
def stamp_order_qty(item, qty_field="qty"):
|
|
152
169
|
"""Derive `order_qty` (and tidy the snapshot) of a line in the stock unit."""
|
|
153
170
|
factor = flt(item.get("conversion_factor"))
|
|
154
|
-
if item.get("order_uom") and math.isfinite(factor) and factor > 0:
|
|
155
|
-
item["order_qty"] = flt(flt(item.get(
|
|
171
|
+
if item.get("order_uom") and math.isfinite(factor) and factor > 0 and item.get(qty_field) not in (None, ""):
|
|
172
|
+
item["order_qty"] = flt(flt(item.get(qty_field)) / factor, QTY_PLACES)
|
|
156
173
|
else:
|
|
157
174
|
item["order_uom"] = None
|
|
158
175
|
item["conversion_factor"] = None
|
|
@@ -182,6 +199,21 @@ def apply_units(doc, rate_fields=RATE_FIELDS, child="items"):
|
|
|
182
199
|
stamp_order_qty(item)
|
|
183
200
|
|
|
184
201
|
|
|
202
|
+
def in_stock_units(row):
|
|
203
|
+
"""(quantity, rate) of a row as it will be stored: per stock unit. For
|
|
204
|
+
code that compares a row as it was sent with one that was saved (the
|
|
205
|
+
content hash of a consignment report)."""
|
|
206
|
+
qty = flt(row.get("qty"))
|
|
207
|
+
rate = None if row.get("rate") in (None, "") else flt(row.get("rate"))
|
|
208
|
+
code = row.get("item_code")
|
|
209
|
+
stock_uom = get_db().get_value("Item", code, "stock_uom") if code else None
|
|
210
|
+
factor = pending_factor(row, stock_uom, "Row") if stock_uom is not None else None
|
|
211
|
+
if factor:
|
|
212
|
+
qty = flt(qty * factor, QTY_PLACES)
|
|
213
|
+
rate = None if rate is None else rate / factor
|
|
214
|
+
return qty, rate
|
|
215
|
+
|
|
216
|
+
|
|
185
217
|
def describe(item, stock_uom=None):
|
|
186
218
|
""""2 Karton (= 100 Stk each)" for a line ordered in a further unit, else ''."""
|
|
187
219
|
if not item.get("order_uom") or not flt(item.get("conversion_factor")):
|
|
@@ -79,6 +79,12 @@ def _row_batch(row):
|
|
|
79
79
|
def validate_return(doc):
|
|
80
80
|
if not doc.get('return_against'):
|
|
81
81
|
raise ValidationError(f'Return Against is required for a return {doc.DOCTYPE}')
|
|
82
|
+
# A return line entered in a further unit of the item (-1 Karton) becomes
|
|
83
|
+
# stock units first: every check below compares with the original
|
|
84
|
+
# document's quantities, which are in stock units (units.py). The
|
|
85
|
+
# documents run this before they price their lines.
|
|
86
|
+
from lambda_erp import units
|
|
87
|
+
units.apply_units(doc)
|
|
82
88
|
db = get_db()
|
|
83
89
|
original = db.get_value(doc.DOCTYPE, doc.return_against, ['name', 'docstatus', 'is_return', 'company', 'customer', 'supplier', 'currency', 'update_stock'])
|
|
84
90
|
if not original:
|
|
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
|