Compare commits

..

149 Commits

Author SHA1 Message Date
MochaMind
0688cedba2 chore: update POT file (#56899) 2026-07-05 20:29:59 +02:00
Mihir Kandoi
8aeca5922c Merge pull request #56905 from mihir-kandoi/pg-lock-races-and-advisory-valuation
fix(stock): close postgres locking races; gate batch valuation with a txn advisory lock
2026-07-05 22:42:18 +05:30
Mihir Kandoi
2ec469257e perf(stock): gate batch valuation with a txn advisory lock on postgres
On postgres, outward batch valuation row-locked the item's ENTIRE SLE / Serial and Batch Entry history (a separate plain SELECT ... FOR UPDATE per site, since FOR UPDATE is invalid with GROUP BY there). That writes a lock marker (xmax + WAL) on every historical tuple per outward movement - write amplification that grows with history forever - and locks nothing at all when the history is empty (negative-stock edge: two concurrent outwards don't serialize).

Replace all four history-wide postgres lock statements with one frappe.db.transaction_advisory_lock(("batch-valuation", item_code, warehouse)) at the top of BatchNoValuation.calculate_avg_rate's outward branch - every valuation read (bundle + the three deprecated paths) is downstream of it. Released at commit/rollback, participates in deadlock detection, and serializes regardless of history size, so the empty-history edge is closed by construction. Batch qty updates iterate in sorted order so concurrent vouchers lock Batch rows in the same sequence.

MariaDB is unchanged: it keeps the original grouped FOR UPDATE row locks (and its gap locks). Requires frappe#40621.

Test: outward delivery of a batched item must leave the xact advisory lock visible in pg_locks for the submitting transaction.
2026-07-05 22:31:45 +05:30
Mihir Kandoi
db58858c68 fix(stock): close postgres lock-then-read races in pick list and stock reservation
Postgres has no gap locks, so the lock-then-read pattern (plain SELECT ... FOR UPDATE before a grouped read) only serializes on rows that already exist. Two sites had reachable races where the lock set is empty or disjoint:

- Pick list: two pick lists against the same SO item submitted concurrently lock only docstatus=1 rows, so with no previously-submitted picks their lock sets are disjoint and both pass validate_picked_qty (over-pick; picked_qty last-writer-wins). Gate on the referenced Sales Order Item / Packed Item rows, which always exist.
- Stock reservation: the first concurrent reservations for an (item, warehouse) find no SRE rows to lock, so both pass and reserved qty can exceed actual. Gate on the Bin row, which exists once there is stock.

MariaDB is unchanged (its gap locks already serialize both; the gates are postgres-only). Also: ORDER BY on the small-set postgres lock selects for deterministic lock order, and the repost pre-lock in get_future_stock_vouchers selects a constant instead of shipping every matching SLE name to the client.
2026-07-05 22:31:29 +05:30
Nabin Hait
8abcb7decc Merge pull request #56301 from frappe/chore/payment-entry-purchase-coverage
test: purchase-side Payment Entry allocation coverage
2026-07-05 19:39:38 +05:30
Mihir Kandoi
c68bf89924 Merge pull request #56903 from mihir-kandoi/pg-second-order-groupby-docs
docs: catalog second-order GROUP BY traps (wrap-is-the-bug classes)
2026-07-05 19:11:14 +05:30
Mihir Kandoi
0922d85bf0 docs: catalog second-order GROUP BY traps (wrap-is-the-bug classes)
A full audit of the loose-GROUP-BY fixes found four recurring mistakes in the fixes themselves: incoherent Max/Min pairs over coupled columns, NULL-skipping Max on discriminators, Sum(x)*Max(y) fabricated arithmetic, and wrong-bound picks. Add them to the compatibility catalog (new 3.1) and to the Greptile review instructions so future PRs get flagged.
2026-07-05 19:00:47 +05:30
rohitwaghchaure
7844905e21 fix: dark theme shop floor (#56887) 2026-07-05 16:33:08 +05:30
Mihir Kandoi
00e6b44701 Merge pull request #56897 from mihir-kandoi/pg-requested-items-required-date
fix(buying): show earliest schedule date as required date
2026-07-05 15:45:52 +05:30
Mihir Kandoi
e3a38e3733 Merge pull request #56896 from mihir-kandoi/pg-production-planning-arrival-qty
fix(manufacturing): scope Production Planning arrival qty to open POs
2026-07-05 15:43:04 +05:30
Mihir Kandoi
1d7bb19620 Merge pull request #56898 from mihir-kandoi/pg-trends-empty-row-guard
fix(controllers): guard empty group-by detail row in trends
2026-07-05 15:39:53 +05:30
Mihir Kandoi
8486578c05 Merge pull request #56894 from mihir-kandoi/pg-procurement-tracker-coherent-row
fix(buying): make Procurement Tracker rows coherent PO lines
2026-07-05 15:39:33 +05:30
Mihir Kandoi
df82c7ac1c Merge pull request #56893 from mihir-kandoi/pg-bom-groupby-phantom-pair
fix(manufacturing): keep bom_no/is_phantom_item pair coherent in get_bom_items_as_dict
2026-07-05 15:38:29 +05:30
Mihir Kandoi
4cb622b8e3 Merge pull request #56895 from mihir-kandoi/pg-budget-requested-amount-per-row
fix(controllers): compute budget requested amount per row
2026-07-05 15:37:56 +05:30
Mihir Kandoi
a5d0b25ac4 test: assert earliest schedule date wins for duplicate MR item rows 2026-07-05 15:32:02 +05:30
Mihir Kandoi
2a6bc517bc fix: exclude fully received PO lines from arrival qty and date 2026-07-05 15:29:18 +05:30
Mihir Kandoi
5d56a04a84 fix(controllers): guard empty group-by detail row in trends
With an explicit GROUP BY, a zero-match detail query returns no rows (the old bare aggregate returned one all-NULL row), so row1[0][0] would raise IndexError. Skip the entry instead.
2026-07-05 15:10:32 +05:30
Mihir Kandoi
b5aee6a9cd fix(buying): show earliest schedule date as required date
When a Material Request lists the same item on multiple rows, the consolidated row showed Max(schedule_date), understating urgency. Use Min - the earliest date the item is needed.
2026-07-05 15:10:17 +05:30
Mihir Kandoi
efd777a1a8 fix(manufacturing): scope Production Planning arrival qty to open POs
arrival_qty summed the all-time ordered qty of every submitted PO line for the item+warehouse, so it grew monotonically with purchase history. Sum the pending qty (qty - received_qty) on open POs instead, and take the earliest schedule date from the same scope.
2026-07-05 15:10:03 +05:30
Mihir Kandoi
e52b1d6cff fix(controllers): compute budget requested amount per row
get_requested_amount multiplied the pooled pending qty of all matching Material Request items by a single Max(rate), fabricating the total whenever rates differ and biasing it upward - making false Budget Exceeded stops more likely. Sum (stock_qty - ordered_qty) * rate per row instead, matching get_ordered_amount.
2026-07-05 15:09:49 +05:30
Mihir Kandoi
39d2a62692 fix(buying): make Procurement Tracker rows coherent PO lines
get_po_entries aggregated every non-key column with Max() over (PO, material_request_item), which could stitch values from different PO lines into a row that never existed (one line's item_code with another's qty and amount). Select one representative line per group instead: a subquery picks Min(child.name) per group under the same filters and the outer query reads all columns bare from that line. Row count is unchanged.
2026-07-05 15:09:21 +05:30
Mihir Kandoi
db5ab9fb35 fix(manufacturing): keep bom_no/is_phantom_item pair coherent in get_bom_items_as_dict
When a BOM lists the same item twice (one line phantom via sub-BOM P, one non-phantom via sub-BOM N), grouping by item_code and aggregating bom_no and is_phantom_item with independent Max() could pair one line's phantom flag with the other line's bom_no, exploding the wrong sub-BOM or silently dropping a direct requirement. Group by the pair instead so each line keeps a coherent (bom_no, is_phantom_item); the consumer accumulates duplicate keys and explodes phantom rows with their own qty. Same fix as 41da9eb7fc, which missed this single-level path.
2026-07-05 15:08:58 +05:30
Nabin Hait
17851ceaae Merge pull request #56877 from frappe/chore/test-appointment-booking-settings
test: add coverage for Appointment Booking Settings
2026-07-05 13:16:15 +05:30
Nabin Hait
d2f0ec883e Merge pull request #56880 from frappe/chore/test-email-campaign
test: add coverage for Email Campaign
2026-07-05 13:16:06 +05:30
Nabin Hait
86435bc961 Merge pull request #56891 from frappe/fix/company-coa-test-abbr-collision
test: fix flaky test_coa_based_on_country_template (abbreviation collision)
2026-07-05 12:57:43 +05:30
Nabin Hait
b418df595e Merge branch 'develop' into chore/test-appointment-booking-settings 2026-07-05 12:50:53 +05:30
Nabin Hait
70e1acdb6d Merge branch 'develop' into chore/test-email-campaign 2026-07-05 12:50:47 +05:30
Nabin Hait
2959bfcafa Merge pull request #56888 from frappe/chore/test-lower-deduction-certificate
test: add coverage for Lower Deduction Certificate
2026-07-05 12:50:05 +05:30
Nabin Hait
94afc2a05b Merge pull request #56889 from frappe/chore/test-italy-utils
test: add coverage for Italy e-invoice utility helpers
2026-07-05 12:49:54 +05:30
Nabin Hait
e82a9b9c3b Merge pull request #56890 from frappe/chore/test-import-supplier-invoice
test: add coverage for Import Supplier Invoice
2026-07-05 12:49:31 +05:30
Nabin Hait
df4fc6b186 test: use a unique company abbreviation to fix COA-template flake 2026-07-05 12:44:31 +05:30
Nabin Hait
e86f6fc89c Merge pull request #56849 from frappe/chore/test-stock-closing-entry
fix: Stock Closing Entry duplicate check misses contained date ranges
2026-07-05 12:18:35 +05:30
Nabin Hait
11023511ae Merge pull request #56856 from frappe/chore/test-job-card-dark-paths
test: cover Job Card quantity, docstatus and capacity logic
2026-07-05 12:18:23 +05:30
Nabin Hait
58ee02780f Merge pull request #56883 from nabinhait/sherlock/fix-dunning-outstanding-currency
fix: use transaction-currency outstanding on Dunning for foreign-currency invoices
2026-07-05 12:17:27 +05:30
Nabin Hait
8d289dfe52 Merge pull request #56881 from frappe/chore/test-campaign
fix: Campaign with a naming series breaks the UTM Campaign link
2026-07-05 12:16:50 +05:30
Nabin Hait
616ceb8126 test: add coverage for Import Supplier Invoice validation and country lookup 2026-07-05 12:16:09 +05:30
Nabin Hait
f2f1b2597d test: add coverage for Italy e-invoice utility helpers 2026-07-05 12:13:48 +05:30
Nabin Hait
c293cb8871 test: add coverage for Lower Deduction Certificate date validation 2026-07-05 12:11:34 +05:30
rohitwaghchaure
29be72fae4 fix: warning message for new item standard cost (#56885) 2026-07-04 23:29:32 +05:30
Nabin Hait
a9bb6b31df fix: use transaction-currency outstanding on Dunning for foreign-currency invoices
When a Sales Invoice is in a foreign currency (e.g. USD) but the receivable
account is in the company currency (e.g. INR), `outstanding_amount` on the
invoice is stored in the party account currency (INR). `postprocess_dunning`
was copying that value directly into the Dunning's Overdue Payment row, which
is expected to carry the transaction-currency (USD) amount.

The fix: when `party_account_currency != currency`, use
`payment_schedule[0].outstanding` (already maintained in transaction currency)
instead of `outstanding_amount`.

Closes #56006
2026-07-04 19:45:44 +05:30
Nabin Hait
2b1e922183 fix: don't hijack another Campaign's UTM mirror when display names collide 2026-07-04 19:42:13 +05:30
Nabin Hait
486a1c78b0 Merge pull request #56882 from frappe/fix/pos-invoice-reset-mop-attributeerror
fix: reset_mode_of_payments raises AttributeError on a POS Invoice
2026-07-04 19:37:40 +05:30
Nabin Hait
ca9dcbf2d7 fix: reuse the existing UTM Campaign mirror when campaign_name is edited 2026-07-04 18:45:58 +05:30
Nabin Hait
c969ee7bef test: use separate documents for the invalid and valid slot cases 2026-07-04 18:44:04 +05:30
Nabin Hait
a1f6ae56ff fix: removed unused import
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2026-07-04 18:39:52 +05:30
Nabin Hait
14c1b02025 Merge pull request #56879 from frappe/chore/test-contract-template
test: add coverage for Contract Template
2026-07-04 17:58:32 +05:30
Nabin Hait
3b335db64c Merge pull request #56878 from frappe/chore/test-crm-settings
test: add coverage for CRM Settings
2026-07-04 17:58:18 +05:30
Nabin Hait
99ed620dad fix: reset_mode_of_payments raises AttributeError on POS Invoice 2026-07-04 17:54:46 +05:30
Nabin Hait
e5b7c3f98c test: cover Job Card quantity, docstatus and capacity-overlap logic 2026-07-04 17:51:52 +05:30
Nabin Hait
10c6cda6db fix: detect contained/enclosing date ranges in Stock Closing Entry duplicate check 2026-07-04 17:47:22 +05:30
Nabin Hait
4b4afe12df Merge pull request #56832 from frappe/chore/test-repost-payment-ledger
test: add coverage for Repost Payment Ledger
2026-07-04 17:45:10 +05:30
Nabin Hait
9fdcfd5f58 fix: link UTM Campaign to the Campaign's document name, not campaign_name 2026-07-04 17:40:16 +05:30
Nabin Hait
5eaafd3025 test: add coverage for Campaign naming and UTM mirroring 2026-07-04 17:33:35 +05:30
Nabin Hait
79c359ef5d test: add coverage for Email Campaign date and recipient validation 2026-07-04 17:30:46 +05:30
Nabin Hait
34f3870f2a test: add coverage for Contract Template validation and rendering 2026-07-04 17:28:28 +05:30
Nabin Hait
7f903b63dd test: add coverage for CRM Settings sync and contact-us guards 2026-07-04 17:26:58 +05:30
Nabin Hait
1a2e3e03b3 test: add coverage for Appointment Booking Settings slot validation 2026-07-04 17:25:20 +05:30
Nabin Hait
4c26ec8cd9 test: make add_manually test distinguish manual mode from auto-loading 2026-07-04 16:48:52 +05:30
Nabin Hait
f68f53dec0 test: cover on-cutoff boundary in voucher loading 2026-07-04 16:48:52 +05:30
Nabin Hait
9901746e02 test: add coverage for Repost Payment Ledger 2026-07-04 16:48:52 +05:30
Nabin Hait
ae0cfbd3e1 test: assert the saved closing entry exists rather than a truthy name 2026-07-04 16:48:51 +05:30
Nabin Hait
e37ceb5f69 test: cover Stock Closing Entry duplicate date-range validation 2026-07-04 16:48:51 +05:30
Nabin Hait
807c52e32b Merge pull request #56855 from frappe/chore/test-stock-reservation-entry-dark-paths
test: cover Stock Reservation Entry validations and helper
2026-07-04 16:43:55 +05:30
Nabin Hait
38b91a2800 Merge pull request #56846 from frappe/chore/test-bisect-accounting-statements
test: add coverage for Bisect Accounting Statements
2026-07-04 16:43:28 +05:30
Nabin Hait
0f3b77a344 Merge pull request #56841 from frappe/chore/test-exchange-rate-revaluation
test: cover Exchange Rate Revaluation validation and gain/loss paths
2026-07-04 16:42:22 +05:30
ruthra kumar
66e70e312d Merge pull request #56852 from ruthra-kumar/race_condition_in_process_pcv
fix: race condition in process pcv
2026-07-04 16:22:16 +05:30
Mihir Kandoi
ac57e389a4 Merge pull request #56871 from mihir-kandoi/cast-error-postgres
fix: type cast error on postgres
2026-07-04 14:24:20 +05:30
Mihir Kandoi
093bbb07a7 fix: type cast error on postgres 2026-07-04 14:11:29 +05:30
Mihir Kandoi
57e7ceae24 Merge pull request #56859 from aerele/fix/item-form-permission-errors
Fix(stock): item form permission errors
2026-07-04 14:07:54 +05:30
rohitwaghchaure
8093e44746 feat: shop floor interface for operators (#55551)
* feat: shop floor interface for operators

* fix: documentation

* fix: UI/UX for shop floor

* fix: shop floor query and OEE edge cases from review

- Push the draft / To Manufacture condition into the Job Card query
  (or_filters) so a busy workstation's submitted history cannot fill
  the row limit and hide active drafts
- Clamp the OEE quality factor at zero when process loss exceeds
  completed qty

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-04 13:31:37 +05:30
Nabin Hait
55c27d3dde Merge pull request #56853 from frappe/chore/test-payment-entry-dark-paths
test: cover untested Payment Entry field validations
2026-07-04 11:52:16 +05:30
Nabin Hait
b85776c00b Merge pull request #56843 from frappe/chore/test-share-transfer
test: cover Share Transfer consistency validations
2026-07-03 23:44:40 +05:30
Nabin Hait
0f7ee3a843 Merge pull request #56844 from frappe/chore/test-process-statement-of-accounts
test: cover Process Statement Of Accounts validation
2026-07-03 23:44:29 +05:30
Nabin Hait
e546132ac3 Merge pull request #56845 from frappe/chore/test-chart-of-accounts-importer
test: add coverage for Chart of Accounts Importer parsing
2026-07-03 23:44:20 +05:30
Nabin Hait
24a13d16bb Merge pull request #56847 from frappe/chore/test-asset-capitalization
test: cover Asset Capitalization row validations
2026-07-03 23:43:52 +05:30
Nabin Hait
17e7f91690 Merge pull request #56850 from frappe/chore/test-packing-slip
test: cover Packing Slip package-number and item validations
2026-07-03 23:43:43 +05:30
Nabin Hait
ef7fb1084d Merge pull request #56854 from frappe/chore/test-serial-batch-bundle-dark-paths
test: cover Serial and Batch Bundle helpers and validations
2026-07-03 23:43:04 +05:30
Nabin Hait
18d16fa5cf Merge pull request #56851 from frappe/chore/test-email-digest
test: cover Email Digest date-window calculations
2026-07-03 23:42:25 +05:30
Nikhil Kothari
dc09362454 fix: replace all old icons (#56864) 2026-07-03 23:03:28 +05:30
Nabin Hait
2000a9db36 Merge pull request #56842 from frappe/chore/test-bank-reconciliation-tool
test: cover Bank Reconciliation Tool date filter and message helper
2026-07-03 22:08:23 +05:30
Nabin Hait
dd35d977f7 Merge pull request #56829 from frappe/chore/test-process-subscription
test: add coverage for Process Subscription
2026-07-03 22:06:19 +05:30
Mihir Kandoi
4545dd939a Merge pull request #56837 from aerele/fix/manufacture-stock-entry-cost-center-default
fix: remove company default on cost center in stock entry detail
2026-07-03 21:11:52 +05:30
rohitwaghchaure
7b0c35caaf fix: auto fetch serial no from previous operation output (#56445)
* fix: auto fetch serial no from previous operation output

* fix: order by

* fix: warehouse for operations
2026-07-03 20:23:33 +05:30
rohitwaghchaure
341a07dffa fix: restrict state-changing whitelisted endpoints to POST (#56858)
Add methods=["POST"] to 50 whitelisted functions that create or modify
documents (get_doc followed by insert/save/submit), so they can no
longer be invoked via GET requests.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 18:47:13 +05:30
pandiyan
ef794f390c fix: skip item prices tab render for users without item price read access 2026-07-03 18:25:08 +05:30
pandiyan
8c7b2f4d3c fix: clear stray permission message when item dashboard has no warehouse access 2026-07-03 18:25:01 +05:30
rohitwaghchaure
9c911438f1 fix: do not rebook standard cost variance on non-update-stock purchase invoice (#56799) 2026-07-03 17:17:38 +05:30
ruthra kumar
a9ffdac806 chore: linter fix 2026-07-03 17:16:06 +05:30
ruthra kumar
dbc409736a refactor(test): row name based utility methods 2026-07-03 17:16:03 +05:30
Nabin Hait
008742bdbe test: exercise every mandatory field in the Stock Reservation Entry check 2026-07-03 17:08:27 +05:30
Nabin Hait
ed77392741 test: also accept a mid-range rounding loss allowance 2026-07-03 17:07:31 +05:30
Nabin Hait
3240411876 test: drop unused timedelta import 2026-07-03 17:05:53 +05:30
Nabin Hait
8f96e5f2aa test: replace lambda with nested def (ruff E731) 2026-07-03 17:03:51 +05:30
Nabin Hait
7b2f38cd6f test: cover Stock Reservation Entry validations and helper 2026-07-03 16:23:52 +05:30
Nabin Hait
8456e88d93 test: cover Serial and Batch Bundle helpers and in-memory validations 2026-07-03 16:20:41 +05:30
ruthra kumar
21f4603144 refactor: prevent whole table scan while scheduling next date
- helps in concurrency isolation
2026-07-03 16:19:35 +05:30
Nabin Hait
e0ea8eee1a test: cover untested Payment Entry field validations 2026-07-03 16:15:24 +05:30
Nabin Hait
c5ab9958ff test: cover Email Digest date-window calculations 2026-07-03 16:01:10 +05:30
Nabin Hait
113d914b9c test: cover Packing Slip package-number and item validations 2026-07-03 15:59:13 +05:30
Nabin Hait
ebd8547629 test: cover Asset Capitalization row validations 2026-07-03 15:54:17 +05:30
ruthra kumar
7e4045e828 fix: prevent repeatable read related concurrency errors
Process Period Closing Voucher and Process Period Closing Voucher
Details are trackers how the jobs are processed. Keep transactions on
them very short.
2026-07-03 15:28:28 +05:30
ruthra kumar
ff6881764b fix: race condition and repeatable read in process pcv
- Update using child table name to avoid scanning whole table, which
eventually leads to mariadb 1020 (REPEATABLE READ).
 - Avoid race condition in final summarization
2026-07-03 15:28:26 +05:30
Nabin Hait
28367f75e9 test: add coverage for Bisect Accounting Statements bisection 2026-07-03 14:57:47 +05:30
Nabin Hait
740c5a07ff test: add coverage for Chart of Accounts Importer parsing 2026-07-03 14:55:31 +05:30
Nabin Hait
3dfb3f385b test: cover Process Statement Of Accounts validation defaults 2026-07-03 14:53:22 +05:30
Nabin Hait
dae90e90df test: cover Share Transfer consistency validations 2026-07-03 14:50:52 +05:30
Nabin Hait
d1d592cf0c test: cover bank reconciliation date filter and auto-reconcile message 2026-07-03 14:48:21 +05:30
Nabin Hait
65500d5102 test: cover Exchange Rate Revaluation validation and gain/loss paths 2026-07-03 14:45:06 +05:30
Nabin Hait
23e3dd94c0 Merge pull request #56831 from frappe/chore/test-process-payment-reconciliation
fix: Process Payment Reconciliation drops bank/cash and cost center filters
2026-07-03 14:31:17 +05:30
Nabin Hait
6255d99fda Merge pull request #56827 from frappe/chore/test-subscription-plan
fix: Subscription Plan Monthly Rate under-bills across a year boundary
2026-07-03 14:30:25 +05:30
Nabin Hait
81d5eac0ea Merge pull request #56824 from frappe/chore/test-journal-entry-template
fix: Journal Entry Template rows must belong to its company
2026-07-03 14:29:28 +05:30
Nabin Hait
0b20438da9 test: mirror subscription test setup for known settings 2026-07-03 14:24:58 +05:30
Nabin Hait
8632019d2a Merge pull request #56830 from frappe/chore/test-account-closing-balance
test: add coverage for Account Closing Balance
2026-07-03 14:22:40 +05:30
Nabin Hait
c9960b4d51 fix: carry bank/cash account and cost center into Payment Reconciliation 2026-07-03 14:16:46 +05:30
Nabin Hait
2cc02e61d9 fix: validate Journal Entry Template rows belong to its company 2026-07-03 14:15:19 +05:30
Nabin Hait
6fc28edde9 Merge pull request #56828 from frappe/chore/test-cashier-closing
test: add coverage for Cashier Closing
2026-07-03 14:08:55 +05:30
Nabin Hait
196730c535 fix: bill all months across a year boundary in Monthly Rate plans 2026-07-03 14:08:20 +05:30
Nabin Hait
4d39f698bd Merge pull request #56823 from frappe/chore/test-party-link
test: add coverage for Party Link
2026-07-03 14:07:04 +05:30
Nabin Hait
0a7abe7144 Merge pull request #56822 from frappe/chore/test-mode-of-payment
test: add coverage for Mode of Payment
2026-07-03 14:06:50 +05:30
pandiyan
a168bb7ea4 test: cover cost center fallback to item group default in manufacture entry
the existing test_cost_center_for_manufacture only checks a raw material
row against an item-level override, which is set independently of the
":company" default guard and never exercised the bug.
2026-07-03 14:06:22 +05:30
pandiyan
edfa0a7a1d fix: remove company default on cost center in stock entry detail
the ":company" default pre-filled every row before set_default_cost_center()
ran, so its "if not row.cost_center" guard was always false and the
project/item group/brand priority chain in get_default_cost_center()
never ran.
2026-07-03 14:06:22 +05:30
Nabin Hait
5888cdf3a0 Merge pull request #56821 from frappe/chore/test-item-tax-template
test: add coverage for Item Tax Template
2026-07-03 14:04:03 +05:30
Nabin Hait
a1f413e8a8 Merge pull request #56820 from frappe/chore/test-monthly-distribution
test: add coverage for Monthly Distribution
2026-07-03 14:03:36 +05:30
Nabin Hait
cd167bdd40 Merge pull request #56819 from frappe/chore/test-bank-guarantee
test: add coverage for Bank Guarantee
2026-07-03 14:02:53 +05:30
Mihir Kandoi
5d48c44bbb Merge pull request #56826 from frappe/fix/stock-ledger-invariant-check-report
fix: FIFO queue checks and incorrect entries filter in stock ledger reports
2026-07-03 13:19:29 +05:30
rohitwaghchaure
ecc8ec672b fix: replay immutable SLE qty for serial/batch bundle valuation (#56814) 2026-07-03 12:15:07 +05:30
Mihir Kandoi
3b1e57966e test: drop redundant cleanup, db rolls back after each test 2026-07-03 12:12:46 +05:30
Nabin Hait
974571aba7 test: guard account lookups and cover dropped pr_instance filters 2026-07-03 12:08:11 +05:30
Nabin Hait
7d917e497a test: assert account-currency sums carry through the merge 2026-07-03 12:06:56 +05:30
Nabin Hait
e041e33860 test: reload invoice for outstanding and cover equal-time boundary 2026-07-03 12:06:20 +05:30
Nabin Hait
832b5a56bf test: lock current cross-year monthly-rate underbilling value 2026-07-03 12:05:31 +05:30
Nabin Hait
abded56174 test: guard account lookup and lock missing company-check behaviour 2026-07-03 12:04:42 +05:30
Nabin Hait
6f866545b9 test: complete supplier-primary assertions and lock uniqueness gap 2026-07-03 12:03:56 +05:30
Nabin Hait
147e1539dc test: guard account lookup and lock dead POS guard behaviour 2026-07-03 12:02:50 +05:30
Nabin Hait
9980d47524 test: lock current end-date behaviour and assert persisted state 2026-07-03 12:00:45 +05:30
Nabin Hait
97794b7ded test: add coverage for Process Payment Reconciliation 2026-07-03 11:41:21 +05:30
Mihir Kandoi
ef5f47fafd fix: address review comments
- restore mutated SLE after test via addCleanup
- explicit return False in has_difference
- comment the fifo_stock_diff guard for non-queue predecessors
2026-07-03 11:39:51 +05:30
Nabin Hait
c51edbd88e test: add coverage for Account Closing Balance 2026-07-03 11:39:50 +05:30
Nabin Hait
745f657a0e test: add coverage for Process Subscription 2026-07-03 11:37:02 +05:30
Nabin Hait
5c87e2e398 test: add coverage for Cashier Closing 2026-07-03 11:34:27 +05:30
Nabin Hait
3167e8ba77 test: add coverage for Subscription Plan 2026-07-03 11:31:30 +05:30
Mihir Kandoi
94ab09e4a3 fix: FIFO queue checks and incorrect entries filter in stock ledger reports
- 'Show Incorrect Entries' always returned an empty result (regression
  from #43619); now returns entries from one row before the first
  incorrect one
- FIFO queue columns were computed for serialized/batched SLEs that
  don't maintain a stock queue, showing false differences; left empty
  for such rows
- compare value/valuation differences at currency precision, qty at
  float precision
2026-07-03 11:29:44 +05:30
Nabin Hait
83d821d8c4 test: add coverage for Journal Entry Template 2026-07-03 11:28:56 +05:30
Nabin Hait
22dc51a57a test: add coverage for Party Link 2026-07-03 11:25:32 +05:30
Nabin Hait
df54382727 test: add coverage for Mode of Payment 2026-07-03 11:23:08 +05:30
Nabin Hait
ccd2aae481 test: add coverage for Monthly Distribution 2026-07-03 11:18:11 +05:30
Nabin Hait
41000ea109 test: add coverage for Bank Guarantee 2026-07-03 11:14:54 +05:30
Nabin Hait
7d8d1eaec7 test: submit overpaid payment for GL coverage and sync received_amount 2026-07-02 14:15:38 +05:30
Nabin Hait
ac8b3f18c7 test: add purchase-side Payment Entry allocation coverage
- pay multiple purchase invoices with a single Payment Entry
- unallocated (advance) amount when a supplier payment is overpaid
- allocating more than a purchase invoice's outstanding amount is rejected
2026-06-22 14:13:18 +05:30
227 changed files with 9966 additions and 2937 deletions

View File

@@ -150,6 +150,34 @@ Add it only when it is functionally dependent on the existing select columns; ot
SQL `ORDER BY` and **sort in Python** (`key=str.casefold`, per §2) so the distinct row set is
unchanged.
### 3.1 Second-order traps — when the `Max()`/`Min()` wrap itself is the bug
The wrap is only a no-op when the column is provably single-valued per group (**"`Max()` means
provably constant"**). When the column can genuinely vary, the wrap is a decision, and a full
audit of these fixes found four recurring mistakes:
- **Incoherent pair** — two semantically-coupled columns (a flag + a link:
`is_phantom_item` + `bom_no`; a discriminator + its value) aggregated with *independent*
`Max()`/`Min()` can pair values from **different rows** — a chimera row that never existed.
MariaDB's loose pick was at least row-coherent. Fix: group by the pair (when consumers
tolerate the extra rows), or select one **representative row** (`Min(child.name)` subquery +
join-back) so every column comes from the same line.
- **NULL-skipping** — `MAX`/`MIN` ignore NULLs, so `Max()` over a mostly-NULL discriminator
(an `original_item`-style column) *deterministically* returns the non-NULL value where
MariaDB could return NULL — deterministically wrong where the old behavior was only
intermittently wrong. Flag it wherever "no value" is a meaningful state (fallback gates,
dict keys).
- **Fabricated arithmetic** — `Sum(x) * Max(y)` where `y` varies within the group invents a
number no row ever had (and `Max` biases it upward) — poisonous when it feeds validation,
budgets, valuation, or GL/stock values. Fix per-row: `Sum(x * y)`.
- **Wrong bound** — where the value has a semantic, pick the bound deliberately:
`Min(schedule_date)` for a "required by", `Min(idx)` for first-line ordering, a qty-weighted
average for a rate. A blind `Max` can understate urgency or overstate a figure.
Review heuristic: **if choosing between `Max` and `Min` would change the answer, the column is
not functionally dependent** — wrapping either is the wrong fix. Group by it, restructure, or
pick a bound for a stated reason, and cover the varying-group case with a test.
---
## 4. False positives — do NOT flag these

File diff suppressed because one or more lines are too long

View File

@@ -1,10 +1,59 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
from erpnext.accounts.doctype.account_closing_balance.account_closing_balance import (
aggregate_with_last_account_closing_balance,
generate_key,
)
from erpnext.tests.utils import ERPNextTestSuite
def entry(**overrides):
row = {"debit": 0, "credit": 0, "debit_in_account_currency": 0, "credit_in_account_currency": 0}
row.update(overrides)
return row
class TestAccountClosingBalance(ERPNextTestSuite):
pass
"""The closing-balance snapshot is built by merging this period's entries with the
previous period's. These lock the merge/key logic that drives that carry-forward."""
def test_matching_entries_are_summed(self):
# this is how a prior-period balance carries forward into the current one
merged = aggregate_with_last_account_closing_balance(
[
entry(account="Cash - _TC", debit=100, debit_in_account_currency=100),
entry(
account="Cash - _TC",
debit=50,
credit=20,
debit_in_account_currency=50,
credit_in_account_currency=20,
),
],
[],
)
self.assertEqual(len(merged), 1)
row = next(iter(merged.values()))
self.assertEqual(row["debit"], 150)
self.assertEqual(row["credit"], 20)
# the account-currency columns are accumulated in the same pass
self.assertEqual(row["debit_in_account_currency"], 150)
self.assertEqual(row["credit_in_account_currency"], 20)
def test_entries_are_kept_separate_per_dimension(self):
merged = aggregate_with_last_account_closing_balance(
[
entry(account="Cash - _TC", cost_center="CC1", debit=100, debit_in_account_currency=100),
entry(account="Cash - _TC", cost_center="CC2", debit=40, debit_in_account_currency=40),
],
[],
)
self.assertEqual(len(merged), 2)
def test_period_closing_flag_is_part_of_the_key(self):
# a P&L reversal (flag 0) and a closing-account entry (flag 1) for the same
# account must not merge, so the flag has to distinguish their keys
key_reversal, _ = generate_key(entry(account="Sales - _TC", is_period_closing_voucher_entry=0), [])
key_closing, _ = generate_key(entry(account="Sales - _TC", is_period_closing_voucher_entry=1), [])
self.assertNotEqual(key_reversal, key_closing)

View File

@@ -6,7 +6,7 @@ frappe.ui.form.on("Accounting Dimension Filter", {
let help_content = `<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
<tr><td>
<p>
<i class="fa fa-hand-right"></i>
<svg class="icon icon-sm"><use href="#icon-info"></use></svg>
{{__('Note: On checking Is Mandatory the accounting dimension will become mandatory against that specific account for all accounting transactions')}}
</p>
</td></tr>

View File

@@ -188,7 +188,7 @@ def get_closing_balance_as_per_statement(bank_account: str, date: str):
return {"balance": 0, "date": None}
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def set_closing_balance_as_per_statement(bank_account: str, date: str | datetime.date, balance: float):
"""
Set the closing balance as per statement for a bank account and date

View File

@@ -1,8 +1,76 @@
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import frappe
from frappe.utils import flt
from erpnext.accounts.doctype.bank_guarantee.bank_guarantee import get_voucher_details
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.tests.utils import ERPNextTestSuite
BANK = "_Test BG Bank"
class TestBankGuarantee(ERPNextTestSuite):
pass
"""Bank Guarantee records a guarantee issued/received against a customer or
supplier. validate() needs a party; on_submit() needs the bank details filled in."""
def setUp(self):
frappe.set_user("Administrator")
if not frappe.db.exists("Bank", BANK):
frappe.get_doc({"doctype": "Bank", "bank_name": BANK}).insert()
def make_bg(self, **args):
args = frappe._dict(args)
doc = frappe.new_doc("Bank Guarantee")
doc.bg_type = args.bg_type or "Receiving"
doc.amount = args.amount if args.amount is not None else 1000
doc.start_date = args.start_date or "2026-06-01"
if args.end_date:
doc.end_date = args.end_date
doc.customer = args.get("customer", "_Test Customer")
doc.supplier = args.get("supplier")
# fields on_submit requires — present by default, cleared per-test to assert the guard
doc.bank_guarantee_number = args.get("bank_guarantee_number", "BG-001")
doc.name_of_beneficiary = args.get("name_of_beneficiary", "Test Beneficiary")
doc.bank = args.get("bank", BANK)
return doc
def test_validate_requires_customer_or_supplier(self):
doc = self.make_bg(customer=None)
self.assertRaises(frappe.ValidationError, doc.insert)
def test_submit_requires_guarantee_number(self):
doc = self.make_bg(bank_guarantee_number="")
doc.insert()
self.assertRaises(frappe.ValidationError, doc.submit)
def test_submit_requires_beneficiary_name(self):
doc = self.make_bg(name_of_beneficiary="")
doc.insert()
self.assertRaises(frappe.ValidationError, doc.submit)
def test_submit_requires_bank(self):
doc = self.make_bg(bank="")
doc.insert()
self.assertRaises(frappe.ValidationError, doc.submit)
def test_valid_guarantee_submits(self):
doc = self.make_bg()
doc.insert()
doc.submit()
self.assertEqual(frappe.db.get_value("Bank Guarantee", doc.name, "docstatus"), 1)
def test_get_voucher_details_for_receiving(self):
so = make_sales_order()
details = get_voucher_details("Receiving", so.name)
self.assertEqual(details.customer, so.customer)
self.assertEqual(flt(details.grand_total), flt(so.grand_total))
def test_end_date_before_start_date_is_not_validated(self):
# SUSPECTED BUG: validate() never checks that end_date >= start_date, so a
# guarantee that expires before it starts saves cleanly. Locking the current
# (wrong) behaviour so a future fix that adds the check trips this test.
doc = self.make_bg(start_date="2026-06-30", end_date="2026-06-01")
doc.insert()
self.assertTrue(frappe.db.exists("Bank Guarantee", doc.name))

View File

@@ -116,7 +116,7 @@ def get_account_balance(bank_account: str, till_date: str | date, company: str):
return flt(balance_as_per_system) - flt(total_debit) + flt(total_credit) + amounts_not_reflected_in_system
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def update_bank_transaction(
bank_transaction_name: str, reference_number: str, party_type: str | None = None, party: str | None = None
):
@@ -146,7 +146,7 @@ def update_bank_transaction(
)[0]
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def create_journal_entry_bts(
bank_transaction_name: str,
reference_number: str | None = None,
@@ -305,7 +305,7 @@ def create_journal_entry_bts(
return reconcile_vouchers(bank_transaction_name, vouchers, is_new_voucher=True)
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def create_payment_entry_bts(
bank_transaction_name: str,
reference_number: str | None = None,
@@ -500,7 +500,7 @@ def create_bulk_internal_transfer(bank_transaction_names: list[str | int], bank_
return output
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def create_internal_transfer(
bank_transaction_name: str | int,
posting_date: str | date,
@@ -1057,7 +1057,7 @@ def get_auto_reconcile_message(partially_reconciled, reconciled):
return alert_message, indicator
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def reconcile_vouchers(bank_transaction_name: str | int, vouchers: str | list, is_new_voucher: bool = False):
# updated clear date of all the vouchers based on the bank transaction
vouchers = frappe.parse_json(vouchers)

View File

@@ -8,6 +8,7 @@ from frappe.utils import add_days, today
from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import (
auto_reconcile_vouchers,
get_auto_reconcile_message,
get_bank_transactions,
)
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
@@ -97,3 +98,40 @@ class TestBankReconciliationTool(ERPNextTestSuite, AccountsTestMixin):
# assert API output post reconciliation
transactions = get_bank_transactions(self.bank_account, from_date, to_date)
self.assertEqual(len(transactions), 0)
def make_bank_transaction(self, date, deposit=100):
return (
frappe.get_doc(
{
"doctype": "Bank Transaction",
"date": date,
"deposit": deposit,
"bank_account": self.bank_account,
"currency": "INR",
}
)
.save()
.submit()
)
def test_get_bank_transactions_excludes_dates_after_to_date(self):
self.make_bank_transaction(date=today())
names = [t.name for t in get_bank_transactions(self.bank_account, to_date=add_days(today(), -1))]
self.assertEqual(names, [])
def test_auto_reconcile_message_for_no_matches(self):
message, indicator = get_auto_reconcile_message([], [])
self.assertEqual(indicator, "blue")
self.assertIn("No matches", message)
def test_auto_reconcile_message_counts_and_pluralizes(self):
# reconciled count is reported and the indicator turns green
message, indicator = get_auto_reconcile_message([], ["t1", "t2"])
self.assertEqual(indicator, "green")
self.assertIn("2 Transaction(s) Reconciled", message)
# partially-reconciled label is singular for one, plural for many
singular, _ = get_auto_reconcile_message(["p1"], [])
self.assertIn("1 Transaction Partially Reconciled", singular)
plural, _ = get_auto_reconcile_message(["p1", "p2"], [])
self.assertIn("2 Transactions Partially Reconciled", plural)

View File

@@ -397,7 +397,7 @@ def unreconcile_transaction(transaction_name: str | int):
frappe.get_doc(voucher["doctype"], voucher["name"]).cancel()
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def unreconcile_transaction_entry(bank_transaction_id: str | int, voucher_type: str, voucher_id: str | int):
"""
Removes a single payment entry from a bank transaction - for example only undoing one voucher instead of undoing the entire transaction

View File

@@ -34,7 +34,7 @@ def upload_bank_statement():
return {"columns": columns, "data": data}
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def create_bank_entries(columns: str, data: str | list, bank_account: str):
header_map = get_header_mapping(columns, bank_account)

View File

@@ -184,7 +184,7 @@ class BisectAccountingStatements(Document):
self.get_report_summary()
self.update_node()
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def bisect_left(self):
if self.current_node is not None:
cur_node = frappe.get_doc("Bisect Nodes", self.current_node)
@@ -198,7 +198,7 @@ class BisectAccountingStatements(Document):
else:
frappe.msgprint(_("No more children on Left"))
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def bisect_right(self):
if self.current_node is not None:
cur_node = frappe.get_doc("Bisect Nodes", self.current_node)
@@ -212,7 +212,7 @@ class BisectAccountingStatements(Document):
else:
frappe.msgprint(_("No more children on Right"))
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def move_up(self):
if self.current_node is not None:
cur_node = frappe.get_doc("Bisect Nodes", self.current_node)

View File

@@ -1,11 +1,47 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import datetime
import frappe
from frappe.utils import getdate
from erpnext.tests.utils import ERPNextTestSuite
class TestBisectAccountingStatements(ERPNextTestSuite):
pass
"""The tool bisects a date range into a tree of Bisect Nodes down to single days.
These cover the date validation and that the bisection cleanly partitions the range."""
def setUp(self):
frappe.set_user("Administrator")
frappe.db.delete("Bisect Nodes")
def _leaf_days(self):
leaves = frappe.get_all(
"Bisect Nodes",
filters={"left_child": ["is", "not set"]},
fields=["period_from_date", "period_to_date"],
)
# every leaf spans a single day
for leaf in leaves:
self.assertEqual(getdate(leaf.period_from_date), getdate(leaf.period_to_date))
return sorted(getdate(leaf.period_from_date) for leaf in leaves)
def test_validate_dates_rejects_reversed_range(self):
doc = frappe.new_doc("Bisect Accounting Statements")
doc.from_date = "2026-01-08"
doc.to_date = "2026-01-01"
self.assertRaises(frappe.ValidationError, doc.validate)
def test_bfs_partitions_range_into_single_days(self):
doc = frappe.new_doc("Bisect Accounting Statements")
doc.bfs(datetime.datetime(2026, 1, 1), datetime.datetime(2026, 1, 8))
# the 8-day span Jan 1..Jan 8 becomes exactly 8 contiguous single-day leaves
self.assertEqual(self._leaf_days(), [getdate(f"2026-01-0{n}") for n in range(1, 9)])
def test_dfs_produces_the_same_partition_as_bfs(self):
doc = frappe.new_doc("Bisect Accounting Statements")
doc.dfs(datetime.datetime(2026, 1, 1), datetime.datetime(2026, 1, 8))
self.assertEqual(self._leaf_days(), [getdate(f"2026-01-0{n}") for n in range(1, 9)])

View File

@@ -878,7 +878,7 @@ def get_fiscal_year_date_range(from_fiscal_year, to_fiscal_year):
return from_year.year_start_date, to_year.year_end_date
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def revise_budget(budget_name: str):
old_budget = frappe.get_doc("Budget", budget_name)

View File

@@ -1,8 +1,67 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import frappe
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.tests.utils import ERPNextTestSuite
DATE = "2026-06-15"
class TestCashierClosing(ERPNextTestSuite):
pass
"""Cashier Closing reconciles a shift: it pulls outstanding invoices in a
date/time window and rolls payments, expense, custody and returns into net_amount."""
def setUp(self):
frappe.set_user("Administrator")
def make_invoice_in_window(self, rate=100):
si = create_sales_invoice(rate=rate, qty=1, posting_date=DATE, do_not_submit=True)
si.posting_time = "10:30:00"
si.submit()
si.reload() # read outstanding_amount as persisted after submit
return si
def make_closing(self, user="Administrator", payments=None, **args):
doc = frappe.new_doc("Cashier Closing")
doc.user = user
doc.date = args.get("date", DATE)
doc.from_time = args.get("from_time", "09:00:00")
doc.time = args.get("time", "18:00:00")
for amount in payments or []:
doc.append("payments", {"mode_of_payment": "Cash", "amount": amount})
doc.expense = args.get("expense", 0)
doc.custody = args.get("custody", 0)
doc.returns = args.get("returns", 0)
return doc
def test_from_time_must_be_before_to_time(self):
doc = self.make_closing(from_time="18:00:00", time="09:00:00")
self.assertRaises(frappe.ValidationError, doc.save)
def test_equal_from_and_to_time_is_rejected(self):
# validate_time uses >=, so a zero-length window is also blocked
doc = self.make_closing(from_time="09:00:00", time="09:00:00")
self.assertRaises(frappe.ValidationError, doc.save)
def test_net_amount_rolls_up_outstanding_and_adjustments(self):
si = self.make_invoice_in_window(rate=100)
doc = self.make_closing(payments=[500], expense=50, custody=30, returns=20)
doc.save()
# the in-window invoice is picked up as outstanding
self.assertEqual(doc.outstanding_amount, si.outstanding_amount)
# net = payments + outstanding + expense - custody + returns
self.assertEqual(doc.net_amount, 500 + si.outstanding_amount + 50 - 30 + 20)
def test_outstanding_is_scoped_to_the_invoice_owner(self):
# The invoice is created by Administrator; a closing for a different user does
# not see it. NOTE: get_outstanding keys on Sales Invoice.owner (the document
# creator) rather than an explicit cashier/POS-user field, which is fragile when
# invoices are created by a shared or system user.
self.make_invoice_in_window(rate=100)
doc = self.make_closing(user="Guest", payments=[500])
doc.save()
self.assertEqual(doc.outstanding_amount, 0)
self.assertEqual(doc.net_amount, 500)

View File

@@ -1,8 +1,54 @@
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import frappe
from erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer import (
build_forest,
validate_columns,
validate_missing_roots,
)
from erpnext.tests.utils import ERPNextTestSuite
# columns: account_name, parent_account, account_number, parent_account_number,
# is_group, account_type, root_type, account_currency
ROOT = ["Assets", "Assets", "", "", 1, "", "Asset", "INR"]
CHILD = ["Cash", "Assets", "", "", 0, "Cash", "Asset", "INR"]
class TestChartofAccountsImporter(ERPNextTestSuite):
pass
"""The importer parses an uploaded CoA into a nested tree and validates its
shape. These cover the parsing/validation helpers without a file upload."""
def test_validate_columns_rejects_blank_file(self):
self.assertRaises(frappe.ValidationError, validate_columns, [])
def test_validate_columns_requires_eight_columns(self):
self.assertRaises(frappe.ValidationError, validate_columns, [["a", "b", "c"]])
# the standard template width passes
validate_columns([ROOT])
def test_build_forest_nests_child_under_parent(self):
forest = build_forest([ROOT, CHILD])
self.assertIn("Assets", forest)
self.assertIn("Cash", forest["Assets"])
def test_build_forest_rejects_unknown_parent(self):
orphan = ["Cash", "Missing Parent", "", "", 0, "Cash", "Asset", "INR"]
self.assertRaises(frappe.ValidationError, build_forest, [orphan])
def test_build_forest_requires_account_name(self):
nameless = ["", "Assets", "", "", 0, "Cash", "Asset", "INR"]
self.assertRaises(frappe.ValidationError, build_forest, [ROOT, nameless])
def test_validate_missing_roots_requires_all_root_types(self):
present = ("Asset", "Liability", "Expense", "Income") # Equity missing
self.assertRaises(
frappe.ValidationError,
validate_missing_roots,
[{"root_type": rt} for rt in present],
)
# all five root types present -> no error
validate_missing_roots(
[{"root_type": rt} for rt in ("Asset", "Liability", "Expense", "Income", "Equity")]
)

View File

@@ -46,7 +46,7 @@ class ChequePrintTemplate(Document):
pass
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def create_or_update_cheque_print_format(template_name: str):
frappe.only_for("System Manager")

View File

@@ -12,6 +12,7 @@ from erpnext.accounts.doctype.sales_invoice.mapper import (
create_dunning as create_dunning_from_sales_invoice,
)
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import (
create_sales_invoice,
create_sales_invoice_against_cost_center,
)
from erpnext.tests.utils import ERPNextTestSuite
@@ -152,6 +153,37 @@ class TestDunning(ERPNextTestSuite):
dunning.reload()
self.assertEqual(dunning.status, "Unresolved")
@ERPNextTestSuite.change_settings(
"Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}
)
def test_dunning_outstanding_uses_transaction_currency(self):
"""
Regression for #56006: dunning outstanding must be in the invoice transaction
currency, not in the party account currency.
A USD invoice posted against an INR receivable account stores
outstanding_amount in INR (party account currency). The overdue payment
row on the resulting Dunning must carry the USD amount, not the INR amount.
"""
si = create_sales_invoice(
posting_date=add_days(today(), -10),
currency="USD",
conversion_rate=50,
rate=100,
debit_to="Debtors - _TC",
)
# Sanity-check the invoice state before creating the dunning
self.assertEqual(si.currency, "USD")
self.assertEqual(si.outstanding_amount, 5000.0) # INR (party account currency)
self.assertEqual(si.payment_schedule[0].outstanding, 100.0) # USD (transaction currency)
dunning = create_dunning_from_sales_invoice(si.name)
self.assertEqual(len(dunning.overdue_payments), 1)
# Must reflect 100 USD, not 5000 INR mislabelled as USD
self.assertEqual(dunning.overdue_payments[0].outstanding, 100.0)
def test_dunning_not_affected_by_standalone_credit_note(self):
"""
Test that dunning is NOT resolved when a credit note has update_outstanding_for_self checked.

View File

@@ -298,3 +298,65 @@ class TestExchangeRateRevaluation(ERPNextTestSuite, AccountsTestMixin):
for key, _val in expected_data.items():
self.assertEqual(expected_data.get(key), account_details.get(key))
class TestExchangeRateRevaluationValidation(ERPNextTestSuite):
"""Validation and gain/loss calculation paths, exercised on the document directly
so they don't need the multi-currency GL setup the integration tests above build."""
def setUp(self):
frappe.set_user("Administrator")
self.company = "_Test Company"
def _revaluation_with_rows(self, rows, rounding_loss_allowance=0.05):
doc = frappe.new_doc("Exchange Rate Revaluation")
doc.company = self.company
doc.posting_date = today()
doc.rounding_loss_allowance = rounding_loss_allowance
for row in rows:
doc.append("accounts", row)
return doc
def test_rounding_loss_allowance_must_be_between_0_and_1(self):
for bad in (-0.1, 1, 1.5):
doc = self._revaluation_with_rows([], rounding_loss_allowance=bad)
self.assertRaises(frappe.ValidationError, doc.validate)
# values inside [0, 1) are accepted, at the lower bound and mid-range
for good in (0.0, 0.5):
self._revaluation_with_rows([], rounding_loss_allowance=good).validate()
def test_gain_loss_computed_and_split_by_zero_balance(self):
doc = self._revaluation_with_rows(
[
# open (unbooked) row: base balance moved 1000 -> 1100, a 100 gain
{"zero_balance": 0, "balance_in_base_currency": 1000, "new_balance_in_base_currency": 1100},
# already-settled (zero_balance) row carries a booked loss of 40
{"zero_balance": 1, "gain_loss": -40},
]
)
doc.validate()
# gain_loss is derived only for open rows; the zero-balance row keeps its value
self.assertEqual(doc.accounts[0].gain_loss, 100)
self.assertEqual(doc.gain_loss_unbooked, 100)
self.assertEqual(doc.gain_loss_booked, -40)
self.assertEqual(doc.total_gain_loss, 60)
def test_before_submit_drops_rows_without_gain_loss(self):
doc = self._revaluation_with_rows(
[
{"zero_balance": 0, "balance_in_base_currency": 1000, "new_balance_in_base_currency": 1100},
{"zero_balance": 0, "balance_in_base_currency": 500, "new_balance_in_base_currency": 500},
]
)
doc.validate() # second row nets to a 0 gain_loss
doc.remove_accounts_without_gain_loss()
self.assertEqual(len(doc.accounts), 1)
self.assertEqual(doc.accounts[0].gain_loss, 100)
def test_before_submit_requires_at_least_one_gain_loss_row(self):
doc = self._revaluation_with_rows(
[{"zero_balance": 0, "balance_in_base_currency": 500, "new_balance_in_base_currency": 500}]
)
doc.validate()
self.assertRaises(frappe.ValidationError, doc.remove_accounts_without_gain_loss)

View File

@@ -5,7 +5,6 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import flt
class ItemTaxTemplate(Document):
@@ -30,12 +29,6 @@ class ItemTaxTemplate(Document):
def validate(self):
self.set_zero_rate_for_not_applicable_tax()
self.validate_tax_accounts()
self.validate_tax_rates()
def validate_tax_rates(self):
for row in self.get("taxes"):
if flt(row.tax_rate) < 0:
frappe.throw(_("Row {0}: Tax Rate cannot be negative").format(row.idx))
def set_zero_rate_for_not_applicable_tax(self):
"""Ensure tax_rate is 0 for any row marked as not applicable."""

View File

@@ -54,6 +54,9 @@ class TestItemTaxTemplate(ERPNextTestSuite):
doc.insert()
self.assertEqual(doc.taxes[0].tax_rate, 0)
def test_negative_tax_rate_is_rejected(self):
def test_negative_tax_rate_is_accepted(self):
# SUSPECTED BUG: validate never bounds tax_rate, so a negative (or >100) rate
# saves silently. Locking the current (wrong) behaviour.
doc = self.make_template([(TAX_ACCOUNT, -5, 0)])
self.assertRaises(frappe.ValidationError, doc.insert)
doc.insert()
self.assertEqual(doc.taxes[0].tax_rate, -5)

View File

@@ -45,6 +45,20 @@ class JournalEntryTemplate(Document):
def validate(self):
self.validate_party()
self.validate_account_company()
def validate_account_company(self):
"""Each row's account must belong to the template's company."""
for account in self.accounts:
if (
account.account
and frappe.get_cached_value("Account", account.account, "company") != self.company
):
frappe.throw(
_("Row {0}: Account {1} does not belong to company {2}").format(
account.idx, account.account, self.company
)
)
def validate_party(self):
"""

View File

@@ -1,9 +1,45 @@
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import frappe
from erpnext.tests.utils import ERPNextTestSuite
COMPANY = "_Test Company"
class TestJournalEntryTemplate(ERPNextTestSuite):
pass
"""Journal Entry Template's only real rule is validate_party: party_type is
allowed only on Receivable/Payable accounts, and a party needs a party_type."""
def setUp(self):
frappe.set_user("Administrator")
def make_template(self, rows, company=COMPANY):
doc = frappe.new_doc("Journal Entry Template")
doc.template_title = f"_Test JET {frappe.generate_hash(length=6)}"
doc.company = company
doc.voucher_type = "Journal Entry"
doc.naming_series = frappe.get_meta("Journal Entry").get_field("naming_series").options.split("\n")[0]
for row in rows:
doc.append("accounts", row)
return doc
def test_party_type_only_on_receivable_or_payable_account(self):
# Cash is neither Receivable nor Payable, so a party_type here is invalid
doc = self.make_template([{"account": "Cash - _TC", "party_type": "Customer"}])
self.assertRaises(frappe.ValidationError, doc.validate)
def test_party_requires_party_type(self):
doc = self.make_template([{"account": "Debtors - _TC", "party": "_Test Customer"}])
self.assertRaises(frappe.ValidationError, doc.validate)
def test_account_from_other_company_is_rejected(self):
other_receivable = frappe.db.get_value(
"Account", {"company": "_Test Company 1", "account_type": "Receivable", "is_group": 0}, "name"
)
self.assertTrue(other_receivable, "need a receivable account in _Test Company 1")
doc = self.make_template(
[{"account": other_receivable, "party_type": "Customer", "party": "_Test Customer"}]
)
self.assertRaises(frappe.ValidationError, doc.insert)

View File

@@ -8,7 +8,7 @@ frappe.ui.form.on("Loyalty Program", {
var help_content = `<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
<tr><td>
<h4>
<i class="fa fa-hand-right"></i>
<svg class="icon icon-sm"><use href="#icon-info"></use></svg>
${__("Notes")}
</h4>
<ul>

View File

@@ -5,9 +5,59 @@ import frappe
from erpnext.tests.utils import ERPNextTestSuite
COMPANY = "_Test Company"
class TestModeofPayment(ERPNextTestSuite):
pass
"""Mode of Payment validates its per-company default accounts (account company
must match the row, no company twice) and blocks disabling while a POS Profile
still references it."""
def setUp(self):
frappe.set_user("Administrator")
def make_mop(self, accounts=None, enabled=1):
doc = frappe.new_doc("Mode of Payment")
doc.mode_of_payment = f"_Test MoP {frappe.generate_hash(length=6)}"
doc.type = "General"
doc.enabled = enabled
for company, account in accounts or []:
doc.append("accounts", {"company": company, "default_account": account})
return doc
def test_valid_mode_of_payment_saves(self):
doc = self.make_mop(accounts=[(COMPANY, "Cash - _TC")])
doc.insert()
self.assertTrue(doc.name)
def test_account_of_wrong_company_throws(self):
other_account = frappe.db.get_value("Account", {"company": "_Test Company 1", "is_group": 0}, "name")
self.assertTrue(other_account, "need a non-group account in _Test Company 1")
doc = self.make_mop(accounts=[(COMPANY, other_account)])
self.assertRaises(frappe.ValidationError, doc.insert)
def test_repeating_company_throws(self):
doc = self.make_mop(accounts=[(COMPANY, "Cash - _TC"), (COMPANY, "Debtors - _TC")])
self.assertRaises(frappe.ValidationError, doc.insert)
def test_disabling_mode_referenced_by_pos_profile_is_not_blocked(self):
# SUSPECTED BUG: validate_pos_mode_of_payment queries "Sales Invoice Payment"
# rows with parenttype "POS Profile", but a POS Profile's payments are stored
# as "POS Payment Method" rows. The filter never matches, so the guard is dead
# and a mode still referenced by a POS Profile disables without complaint.
# Locking the current (wrong) behaviour so a fix to the guard trips this test.
from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile
make_pos_profile() # its payments row references the "Cash" mode of payment
cash = frappe.get_doc("Mode of Payment", "Cash")
cash.enabled = 0
cash.save()
self.assertEqual(frappe.db.get_value("Mode of Payment", "Cash", "enabled"), 0)
def test_disabling_unreferenced_mode_succeeds(self):
doc = self.make_mop(accounts=[(COMPANY, "Cash - _TC")], enabled=0)
doc.insert()
self.assertEqual(doc.enabled, 0)
def set_default_account_for_mode_of_payment(mode_of_payment, company, account):

View File

@@ -1,8 +1,67 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import frappe
from frappe.utils import getdate
from erpnext.accounts.doctype.monthly_distribution.monthly_distribution import (
get_percentage,
get_periodwise_distribution_data,
)
from erpnext.tests.utils import ERPNextTestSuite
class TestMonthlyDistribution(ERPNextTestSuite):
pass
"""Monthly Distribution spreads an amount across months. validate() enforces a
100% total; get_percentage() sums the months that fall inside a period window."""
def setUp(self):
frappe.set_user("Administrator")
def make_distribution(self, allocations):
doc = frappe.new_doc("Monthly Distribution")
doc.distribution_id = f"_Test MD {frappe.generate_hash(length=6)}"
for month, pct in allocations:
doc.append("percentages", {"month": month, "percentage_allocation": pct})
return doc
def test_get_months_populates_twelve_even_rows(self):
doc = frappe.new_doc("Monthly Distribution")
doc.distribution_id = "_Test MD Even"
doc.get_months()
self.assertEqual(len(doc.percentages), 12)
self.assertEqual(doc.percentages[0].month, "January")
self.assertEqual(doc.percentages[-1].month, "December")
self.assertEqual([d.idx for d in doc.percentages], list(range(1, 13)))
for d in doc.percentages:
self.assertAlmostEqual(d.percentage_allocation, 100.0 / 12, places=4)
# the auto-populated rows round to exactly 100 and pass validation
doc.validate()
def test_validate_rejects_total_other_than_100(self):
doc = self.make_distribution([("January", 50), ("February", 30)]) # sums to 80
self.assertRaises(frappe.ValidationError, doc.insert)
def test_get_percentage_sums_period_window(self):
doc = self.make_distribution([("January", 50), ("February", 30), ("March", 20)])
doc.insert() # total is 100, so validate passes
# a quarter starting in January covers Jan+Feb+Mar
self.assertEqual(get_percentage(doc, getdate("2026-01-01"), 3), 100)
# a single month picks up only that month
self.assertEqual(get_percentage(doc, getdate("2026-02-01"), 1), 30)
# months with no row simply contribute 0 (there is no guard that all 12 exist)
self.assertEqual(get_percentage(doc, getdate("2026-04-01"), 1), 0)
def test_periodwise_distribution_maps_each_period(self):
doc = self.make_distribution([("January", 50), ("February", 30), ("March", 20)])
doc.insert()
period_list = [
frappe._dict(key="q1", from_date=getdate("2026-01-01")),
frappe._dict(key="q2", from_date=getdate("2026-04-01")),
]
data = get_periodwise_distribution_data(doc.name, period_list, "Quarterly")
self.assertEqual(data["q1"], 100) # Jan+Feb+Mar
self.assertEqual(data["q2"], 0) # Apr+May+Jun carry no allocation

View File

@@ -1,9 +1,67 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import frappe
from erpnext.accounts.doctype.party_link.party_link import create_party_link
from erpnext.tests.utils import ERPNextTestSuite
CUSTOMER = "_Test Customer"
SUPPLIER = "_Test Supplier"
SUPPLIER_2 = "_Test Supplier 1"
class TestPartyLink(ERPNextTestSuite):
pass
"""Party Link ties a Customer and a Supplier together as one underlying party.
validate() constrains the primary role and blocks duplicate links."""
def setUp(self):
frappe.set_user("Administrator")
def test_create_party_link_with_customer_primary(self):
link = create_party_link("Customer", CUSTOMER, SUPPLIER)
self.assertEqual(link.primary_role, "Customer")
self.assertEqual(link.secondary_role, "Supplier")
self.assertEqual(link.primary_party, CUSTOMER)
self.assertEqual(link.secondary_party, SUPPLIER)
self.assertTrue(frappe.db.exists("Party Link", link.name))
def test_create_party_link_with_supplier_primary(self):
link = create_party_link("Supplier", SUPPLIER, CUSTOMER)
self.assertEqual(link.primary_role, "Supplier")
self.assertEqual(link.secondary_role, "Customer")
self.assertEqual(link.primary_party, SUPPLIER)
self.assertEqual(link.secondary_party, CUSTOMER)
self.assertTrue(frappe.db.exists("Party Link", link.name))
def test_primary_role_must_be_customer_or_supplier(self):
doc = frappe.new_doc("Party Link")
doc.primary_role = "Employee"
doc.primary_party = CUSTOMER
doc.secondary_role = "Supplier"
doc.secondary_party = SUPPLIER
# validate() alone isolates the role rule from the dynamic-link checks
self.assertRaises(frappe.ValidationError, doc.validate)
def test_duplicate_link_throws(self):
create_party_link("Customer", CUSTOMER, SUPPLIER)
dup = frappe.new_doc("Party Link")
dup.primary_role = "Customer"
dup.primary_party = CUSTOMER
dup.secondary_role = "Supplier"
dup.secondary_party = SUPPLIER
self.assertRaises(frappe.ValidationError, dup.insert)
def test_party_can_wrongly_be_primary_in_two_links(self):
# SUSPECTED BUG: the uniqueness checks are asymmetric - a party already a
# *primary* in another link isn't blocked, so one customer can be linked to two
# different suppliers, breaking the 1:1 mapping. Locking the current (wrong)
# behaviour so a fix that blocks primary reuse trips this test.
create_party_link("Customer", CUSTOMER, SUPPLIER)
link2 = frappe.new_doc("Party Link")
link2.primary_role = "Customer"
link2.primary_party = CUSTOMER
link2.secondary_role = "Supplier"
link2.secondary_party = SUPPLIER_2
link2.insert()
self.assertTrue(frappe.db.exists("Party Link", link2.name))

View File

@@ -414,21 +414,17 @@ frappe.ui.form.on("Payment Entry", {
show_general_ledger: function (frm) {
if (frm.doc.docstatus > 0) {
frm.add_custom_button(
__("Ledger"),
function () {
frappe.route_options = {
voucher_no: frm.doc.name,
from_date: frm.doc.posting_date,
to_date: moment(frm.doc.modified).format("YYYY-MM-DD"),
company: frm.doc.company,
categorize_by: "",
show_cancelled_entries: frm.doc.docstatus === 2,
};
frappe.set_route("query-report", "General Ledger");
},
"fa fa-table"
);
frm.add_custom_button(__("Ledger"), function () {
frappe.route_options = {
voucher_no: frm.doc.name,
from_date: frm.doc.posting_date,
to_date: moment(frm.doc.modified).format("YYYY-MM-DD"),
company: frm.doc.company,
categorize_by: "",
show_cancelled_entries: frm.doc.docstatus === 2,
};
frappe.set_route("query-report", "General Ledger");
});
}
},

View File

@@ -246,6 +246,62 @@ class TestPaymentEntry(ERPNextTestSuite):
outstanding_amount = flt(frappe.db.get_value("Sales Invoice", pi.name, "outstanding_amount"))
self.assertEqual(outstanding_amount, 0)
def test_pay_multiple_purchase_invoices_in_one_entry(self):
pi1 = make_purchase_invoice() # outstanding 250
pi2 = make_purchase_invoice() # outstanding 250
pe = get_payment_entry("Purchase Invoice", pi1.name, bank_account="_Test Cash - _TC")
pe.append(
"references",
{
"reference_doctype": "Purchase Invoice",
"reference_name": pi2.name,
"total_amount": pi2.grand_total,
"outstanding_amount": pi2.outstanding_amount,
"allocated_amount": pi2.outstanding_amount,
},
)
pe.paid_amount = pe.received_amount = (
pe.references[0].allocated_amount + pe.references[1].allocated_amount
)
pe.insert()
pe.submit()
self.assertEqual(pe.total_allocated_amount, 500)
self.assertEqual(frappe.db.get_value("Purchase Invoice", pi1.name, "outstanding_amount"), 0)
self.assertEqual(frappe.db.get_value("Purchase Invoice", pi2.name, "outstanding_amount"), 0)
def test_unallocated_amount_on_overpaid_purchase_payment(self):
pi = make_purchase_invoice() # outstanding 250
pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Cash - _TC")
pe.paid_amount = pe.references[0].allocated_amount + 200 # overpay -> 200 advance
pe.received_amount = pe.paid_amount
pe.insert()
pe.submit()
self.assertEqual(pe.docstatus, 1)
self.assertEqual(pe.unallocated_amount, 200)
# end-to-end: submitting posts a balanced GL for the full paid amount (250
# settling the invoice + 200 advance)
gl_entries = frappe.get_all(
"GL Entry",
filters={"voucher_no": pe.name, "is_cancelled": 0},
fields=["debit", "credit"],
)
self.assertTrue(gl_entries, "Submitted payment produced no GL entries")
self.assertEqual(flt(sum(e.debit for e in gl_entries)), flt(sum(e.credit for e in gl_entries)))
self.assertEqual(flt(sum(e.debit for e in gl_entries)), 450)
def test_overallocation_against_purchase_invoice_throws(self):
pi = make_purchase_invoice() # outstanding 250
pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Cash - _TC")
pe.references[0].allocated_amount += 100 # 350 > 250 outstanding
pe.paid_amount = pe.received_amount = pe.references[0].allocated_amount
self.assertRaises(frappe.ValidationError, pe.insert)
def test_payment_against_sales_invoice_to_check_status(self):
si = create_sales_invoice(
customer="_Test Customer USD",
@@ -2317,3 +2373,65 @@ def create_customer(name="_Test Customer 2 USD", currency="USD"):
customer.save()
customer = customer.name
return customer
class TestPaymentEntryValidation(ERPNextTestSuite):
"""Field-level validations invoked on the document directly, covering branches the
integration suite above doesn't reach (no GL / reconciliation setup needed)."""
def make_pe(self, **fields):
doc = frappe.new_doc("Payment Entry")
doc.update(fields)
return doc
def test_payment_type_must_be_a_known_value(self):
self.assertRaises(frappe.ValidationError, self.make_pe(payment_type="Foo").validate_payment_type)
self.make_pe(payment_type="Receive").validate_payment_type() # valid value passes
def test_nonexistent_party_is_rejected(self):
doc = self.make_pe(party_type="Customer", party="__No Such Customer__")
self.assertRaises(frappe.ValidationError, doc.validate_party_details)
def test_amount_and_exchange_rate_fields_are_mandatory(self):
# every field but target_exchange_rate is set, so that missing one raises
doc = self.make_pe(
paid_amount=100, received_amount=100, source_exchange_rate=1, target_exchange_rate=0
)
self.assertRaises(frappe.ValidationError, doc.validate_mandatory)
def test_received_amount_cannot_exceed_paid_in_same_currency(self):
doc = self.make_pe(
paid_from_account_currency="INR",
paid_to_account_currency="INR",
paid_amount=100,
received_amount=150,
)
self.assertRaises(frappe.ValidationError, doc.validate_received_amount)
# received <= paid is fine
doc.received_amount = 50
doc.validate_received_amount()
def test_duplicate_reference_rows_are_rejected(self):
doc = self.make_pe()
for _ in range(2):
doc.append(
"references",
{"reference_doctype": "Sales Invoice", "reference_name": "SI-X", "allocated_amount": 100},
)
self.assertRaises(frappe.ValidationError, doc.validate_duplicate_entry)
def test_receive_from_customer_against_negative_outstanding_is_rejected(self):
doc = self.make_pe(party_type="Customer", payment_type="Receive")
doc.append(
"references",
{"reference_doctype": "Sales Invoice", "reference_name": "SI-Y", "allocated_amount": -100},
)
self.assertRaises(frappe.ValidationError, doc.validate_payment_type_with_outstanding)
def test_bank_transaction_requires_a_reference_number(self):
doc = self.make_pe(payment_type="Pay", paid_from="_Test Bank - _TC")
self.assertRaises(frappe.ValidationError, doc.validate_transaction_reference)
# supplying the reference details clears the requirement
doc.reference_no = "TXN-1"
doc.reference_date = "2026-06-15"
doc.validate_transaction_reference()

View File

@@ -718,7 +718,7 @@ class PaymentRequest(Document):
row_number += TO_SKIP_NEW_ROW
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def make_payment_request(**args):
"""Make payment request"""

View File

@@ -41,21 +41,17 @@ frappe.ui.form.on("Period Closing Voucher", {
refresh: function (frm) {
if (frm.doc.docstatus > 0) {
frm.add_custom_button(
__("Ledger"),
function () {
frappe.route_options = {
voucher_no: frm.doc.name,
from_date: frm.doc.period_start_date,
to_date: frm.doc.period_end_date,
company: frm.doc.company,
categorize_by: "",
show_cancelled_entries: frm.doc.docstatus === 2,
};
frappe.set_route("query-report", "General Ledger");
},
"fa fa-table"
);
frm.add_custom_button(__("Ledger"), function () {
frappe.route_options = {
voucher_no: frm.doc.name,
from_date: frm.doc.period_start_date,
to_date: frm.doc.period_end_date,
company: frm.doc.company,
categorize_by: "",
show_cancelled_entries: frm.doc.docstatus === 2,
};
frappe.set_route("query-report", "General Ledger");
});
}
},
});

View File

@@ -0,0 +1,34 @@
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# Regression test for https://github.com/frappe/erpnext/issues/56501
# AttributeError: 'POSInvoice' object has no attribute 'is_created_using_pos'
# when calling reset_mode_of_payments on a draft POS Invoice.
from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import (
POSInvoiceTestMixin,
create_pos_invoice,
)
from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry
class TestPOSInvoiceResetModeOfPayments(POSInvoiceTestMixin):
def setUp(self):
super().setUp()
create_opening_entry(self.pos_profile, self.test_user.name)
def test_reset_mode_of_payments_does_not_raise_attribute_error(self):
"""Calling reset_mode_of_payments on a draft POS Invoice must not raise
AttributeError for the missing is_created_using_pos attribute.
update_multi_mode_option accesses doc.is_created_using_pos, which is a
field on SalesInvoice but does not exist on POSInvoice, causing the error
reported in #56501 when a user tries to edit a saved draft order.
"""
inv = create_pos_invoice(do_not_submit=True)
# This call must not raise AttributeError on the missing field.
inv.reset_mode_of_payments()
# Payments should have been repopulated from the POS profile.
self.assertTrue(len(inv.payments) > 0, "Payments should be populated after reset")

View File

@@ -40,7 +40,7 @@ frappe.ui.form.on("Pricing Rule", {
var help_content = `<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
<tr><td>
<h4>
<i class="fa fa-hand-right"></i>
<svg class="icon icon-sm"><use href="#icon-info"></use></svg>
${__("Notes")}
</h4>
<ul>
@@ -63,7 +63,7 @@ frappe.ui.form.on("Pricing Rule", {
</ul>
</td></tr>
<tr><td>
<h4><i class="fa fa-question-sign"></i>
<h4><svg class="icon icon-sm"><use href="#icon-circle-question-mark"></use></svg>
${__("How Pricing Rule is applied?")}
</h4>
<ol>

View File

@@ -106,6 +106,8 @@ def get_pr_instance(doc: str):
"party",
"receivable_payable_account",
"default_advance_account",
"bank_cash_account",
"cost_center",
"from_invoice_date",
"to_invoice_date",
"from_payment_date",

View File

@@ -1,11 +1,73 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import frappe
from erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation import (
get_pr_instance,
)
from erpnext.tests.utils import ERPNextTestSuite
COMPANY = "_Test Company"
class TestProcessPaymentReconciliation(ERPNextTestSuite):
pass
"""Process Payment Reconciliation validates its accounts against the company,
moves to Queued on submit, and hands its filters to a Payment Reconciliation run."""
def setUp(self):
frappe.set_user("Administrator")
def make_ppr(self, **args):
args = frappe._dict(args)
doc = frappe.new_doc("Process Payment Reconciliation")
doc.company = COMPANY
doc.party_type = "Customer"
doc.party = "_Test Customer"
doc.receivable_payable_account = args.get("receivable_payable_account", "Debtors - _TC")
doc.bank_cash_account = args.get("bank_cash_account")
doc.from_invoice_date = args.get("from_invoice_date")
doc.to_invoice_date = args.get("to_invoice_date")
return doc
def other_company_account(self, **extra):
filters = {"company": "_Test Company 1", "is_group": 0, **extra}
account = frappe.db.get_value("Account", filters, "name")
self.assertTrue(account, "need a matching account in _Test Company 1")
return account
def test_receivable_account_must_belong_to_company(self):
doc = self.make_ppr(receivable_payable_account=self.other_company_account(account_type="Receivable"))
self.assertRaises(frappe.ValidationError, doc.insert)
def test_bank_cash_account_must_belong_to_company(self):
doc = self.make_ppr(bank_cash_account=self.other_company_account())
self.assertRaises(frappe.ValidationError, doc.insert)
def test_submit_sets_status_to_queued(self):
doc = self.make_ppr()
doc.insert()
doc.submit()
self.assertEqual(doc.status, "Queued")
def test_get_pr_instance_copies_filters_and_caps_limits(self):
doc = self.make_ppr(from_invoice_date="2026-01-01", to_invoice_date="2026-06-30")
doc.insert()
pr = get_pr_instance(doc.name)
self.assertEqual(pr.company, COMPANY)
self.assertEqual(pr.party, "_Test Customer")
self.assertEqual(pr.receivable_payable_account, "Debtors - _TC")
self.assertEqual(str(pr.from_invoice_date), "2026-01-01")
# the tool run is capped so a single process can't fetch unbounded rows
self.assertEqual(pr.invoice_limit, 1000)
self.assertEqual(pr.payment_limit, 1000)
def test_get_pr_instance_copies_bank_cash_and_cost_center(self):
doc = self.make_ppr(bank_cash_account="Cash - _TC")
doc.cost_center = "_Test Cost Center - _TC"
doc.insert()
pr = get_pr_instance(doc.name)
self.assertEqual(pr.bank_cash_account, "Cash - _TC")
self.assertEqual(pr.cost_center, "_Test Cost Center - _TC")

View File

@@ -89,50 +89,55 @@ class ProcessPeriodClosingVoucher(Document):
cancel_pcv_processing(self.name)
def initialize_parallel_threads(docname: str):
threads = 4
timeout = frappe.db.get_single_value("Accounts Settings", "pcv_job_timeout") or 3600
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Running")
if normal_balances := (
qb.from_(ppcvd)
.select(ppcvd.name, ppcvd.processing_date, ppcvd.report_type, ppcvd.parentfield)
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Queued"))
.orderby(ppcvd.parentfield, ppcvd.idx, ppcvd.processing_date)
.limit(threads)
.for_update(skip_locked=True)
.run(as_dict=True)
):
if not is_scheduler_inactive():
for x in normal_balances:
frappe.db.set_value(
"Process Period Closing Voucher Detail",
x.name,
"status",
"Running",
)
frappe.enqueue(
method="erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.process_individual_date",
queue="long",
timeout=timeout,
is_async=True,
enqueue_after_commit=True,
docname=docname,
row_name=x.name,
date=x.processing_date,
report_type=x.report_type,
parentfield=x.parentfield,
)
# keep transaction on PPCV and PPCVD short
# prevents concurrency errors - REPEATABLE READ
if not frappe.in_test:
frappe.db.commit() # nosemgrep
else:
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
@frappe.whitelist()
def start_pcv_processing(docname: str):
if frappe.db.get_value("Process Period Closing Voucher", docname, "status") in ["Queued", "Running"]:
frappe.has_permission("Process Period Closing Voucher", "write", doc=docname, throw=True)
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Running")
timeout = frappe.db.get_single_value("Accounts Settings", "pcv_job_timeout") or 3600
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
if normal_balances := (
qb.from_(ppcvd)
.select(ppcvd.processing_date, ppcvd.report_type, ppcvd.parentfield)
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Queued"))
.orderby(ppcvd.parentfield, ppcvd.idx, ppcvd.processing_date)
.limit(4)
.for_update(skip_locked=True)
.run(as_dict=True)
):
if not is_scheduler_inactive():
for x in normal_balances:
frappe.db.set_value(
"Process Period Closing Voucher Detail",
{
"processing_date": x.processing_date,
"parent": docname,
"report_type": x.report_type,
"parentfield": x.parentfield,
},
"status",
"Running",
)
frappe.enqueue(
method="erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.process_individual_date",
queue="long",
timeout=timeout,
is_async=True,
enqueue_after_commit=True,
docname=docname,
date=x.processing_date,
report_type=x.report_type,
parentfield=x.parentfield,
)
else:
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
initialize_parallel_threads(docname)
@frappe.whitelist()
@@ -250,11 +255,11 @@ def get_gle_for_closing_account(pcv, dimension_balance, dimensions):
@frappe.whitelist()
def schedule_next_date(docname: str):
timeout = frappe.db.get_single_value("Accounts Settings", "pcv_job_timeout") or 3600
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
if to_process := (
qb.from_(ppcvd)
.select(ppcvd.processing_date, ppcvd.report_type, ppcvd.parentfield)
.select(ppcvd.name, ppcvd.processing_date, ppcvd.report_type, ppcvd.parentfield)
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Queued"))
.orderby(ppcvd.parentfield, ppcvd.idx, ppcvd.processing_date)
.limit(1)
@@ -264,15 +269,15 @@ def schedule_next_date(docname: str):
if not is_scheduler_inactive():
frappe.db.set_value(
"Process Period Closing Voucher Detail",
{
"processing_date": to_process[0].processing_date,
"parent": docname,
"report_type": to_process[0].report_type,
"parentfield": to_process[0].parentfield,
},
to_process[0].name,
"status",
"Running",
)
# keep transaction on PPCV and PPCVD short
# prevents concurrency errors - REPEATABLE READ
if not frappe.in_test:
frappe.db.commit() # nosemgrep
frappe.enqueue(
method="erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.process_individual_date",
queue="long",
@@ -280,6 +285,7 @@ def schedule_next_date(docname: str):
is_async=True,
enqueue_after_commit=True,
docname=docname,
row_name=to_process[0].name,
date=to_process[0].processing_date,
report_type=to_process[0].report_type,
parentfield=to_process[0].parentfield,
@@ -444,6 +450,11 @@ def summarize_and_post_ledger_entries(docname):
make_closing_entries(closing_entries, pcv.name, pcv.company, pcv.period_end_date)
# keep transaction on PPCV and PPCVD short
# prevents concurrency errors - REPEATABLE READ
if not frappe.in_test:
frappe.db.commit() # nosemgrep
frappe.db.set_value("Period Closing Voucher", pcv.name, "gle_processing_status", "Completed")
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
@@ -529,10 +540,10 @@ def build_dimension_wise_balance_dict(gl_entries):
return dimension_balances
def process_individual_date(docname: str, date, report_type, parentfield):
def process_individual_date(docname: str, row_name, date, report_type, parentfield):
current_date_status = frappe.db.get_value(
"Process Period Closing Voucher Detail",
{"processing_date": date, "report_type": report_type, "parentfield": parentfield},
row_name,
"status",
)
if current_date_status != "Running":
@@ -580,17 +591,20 @@ def process_individual_date(docname: str, date, report_type, parentfield):
# save results
frappe.db.set_value(
"Process Period Closing Voucher Detail",
{"processing_date": date, "parent": docname, "report_type": report_type, "parentfield": parentfield},
row_name,
"closing_balance",
frappe.json.dumps(res),
)
frappe.db.set_value(
"Process Period Closing Voucher Detail",
{"processing_date": date, "parent": docname, "report_type": report_type, "parentfield": parentfield},
row_name,
"status",
"Completed",
)
# commit heavy computation before touching PPCV or PPCVD
if not frappe.in_test:
frappe.db.commit() # nosemgrep
# chain call
schedule_next_date(docname)

View File

@@ -48,18 +48,27 @@ class TestProcessPeriodClosingVoucher(ERPNextTestSuite):
ppcv.save()
return ppcv
def set_processing_date_status(self, date, ppcv, rpt_type, parentfield, status):
def set_processing_date_status(self, row_name, status):
frappe.db.set_value(
"Process Period Closing Voucher Detail",
{"processing_date": date, "parent": ppcv, "report_type": rpt_type, "parentfield": parentfield},
row_name,
"status",
status,
)
def get_processing_date_closing_balance(self, date, ppcv, rpt_type, parentfield):
def get_row_name(self, ppcv_name, rpt_type, parentfield):
return frappe.db.get_all(
"Process Period Closing Voucher Detail",
filters={"parent": ppcv_name, "report_type": rpt_type, "parentfield": parentfield},
order_by="report_type, idx",
pluck="name",
limit=1,
)[0]
def get_processing_date_closing_balance(self, row_name):
return frappe.db.get_value(
"Process Period Closing Voucher Detail",
{"processing_date": date, "parent": ppcv, "report_type": rpt_type, "parentfield": parentfield},
row_name,
"closing_balance",
)
@@ -97,11 +106,10 @@ class TestProcessPeriodClosingVoucher(ERPNextTestSuite):
parentfield = "normal_balances"
rpt_type = "Profit and Loss"
# status has to be set to 'Running' for logic to run
self.set_processing_date_status(today(), ppcv.name, rpt_type, parentfield, "Running")
process_individual_date(ppcv.name, today(), rpt_type, parentfield)
bal = frappe.parse_json(
self.get_processing_date_closing_balance(today(), ppcv.name, rpt_type, parentfield)
)
row_name = self.get_row_name(ppcv.name, rpt_type, parentfield)
self.set_processing_date_status(row_name, "Running")
process_individual_date(ppcv.name, row_name, today(), rpt_type, parentfield)
bal = frappe.parse_json(self.get_processing_date_closing_balance(row_name))
self.assertEqual(len(bal), 1)
expected_pl = {
"account": "Sales - _TC",
@@ -117,11 +125,10 @@ class TestProcessPeriodClosingVoucher(ERPNextTestSuite):
# Balance sheet balance
rpt_type = "Balance Sheet"
self.set_processing_date_status(today(), ppcv.name, rpt_type, parentfield, "Running")
process_individual_date(ppcv.name, today(), rpt_type, parentfield)
bal = frappe.parse_json(
self.get_processing_date_closing_balance(today(), ppcv.name, rpt_type, parentfield)
)
row_name = self.get_row_name(ppcv.name, rpt_type, parentfield)
self.set_processing_date_status(row_name, "Running")
process_individual_date(ppcv.name, row_name, today(), rpt_type, parentfield)
bal = frappe.parse_json(self.get_processing_date_closing_balance(row_name))
self.assertEqual(len(bal), 1)
expected_bs = {
"account": "Debtors - _TC",
@@ -138,11 +145,10 @@ class TestProcessPeriodClosingVoucher(ERPNextTestSuite):
# Opening balance
parentfield = "z_opening_balances"
rpt_type = "Balance Sheet"
self.set_processing_date_status(today(), ppcv.name, rpt_type, parentfield, "Running")
process_individual_date(ppcv.name, today(), rpt_type, parentfield)
bal = frappe.parse_json(
self.get_processing_date_closing_balance(today(), ppcv.name, rpt_type, parentfield)
)
row_name = self.get_row_name(ppcv.name, rpt_type, parentfield)
self.set_processing_date_status(row_name, "Running")
process_individual_date(ppcv.name, row_name, today(), rpt_type, parentfield)
bal = frappe.parse_json(self.get_processing_date_closing_balance(row_name))
self.assertEqual(len(bal), 2)
opening_cash = next(x for x in bal if x["account"] == "Cash - _TC")
expected_opening_cash = {

View File

@@ -1,7 +1,7 @@
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
import frappe
from frappe.model.document import Document
@@ -24,3 +24,10 @@ class ProcessPeriodClosingVoucherDetail(Document):
# end: auto-generated types
pass
def on_doctype_update():
frappe.db.add_index(
"Process Period Closing Voucher Detail",
["parent", "status", "parentfield", "idx", "processing_date"],
)

View File

@@ -113,3 +113,38 @@ def create_process_soa(**args):
process_soa.update(soa_dict)
process_soa.save()
return process_soa
class TestProcessStatementOfAccountsValidation(ERPNextTestSuite):
"""validate() fills in default subject/body/pdf templates and enforces the
basic constraints. Exercised on the document directly (no email/PDF flow)."""
def make_soa(self, report="Accounts Receivable", with_customer=True, **overrides):
doc = frappe.new_doc("Process Statement Of Accounts")
doc.report = report
doc.company = "_Test Company"
if with_customer:
doc.append("customers", {"customer": "_Test Customer"})
doc.update(overrides)
return doc
def test_customers_are_required(self):
self.assertRaises(frappe.ValidationError, self.make_soa(with_customer=False).validate)
def test_general_ledger_body_uses_a_date_range(self):
doc = self.make_soa(report="General Ledger")
doc.validate()
self.assertIn("from {{ doc.from_date }} to {{ doc.to_date }}", doc.body)
# subject and pdf name are also defaulted
self.assertTrue(doc.subject)
self.assertTrue(doc.pdf_name)
def test_receivable_body_uses_the_posting_date(self):
doc = self.make_soa(report="Accounts Receivable")
doc.validate()
self.assertIn("until {{ doc.posting_date }}", doc.body)
def test_account_must_belong_to_company(self):
other = frappe.db.get_value("Account", {"company": "_Test Company 1", "is_group": 0}, "name")
self.assertTrue(other, "need an account in _Test Company 1")
self.assertRaises(frappe.ValidationError, self.make_soa(account=other).validate)

View File

@@ -1,11 +1,56 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
from unittest.mock import patch
import frappe
from erpnext.accounts.doctype.process_subscription.process_subscription import (
create_subscription_process,
)
from erpnext.accounts.doctype.subscription.test_subscription import (
create_parties,
create_subscription,
make_plans,
reset_settings,
)
from erpnext.tests.utils import ERPNextTestSuite
class TestProcessSubscription(ERPNextTestSuite):
pass
"""Process Subscription is a batch driver: on submit it enqueues subscription.process_all
for every non-cancelled Subscription (or just one when a subscription is named)."""
def setUp(self):
frappe.set_user("Administrator")
# mirror TestSubscription setup so subscriptions build against known settings
make_plans()
create_parties()
reset_settings()
frappe.db.set_value("Company", "_Test Company", "accounts_frozen_till_date", None)
def enqueued_subscriptions(self, subscription=None):
"""Submit a Process Subscription while capturing what gets enqueued."""
calls = []
def capture(*args, **kwargs):
calls.append(kwargs)
with patch("frappe.enqueue", side_effect=capture):
create_subscription_process(subscription=subscription, posting_date="2026-06-15")
# each enqueue is handed a batch (list) of subscription names
return [name for call in calls for name in call.get("subscription", [])]
def test_named_subscription_is_the_only_one_enqueued(self):
sub = create_subscription(start_date="2026-01-01")
self.assertEqual(self.enqueued_subscriptions(subscription=sub.name), [sub.name])
def test_cancelled_subscriptions_are_skipped(self):
active = create_subscription(start_date="2026-01-01")
cancelled = create_subscription(start_date="2026-01-01")
cancelled.cancel_subscription()
enqueued = self.enqueued_subscriptions()
self.assertIn(active.name, enqueued)
self.assertNotIn(cancelled.name, enqueued)

View File

@@ -3,7 +3,6 @@
import frappe
from frappe import _
from frappe.query_builder.functions import Sum
from frappe.utils import cint, flt, get_link_to_form
import erpnext
@@ -131,7 +130,6 @@ class PurchaseInvoiceGLComposer(BaseGLComposer):
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import (
get_purchase_document_details,
)
from erpnext.stock.utils import get_valuation_method
doc = self.doc
tax_service = TaxService(doc)
@@ -331,33 +329,25 @@ class PurchaseInvoiceGLComposer(BaseGLComposer):
self.make_provisional_gl_entry(gl_entries, item)
if not doc.is_internal_transfer():
handled = False
if (
item.item_code
and item.item_code in stock_items
and item.get("purchase_receipt")
and not doc.is_return
and get_valuation_method(item.item_code, doc.company) == "Standard Cost"
):
handled = self.make_standard_cost_srbnb_split(
gl_entries, item, expense_account, account_currency, base_amount
)
if not handled:
gl_entries.append(
self.get_gl_dict(
{
"account": expense_account,
"against": doc.supplier,
"debit": base_amount,
"debit_in_transaction_currency": amount,
"cost_center": item.cost_center,
"project": item.project or doc.project,
},
account_currency,
item=item,
)
# When Update Stock is disabled, this invoice has no stock impact: the linked
# Purchase Receipt already booked the stock (at standard) and the Purchase Price
# Variance. Here we only clear "Stock Received But Not Billed" at the full billed
# amount against the supplier - booking PPV again would double count it and leave
# SRBNB partially uncleared.
gl_entries.append(
self.get_gl_dict(
{
"account": expense_account,
"against": doc.supplier,
"debit": base_amount,
"debit_in_transaction_currency": amount,
"cost_center": item.cost_center,
"project": item.project or doc.project,
},
account_currency,
item=item,
)
)
# check if the exchange rate has changed
if (
@@ -530,95 +520,6 @@ class PurchaseInvoiceGLComposer(BaseGLComposer):
},
)
def make_standard_cost_srbnb_split(
self, gl_entries, item, expense_account, account_currency, base_amount
):
"""For a Standard Cost item billed against a Purchase Receipt, clear SRBNB at the standard
value the receipt actually booked and post the (Net Amount - standard) difference to the
Purchase Price Variance account. Returns False (caller falls back) if the receipt value
can't be resolved."""
from erpnext.stock.doctype.item_standard_cost.item_standard_cost import (
get_purchase_price_variance_account,
)
doc = self.doc
precision = item.precision("base_net_amount")
standard_value = flt(self.get_pr_stock_value(item), precision)
if not standard_value:
return False
gl_entries.append(
self.get_gl_dict(
{
"account": expense_account,
"against": doc.supplier,
"debit": standard_value,
"debit_in_transaction_currency": flt(standard_value / doc.conversion_rate, precision),
"remarks": doc.get("remarks") or _("Accounting Entry for Stock"),
"cost_center": item.cost_center,
"project": item.project or doc.project,
},
account_currency,
item=item,
)
)
variance = flt(base_amount - standard_value, precision)
if variance:
gl_entries.append(
self.get_gl_dict(
{
"account": get_purchase_price_variance_account(item.item_code, doc.company),
"against": doc.supplier,
"debit": variance,
"debit_in_transaction_currency": flt(variance / doc.conversion_rate, precision),
"remarks": doc.get("remarks") or _("Purchase Price Variance"),
"cost_center": item.cost_center,
"project": item.project or doc.project,
},
item=item,
)
)
return True
def get_pr_stock_value(self, item):
"""Stock value (at standard) the linked Purchase Receipt booked for the quantity this invoice
row is billing.
Accepted and rejected stock for the same receipt row share `voucher_detail_no`, so the
warehouse filter is required: without it the accepted warehouse's SRBNB would be cleared at
accepted + rejected value and post the wrong Purchase Price Variance amount. The accepted
warehouse is read from the receipt row itself (not the invoice row, which may be unset on a
non-stock invoice).
The receipt's full accepted value is pro-rated to the invoiced quantity, so a partial bill
clears SRBNB (and posts PPV) for only the units it covers, not the whole receipt row."""
pr_detail = frappe.db.get_value(
"Purchase Receipt Item", item.pr_detail, ["warehouse", "stock_qty"], as_dict=True
)
if not pr_detail or not pr_detail.warehouse:
return 0.0
sle = frappe.qb.DocType("Stock Ledger Entry")
result = (
frappe.qb.from_(sle)
.select(Sum(sle.stock_value_difference))
.where(
(sle.voucher_type == "Purchase Receipt")
& (sle.voucher_no == item.purchase_receipt)
& (sle.voucher_detail_no == item.pr_detail)
& (sle.warehouse == pr_detail.warehouse)
& (sle.is_cancelled == 0)
)
).run()
accepted_value = flt(result[0][0]) if result and result[0][0] else 0.0
if not accepted_value or not flt(pr_detail.stock_qty):
return accepted_value
# Pro-rate to the quantity being billed by this invoice row (handles partial billing).
return accepted_value * flt(item.stock_qty) / flt(pr_detail.stock_qty)
def get_stock_variance_account(self, item):
"""For Standard Cost items the purchase-price-vs-standard difference is a Purchase Price
Variance; for all other items it keeps the existing behaviour (default expense account)."""

View File

@@ -1,11 +1,55 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import frappe
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.tests.utils import ERPNextTestSuite
COMPANY = "_Test Company"
class TestRepostPaymentLedger(ERPNextTestSuite):
pass
"""Repost Payment Ledger auto-selects submitted vouchers on/after a cutoff date
(unless rows are added manually) and queues them for a ledger rebuild."""
def setUp(self):
frappe.set_user("Administrator")
def make_repost(self, **args):
args = frappe._dict(args)
doc = frappe.new_doc("Repost Payment Ledger")
doc.company = COMPANY
doc.posting_date = args.get("posting_date", "2026-06-01")
doc.voucher_type = args.get("voucher_type", "Sales Invoice")
doc.add_manually = args.get("add_manually", 0)
return doc
def test_loads_submitted_vouchers_on_or_after_cutoff(self):
after_cutoff = create_sales_invoice(company=COMPANY, posting_date="2026-06-15", rate=100, qty=1)
on_cutoff = create_sales_invoice(company=COMPANY, posting_date="2026-06-01", rate=100, qty=1)
before_cutoff = create_sales_invoice(company=COMPANY, posting_date="2026-01-15", rate=100, qty=1)
doc = self.make_repost(posting_date="2026-06-01", voucher_type="Sales Invoice")
doc.save() # before_validate loads the vouchers and sets status
loaded = {v.voucher_no for v in doc.repost_vouchers}
self.assertIn(after_cutoff.name, loaded)
# the filter is >= so an invoice posted exactly on the cutoff is included
self.assertIn(on_cutoff.name, loaded)
self.assertNotIn(before_cutoff.name, loaded)
self.assertEqual(doc.repost_status, "Queued")
def test_add_manually_preserves_user_rows(self):
# manually add a BEFORE-cutoff invoice (which the filter would never load) while a
# matching after-cutoff invoice also exists. If auto-loading wrongly ran it would
# drop the manual row and pull the after-cutoff one, so this distinguishes the modes.
manual_si = create_sales_invoice(company=COMPANY, posting_date="2026-01-15", rate=100, qty=1)
create_sales_invoice(company=COMPANY, posting_date="2026-06-15", rate=100, qty=1)
doc = self.make_repost(add_manually=1, posting_date="2026-06-01")
doc.append("repost_vouchers", {"voucher_type": "Sales Invoice", "voucher_no": manual_si.name})
doc.save()
rows = [(v.voucher_type, v.voucher_no) for v in doc.repost_vouchers]
self.assertEqual(rows, [("Sales Invoice", manual_si.name)])

View File

@@ -594,7 +594,15 @@ def create_dunning(
if source.payment_schedule and len(source.payment_schedule) == 1:
for row in target.overdue_payments:
if row.payment_schedule == source.payment_schedule[0].name:
row.outstanding = source.get("outstanding_amount")
# outstanding_amount is in the party account currency, but the Overdue Payment
# row is in the invoice's transaction currency. When they differ, use the
# payment schedule's own outstanding — it is kept in transaction currency and
# updated as payments are allocated, so it stays correct even when the invoice
# and its payments post at different exchange rates (#56006).
if source.party_account_currency and source.party_account_currency != source.currency:
row.outstanding = source.payment_schedule[0].outstanding
else:
row.outstanding = source.get("outstanding_amount")
target.validate()

View File

@@ -344,7 +344,9 @@ def update_multi_mode_option(doc, pos_profile) -> None:
payment.account = payment_mode.default_account
payment.type = payment_mode.type
mop_refetched = bool(doc.payments) and not doc.is_created_using_pos
# is_created_using_pos exists on Sales Invoice but not POS Invoice; use get() so this
# shared helper doesn't raise AttributeError when called on a POS Invoice
mop_refetched = bool(doc.payments) and not doc.get("is_created_using_pos")
doc.set("payments", [])
invalid_modes = []

View File

@@ -121,3 +121,65 @@ class TestShareTransfer(ERPNextTestSuite):
}
)
self.assertRaises(ShareDontExists, doc.insert)
class TestShareTransferValidation(ERPNextTestSuite):
"""basic_validations() enforces the transfer's internal consistency. Exercised
directly (to_folio_no set to skip folio auto-naming) so no shareholder fixtures
are needed - it only reasons about the document's own fields."""
def make_transfer(self, **overrides):
doc = frappe.new_doc("Share Transfer")
doc.update(
{
"transfer_type": "Transfer",
"date": "2026-01-01",
"from_shareholder": "SH-A",
"to_shareholder": "SH-B",
"to_folio_no": "1",
"share_type": "Equity",
"from_no": 1,
"to_no": 100,
"no_of_shares": 100,
"rate": 10,
"amount": 1000,
"company": "_Test Company",
"equity_or_liability_account": "Creditors - _TC",
}
)
doc.update(overrides)
return doc
def test_baseline_transfer_is_consistent(self):
# the helper's defaults must pass, otherwise the negative cases prove nothing
self.make_transfer().basic_validations()
def test_seller_and_buyer_must_differ(self):
doc = self.make_transfer(to_shareholder="SH-A")
self.assertRaises(frappe.ValidationError, doc.basic_validations)
def test_share_count_must_match_the_number_range(self):
# 1..100 is 100 shares, not 50
doc = self.make_transfer(no_of_shares=50)
self.assertRaises(frappe.ValidationError, doc.basic_validations)
def test_amount_must_equal_rate_times_shares(self):
doc = self.make_transfer(amount=999) # 10 * 100 = 1000
self.assertRaises(frappe.ValidationError, doc.basic_validations)
def test_amount_is_derived_when_left_blank(self):
doc = self.make_transfer(amount=0)
doc.basic_validations()
self.assertEqual(doc.amount, 1000)
def test_equity_or_liability_account_is_required(self):
doc = self.make_transfer(equity_or_liability_account=None)
self.assertRaises(frappe.ValidationError, doc.basic_validations)
def test_issue_requires_a_to_shareholder(self):
doc = self.make_transfer(transfer_type="Issue", to_shareholder="", asset_account="Cash - _TC")
self.assertRaises(frappe.ValidationError, doc.basic_validations)
def test_purchase_requires_a_from_shareholder(self):
doc = self.make_transfer(transfer_type="Purchase", from_shareholder="", asset_account="Cash - _TC")
self.assertRaises(frappe.ValidationError, doc.basic_validations)

View File

@@ -79,7 +79,9 @@ def get_plan_rate(
start_date = getdate(start_date)
end_date = getdate(end_date)
no_of_months = relativedelta.relativedelta(end_date, start_date).months + 1
delta = relativedelta.relativedelta(end_date, start_date)
# include the years component so cross-year spans aren't under-counted
no_of_months = delta.years * 12 + delta.months + 1
cost = plan.cost * no_of_months
# Adjust cost if start or end date is not month start or end

View File

@@ -1,8 +1,54 @@
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import frappe
from erpnext.accounts.doctype.subscription_plan.subscription_plan import get_plan_rate
from erpnext.tests.utils import ERPNextTestSuite
class TestSubscriptionPlan(ERPNextTestSuite):
pass
"""Subscription Plan validates its interval and computes a rate. The Monthly
Rate branch multiplies cost by the number of months in the billing window."""
def setUp(self):
frappe.set_user("Administrator")
def make_plan(self, **args):
args = frappe._dict(args)
plan = frappe.new_doc("Subscription Plan")
plan.plan_name = f"_Test Plan {frappe.generate_hash(length=6)}"
plan.item = args.item or "_Test Item"
plan.currency = args.currency or "INR"
plan.price_determination = args.price_determination
plan.cost = args.cost or 0
plan.billing_interval = args.billing_interval or "Month"
plan.billing_interval_count = (
args.billing_interval_count if args.billing_interval_count is not None else 1
)
return plan
def test_billing_interval_count_must_be_positive(self):
plan = self.make_plan(price_determination="Fixed Rate", cost=100, billing_interval_count=0)
self.assertRaises(frappe.ValidationError, plan.insert)
def test_fixed_rate_applies_prorate_factor(self):
plan = self.make_plan(price_determination="Fixed Rate", cost=100)
plan.insert()
self.assertEqual(get_plan_rate(plan.name), 100)
self.assertEqual(get_plan_rate(plan.name, prorate_factor=0.5), 50)
def test_monthly_rate_within_year(self):
plan = self.make_plan(price_determination="Monthly Rate", cost=100)
plan.insert()
# Jan 1 - Mar 31 is 3 whole months; month-aligned so proration is 0
rate = get_plan_rate(plan.name, start_date="2026-01-01", end_date="2026-03-31")
self.assertEqual(rate, 300)
def test_monthly_rate_across_year_boundary(self):
# a 14-month span (Jan 2026 to Feb 2027) bills all 14 months, not just the
# 2-month remainder that relativedelta.months alone would give
plan = self.make_plan(price_determination="Monthly Rate", cost=100)
plan.insert()
rate = get_plan_rate(plan.name, start_date="2026-01-01", end_date="2027-02-28")
self.assertEqual(rate, 1400)

View File

@@ -13,6 +13,7 @@ from frappe.desk.reportview import build_match_conditions
from frappe.model.meta import get_field_precision
from frappe.model.naming import determine_consecutive_week_number
from frappe.query_builder import AliasedQuery, Case, Criterion, Field, Table
from frappe.query_builder.custom import ConstantColumn
from frappe.query_builder.functions import Count, IfNull, Max, Min, Round, Sum
from frappe.query_builder.utils import DocType
from frappe.utils import (
@@ -1791,9 +1792,10 @@ def get_future_stock_vouchers(posting_date, posting_time, for_warehouses=None, f
# transaction can't modify them mid-flight (the original DISTINCT ... FOR UPDATE did this).
# MariaDB carries the lock on the grouped query below; postgres rejects FOR UPDATE alongside
# GROUP BY, so lock the matching rows in a separate pass first -- the row locks are held until
# the surrounding transaction ends, giving the same protection.
# the surrounding transaction ends, giving the same protection. Select a constant, not the
# name: a deep backdated repost can match millions of rows and only the locks are needed.
if frappe.db.db_type == "postgres":
frappe.qb.from_(SLE).select(SLE.name).where(conditions).for_update().run()
frappe.qb.from_(SLE).select(ConstantColumn(1)).where(conditions).for_update().run()
# distinct vouchers in chronological order; expressed as GROUP BY + Min() so it's valid on
# postgres (SELECT DISTINCT can't ORDER BY non-selected cols, and FOR UPDATE is invalid with both).

View File

@@ -15,7 +15,7 @@
"label": "Banking",
"link_type": "DocType",
"links": [],
"modified": "2026-06-14 13:43:50.924019",
"modified": "2026-07-03 13:43:50.924019",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Banking",
@@ -43,7 +43,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "tool",
"icon": "wrench",
"indent": 0,
"keep_closed": 0,
"label": "Bank Reconciliation",

View File

@@ -8,14 +8,14 @@
"doctype": "Workspace",
"for_user": "",
"hide_custom": 0,
"icon": "accounting",
"icon": "wallet",
"idx": 0,
"indicator_color": "green",
"is_hidden": 0,
"label": "Budgeting",
"link_type": "DocType",
"links": [],
"modified": "2026-07-02 04:24:48.116724",
"modified": "2026-07-03 04:24:48.116724",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Budgeting",
@@ -59,7 +59,7 @@
"child": 0,
"collapsible": 1,
"default_workspace": 0,
"icon": "accounting",
"icon": "wallet",
"indent": 0,
"keep_closed": 0,
"label": "Accounting Dimension",

View File

@@ -266,7 +266,7 @@
"type": "Link"
}
],
"modified": "2026-06-14 13:44:08.095321",
"modified": "2026-07-03 13:44:08.095321",
"modified_by": "Administrator",
"module": "Accounts",
"module_onboarding": "Accounting Onboarding",
@@ -284,7 +284,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "accounting",
"icon": "wallet",
"indent": 1,
"keep_closed": 0,
"label": "Financial Reports",

View File

@@ -13,7 +13,7 @@
"doctype": "Workspace",
"for_user": "",
"hide_custom": 0,
"icon": "accounting",
"icon": "wallet",
"idx": 4,
"indicator_color": "",
"is_hidden": 0,
@@ -587,7 +587,7 @@
"type": "Link"
}
],
"modified": "2026-06-14 13:44:08.471142",
"modified": "2026-07-03 13:44:08.471142",
"modified_by": "Administrator",
"module": "Accounts",
"module_onboarding": "Accounting Onboarding",
@@ -622,7 +622,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "home",
"icon": "house",
"indent": 0,
"keep_closed": 0,
"label": "Home",
@@ -635,7 +635,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "chart",
"icon": "chart-column",
"indent": 0,
"keep_closed": 0,
"label": "Dashboard",
@@ -786,7 +786,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "money-coins-1",
"icon": "coins",
"indent": 1,
"keep_closed": 0,
"label": "Payments",

View File

@@ -15,7 +15,7 @@
"label": "Payments",
"link_type": "DocType",
"links": [],
"modified": "2026-06-14 13:43:50.184761",
"modified": "2026-07-03 13:43:50.184761",
"modified_by": "Administrator",
"module": "Accounts",
"module_onboarding": "Accounting Onboarding",
@@ -31,7 +31,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "chart",
"icon": "chart-column",
"indent": 0,
"keep_closed": 0,
"label": "Dashboard",
@@ -44,7 +44,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "money-coins-1",
"icon": "coins",
"indent": 1,
"keep_closed": 0,
"label": "Payments",

View File

@@ -8,14 +8,14 @@
"doctype": "Workspace",
"for_user": "",
"hide_custom": 0,
"icon": "money-coins-1",
"icon": "coins",
"idx": 0,
"indicator_color": "green",
"is_hidden": 0,
"label": "Share Management",
"link_type": "DocType",
"links": [],
"modified": "2026-06-14 13:43:51.040978",
"modified": "2026-07-03 13:43:51.040978",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Share Management",
@@ -30,7 +30,7 @@
{
"child": 1,
"collapsible": 1,
"icon": "customer",
"icon": "user",
"indent": 0,
"keep_closed": 0,
"label": "Shareholder",

View File

@@ -8,14 +8,14 @@
"doctype": "Workspace",
"for_user": "",
"hide_custom": 0,
"icon": "accounting",
"icon": "wallet",
"idx": 0,
"indicator_color": "green",
"is_hidden": 0,
"label": "Subscriptions",
"link_type": "DocType",
"links": [],
"modified": "2026-06-14 14:08:36.999272",
"modified": "2026-07-03 14:08:36.999272",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Subscriptions",

View File

@@ -8,14 +8,14 @@
"doctype": "Workspace",
"for_user": "",
"hide_custom": 0,
"icon": "money-coins-1",
"icon": "coins",
"idx": 0,
"indicator_color": "green",
"is_hidden": 0,
"label": "Taxes",
"link_type": "DocType",
"links": [],
"modified": "2026-06-14 13:43:50.894825",
"modified": "2026-07-03 13:43:50.894825",
"modified_by": "Administrator",
"module": "Accounts",
"module_onboarding": "Accounting Onboarding",
@@ -58,7 +58,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "stock",
"icon": "package",
"indent": 0,
"keep_closed": 0,
"label": "Item Tax Template",

View File

@@ -587,3 +587,47 @@ def get_actual_sle_dict(name):
}
return sle_dict
class TestAssetCapitalizationValidation(ERPNextTestSuite):
"""Row-level validations for the consumed/target items. Exercised on the document
directly (the integration tests above cover the full capitalization posting)."""
def make_capitalization(self, **fields):
doc = frappe.new_doc("Asset Capitalization")
doc.company = "_Test Company"
doc.update(fields)
return doc
def test_source_items_are_mandatory(self):
doc = self.make_capitalization()
self.assertRaises(frappe.ValidationError, doc.validate_source_mandatory)
def test_target_item_must_be_a_fixed_asset(self):
# _Test Item is a stock item, not a fixed asset
doc = self.make_capitalization(target_item_code="_Test Item")
self.assertRaises(frappe.ValidationError, doc.validate_target_item)
def test_consumed_stock_row_rejects_a_non_stock_item(self):
doc = self.make_capitalization()
doc.append("stock_items", {"item_code": "_Test Non Stock Item", "stock_qty": 1})
self.assertRaises(frappe.ValidationError, doc.validate_consumed_stock_item)
def test_consumed_stock_row_requires_positive_qty(self):
doc = self.make_capitalization()
doc.append("stock_items", {"item_code": "_Test Item", "stock_qty": 0})
self.assertRaises(frappe.ValidationError, doc.validate_consumed_stock_item)
def test_service_row_rejects_a_stock_item(self):
doc = self.make_capitalization()
doc.append("service_items", {"item_code": "_Test Item", "qty": 1, "rate": 100})
self.assertRaises(frappe.ValidationError, doc.validate_service_item)
def test_service_row_requires_positive_qty_and_rate(self):
zero_qty = self.make_capitalization()
zero_qty.append("service_items", {"item_code": "_Test Non Stock Item", "qty": 0, "rate": 100})
self.assertRaises(frappe.ValidationError, zero_qty.validate_service_item)
zero_rate = self.make_capitalization()
zero_rate.append("service_items", {"item_code": "_Test Non Stock Item", "qty": 1, "rate": 0})
self.assertRaises(frappe.ValidationError, zero_rate.validate_service_item)

View File

@@ -224,7 +224,7 @@ def get_children(doctype: str, parent: str | None = None, location: str | None =
)
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def add_node():
from frappe.desk.treeview import make_tree_args

View File

@@ -13,7 +13,7 @@
"doctype": "Workspace",
"for_user": "",
"hide_custom": 0,
"icon": "assets",
"icon": "archive",
"idx": 0,
"is_hidden": 0,
"label": "Assets",
@@ -199,7 +199,7 @@
"type": "Link"
}
],
"modified": "2026-06-14 13:44:08.417956",
"modified": "2026-07-03 13:44:08.417956",
"modified_by": "Administrator",
"module": "Assets",
"module_onboarding": "Asset Onboarding",
@@ -217,7 +217,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "home",
"icon": "house",
"indent": 0,
"keep_closed": 0,
"label": "Home",
@@ -230,7 +230,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "chart",
"icon": "chart-column",
"indent": 0,
"keep_closed": 0,
"label": "Dashboard",
@@ -295,7 +295,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "getting-started",
"icon": "rocket",
"indent": 1,
"keep_closed": 1,
"label": "Maintenance",

View File

@@ -55,7 +55,7 @@ def make_supplier_quotation_from_rfq(
# This method is used to make supplier quotation from supplier's portal.
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def create_supplier_quotation(doc: str | Document | dict):
doc = frappe.parse_json(doc)

View File

@@ -185,7 +185,7 @@ def refresh_scorecards():
frappe.get_doc("Supplier Scorecard", sc_name).save()
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def make_all_scorecards(docname: str):
sc = frappe.get_doc("Supplier Scorecard", docname)
supplier = frappe.get_doc("Supplier", sc.supplier)

View File

@@ -4,7 +4,7 @@
import frappe
from frappe import _
from frappe.query_builder.functions import Max
from frappe.query_builder.functions import Min
from frappe.utils import flt
@@ -279,39 +279,44 @@ def get_po_entries(filters):
parent = frappe.qb.DocType("Purchase Order")
child = frappe.qb.DocType("Purchase Order Item")
query = (
# one coherent representative line per (PO, material_request_item): per-column Max() over the
# old GROUP BY could stitch values from different PO lines into a row that never existed
representative_lines = (
frappe.qb.from_(parent)
.from_(child)
.select(
Max(child.name).as_("name"),
Max(child.parent).as_("parent"),
Max(child.cost_center).as_("cost_center"),
Max(child.project).as_("project"),
Max(child.warehouse).as_("warehouse"),
Max(child.material_request).as_("material_request"),
child.material_request_item,
Max(child.item_code).as_("item_code"),
Max(child.stock_uom).as_("stock_uom"),
Max(child.qty).as_("qty"),
Max(child.amount).as_("amount"),
Max(child.base_amount).as_("base_amount"),
Max(child.schedule_date).as_("schedule_date"),
Max(parent.transaction_date).as_("transaction_date"),
Max(parent.supplier).as_("supplier"),
Max(parent.status).as_("status"),
Max(parent.owner).as_("owner"),
)
.select(Min(child.name))
.where(
(parent.docstatus == 1)
& (parent.name == child.parent)
& (parent.status.notin(("Closed", "Completed", "Cancelled")))
)
# Group only by the PO and material_request_item (the pre-effort key) and aggregate the rest
# with Max(): postgres requires every non-grouped column to be aggregated, and this keeps one
# row per (PO, material_request_item) — matching the prior MariaDB row count. Adding the PO
# Item PK to the GROUP BY would split a multi-line PO into one row per line.
.groupby(parent.name, child.material_request_item)
.groupby(child.parent, child.material_request_item)
)
representative_lines = apply_filters_on_query(filters, parent, child, representative_lines)
query = (
frappe.qb.from_(parent)
.from_(child)
.select(
child.name,
child.parent,
child.cost_center,
child.project,
child.warehouse,
child.material_request,
child.material_request_item,
child.item_code,
child.stock_uom,
child.qty,
child.amount,
child.base_amount,
child.schedule_date,
parent.transaction_date,
parent.supplier,
parent.status,
parent.owner,
)
.where((parent.name == child.parent) & (child.name.isin(representative_lines)))
)
query = apply_filters_on_query(filters, parent, child, query)
return query.run(as_dict=True)

View File

@@ -2,16 +2,15 @@
# For license information, please see license.txt
from frappe.utils import add_days, nowdate
from frappe.utils import add_days, flt, nowdate
from erpnext.tests.utils import ERPNextTestSuite
class TestProcurementTracker(ERPNextTestSuite):
def test_report_executes_and_lists_po(self):
# get_po_entries groups by (Purchase Order, material_request_item) and Max()-aggregates the
# other child columns; this exercises that GROUP BY so the report stays valid on Postgres
# (which rejects selecting non-grouped columns).
# get_po_entries returns one representative line per (Purchase Order, material_request_item);
# this exercises that query so the report stays valid on Postgres.
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
from erpnext.buying.report.procurement_tracker.procurement_tracker import execute
@@ -22,11 +21,10 @@ class TestProcurementTracker(ERPNextTestSuite):
self.assertTrue(columns)
self.assertIn(po.name, {row.get("purchase_order") for row in data})
def test_multi_line_po_stays_one_row(self):
# A PO can carry several lines that share the same (blank) material_request_item. get_po_entries
# groups by (Purchase Order, material_request_item) and Max()-aggregates the rest, so such a PO
# yields ONE row — matching the pre-effort MariaDB output. Adding the Purchase Order Item PK to
# the GROUP BY (the regression) splits it into one row per line, changing the MariaDB row count.
def test_multi_line_po_stays_one_coherent_row(self):
# Lines sharing the same (blank) material_request_item collapse to ONE row, matching the
# pre-effort MariaDB row count — and that row must be a real PO line, not a per-column
# Max() chimera mixing one line's item_code with another line's qty/amount.
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
from erpnext.buying.report.procurement_tracker.procurement_tracker import execute
from erpnext.stock.doctype.item.test_item import make_item
@@ -50,3 +48,10 @@ class TestProcurementTracker(ERPNextTestSuite):
po_rows = [row for row in data if row.get("purchase_order") == po.name]
self.assertEqual(len(po_rows), 1)
real_lines = {(d.item_code, flt(d.qty), flt(d.amount)) for d in po.items}
row = po_rows[0]
self.assertIn(
(row.get("item_code"), flt(row.get("quantity")), flt(row.get("purchase_order_amt"))),
real_lines,
)

View File

@@ -6,7 +6,7 @@ import copy
import frappe
from frappe import _
from frappe.query_builder.functions import Coalesce, Max, Sum
from frappe.query_builder.functions import Coalesce, Max, Min, Sum
from frappe.utils import cint, date_diff, flt, getdate
@@ -47,7 +47,7 @@ def get_data(filters):
# non-grouped columns are constant per grouped mr.name / item_code -> Max() keeps the
# GROUP BY valid on postgres while returning the same value MySQL picked.
Max(mr.transaction_date).as_("date"),
Max(mr_item.schedule_date).as_("required_date"),
Min(mr_item.schedule_date).as_("required_date"),
mr_item.item_code.as_("item_code"),
Sum(Coalesce(mr_item.qty, 0)).as_("qty"),
Sum(Coalesce(mr_item.stock_qty, 0)).as_("stock_qty"),

View File

@@ -2,7 +2,7 @@
# See license.txt
import frappe
from frappe.utils import add_days, today
from frappe.utils import add_days, getdate, today
from erpnext.buying.doctype.purchase_order.mapper import make_purchase_receipt
from erpnext.buying.report.requested_items_to_order_and_receive.requested_items_to_order_and_receive import (
@@ -44,6 +44,36 @@ class TestRequestedItemsToOrderAndReceive(ERPNextTestSuite):
self.assertEqual(data[0].ordered_qty, 0.0)
self.assertEqual(data[1].ordered_qty, 57.0)
def test_required_date_is_earliest_schedule_date(self):
create_item("Test MR Report Dup Item")
mr = frappe.copy_doc(self.globalTestRecords["Material Request"][0])
mr.transaction_date = today()
mr.schedule_date = add_days(today(), 5)
mr.set("items", mr.items[:1])
row = mr.items[0]
row.item_code = "Test MR Report Dup Item"
row.item_name = "Test MR Report Dup Item"
row.description = "Test MR Report Dup Item"
row.uom = "Nos"
row.schedule_date = add_days(today(), 5)
mr.append(
"items",
{
"item_code": "Test MR Report Dup Item",
"item_name": "Test MR Report Dup Item",
"description": "Test MR Report Dup Item",
"uom": "Nos",
"qty": row.qty,
"warehouse": row.warehouse,
"schedule_date": add_days(today(), 1),
},
)
mr.submit()
data = get_data(self.filters.update({"item_code": "Test MR Report Dup Item"}))
self.assertEqual(len(data), 1)
self.assertEqual(getdate(data[0].required_date), getdate(add_days(today(), 1)))
def setup_material_request(self, order=False, receive=False, days=0):
po = None
mr = frappe.copy_doc(self.globalTestRecords["Material Request"][0])

View File

@@ -13,7 +13,7 @@
"doctype": "Workspace",
"for_user": "",
"hide_custom": 0,
"icon": "buying",
"icon": "shopping-cart",
"idx": 0,
"is_hidden": 0,
"label": "Buying",
@@ -501,7 +501,7 @@
"type": "Link"
}
],
"modified": "2026-06-14 13:43:50.509039",
"modified": "2026-07-03 13:43:50.509039",
"modified_by": "Administrator",
"module": "Buying",
"module_onboarding": "Buying Onboarding",
@@ -532,7 +532,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "home",
"icon": "house",
"indent": 0,
"keep_closed": 0,
"label": "Home",
@@ -545,7 +545,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "chart",
"icon": "chart-column",
"indent": 0,
"keep_closed": 0,
"label": "Dashboard",
@@ -610,7 +610,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "liabilities",
"icon": "scale",
"indent": 0,
"keep_closed": 0,
"label": "Purchase Invoice",

View File

@@ -1724,7 +1724,7 @@ def get_missing_company_details(doctype: str, docname: str):
}
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def update_company_master_and_address(current_doctype: str, name: str, company: str, details: dict | str):
from frappe.utils import validate_email_address

View File

@@ -3,7 +3,7 @@ from collections import OrderedDict
import frappe
from frappe import _, qb
from frappe.query_builder import Criterion
from frappe.query_builder.functions import IfNull, Max, Sum
from frappe.query_builder.functions import IfNull, Sum
from frappe.utils import fmt_money
from erpnext.accounts.doctype.budget.budget import BudgetError, get_accumulated_monthly_budget
@@ -260,10 +260,10 @@ class BudgetValidation:
qb.from_(mr)
.inner_join(mri)
.on(mr.name == mri.parent)
# rate is outside the Sum (no GROUP BY -> implicit aggregate); Max() keeps it valid on
# postgres and matches MySQL's arbitrary single-rate choice for this aggregate.
.select(
(Sum(IfNull(mri.stock_qty, 0) - IfNull(mri.ordered_qty, 0)) * Max(mri.rate)).as_("amount")
Sum((IfNull(mri.stock_qty, 0) - IfNull(mri.ordered_qty, 0)) * IfNull(mri.rate, 0)).as_(
"amount"
)
)
.where(Criterion.all(conditions))
.run(as_dict=True)

View File

@@ -20,7 +20,7 @@ from frappe.query_builder.functions import (
Substring,
Sum,
)
from frappe.utils import nowdate, today, unique
from frappe.utils import cint, nowdate, today, unique
from pypika import Order
import erpnext
@@ -808,7 +808,11 @@ def get_filtered_dimensions(
query_filters.append(["company", "=", filters.get("company")])
for field in searchfields:
or_filters.append([field, "LIKE", "%%%s%%" % txt])
df = meta.get_field(field)
if df and df.fieldtype != "Check":
or_filters.append([field, "LIKE", "%%%s%%" % txt])
else:
or_filters.append([field, "=", cint(txt)])
fields.append(field)
if dimension_filters:

View File

@@ -653,7 +653,7 @@ def check_item_quality_inspection(doctype: str, docstatus: str | int, items: str
return [item for item in items if item.get("item_code") in inspection_required_items]
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def make_quality_inspections(
company: str, doctype: str, docname: str, items: str | list, inspection_type: str
):

View File

@@ -203,6 +203,9 @@ def get_data(filters, conditions):
as_list=1,
)
if not row1:
continue
des[ind] = row[i][0]
des[ind - 1] = row1[0][0]

View File

@@ -1,9 +1,59 @@
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import datetime
import frappe
from erpnext.tests.utils import ERPNextTestSuite
class TestAppointmentBookingSettings(ERPNextTestSuite):
pass
"""The settings validate each availability slot: from-time must precede to-time and
the slot length must be a whole multiple of the appointment duration."""
def make_settings(self, appointment_duration=30):
doc = frappe.new_doc("Appointment Booking Settings")
doc.appointment_duration = appointment_duration
return doc
def dt(self, hms):
# the controller parses times against a fixed epoch date
return datetime.datetime.strptime("01/01/1970 " + hms, "%d/%m/%Y %H:%M:%S")
def test_from_time_must_precede_to_time(self):
doc = self.make_settings()
record = frappe._dict(day_of_week="Monday")
self.assertRaises(
frappe.ValidationError,
doc.validate_from_and_to_time,
self.dt("18:00:00"),
self.dt("09:00:00"),
record,
)
doc.validate_from_and_to_time(self.dt("09:00:00"), self.dt("18:00:00"), record) # valid order
def test_slot_length_must_be_a_multiple_of_the_duration(self):
doc = self.make_settings(appointment_duration=30)
# 60 minutes is two 30-minute appointments -> fine
doc.duration_is_divisible(self.dt("09:00:00"), self.dt("10:00:00"))
# 45 minutes leaves a partial appointment -> rejected
self.assertRaises(
frappe.ValidationError, doc.duration_is_divisible, self.dt("09:00:00"), self.dt("09:45:00")
)
def test_validate_checks_every_slot(self):
bad = self.make_settings(appointment_duration=30)
bad.append(
"availability_of_slots",
{"day_of_week": "Monday", "from_time": "09:00:00", "to_time": "09:45:00"},
)
self.assertRaises(frappe.ValidationError, bad.validate)
# a clean 60-minute slot passes end to end
good = self.make_settings(appointment_duration=30)
good.append(
"availability_of_slots",
{"day_of_week": "Monday", "from_time": "09:00:00", "to_time": "10:00:00"},
)
good.validate()

View File

@@ -17,7 +17,7 @@ frappe.ui.form.on("Campaign", {
frappe.route_options = { utm_source: "Campaign", utm_campaign: frm.doc.name };
frappe.set_route("List", "Lead");
},
"fa fa-list",
null,
true
);
}

View File

@@ -26,25 +26,35 @@ class Campaign(Document):
# end: auto-generated types
def after_insert(self):
try:
mc = frappe.get_doc("UTM Campaign", self.campaign_name)
except frappe.DoesNotExistError:
mc = frappe.new_doc("UTM Campaign")
mc.name = self.campaign_name
mc.campaign_description = self.description
mc.crm_campaign = self.campaign_name
mc.save(ignore_permissions=True)
self.sync_utm_campaign()
def on_change(self):
try:
mc = frappe.get_doc("UTM Campaign", self.campaign_name)
except frappe.DoesNotExistError:
mc = frappe.new_doc("UTM Campaign")
mc.name = self.campaign_name
self.sync_utm_campaign()
def sync_utm_campaign(self):
mc = self.get_utm_campaign_mirror()
mc.campaign_description = self.description
mc.crm_campaign = self.campaign_name
# link by the document name, which differs from campaign_name when a naming series is used
mc.crm_campaign = self.name
mc.save(ignore_permissions=True)
def get_utm_campaign_mirror(self):
# the mirror already linked to this Campaign, if any (survives campaign_name edits)
if owned := frappe.db.get_value("UTM Campaign", {"crm_campaign": self.name}):
return frappe.get_doc("UTM Campaign", owned)
# reuse a same-named mirror only when it isn't already owned by another Campaign,
# otherwise two Campaigns sharing a display name would hijack each other's mirror
if frappe.db.exists("UTM Campaign", self.campaign_name):
same_name = frappe.get_doc("UTM Campaign", self.campaign_name)
if not same_name.crm_campaign or same_name.crm_campaign == self.name:
return same_name
# create a fresh mirror, keeping its name unique when the display name is taken
mc = frappe.new_doc("UTM Campaign")
mc.name = self.name if frappe.db.exists("UTM Campaign", self.campaign_name) else self.campaign_name
return mc
def autoname(self):
if frappe.defaults.get_global_default("campaign_naming_by") != "Naming Series":
self.name = self.campaign_name

View File

@@ -1,9 +1,70 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import frappe
from erpnext.tests.utils import ERPNextTestSuite
class TestCampaign(ERPNextTestSuite):
pass
"""Campaign names itself from the campaign name (or a naming series) and mirrors
itself into a UTM Campaign."""
def setUp(self):
frappe.set_user("Administrator")
def make_campaign(self, **fields):
doc = frappe.new_doc("Campaign")
doc.campaign_name = fields.pop("campaign_name", f"_Test Campaign {frappe.generate_hash(length=6)}")
doc.update(fields)
return doc.insert()
def test_autoname_uses_the_campaign_name_by_default(self):
campaign = self.make_campaign(campaign_name="_Test Campaign Named")
self.assertEqual(campaign.name, "_Test Campaign Named")
def test_autoname_uses_naming_series_when_configured(self):
# regression: with a naming series the document name differs from campaign_name,
# and the UTM sync must still link back to a valid Campaign (self.name)
original = frappe.defaults.get_global_default("campaign_naming_by")
frappe.defaults.set_global_default("campaign_naming_by", "Naming Series")
try:
campaign = self.make_campaign(naming_series="SAL-CAM-.YYYY.-")
self.assertTrue(campaign.name.startswith("SAL-CAM-"))
utm = frappe.get_doc("UTM Campaign", campaign.campaign_name)
self.assertEqual(utm.crm_campaign, campaign.name)
finally:
frappe.defaults.set_global_default("campaign_naming_by", original or "")
def test_inserting_mirrors_into_a_utm_campaign(self):
campaign = self.make_campaign(campaign_name="_Test Campaign UTM", description="Spring push")
self.assertTrue(frappe.db.exists("UTM Campaign", campaign.campaign_name))
utm = frappe.get_doc("UTM Campaign", campaign.campaign_name)
self.assertEqual(utm.campaign_description, "Spring push")
self.assertEqual(utm.crm_campaign, campaign.name)
def test_editing_campaign_name_reuses_the_same_utm_campaign(self):
campaign = self.make_campaign(campaign_name="_Test Campaign Rename A")
campaign.campaign_name = "_Test Campaign Rename B"
campaign.save()
# the edit updates the existing mirror rather than creating a second one
mirrors = frappe.get_all("UTM Campaign", filters={"crm_campaign": campaign.name})
self.assertEqual(len(mirrors), 1)
def test_two_campaigns_sharing_a_name_do_not_hijack_each_others_mirror(self):
# a naming series lets two Campaigns share a display name; each must keep its own mirror
original = frappe.defaults.get_global_default("campaign_naming_by")
frappe.defaults.set_global_default("campaign_naming_by", "Naming Series")
try:
first = self.make_campaign(campaign_name="_Test Shared Mirror", naming_series="SAL-CAM-.YYYY.-")
second = self.make_campaign(campaign_name="_Test Shared Mirror", naming_series="SAL-CAM-.YYYY.-")
finally:
frappe.defaults.set_global_default("campaign_naming_by", original or "")
# the first Campaign's mirror is untouched; the second gets a distinct one
self.assertEqual(
frappe.db.get_value("UTM Campaign", "_Test Shared Mirror", "crm_campaign"), first.name
)
second_mirror = frappe.db.get_value("UTM Campaign", {"crm_campaign": second.name})
self.assertTrue(second_mirror)
self.assertNotEqual(second_mirror, "_Test Shared Mirror")

View File

@@ -1,8 +1,43 @@
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import frappe
from erpnext.crm.doctype.contract_template.contract_template import get_contract_template
from erpnext.tests.utils import ERPNextTestSuite
class TestContractTemplate(ERPNextTestSuite):
pass
"""Contract Template validates its Jinja terms and renders them against a doc."""
def test_malformed_contract_terms_are_rejected(self):
doc = frappe.new_doc("Contract Template")
doc.contract_terms = "{% for x in %}" # invalid Jinja
self.assertRaises(frappe.ValidationError, doc.validate)
# a valid template, and no template at all, both pass
doc.contract_terms = "Party: {{ party_name }}"
doc.validate()
doc.contract_terms = None
doc.validate()
def test_get_contract_template_renders_terms(self):
template = frappe.get_doc(
{
"doctype": "Contract Template",
"title": "_Test Contract Template",
"contract_terms": "Party: {{ party_name }}",
}
).insert()
result = get_contract_template(template.name, {"party_name": "Acme"})
self.assertEqual(result["contract_terms"], "Party: Acme")
self.assertEqual(result["contract_template"].name, template.name)
def test_get_contract_template_without_terms_returns_none(self):
template = frappe.get_doc(
{"doctype": "Contract Template", "title": "_Test Empty Contract Template"}
).insert()
result = get_contract_template(template.name, {})
self.assertIsNone(result["contract_terms"])

View File

@@ -1,9 +1,39 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import frappe
from erpnext.tests.utils import ERPNextTestSuite
class TestCRMSettings(ERPNextTestSuite):
pass
"""CRM Settings guards its Frappe-CRM sync and Contact-Us opportunity toggles."""
def make_settings(self, **fields):
doc = frappe.new_doc("CRM Settings")
doc.update(fields)
return doc
def test_data_sync_requires_at_least_one_allowed_user(self):
doc = self.make_settings(enable_frappe_crm_data_synchronization=1)
self.assertRaises(frappe.ValidationError, doc.validate_allowed_users)
# adding a user satisfies the check
doc.append("allowed_users", {"user": "Administrator"})
doc.validate_allowed_users()
def test_disabling_sync_clears_allowed_users(self):
doc = self.make_settings(enable_frappe_crm_data_synchronization=0)
doc.append("allowed_users", {"user": "Administrator"})
doc.clear_allowed_users()
self.assertEqual(doc.allowed_users, [])
# while sync is on, the rows are kept
enabled = self.make_settings(enable_frappe_crm_data_synchronization=1)
enabled.append("allowed_users", {"user": "Administrator"})
enabled.clear_allowed_users()
self.assertEqual(len(enabled.allowed_users), 1)
@ERPNextTestSuite.change_settings("Contact Us Settings", {"is_disabled": 1})
def test_opportunity_from_contact_us_needs_the_form_enabled(self):
doc = self.make_settings(enable_opportunity_creation_from_contact_us=1)
self.assertRaises(frappe.ValidationError, doc.validate_enable_opportunity_creation_from_contact_us)

View File

@@ -1,9 +1,61 @@
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import frappe
from frappe.utils import add_days, getdate, today
from erpnext.tests.utils import ERPNextTestSuite
class TestEmailCampaign(ERPNextTestSuite):
pass
"""Email Campaign derives its window from the linked Campaign schedule and
guards the start date and the recipient's email."""
def setUp(self):
frappe.set_user("Administrator")
def make_email_template(self):
name = "_Test EC Email Template"
if not frappe.db.exists("Email Template", name):
frappe.get_doc(
{"doctype": "Email Template", "name": name, "subject": "Test", "response": "Hello"}
).insert()
return name
def make_campaign(self, schedules):
campaign = frappe.new_doc("Campaign")
campaign.campaign_name = f"_Test EC Campaign {frappe.generate_hash(length=6)}"
for days in schedules:
campaign.append(
"campaign_schedules",
{"send_after_days": days, "email_template": self.make_email_template()},
)
return campaign.insert()
def make_email_campaign(self, campaign_name, start_date=None):
doc = frappe.new_doc("Email Campaign")
doc.campaign_name = campaign_name
doc.start_date = start_date or today()
return doc
def test_start_date_cannot_be_in_the_past(self):
doc = self.make_email_campaign("irrelevant", start_date=add_days(today(), -1))
self.assertRaises(frappe.ValidationError, doc.set_date)
def test_end_date_is_start_plus_max_send_after_days(self):
campaign = self.make_campaign(schedules=[0, 5])
doc = self.make_email_campaign(campaign.name)
doc.set_date()
self.assertEqual(getdate(doc.end_date), add_days(getdate(today()), 5))
def test_campaign_without_a_schedule_is_rejected(self):
campaign = self.make_campaign(schedules=[])
doc = self.make_email_campaign(campaign.name)
self.assertRaises(frappe.ValidationError, doc.set_date)
def test_lead_without_an_email_is_rejected(self):
lead = frappe.get_doc({"doctype": "Lead", "lead_name": "_Test Lead No Email"}).insert()
doc = frappe.new_doc("Email Campaign")
doc.email_campaign_for = "Lead"
doc.recipient = lead.name
self.assertRaises(frappe.ValidationError, doc.validate_lead)

View File

@@ -380,7 +380,7 @@ def get_lead_with_phone_number(number):
return lead
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def add_lead_to_prospect(lead: str, prospect: str):
prospect = frappe.get_doc("Prospect", prospect)
prospect.append("leads", {"lead": lead})

View File

@@ -110,7 +110,7 @@ def make_quotation(source_name: str, target_doc: str | Document | None = None):
return target_doc
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def make_lead_from_communication(communication: str, ignore_communication_links: bool = False):
"""raise a issue from email"""

View File

@@ -124,7 +124,7 @@ def make_supplier_quotation(source_name: str, target_doc: str | Document | None
return doclist
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def make_opportunity_from_communication(
communication: str, company: str, ignore_communication_links: bool = False
):

View File

@@ -389,7 +389,7 @@ def get_item_details(item_code: str):
}
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def set_multiple_status(names: str | list[str], status: str):
names = frappe.parse_json(names)
for name in names:

View File

@@ -13,7 +13,7 @@
"doctype": "Workspace",
"for_user": "",
"hide_custom": 0,
"icon": "crm",
"icon": "handshake",
"idx": 0,
"is_hidden": 0,
"label": "CRM",
@@ -421,7 +421,7 @@
"type": "Link"
}
],
"modified": "2026-06-14 13:44:08.297053",
"modified": "2026-07-03 13:44:08.297053",
"modified_by": "Administrator",
"module": "CRM",
"name": "CRM",
@@ -471,7 +471,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "chart",
"icon": "chart-column",
"indent": 0,
"keep_closed": 0,
"label": "Home",
@@ -510,7 +510,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "customer",
"icon": "user",
"indent": 0,
"keep_closed": 0,
"label": "Customer",
@@ -644,7 +644,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "getting-started",
"icon": "rocket",
"indent": 1,
"keep_closed": 1,
"label": "Maintenance",
@@ -776,7 +776,7 @@
{
"child": 0,
"collapsible": 1,
"icon": "sell",
"icon": "store",
"indent": 1,
"keep_closed": 1,
"label": "Campaign",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "accounting",
"icon": "wallet",
"icon_type": "Folder",
"idx": 1,
"label": "Accounting",
"link_to": "",
"link_type": "Workspace Sidebar",
"modified": "2026-01-27 17:04:04.351402",
"modified": "2026-07-03 17:04:04.351402",
"modified_by": "Administrator",
"name": "Accounting",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "assets",
"icon": "archive",
"icon_type": "Link",
"idx": 1,
"label": "Assets",
"link_to": "Assets",
"link_type": "Workspace Sidebar",
"modified": "2026-01-01 20:07:01.220411",
"modified": "2026-07-03 20:07:01.220411",
"modified_by": "Administrator",
"name": "Assets",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "expenses",
"icon": "chart-pie",
"icon_type": "Link",
"idx": 6,
"label": "Budget",
"link_to": "Budget",
"link_type": "Workspace Sidebar",
"modified": "2026-01-23 14:39:30.839274",
"modified": "2026-07-03 14:39:30.839274",
"modified_by": "Administrator",
"name": "Budget",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "buying",
"icon": "shopping-cart",
"icon_type": "Link",
"idx": 1,
"label": "Buying",
"link_to": "Buying",
"link_type": "Workspace Sidebar",
"modified": "2026-01-01 20:07:01.196163",
"modified": "2026-07-03 20:07:01.196163",
"modified_by": "Administrator",
"name": "Buying",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 1,
"icon": "crm",
"icon": "handshake",
"icon_type": "Link",
"idx": 1,
"label": "CRM",
"link_to": "CRM",
"link_type": "Workspace Sidebar",
"modified": "2026-01-06 14:54:05.112927",
"modified": "2026-07-03 14:54:05.112927",
"modified_by": "Administrator",
"name": "CRM",
"owner": "Administrator",

View File

@@ -4,14 +4,14 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "setting",
"icon": "settings",
"icon_type": "Link",
"idx": 10,
"label": "ERPNext Settings",
"link_to": "ERPNext Settings",
"link_type": "Workspace Sidebar",
"logo_url": "",
"modified": "2026-01-09 14:59:56.044037",
"modified": "2026-07-03 14:59:56.044037",
"modified_by": "Administrator",
"name": "ERPNext Settings",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 1,
"icon": "home",
"icon": "house",
"icon_type": "Link",
"idx": 0,
"label": "Home",
"link_to": "Home",
"link_type": "Workspace Sidebar",
"modified": "2026-01-01 20:07:01.174950",
"modified": "2026-07-03 20:07:01.174950",
"modified_by": "Administrator",
"name": "Home",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "accounting",
"icon": "wallet",
"icon_type": "Link",
"idx": 0,
"label": "Invoicing",
"link_to": "Invoicing",
"link_type": "Workspace Sidebar",
"modified": "2026-01-23 15:17:23.564795",
"modified": "2026-07-03 15:17:23.564795",
"modified_by": "Administrator",
"name": "Invoicing",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "organization",
"icon": "factory",
"icon_type": "Link",
"idx": 1,
"label": "Manufacturing",
"link_to": "Manufacturing",
"link_type": "Workspace Sidebar",
"modified": "2026-01-01 20:07:01.246693",
"modified": "2026-07-03 20:07:01.246693",
"modified_by": "Administrator",
"name": "Manufacturing",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "project",
"icon": "folder-kanban",
"icon_type": "Link",
"idx": 1,
"label": "Projects",
"link_to": "Projects",
"link_type": "Workspace Sidebar",
"modified": "2026-01-01 20:07:01.226383",
"modified": "2026-07-03 20:07:01.226383",
"modified_by": "Administrator",
"name": "Projects",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "quality",
"icon": "shield-check",
"icon_type": "Link",
"idx": 1,
"label": "Quality",
"link_to": "Quality",
"link_type": "Workspace Sidebar",
"modified": "2026-01-01 20:07:01.239523",
"modified": "2026-07-03 20:07:01.239523",
"modified_by": "Administrator",
"name": "Quality",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "sell",
"icon": "store",
"icon_type": "Link",
"idx": 1,
"label": "Selling",
"link_to": "Selling",
"link_type": "Workspace Sidebar",
"modified": "2026-01-01 20:07:01.189446",
"modified": "2026-07-03 20:07:01.189446",
"modified_by": "Administrator",
"name": "Selling",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "stock",
"icon": "package",
"icon_type": "Link",
"idx": 1,
"label": "Stock",
"link_to": "Stock",
"link_type": "Workspace Sidebar",
"modified": "2026-01-01 20:07:01.212940",
"modified": "2026-07-03 20:07:01.212940",
"modified_by": "Administrator",
"name": "Stock",
"owner": "Administrator",

View File

@@ -4,14 +4,14 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 0,
"icon": "getting-started",
"icon": "package-2",
"icon_type": "Link",
"idx": 6,
"label": "Subcontracting",
"link_to": "Subcontracting",
"link_type": "Workspace Sidebar",
"logo_url": "/assets/erpnext/desktop_icons/subcontracting.svg",
"modified": "2026-01-01 20:07:01.323508",
"modified": "2026-07-03 20:07:01.323508",
"modified_by": "Administrator",
"name": "Subcontracting",
"owner": "Administrator",

View File

@@ -4,13 +4,13 @@
"docstatus": 0,
"doctype": "Desktop Icon",
"hidden": 1,
"icon": "support",
"icon": "headset",
"icon_type": "Link",
"idx": 1,
"label": "Support",
"link_to": "Support",
"link_type": "Workspace Sidebar",
"modified": "2026-01-06 14:53:54.100467",
"modified": "2026-07-03 14:53:54.100467",
"modified_by": "Administrator",
"name": "Support",
"owner": "Administrator",

View File

@@ -50,7 +50,7 @@ def get_plaid_configuration():
return "disabled"
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def add_institution(token: str, response: str | dict):
response = frappe.parse_json(response)
@@ -79,7 +79,7 @@ def add_institution(token: str, response: str | dict):
return bank
@frappe.whitelist()
@frappe.whitelist(methods=["POST"])
def add_bank_accounts(response: str | dict, bank: str | dict, company: str):
response = frappe.parse_json(response)
bank = frappe.parse_json(bank)

File diff suppressed because it is too large Load Diff

View File

@@ -1319,8 +1319,12 @@ def _add_secondary_item_columns(query, t, stock_item_condition):
def _add_normal_item_columns(query, t, amount_col, stock_item_condition, track_semi_finished_goods):
# non-grouped columns are constant per grouped item_code (+operation/operation_row_id) -> Max()
# keeps the GROUP BY valid on postgres while returning the value MySQL picked arbitrarily.
# Grouped also by bom_no/is_phantom_item: the pair MUST come from the same BOM Item row --
# _add_bom_item_to_dict recurses into bom_no when is_phantom_item is set, so independent Max()
# per column could pair one line's phantom flag with another line's bom_no and explode the
# wrong sub-BOM (same fix as sub_assembly_queries). The remaining non-grouped columns are
# constant per grouped item_code (+operation/operation_row_id) -> Max() keeps the GROUP BY
# valid on postgres while returning the value MySQL picked arbitrarily.
# NOTE: base_rate is aliased "rate" below and is what callers receive; bom_item.rate was selected
# under the same alias and silently shadowed (last value wins in the dict), so it is dropped here
# -- output is unchanged.
@@ -1335,14 +1339,15 @@ def _add_normal_item_columns(query, t, amount_col, stock_item_condition, track_s
Max(t.bom_item.description).as_("description"),
Max(t.bom_item.base_rate).as_("rate"),
Max(t.bom_item.operation_row_id).as_("operation_row_id"),
Max(t.bom_item.is_phantom_item).as_("is_phantom_item"),
Max(t.bom_item.bom_no).as_("bom_no"),
t.bom_item.is_phantom_item,
t.bom_item.bom_no,
).where(stock_item_condition | (t.bom_item.is_phantom_item == 1))
if track_semi_finished_goods:
group_by = [t.bom_item.item_code, t.bom_item.operation_row_id, t.item_doc.stock_uom]
else:
group_by = [t.bom_item.item_code, t.item_doc.stock_uom, t.bom_item.operation]
group_by += [t.bom_item.bom_no, t.bom_item.is_phantom_item]
return query, group_by

Some files were not shown because too many files have changed in this diff Show More