mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-07 19:51:45 +00:00
Compare commits
378 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bf12a6683 | ||
|
|
6205be5e73 | ||
|
|
38c44533b3 | ||
|
|
a66ce02520 | ||
|
|
3c43b42a01 | ||
|
|
8ed3a0ec65 | ||
|
|
488d635dc9 | ||
|
|
08d230b3e3 | ||
|
|
f383fafb15 | ||
|
|
38124a7616 | ||
|
|
56cf5382f0 | ||
|
|
56f03aee02 | ||
|
|
841f5c24ad | ||
|
|
e8051ba180 | ||
|
|
2b7d58602d | ||
|
|
e8e09cf8ea | ||
|
|
188c633d6e | ||
|
|
1995291194 | ||
|
|
bb0d75eb78 | ||
|
|
475eada727 | ||
|
|
6cffba9a71 | ||
|
|
35f9f9f330 | ||
|
|
5b60fbbd30 | ||
|
|
2678694c5f | ||
|
|
b6a80da457 | ||
|
|
2e9a0cb01c | ||
|
|
38c1867ade | ||
|
|
a48b999af9 | ||
|
|
c082edabf4 | ||
|
|
60ec7d0fb8 | ||
|
|
7ed3c6d18a | ||
|
|
b7e4fb9d83 | ||
|
|
e49e7b621d | ||
|
|
0a67d20ff8 | ||
|
|
83c6d861eb | ||
|
|
f62e5e69b8 | ||
|
|
45bc218acb | ||
|
|
2809c46a6e | ||
|
|
15c41178d0 | ||
|
|
64950d39b5 | ||
|
|
ff1b83025a | ||
|
|
b1d40de87e | ||
|
|
532031c21d | ||
|
|
cb70efb8ed | ||
|
|
ca0b4696ba | ||
|
|
4ba4da090d | ||
|
|
e3b2cc24b2 | ||
|
|
a24733791d | ||
|
|
aa94c91c12 | ||
|
|
87ffbdf129 | ||
|
|
5ef7b8c526 | ||
|
|
25cd230471 | ||
|
|
f05933e814 | ||
|
|
8df2612694 | ||
|
|
0bc98b609f | ||
|
|
02a1f815da | ||
|
|
6b6e017e36 | ||
|
|
89fcdbf56b | ||
|
|
eb2571492f | ||
|
|
55f2f1c515 | ||
|
|
673b893942 | ||
|
|
c85ce55f27 | ||
|
|
a19252e3b3 | ||
|
|
7ece6fd558 | ||
|
|
1d6e3e4e7d | ||
|
|
015f946a14 | ||
|
|
533a2dbc32 | ||
|
|
99aeb8ecd1 | ||
|
|
371030f8d4 | ||
|
|
2550b44db8 | ||
|
|
5b1674018b | ||
|
|
d8dab986fa | ||
|
|
f25e2295d0 | ||
|
|
b4fd4812cd | ||
|
|
876dec5077 | ||
|
|
36e9aae9d0 | ||
|
|
8ccb9a5ad2 | ||
|
|
85c0c16964 | ||
|
|
6a46045804 | ||
|
|
befa4bef0d | ||
|
|
f8294f1754 | ||
|
|
2d6640ac61 | ||
|
|
627b34a120 | ||
|
|
a2c82b4dc3 | ||
|
|
799119ad3e | ||
|
|
a4a0a2a0fb | ||
|
|
35fb2b8ede | ||
|
|
c844bf5547 | ||
|
|
81a16286a1 | ||
|
|
3c8534c4cc | ||
|
|
ac40b59665 | ||
|
|
3f2081b440 | ||
|
|
2db91ee67e | ||
|
|
f0eac47037 | ||
|
|
4df80c5b53 | ||
|
|
c150e5795e | ||
|
|
57282999ad | ||
|
|
623a0a932e | ||
|
|
9b06eaab78 | ||
|
|
2a5c9b469c | ||
|
|
0a0177cb9e | ||
|
|
eed144d7c9 | ||
|
|
a5ec0e4f50 | ||
|
|
8c98f1692a | ||
|
|
182e84e94c | ||
|
|
33962ac995 | ||
|
|
3b636d5db7 | ||
|
|
70b8b3bb9e | ||
|
|
c42954bec7 | ||
|
|
eab6d69ec9 | ||
|
|
3f0bea2d9f | ||
|
|
34ed9b455f | ||
|
|
2b7abfb34b | ||
|
|
2ba1731d3f | ||
|
|
b4b8459f2c | ||
|
|
d5160c4c86 | ||
|
|
af19b81343 | ||
|
|
650d2f74ba | ||
|
|
68747b5818 | ||
|
|
38848ff43b | ||
|
|
87e8305753 | ||
|
|
a2345d467e | ||
|
|
3d8a344173 | ||
|
|
e112290728 | ||
|
|
3149785960 | ||
|
|
736cff84f2 | ||
|
|
0023476500 | ||
|
|
0c4295fb6f | ||
|
|
13371275db | ||
|
|
313e6af528 | ||
|
|
e2a0d6e5f6 | ||
|
|
25f5fb7637 | ||
|
|
22848eb4da | ||
|
|
b4df87e545 | ||
|
|
9ed40cc17d | ||
|
|
22b6760164 | ||
|
|
e559fafa83 | ||
|
|
44539f0944 | ||
|
|
a0d94c38c1 | ||
|
|
95ea9ca66b | ||
|
|
ce7ab8df9a | ||
|
|
798858bd4f | ||
|
|
c6774e35f2 | ||
|
|
2a2ae9a20c | ||
|
|
f039bfe35a | ||
|
|
1747e83cb1 | ||
|
|
de14c0838c | ||
|
|
3788d0f4f0 | ||
|
|
ba98a00c6c | ||
|
|
2c4510ed1e | ||
|
|
87f3ba5794 | ||
|
|
197d09b90a | ||
|
|
32d3fbf1e8 | ||
|
|
4ec25ac82e | ||
|
|
3dbc90a0b4 | ||
|
|
f00236e669 | ||
|
|
d4f6ca3564 | ||
|
|
10e7ae4dd3 | ||
|
|
0f00581f83 | ||
|
|
a3ddc9533a | ||
|
|
2b766bca97 | ||
|
|
38c2633594 | ||
|
|
9012a72185 | ||
|
|
249d14b072 | ||
|
|
f2fef54b83 | ||
|
|
1b1e4e4688 | ||
|
|
8f2002d419 | ||
|
|
5b643433e5 | ||
|
|
e02aaa9f1b | ||
|
|
b1816864de | ||
|
|
3f490f11d5 | ||
|
|
b545b69e4b | ||
|
|
6ba24912c3 | ||
|
|
73b8a294cf | ||
|
|
b5485dc909 | ||
|
|
292f71bcef | ||
|
|
1e4acb3703 | ||
|
|
cf66b5aa34 | ||
|
|
9d2c456668 | ||
|
|
5ed4fea3e3 | ||
|
|
b8ec3ae23a | ||
|
|
0e7f9711e1 | ||
|
|
3cad1304a0 | ||
|
|
9dc1f5f649 | ||
|
|
df6ca3af57 | ||
|
|
95db1677e2 | ||
|
|
ca9f1b6c7b | ||
|
|
e8e26a91bb | ||
|
|
dc88f7b30b | ||
|
|
ac0375fc2e | ||
|
|
2863b0fe52 | ||
|
|
6096b56a10 | ||
|
|
88fdab99a9 | ||
|
|
7466d91e12 | ||
|
|
5bb2e8a8ff | ||
|
|
3989a7ede6 | ||
|
|
ef719fe729 | ||
|
|
9d979e34ab | ||
|
|
080e9a3d73 | ||
|
|
79b3af6d3e | ||
|
|
29c976e9ae | ||
|
|
635fe427fe | ||
|
|
dc5b8367c5 | ||
|
|
3380deab02 | ||
|
|
8e199af118 | ||
|
|
7e3f30baad | ||
|
|
90500f0ffc | ||
|
|
32182d7cc7 | ||
|
|
4f02677d6f | ||
|
|
56bb88d281 | ||
|
|
124a0fe45d | ||
|
|
3fad90ebb9 | ||
|
|
99b6dc508e | ||
|
|
7d593dd3db | ||
|
|
c48647100f | ||
|
|
ad4fe2db9e | ||
|
|
13de175b0f | ||
|
|
a333ec28e9 | ||
|
|
e6d38d009f | ||
|
|
178eded259 | ||
|
|
5db7888a8d | ||
|
|
83e0ce4020 | ||
|
|
6f58614ef2 | ||
|
|
a3068c8bf6 | ||
|
|
bdeee94c18 | ||
|
|
db5013fca1 | ||
|
|
2712310c0a | ||
|
|
a624ae07f0 | ||
|
|
347a7e3b1f | ||
|
|
df4347a6cb | ||
|
|
7edbf25e60 | ||
|
|
7c85d7f163 | ||
|
|
6216547027 | ||
|
|
ac0a837bf3 | ||
|
|
8be8a73a36 | ||
|
|
f49f60b5f4 | ||
|
|
3a13c04a71 | ||
|
|
62e8d4753e | ||
|
|
18c7121230 | ||
|
|
37c1d665e3 | ||
|
|
0d9c711b6d | ||
|
|
3b0a1bce3d | ||
|
|
efd90f554f | ||
|
|
5992ce533e | ||
|
|
1c044759ac | ||
|
|
86a36b3ef4 | ||
|
|
cd830a6b6c | ||
|
|
dc1147d504 | ||
|
|
797b418af4 | ||
|
|
8cdbaacfff | ||
|
|
c54d995354 | ||
|
|
5c6cc1ea2a | ||
|
|
e09ee63d32 | ||
|
|
d8e5075424 | ||
|
|
d5a36fe8aa | ||
|
|
10df192275 | ||
|
|
4ebddc591f | ||
|
|
5cc6a1771d | ||
|
|
29e8801b7f | ||
|
|
d94000fecf | ||
|
|
5071cad161 | ||
|
|
0151f5f191 | ||
|
|
d139db296a | ||
|
|
3406e44b03 | ||
|
|
449fa05d7d | ||
|
|
55222468f9 | ||
|
|
f381b99b14 | ||
|
|
2c880dd609 | ||
|
|
87e297e899 | ||
|
|
6c94ca664f | ||
|
|
d911e1dab2 | ||
|
|
908f8ed462 | ||
|
|
633ccef2ff | ||
|
|
e8f8abd685 | ||
|
|
b6b5524228 | ||
|
|
76bdf7944c | ||
|
|
1999de0b75 | ||
|
|
43acfdff82 | ||
|
|
19b911120c | ||
|
|
bc07de8c12 | ||
|
|
b484db3ffd | ||
|
|
902ce45a36 | ||
|
|
bfc0044d23 | ||
|
|
c8e3da0a71 | ||
|
|
2eed8ee343 | ||
|
|
670c6dcdd7 | ||
|
|
09d12f2f9f | ||
|
|
19f66c6018 | ||
|
|
de80215df5 | ||
|
|
017dc792e6 | ||
|
|
d920520843 | ||
|
|
ac901dee3c | ||
|
|
eed1abd272 | ||
|
|
ae23cdd8e9 | ||
|
|
5d4da9c68f | ||
|
|
990ada1656 | ||
|
|
1e40fb00f5 | ||
|
|
3d7827731b | ||
|
|
164333a730 | ||
|
|
e1afcb39db | ||
|
|
65e37756f6 | ||
|
|
c897220535 | ||
|
|
b04c06e034 | ||
|
|
4076798707 | ||
|
|
8b8427cbf5 | ||
|
|
e3110b3993 | ||
|
|
b5f8f2b6fa | ||
|
|
1a3652bee1 | ||
|
|
253b945816 | ||
|
|
d9d9230d4a | ||
|
|
668ec641c1 | ||
|
|
053765a466 | ||
|
|
288570acde | ||
|
|
4ef07f97c9 | ||
|
|
670579bde3 | ||
|
|
8bd1e8ff74 | ||
|
|
83f4970255 | ||
|
|
12903b11ed | ||
|
|
7658076070 | ||
|
|
b019d2f45e | ||
|
|
397bc96b40 | ||
|
|
f72d14b1ca | ||
|
|
0405d82b75 | ||
|
|
7d607b82f1 | ||
|
|
afe42ee3e9 | ||
|
|
49f66a8a51 | ||
|
|
0a09bb8d17 | ||
|
|
ba700bce90 | ||
|
|
22767410d5 | ||
|
|
89e7a260fd | ||
|
|
2a90bffb5f | ||
|
|
7434522ea1 | ||
|
|
158e1b28a9 | ||
|
|
a7672530f4 | ||
|
|
ad33735541 | ||
|
|
977f385006 | ||
|
|
b52b04a10c | ||
|
|
05b89b4121 | ||
|
|
36983c97cb | ||
|
|
23006601b2 | ||
|
|
37e9461ece | ||
|
|
126d79dcd2 | ||
|
|
93b2786865 | ||
|
|
2680f85430 | ||
|
|
2d7fde024d | ||
|
|
85bf9366b0 | ||
|
|
86f507bb6e | ||
|
|
81f19b950d | ||
|
|
7b4eac2294 | ||
|
|
aff4b62258 | ||
|
|
5798409f69 | ||
|
|
1b227b8b4f | ||
|
|
376da8df0a | ||
|
|
4eca7f0524 | ||
|
|
4bb66179ab | ||
|
|
d84a29e1a1 | ||
|
|
482a796212 | ||
|
|
41694d3751 | ||
|
|
82ca729e2b | ||
|
|
e67361257e | ||
|
|
e9f4a34d8d | ||
|
|
c6c4e31b32 | ||
|
|
ee5e4eccec | ||
|
|
a82fa8c26b | ||
|
|
97147a484d | ||
|
|
d8eddbfd03 | ||
|
|
977464e6a7 | ||
|
|
db84df0cbd | ||
|
|
1a7092d7b6 | ||
|
|
fcd05bb7e4 | ||
|
|
6c0694ff17 | ||
|
|
4988ff84df | ||
|
|
e5d0116924 | ||
|
|
38d3b17dfe | ||
|
|
89d305ac9f | ||
|
|
8b2be43897 | ||
|
|
0bd3b5aac2 | ||
|
|
8a995f28c9 |
@@ -4,7 +4,7 @@ import inspect
|
||||
import frappe
|
||||
from frappe.utils.user import is_website_user
|
||||
|
||||
__version__ = "15.84.0"
|
||||
__version__ = "15.90.1"
|
||||
|
||||
|
||||
def get_default_company(user=None):
|
||||
|
||||
@@ -110,6 +110,7 @@ class Account(NestedSet):
|
||||
self.validate_parent_child_account_type()
|
||||
self.validate_root_details()
|
||||
self.validate_account_number()
|
||||
self.validate_disabled()
|
||||
self.validate_group_or_ledger()
|
||||
self.set_root_and_report_type()
|
||||
self.validate_mandatory()
|
||||
@@ -254,6 +255,14 @@ class Account(NestedSet):
|
||||
|
||||
self.create_account_for_child_company(parent_acc_name_map, descendants, parent_acc_name)
|
||||
|
||||
def validate_disabled(self):
|
||||
doc_before_save = self.get_doc_before_save()
|
||||
if not doc_before_save or cint(doc_before_save.disabled) == cint(self.disabled):
|
||||
return
|
||||
|
||||
if cint(self.disabled):
|
||||
self.validate_default_accounts_in_company()
|
||||
|
||||
def validate_group_or_ledger(self):
|
||||
doc_before_save = self.get_doc_before_save()
|
||||
if not doc_before_save or cint(doc_before_save.is_group) == cint(self.is_group):
|
||||
@@ -264,9 +273,32 @@ class Account(NestedSet):
|
||||
elif cint(self.is_group):
|
||||
if self.account_type and not self.flags.exclude_account_type_check:
|
||||
throw(_("Cannot covert to Group because Account Type is selected."))
|
||||
self.validate_default_accounts_in_company()
|
||||
elif self.check_if_child_exists():
|
||||
throw(_("Account with child nodes cannot be set as ledger"))
|
||||
|
||||
def validate_default_accounts_in_company(self):
|
||||
default_account_fields = get_company_default_account_fields()
|
||||
|
||||
company_default_accounts = frappe.db.get_value(
|
||||
"Company", self.company, list(default_account_fields.keys()), as_dict=1
|
||||
)
|
||||
|
||||
msg = _("Account {0} cannot be disabled as it is already set as {1} for {2}.")
|
||||
|
||||
if not self.disabled:
|
||||
msg = _("Account {0} cannot be converted to Group as it is already set as {1} for {2}.")
|
||||
|
||||
for d in default_account_fields:
|
||||
if company_default_accounts.get(d) == self.name:
|
||||
throw(
|
||||
msg.format(
|
||||
frappe.bold(self.name),
|
||||
frappe.bold(default_account_fields.get(d)),
|
||||
frappe.bold(self.company),
|
||||
)
|
||||
)
|
||||
|
||||
def validate_frozen_accounts_modifier(self):
|
||||
doc_before_save = self.get_doc_before_save()
|
||||
if not doc_before_save or doc_before_save.freeze_account == self.freeze_account:
|
||||
@@ -627,3 +659,27 @@ def _ensure_idle_system():
|
||||
).format(pretty_date(last_gl_update)),
|
||||
title=_("System In Use"),
|
||||
)
|
||||
|
||||
|
||||
def get_company_default_account_fields():
|
||||
return {
|
||||
"default_bank_account": "Default Bank Account",
|
||||
"default_cash_account": "Default Cash Account",
|
||||
"default_receivable_account": "Default Receivable Account",
|
||||
"default_payable_account": "Default Payable Account",
|
||||
"default_expense_account": "Default Expense Account",
|
||||
"default_income_account": "Default Income Account",
|
||||
"stock_received_but_not_billed": "Stock Received But Not Billed Account",
|
||||
"stock_adjustment_account": "Stock Adjustment Account",
|
||||
"write_off_account": "Write Off Account",
|
||||
"default_discount_account": "Default Payment Discount Account",
|
||||
"unrealized_profit_loss_account": "Unrealized Profit / Loss Account",
|
||||
"exchange_gain_loss_account": "Exchange Gain / Loss Account",
|
||||
"unrealized_exchange_gain_loss_account": "Unrealized Exchange Gain / Loss Account",
|
||||
"round_off_account": "Round Off Account",
|
||||
"default_deferred_revenue_account": "Default Deferred Revenue Account",
|
||||
"default_deferred_expense_account": "Default Deferred Expense Account",
|
||||
"accumulated_depreciation_account": "Accumulated Depreciation Account",
|
||||
"depreciation_expense_account": "Depreciation Expense Account",
|
||||
"disposal_account": "Gain/Loss Account on Asset Disposal",
|
||||
}
|
||||
|
||||
@@ -309,8 +309,8 @@ def get_dimensions(with_cost_center_and_project=False):
|
||||
if with_cost_center_and_project:
|
||||
dimension_filters.extend(
|
||||
[
|
||||
{"fieldname": "cost_center", "document_type": "Cost Center"},
|
||||
{"fieldname": "project", "document_type": "Project"},
|
||||
frappe._dict({"fieldname": "cost_center", "document_type": "Cost Center"}),
|
||||
frappe._dict({"fieldname": "project", "document_type": "Project"}),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@
|
||||
"reconciliation_queue_size",
|
||||
"column_break_resa",
|
||||
"exchange_gain_loss_posting_date",
|
||||
"payment_entry_settings",
|
||||
"show_account_balance",
|
||||
"show_party_balance",
|
||||
"invoicing_settings_tab",
|
||||
"accounts_transactions_settings_section",
|
||||
"over_billing_allowance",
|
||||
@@ -75,6 +78,7 @@
|
||||
"period_closing_settings_section",
|
||||
"acc_frozen_upto",
|
||||
"ignore_account_closing_balance",
|
||||
"use_legacy_controller_for_pcv",
|
||||
"column_break_25",
|
||||
"frozen_accounts_modifier",
|
||||
"tab_break_dpet",
|
||||
@@ -94,7 +98,8 @@
|
||||
"legacy_section",
|
||||
"ignore_is_opening_check_for_reporting",
|
||||
"payment_request_settings",
|
||||
"create_pr_in_draft_status"
|
||||
"create_pr_in_draft_status",
|
||||
"column_break_xrnd"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -629,6 +634,29 @@
|
||||
"fieldname": "fetch_valuation_rate_for_internal_transaction",
|
||||
"fieldtype": "Check",
|
||||
"label": "Fetch Valuation Rate for Internal Transaction"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "use_legacy_controller_for_pcv",
|
||||
"fieldtype": "Check",
|
||||
"label": "Use Legacy Controller For Period Closing Voucher"
|
||||
},
|
||||
{
|
||||
"fieldname": "payment_entry_settings",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Payment Entry Settings"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "show_account_balance",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Account Balance"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "show_party_balance",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Party Balance"
|
||||
}
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
@@ -636,7 +664,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2025-07-18 13:56:47.192437",
|
||||
"modified": "2025-11-06 17:48:07.682837",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Accounts Settings",
|
||||
@@ -661,8 +689,9 @@
|
||||
}
|
||||
],
|
||||
"quick_entry": 1,
|
||||
"row_format": "Dynamic",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "ASC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
@@ -65,14 +65,17 @@ class AccountsSettings(Document):
|
||||
role_allowed_to_over_bill: DF.Link | None
|
||||
role_to_override_stop_action: DF.Link | None
|
||||
round_row_wise_tax: DF.Check
|
||||
show_account_balance: DF.Check
|
||||
show_balance_in_coa: DF.Check
|
||||
show_inclusive_tax_in_print: DF.Check
|
||||
show_party_balance: DF.Check
|
||||
show_payment_schedule_in_print: DF.Check
|
||||
show_taxes_as_table_in_print: DF.Check
|
||||
stale_days: DF.Int
|
||||
submit_journal_entries: DF.Check
|
||||
unlink_advance_payment_on_cancelation_of_order: DF.Check
|
||||
unlink_payment_on_cancellation_of_invoice: DF.Check
|
||||
use_legacy_controller_for_pcv: DF.Check
|
||||
# end: auto-generated types
|
||||
|
||||
def validate(self):
|
||||
@@ -104,6 +107,7 @@ class AccountsSettings(Document):
|
||||
frappe.clear_cache()
|
||||
|
||||
self.validate_and_sync_auto_reconcile_config()
|
||||
self.hide_or_show_party_and_account_balance()
|
||||
|
||||
def validate_stale_days(self):
|
||||
if not self.allow_stale and cint(self.stale_days) <= 0:
|
||||
@@ -111,6 +115,18 @@ class AccountsSettings(Document):
|
||||
_("Stale Days should start from 1."), title="Error", indicator="red", raise_exception=1
|
||||
)
|
||||
|
||||
def hide_or_show_party_and_account_balance(self):
|
||||
def set_property(fieldname, value):
|
||||
make_property_setter("Payment Entry", fieldname, "hidden", value, "Check")
|
||||
|
||||
if self.has_value_changed("show_party_balance"):
|
||||
set_property("party_balance", not self.show_party_balance)
|
||||
|
||||
if self.has_value_changed("show_account_balance"):
|
||||
account_fields = ["paid_from_account_balance", "paid_to_account_balance"]
|
||||
for field in account_fields:
|
||||
set_property(field, not self.show_account_balance)
|
||||
|
||||
def enable_payment_schedule_in_print(self):
|
||||
show_in_print = cint(self.show_payment_schedule_in_print)
|
||||
for doctype in ("Sales Order", "Sales Invoice", "Purchase Order", "Purchase Invoice"):
|
||||
|
||||
@@ -9,13 +9,6 @@ cur_frm.add_fetch("bank", "swift_number", "swift_number");
|
||||
|
||||
frappe.ui.form.on("Bank Guarantee", {
|
||||
setup: function (frm) {
|
||||
frm.set_query("bank", function () {
|
||||
return {
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
},
|
||||
};
|
||||
});
|
||||
frm.set_query("bank_account", function () {
|
||||
return {
|
||||
filters: {
|
||||
|
||||
@@ -123,8 +123,7 @@
|
||||
"fieldname": "transaction_id",
|
||||
"fieldtype": "Data",
|
||||
"label": "Transaction ID",
|
||||
"read_only": 1,
|
||||
"unique": 1
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
@@ -239,7 +238,7 @@
|
||||
"grid_page_length": 50,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-10-14 11:53:45.908169",
|
||||
"modified": "2025-10-23 17:32:58.514807",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Bank Transaction",
|
||||
|
||||
@@ -19,7 +19,7 @@ frappe.ui.form.on("Currency Exchange Settings", {
|
||||
to: "{to_currency}",
|
||||
};
|
||||
add_param(frm, r.message, params, result);
|
||||
} else if (frm.doc.service_provider == "frankfurter.app") {
|
||||
} else if (frm.doc.service_provider == "frankfurter.dev") {
|
||||
let result = ["rates", "{to_currency}"];
|
||||
let params = {
|
||||
base: "{from_currency}",
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
"fieldname": "service_provider",
|
||||
"fieldtype": "Select",
|
||||
"label": "Service Provider",
|
||||
"options": "frankfurter.app\nexchangerate.host\nCustom",
|
||||
"options": "frankfurter.dev\nexchangerate.host\nCustom",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -104,7 +104,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2024-03-18 08:32:26.895076",
|
||||
"modified": "2025-11-25 13:03:41.896424",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Currency Exchange Settings",
|
||||
@@ -141,8 +141,9 @@
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"row_format": "Dynamic",
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class CurrencyExchangeSettings(Document):
|
||||
disabled: DF.Check
|
||||
req_params: DF.Table[CurrencyExchangeSettingsDetails]
|
||||
result_key: DF.Table[CurrencyExchangeSettingsResult]
|
||||
service_provider: DF.Literal["frankfurter.app", "exchangerate.host", "Custom"]
|
||||
service_provider: DF.Literal["frankfurter.dev", "exchangerate.host", "Custom"]
|
||||
url: DF.Data | None
|
||||
use_http: DF.Check
|
||||
# end: auto-generated types
|
||||
@@ -60,7 +60,7 @@ class CurrencyExchangeSettings(Document):
|
||||
self.append("req_params", {"key": "date", "value": "{transaction_date}"})
|
||||
self.append("req_params", {"key": "from", "value": "{from_currency}"})
|
||||
self.append("req_params", {"key": "to", "value": "{to_currency}"})
|
||||
elif self.service_provider == "frankfurter.app":
|
||||
elif self.service_provider == "frankfurter.dev":
|
||||
self.set("result_key", [])
|
||||
self.set("req_params", [])
|
||||
|
||||
@@ -105,11 +105,11 @@ class CurrencyExchangeSettings(Document):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_api_endpoint(service_provider: str | None = None, use_http: bool = False):
|
||||
if service_provider and service_provider in ["exchangerate.host", "frankfurter.app"]:
|
||||
if service_provider and service_provider in ["exchangerate.host", "frankfurter.dev"]:
|
||||
if service_provider == "exchangerate.host":
|
||||
api = "api.exchangerate.host/convert"
|
||||
elif service_provider == "frankfurter.app":
|
||||
api = "api.frankfurter.app/{transaction_date}"
|
||||
elif service_provider == "frankfurter.dev":
|
||||
api = "api.frankfurter.dev/v1/{transaction_date}"
|
||||
|
||||
protocol = "https://"
|
||||
if use_http:
|
||||
|
||||
@@ -99,7 +99,7 @@ class FiscalYear(Document):
|
||||
)
|
||||
|
||||
overlap = False
|
||||
if not self.get("companies") or not company_for_existing:
|
||||
if not self.get("companies") and not company_for_existing:
|
||||
overlap = True
|
||||
|
||||
for d in self.get("companies"):
|
||||
|
||||
@@ -26,6 +26,27 @@ class TestFiscalYear(unittest.TestCase):
|
||||
|
||||
self.assertRaises(frappe.exceptions.InvalidDates, fy.insert)
|
||||
|
||||
def test_company_fiscal_year_overlap(self):
|
||||
for name in ["_Test Global FY 2001", "_Test Company FY 2001"]:
|
||||
if frappe.db.exists("Fiscal Year", name):
|
||||
frappe.delete_doc("Fiscal Year", name)
|
||||
|
||||
global_fy = frappe.new_doc("Fiscal Year")
|
||||
global_fy.year = "_Test Global FY 2001"
|
||||
global_fy.year_start_date = "2001-04-01"
|
||||
global_fy.year_end_date = "2002-03-31"
|
||||
global_fy.insert()
|
||||
|
||||
company_fy = frappe.new_doc("Fiscal Year")
|
||||
company_fy.year = "_Test Company FY 2001"
|
||||
company_fy.year_start_date = "2001-01-01"
|
||||
company_fy.year_end_date = "2001-12-31"
|
||||
company_fy.append("companies", {"company": "_Test Company"})
|
||||
|
||||
company_fy.insert()
|
||||
self.assertTrue(frappe.db.exists("Fiscal Year", global_fy.name))
|
||||
self.assertTrue(frappe.db.exists("Fiscal Year", company_fy.name))
|
||||
|
||||
|
||||
def test_record_generator():
|
||||
test_records = [
|
||||
|
||||
@@ -106,7 +106,6 @@
|
||||
"fieldname": "account_currency",
|
||||
"fieldtype": "Link",
|
||||
"label": "Account Currency",
|
||||
"no_copy": 1,
|
||||
"options": "Currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
@@ -288,7 +287,7 @@
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-10-20 17:46:47.344089",
|
||||
"modified": "2025-10-27 13:48:32.805100",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Journal Entry Account",
|
||||
|
||||
@@ -592,6 +592,8 @@ frappe.ui.form.on("Payment Entry", {
|
||||
paid_from: function (frm) {
|
||||
if (frm.set_party_account_based_on_party) return;
|
||||
|
||||
frm.events.set_company_bank_account(frm);
|
||||
|
||||
frm.events.set_account_currency_and_balance(
|
||||
frm,
|
||||
frm.doc.paid_from,
|
||||
@@ -609,6 +611,8 @@ frappe.ui.form.on("Payment Entry", {
|
||||
paid_to: function (frm) {
|
||||
if (frm.set_party_account_based_on_party) return;
|
||||
|
||||
frm.events.set_company_bank_account(frm);
|
||||
|
||||
frm.events.set_account_currency_and_balance(
|
||||
frm,
|
||||
frm.doc.paid_to,
|
||||
@@ -1350,6 +1354,8 @@ frappe.ui.form.on("Payment Entry", {
|
||||
},
|
||||
|
||||
bank_account: function (frm) {
|
||||
if (frm.set_company_bank_account_based_on_coa) return;
|
||||
|
||||
const field = frm.doc.payment_type == "Pay" ? "paid_from" : "paid_to";
|
||||
if (frm.doc.bank_account && ["Pay", "Receive"].includes(frm.doc.payment_type)) {
|
||||
frappe.call({
|
||||
@@ -1388,6 +1394,34 @@ frappe.ui.form.on("Payment Entry", {
|
||||
}
|
||||
},
|
||||
|
||||
set_company_bank_account: function (frm) {
|
||||
if (!["Pay", "Receive"].includes(frm.doc.payment_type)) return;
|
||||
|
||||
const field = frm.doc.payment_type == "Pay" ? "paid_from" : "paid_to";
|
||||
|
||||
if (!frm.doc.company || !frm.doc[field]) return;
|
||||
|
||||
frm.set_company_bank_account_based_on_coa = true;
|
||||
|
||||
frappe.call({
|
||||
method: "frappe.client.get_value",
|
||||
args: {
|
||||
doctype: "Bank Account",
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
account: frm.doc[field],
|
||||
disabled: 0,
|
||||
},
|
||||
fieldname: ["name"],
|
||||
},
|
||||
callback: async function (r) {
|
||||
if (r.message) await frm.set_value("bank_account", r.message.name);
|
||||
|
||||
frm.set_company_bank_account_based_on_coa = false;
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
sales_taxes_and_charges_template: function (frm) {
|
||||
frm.trigger("fetch_taxes_from_template");
|
||||
},
|
||||
|
||||
@@ -449,7 +449,7 @@ class PaymentEntry(AccountsController):
|
||||
self.contact_person = get_default_contact(self.party_type, self.party)
|
||||
|
||||
complete_contact_details(self)
|
||||
if not self.party_balance:
|
||||
if not self.party_balance and frappe.get_single_value("Accounts Settings", "show_party_balance"):
|
||||
self.party_balance = get_balance_on(
|
||||
party_type=self.party_type, party=self.party, date=self.posting_date, company=self.company
|
||||
)
|
||||
@@ -1800,7 +1800,7 @@ class PaymentEntry(AccountsController):
|
||||
else:
|
||||
self.total_taxes_and_charges += current_tax_amount
|
||||
|
||||
self.base_total_taxes_and_charges += tax.base_tax_amount
|
||||
self.base_total_taxes_and_charges += current_tax_amount
|
||||
|
||||
if self.get("taxes"):
|
||||
self.paid_amount_after_tax = self.get("taxes")[-1].base_total
|
||||
@@ -2684,11 +2684,17 @@ def get_party_details(company, party_type, party, date, cost_center=None):
|
||||
|
||||
party_account = get_party_account(party_type, party, company)
|
||||
account_currency = get_account_currency(party_account)
|
||||
account_balance = get_balance_on(party_account, date, cost_center=cost_center)
|
||||
account_balance = (
|
||||
get_balance_on(party_account, date, cost_center=cost_center)
|
||||
if frappe.get_single_value("Accounts Settings", "show_account_balance")
|
||||
else 0
|
||||
)
|
||||
_party_name = "title" if party_type == "Shareholder" else party_type.lower() + "_name"
|
||||
party_name = frappe.db.get_value(party_type, party, _party_name)
|
||||
party_balance = get_balance_on(
|
||||
party_type=party_type, party=party, company=company, cost_center=cost_center
|
||||
party_balance = (
|
||||
get_balance_on(party_type=party_type, party=party, company=company, cost_center=cost_center)
|
||||
if frappe.get_single_value("Accounts Settings", "show_party_balance")
|
||||
else 0
|
||||
)
|
||||
if party_type in ["Customer", "Supplier"]:
|
||||
party_bank_account = get_party_bank_account(party_type, party)
|
||||
@@ -2717,7 +2723,11 @@ def get_account_details(account, date, cost_center=None):
|
||||
if not account_list:
|
||||
frappe.throw(_("Account: {0} is not permitted under Payment Entry").format(account))
|
||||
|
||||
account_balance = get_balance_on(account, date, cost_center=cost_center, ignore_account_permission=True)
|
||||
account_balance = (
|
||||
get_balance_on(account, date, cost_center=cost_center, ignore_account_permission=True)
|
||||
if frappe.get_single_value("Accounts Settings", "show_account_balance")
|
||||
else 0
|
||||
)
|
||||
|
||||
return frappe._dict(
|
||||
{
|
||||
@@ -3529,11 +3539,18 @@ def get_paid_amount(dt, dn, party_type, party, account, due_date):
|
||||
def get_party_and_account_balance(
|
||||
company, date, paid_from=None, paid_to=None, ptype=None, pty=None, cost_center=None
|
||||
):
|
||||
show_account_balance = frappe.get_single_value("Accounts Settings", "show_account_balance")
|
||||
return frappe._dict(
|
||||
{
|
||||
"party_balance": get_balance_on(party_type=ptype, party=pty, cost_center=cost_center),
|
||||
"paid_from_account_balance": get_balance_on(paid_from, date, cost_center=cost_center),
|
||||
"paid_to_account_balance": get_balance_on(paid_to, date=date, cost_center=cost_center),
|
||||
"party_balance": get_balance_on(party_type=ptype, party=pty, cost_center=cost_center)
|
||||
if frappe.get_single_value("Accounts Settings", "show_party_balance")
|
||||
else 0,
|
||||
"paid_from_account_balance": get_balance_on(paid_from, date, cost_center=cost_center)
|
||||
if show_account_balance
|
||||
else 0,
|
||||
"paid_to_account_balance": get_balance_on(paid_to, date=date, cost_center=cost_center)
|
||||
if show_account_balance
|
||||
else 0,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -61,6 +61,22 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
||||
},
|
||||
};
|
||||
});
|
||||
this.frm.set_query("cost_center", "payments", () => {
|
||||
return {
|
||||
filters: {
|
||||
company: this.frm.doc.company,
|
||||
is_group: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
this.frm.set_query("cost_center", "allocation", () => {
|
||||
return {
|
||||
filters: {
|
||||
company: this.frm.doc.company,
|
||||
is_group: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
refresh() {
|
||||
@@ -385,6 +401,16 @@ frappe.ui.form.on("Payment Reconciliation Allocation", {
|
||||
// filter payment
|
||||
let payment = frm.doc.payments.filter((x) => x.reference_name == row.reference_name);
|
||||
|
||||
let amount = payment[0].amount;
|
||||
for (const d of frm.doc.allocation) {
|
||||
if (row.reference_name == d.reference_name && amount) {
|
||||
if (d.allocated_amount <= amount) {
|
||||
d.amount = amount;
|
||||
amount -= d.allocated_amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frm.call({
|
||||
doc: frm.doc,
|
||||
method: "calculate_difference_on_allocation_change",
|
||||
|
||||
@@ -72,7 +72,7 @@ class PaymentReconciliation(Document):
|
||||
self.common_filter_conditions = []
|
||||
self.accounting_dimension_filter_conditions = []
|
||||
self.ple_posting_date_filter = []
|
||||
self.dimensions = get_dimensions()[0]
|
||||
self.dimensions = get_dimensions(with_cost_center_and_project=True)[0]
|
||||
|
||||
def load_from_db(self):
|
||||
# 'modified' attribute is required for `run_doc_method` to work properly.
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
frappe.ui.form.on("Period Closing Voucher", {
|
||||
onload: function (frm) {
|
||||
if (!frm.doc.transaction_date) frm.doc.transaction_date = frappe.datetime.obj_to_str(new Date());
|
||||
|
||||
frm.ignore_doctypes_on_cancel_all = ["Process Period Closing Voucher"];
|
||||
},
|
||||
|
||||
setup: function (frm) {
|
||||
|
||||
@@ -132,7 +132,11 @@ class PeriodClosingVoucher(AccountsController):
|
||||
|
||||
def on_submit(self):
|
||||
self.db_set("gle_processing_status", "In Progress")
|
||||
self.make_gl_entries()
|
||||
if frappe.get_single_value("Accounts Settings", "use_legacy_controller_for_pcv"):
|
||||
self.make_gl_entries()
|
||||
else:
|
||||
ppcv = frappe.get_doc({"doctype": "Process Period Closing Voucher", "parent_pcv": self.name})
|
||||
ppcv.save().submit()
|
||||
|
||||
def on_cancel(self):
|
||||
self.ignore_linked_doctypes = (
|
||||
@@ -140,11 +144,29 @@ class PeriodClosingVoucher(AccountsController):
|
||||
"Stock Ledger Entry",
|
||||
"Payment Ledger Entry",
|
||||
"Account Closing Balance",
|
||||
"Process Period Closing Voucher",
|
||||
)
|
||||
self.block_if_future_closing_voucher_exists()
|
||||
|
||||
if not frappe.get_single_value("Accounts Settings", "use_legacy_controller_for_pcv"):
|
||||
self.cancel_process_pcv_docs()
|
||||
|
||||
self.db_set("gle_processing_status", "In Progress")
|
||||
self.cancel_gl_entries()
|
||||
|
||||
def cancel_process_pcv_docs(self):
|
||||
ppcvs = frappe.db.get_all("Process Period Closing Voucher", {"parent_pcv": self.name, "docstatus": 1})
|
||||
for x in ppcvs:
|
||||
frappe.get_doc("Process Period Closing Voucher", x.name).cancel()
|
||||
|
||||
def on_trash(self):
|
||||
super().on_trash()
|
||||
ppcvs = frappe.db.get_all(
|
||||
"Process Period Closing Voucher", {"parent_pcv": self.name, "docstatus": ["in", [1, 2]]}
|
||||
)
|
||||
for x in ppcvs:
|
||||
frappe.delete_doc("Process Period Closing Voucher", x.name, force=True, ignore_permissions=True)
|
||||
|
||||
def make_gl_entries(self):
|
||||
if frappe.db.estimate_count("GL Entry") > 100_000:
|
||||
frappe.enqueue(
|
||||
@@ -453,8 +475,15 @@ def process_gl_and_closing_entries(doc):
|
||||
frappe.db.set_value(doc.doctype, doc.name, "gle_processing_status", "Completed")
|
||||
except Exception as e:
|
||||
frappe.db.rollback()
|
||||
frappe.log_error(e)
|
||||
frappe.db.set_value(doc.doctype, doc.name, "gle_processing_status", "Failed")
|
||||
frappe.log_error(title=_("Period Closing Voucher {0} GL Entry Processing Failed").format(doc.name))
|
||||
frappe.db.set_value(
|
||||
doc.doctype,
|
||||
doc.name,
|
||||
{
|
||||
"error_message": str(e),
|
||||
"gle_processing_status": "Failed",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def process_cancellation(voucher_type, voucher_no):
|
||||
@@ -466,8 +495,17 @@ def process_cancellation(voucher_type, voucher_no):
|
||||
frappe.db.set_value("Period Closing Voucher", voucher_no, "gle_processing_status", "Completed")
|
||||
except Exception as e:
|
||||
frappe.db.rollback()
|
||||
frappe.log_error(e)
|
||||
frappe.db.set_value("Period Closing Voucher", voucher_no, "gle_processing_status", "Failed")
|
||||
frappe.log_error(
|
||||
title=_("Period Closing Voucher {0} GL Entry Cancellation Failed").format(voucher_no)
|
||||
)
|
||||
frappe.db.set_value(
|
||||
voucher_type,
|
||||
voucher_no,
|
||||
{
|
||||
"error_message": str(e),
|
||||
"gle_processing_status": "Failed",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def delete_closing_entries(voucher_no):
|
||||
|
||||
@@ -14,6 +14,10 @@ from erpnext.accounts.utils import get_fiscal_year
|
||||
|
||||
|
||||
class TestPeriodClosingVoucher(unittest.TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
frappe.db.set_single_value("Accounts Settings", "use_legacy_controller_for_pcv", 1)
|
||||
|
||||
def test_closing_entry(self):
|
||||
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
|
||||
frappe.db.sql("delete from `tabPeriod Closing Voucher` where company='Test PCV Company'")
|
||||
|
||||
@@ -161,6 +161,8 @@ def get_pos_invoices(start, end, pos_profile, user):
|
||||
`tabPOS Invoice`
|
||||
where
|
||||
owner = %s and docstatus = 1 and pos_profile = %s and ifnull(consolidated_invoice,'') = ''
|
||||
order by
|
||||
timestamp
|
||||
""",
|
||||
(user, pos_profile),
|
||||
as_dict=1,
|
||||
|
||||
@@ -189,6 +189,9 @@ class POSInvoice(SalesInvoice):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def validate(self):
|
||||
if not self.customer:
|
||||
frappe.throw(_("Please select Customer first"))
|
||||
|
||||
if not cint(self.is_pos):
|
||||
frappe.throw(
|
||||
_("POS Invoice should have the field {0} checked.").format(frappe.bold(_("Include Payment")))
|
||||
@@ -345,14 +348,14 @@ class POSInvoice(SalesInvoice):
|
||||
):
|
||||
return
|
||||
|
||||
from erpnext.stock.stock_ledger import is_negative_stock_allowed
|
||||
|
||||
for d in self.get("items"):
|
||||
if not d.serial_and_batch_bundle:
|
||||
if is_negative_stock_allowed(item_code=d.item_code):
|
||||
return
|
||||
available_stock, is_stock_item, is_negative_stock_allowed = get_stock_availability(
|
||||
d.item_code, d.warehouse
|
||||
)
|
||||
|
||||
available_stock, is_stock_item = get_stock_availability(d.item_code, d.warehouse)
|
||||
if is_negative_stock_allowed:
|
||||
continue
|
||||
|
||||
item_code, warehouse, _qty = (
|
||||
frappe.bold(d.item_code),
|
||||
@@ -760,20 +763,22 @@ class POSInvoice(SalesInvoice):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_stock_availability(item_code, warehouse):
|
||||
from erpnext.stock.stock_ledger import is_negative_stock_allowed
|
||||
|
||||
if frappe.db.get_value("Item", item_code, "is_stock_item"):
|
||||
is_stock_item = True
|
||||
bin_qty = get_bin_qty(item_code, warehouse)
|
||||
pos_sales_qty = get_pos_reserved_qty(item_code, warehouse)
|
||||
|
||||
return bin_qty - pos_sales_qty, is_stock_item
|
||||
return bin_qty - pos_sales_qty, is_stock_item, is_negative_stock_allowed(item_code=item_code)
|
||||
else:
|
||||
is_stock_item = True
|
||||
if frappe.db.exists("Product Bundle", {"name": item_code, "disabled": 0}):
|
||||
return get_bundle_availability(item_code, warehouse), is_stock_item
|
||||
return get_bundle_availability(item_code, warehouse), is_stock_item, False
|
||||
else:
|
||||
is_stock_item = False
|
||||
# Is a service item or non_stock item
|
||||
return 0, is_stock_item
|
||||
return 0, is_stock_item, False
|
||||
|
||||
|
||||
def get_bundle_availability(bundle_item_code, warehouse):
|
||||
|
||||
@@ -41,9 +41,19 @@ class POSOpeningEntry(StatusUpdater):
|
||||
self.set_status()
|
||||
|
||||
def validate_pos_profile_and_cashier(self):
|
||||
if self.company != frappe.db.get_value("POS Profile", self.pos_profile, "company"):
|
||||
if not frappe.db.exists("POS Profile", self.pos_profile):
|
||||
frappe.throw(_("POS Profile {} does not exist.").format(self.pos_profile))
|
||||
|
||||
pos_profile_company, pos_profile_disabled = frappe.db.get_value(
|
||||
"POS Profile", self.pos_profile, ["company", "disabled"]
|
||||
)
|
||||
|
||||
if pos_profile_disabled:
|
||||
frappe.throw(_("POS Profile {} is disabled.").format(frappe.bold(self.pos_profile)))
|
||||
|
||||
if self.company != pos_profile_company:
|
||||
frappe.throw(
|
||||
_("POS Profile {} does not belongs to company {}").format(self.pos_profile, self.company)
|
||||
_("POS Profile {} does not belong to company {}").format(self.pos_profile, self.company)
|
||||
)
|
||||
|
||||
if not cint(frappe.db.get_value("User", self.user, "enabled")):
|
||||
|
||||
@@ -70,6 +70,7 @@ class POSProfile(Document):
|
||||
# end: auto-generated types
|
||||
|
||||
def validate(self):
|
||||
self.validate_disabled()
|
||||
self.validate_default_profile()
|
||||
self.validate_all_link_fields()
|
||||
self.validate_duplicate_groups()
|
||||
@@ -94,6 +95,21 @@ class POSProfile(Document):
|
||||
title=_("Mandatory Accounting Dimension"),
|
||||
)
|
||||
|
||||
def validate_disabled(self):
|
||||
old_doc = self.get_doc_before_save()
|
||||
|
||||
if (
|
||||
old_doc
|
||||
and self.disabled
|
||||
and old_doc.disabled != self.disabled
|
||||
and frappe.db.exists("POS Opening Entry", {"pos_profile": self.name, "status": "Open"})
|
||||
):
|
||||
frappe.throw(
|
||||
_("POS Profile {0} cannot be disabled as there are ongoing POS sessions.").format(
|
||||
frappe.bold(self.name)
|
||||
)
|
||||
)
|
||||
|
||||
def validate_default_profile(self):
|
||||
for row in self.applicable_for_users:
|
||||
res = frappe.db.sql(
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.utils import cint
|
||||
|
||||
from erpnext.accounts.doctype.pos_profile.pos_profile import (
|
||||
get_child_nodes,
|
||||
@@ -38,6 +39,51 @@ class TestPOSProfile(unittest.TestCase):
|
||||
|
||||
frappe.db.sql("delete from `tabPOS Profile`")
|
||||
|
||||
def test_disabled_pos_profile_creation(self):
|
||||
make_pos_profile(name="_Test POS Profile 001", disabled=1)
|
||||
|
||||
pos_profile = frappe.get_doc("POS Profile", "_Test POS Profile 001")
|
||||
|
||||
if pos_profile:
|
||||
self.assertEqual(pos_profile.disabled, 1)
|
||||
|
||||
def test_disabled_pos_profile_after_opening(self):
|
||||
from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile
|
||||
from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry
|
||||
|
||||
test_user, pos_profile = init_user_and_profile()
|
||||
|
||||
if pos_profile:
|
||||
create_opening_entry(pos_profile, test_user.name)
|
||||
self.assertEqual(pos_profile.disabled, 0)
|
||||
|
||||
pos_profile.disabled = 1
|
||||
self.assertRaises(frappe.ValidationError, pos_profile.save)
|
||||
|
||||
def test_disabled_pos_profile_after_completing_session(self):
|
||||
from erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry import (
|
||||
make_closing_entry_from_opening,
|
||||
)
|
||||
from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile
|
||||
from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import (
|
||||
create_opening_entry,
|
||||
)
|
||||
|
||||
test_user, pos_profile = init_user_and_profile()
|
||||
frappe.db.delete("POS Opening Entry", {"pos_profile": pos_profile.name})
|
||||
|
||||
if pos_profile:
|
||||
opening_entry = create_opening_entry(pos_profile, test_user.name)
|
||||
|
||||
closing_entry = make_closing_entry_from_opening(opening_entry)
|
||||
closing_entry.submit()
|
||||
|
||||
pos_profile.disabled = 1
|
||||
pos_profile.save()
|
||||
pos_profile.reload()
|
||||
|
||||
self.assertEqual(pos_profile.disabled, 1)
|
||||
|
||||
|
||||
def get_customers_list(pos_profile=None):
|
||||
if pos_profile is None:
|
||||
@@ -117,6 +163,7 @@ def make_pos_profile(**args):
|
||||
"write_off_account": args.write_off_account or "_Test Write Off - _TC",
|
||||
"write_off_cost_center": args.write_off_cost_center or "_Test Write Off Cost Center - _TC",
|
||||
"location": "Block 1" if not args.do_not_set_accounting_dimension else None,
|
||||
"disabled": cint(args.disabled) or 0,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -243,10 +243,13 @@ def get_other_conditions(conditions, values, args):
|
||||
if group_condition:
|
||||
conditions += " and " + group_condition
|
||||
|
||||
if args.get("transaction_date"):
|
||||
date = args.get("transaction_date") or frappe.get_value(
|
||||
args.get("doctype"), args.get("name"), "posting_date", ignore=True
|
||||
)
|
||||
if date:
|
||||
conditions += """ and %(transaction_date)s between ifnull(`tabPricing Rule`.valid_from, '2000-01-01')
|
||||
and ifnull(`tabPricing Rule`.valid_upto, '2500-12-31')"""
|
||||
values["transaction_date"] = args.get("transaction_date")
|
||||
values["transaction_date"] = date
|
||||
|
||||
if args.get("doctype") in [
|
||||
"Quotation",
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on("Process Period Closing Voucher", {
|
||||
refresh(frm) {
|
||||
if (frm.doc.docstatus == 1 && ["Queued"].find((x) => x == frm.doc.status)) {
|
||||
let execute_btn = __("Start");
|
||||
|
||||
frm.add_custom_button(execute_btn, () => {
|
||||
frm.call({
|
||||
method: "erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.start_pcv_processing",
|
||||
args: {
|
||||
docname: frm.doc.name,
|
||||
},
|
||||
}).then((r) => {
|
||||
if (!r.exc) {
|
||||
frappe.show_alert(__("Job Started"));
|
||||
frm.reload_doc();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (frm.doc.docstatus == 1 && ["Running"].find((x) => x == frm.doc.status)) {
|
||||
let execute_btn = __("Pause");
|
||||
|
||||
frm.add_custom_button(execute_btn, () => {
|
||||
frm.call({
|
||||
method: "erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.pause_pcv_processing",
|
||||
args: {
|
||||
docname: frm.doc.name,
|
||||
},
|
||||
}).then((r) => {
|
||||
if (!r.exc) {
|
||||
frappe.show_alert(__("PCV Paused"));
|
||||
frm.reload_doc();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (frm.doc.docstatus == 1 && ["Paused"].find((x) => x == frm.doc.status)) {
|
||||
let execute_btn = __("Resume");
|
||||
|
||||
frm.add_custom_button(execute_btn, () => {
|
||||
frm.call({
|
||||
method: "erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.resume_pcv_processing",
|
||||
args: {
|
||||
docname: frm.doc.name,
|
||||
},
|
||||
}).then((r) => {
|
||||
if (!r.exc) {
|
||||
frappe.show_alert(__("PCV Resumed"));
|
||||
frm.reload_doc();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// progress bar
|
||||
let progress = 0;
|
||||
|
||||
let normal_finished = frm.doc.normal_balances.filter((x) => x.status == "Completed").length;
|
||||
let opening_finished = frm.doc.z_opening_balances.filter((x) => x.status == "Completed").length;
|
||||
|
||||
progress =
|
||||
((normal_finished + opening_finished) /
|
||||
(frm.doc.normal_balances.length + frm.doc.z_opening_balances.length)) *
|
||||
100;
|
||||
frm.dashboard.add_progress("Books closure progress", progress, "");
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "format:Process-PCV-{###}",
|
||||
"creation": "2025-09-25 15:44:03.534699",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"parent_pcv",
|
||||
"status",
|
||||
"p_l_closing_balance",
|
||||
"normal_balances",
|
||||
"bs_closing_balance",
|
||||
"z_opening_balances",
|
||||
"amended_from"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "parent_pcv",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "PCV",
|
||||
"options": "Period Closing Voucher",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "Queued",
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"label": "Status",
|
||||
"no_copy": 1,
|
||||
"options": "Queued\nRunning\nPaused\nCompleted\nCancelled"
|
||||
},
|
||||
{
|
||||
"fieldname": "amended_from",
|
||||
"fieldtype": "Link",
|
||||
"label": "Amended From",
|
||||
"no_copy": 1,
|
||||
"options": "Process Period Closing Voucher",
|
||||
"print_hide": 1,
|
||||
"read_only": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "p_l_closing_balance",
|
||||
"fieldtype": "JSON",
|
||||
"label": "P&L Closing Balance",
|
||||
"no_copy": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "normal_balances",
|
||||
"fieldtype": "Table",
|
||||
"label": "Dates to Process",
|
||||
"no_copy": 1,
|
||||
"options": "Process Period Closing Voucher Detail"
|
||||
},
|
||||
{
|
||||
"fieldname": "z_opening_balances",
|
||||
"fieldtype": "Table",
|
||||
"label": "Opening Balances",
|
||||
"no_copy": 1,
|
||||
"options": "Process Period Closing Voucher Detail"
|
||||
},
|
||||
{
|
||||
"fieldname": "bs_closing_balance",
|
||||
"fieldtype": "JSON",
|
||||
"label": "Balance Sheet Closing Balance"
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-11-05 11:40:24.996403",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Process Period Closing Voucher",
|
||||
"naming_rule": "Expression",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"submit": 1,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Accounts Manager",
|
||||
"share": 1,
|
||||
"submit": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"row_format": "Dynamic",
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
@@ -0,0 +1,559 @@
|
||||
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import copy
|
||||
from datetime import timedelta
|
||||
|
||||
import frappe
|
||||
from frappe import qb
|
||||
from frappe.model.document import Document
|
||||
from frappe.query_builder.functions import Count, Max, Min, Sum
|
||||
from frappe.utils import add_days, flt, get_datetime
|
||||
from frappe.utils.scheduler import is_scheduler_inactive
|
||||
|
||||
from erpnext.accounts.doctype.account_closing_balance.account_closing_balance import (
|
||||
make_closing_entries,
|
||||
)
|
||||
|
||||
|
||||
class ProcessPeriodClosingVoucher(Document):
|
||||
# begin: auto-generated types
|
||||
# This code is auto-generated. Do not modify anything in this block.
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from frappe.types import DF
|
||||
|
||||
from erpnext.accounts.doctype.process_period_closing_voucher_detail.process_period_closing_voucher_detail import (
|
||||
ProcessPeriodClosingVoucherDetail,
|
||||
)
|
||||
|
||||
amended_from: DF.Link | None
|
||||
bs_closing_balance: DF.JSON | None
|
||||
normal_balances: DF.Table[ProcessPeriodClosingVoucherDetail]
|
||||
p_l_closing_balance: DF.JSON | None
|
||||
parent_pcv: DF.Link
|
||||
status: DF.Literal["Queued", "Running", "Paused", "Completed", "Cancelled"]
|
||||
z_opening_balances: DF.Table[ProcessPeriodClosingVoucherDetail]
|
||||
# end: auto-generated types
|
||||
|
||||
def validate(self):
|
||||
self.status = "Queued"
|
||||
self.populate_processing_tables()
|
||||
|
||||
def populate_processing_tables(self):
|
||||
self.generate_pcv_dates()
|
||||
self.generate_opening_balances_dates()
|
||||
|
||||
def get_dates(self, start, end):
|
||||
return [start + timedelta(days=x) for x in range((end - start).days + 1)]
|
||||
|
||||
def generate_pcv_dates(self):
|
||||
self.normal_balances = []
|
||||
pcv = frappe.get_doc("Period Closing Voucher", self.parent_pcv)
|
||||
|
||||
dates = self.get_dates(get_datetime(pcv.period_start_date), get_datetime(pcv.period_end_date))
|
||||
for x in dates:
|
||||
self.append(
|
||||
"normal_balances",
|
||||
{"processing_date": x, "status": "Queued", "report_type": "Profit and Loss"},
|
||||
)
|
||||
self.append(
|
||||
"normal_balances", {"processing_date": x, "status": "Queued", "report_type": "Balance Sheet"}
|
||||
)
|
||||
|
||||
def generate_opening_balances_dates(self):
|
||||
self.z_opening_balances = []
|
||||
|
||||
pcv = frappe.get_doc("Period Closing Voucher", self.parent_pcv)
|
||||
if pcv.is_first_period_closing_voucher():
|
||||
gl = qb.DocType("GL Entry")
|
||||
min = qb.from_(gl).select(Min(gl.posting_date)).where(gl.company.eq(pcv.company)).run()[0][0]
|
||||
max = qb.from_(gl).select(Max(gl.posting_date)).where(gl.company.eq(pcv.company)).run()[0][0]
|
||||
|
||||
dates = self.get_dates(get_datetime(min), get_datetime(max))
|
||||
for x in dates:
|
||||
self.append(
|
||||
"z_opening_balances",
|
||||
{"processing_date": x, "status": "Queued", "report_type": "Balance Sheet"},
|
||||
)
|
||||
|
||||
def on_submit(self):
|
||||
start_pcv_processing(self.name)
|
||||
|
||||
def on_cancel(self):
|
||||
cancel_pcv_processing(self.name)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def start_pcv_processing(docname: str):
|
||||
if frappe.db.get_value("Process Period Closing Voucher", docname, "status") in ["Queued", "Running"]:
|
||||
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Running")
|
||||
if normal_balances := frappe.db.get_all(
|
||||
"Process Period Closing Voucher Detail",
|
||||
filters={"parent": docname, "status": "Queued"},
|
||||
fields=["processing_date", "report_type", "parentfield"],
|
||||
order_by="parentfield, idx, processing_date",
|
||||
limit=4,
|
||||
):
|
||||
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="3600",
|
||||
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")
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def pause_pcv_processing(docname: str):
|
||||
ppcv = qb.DocType("Process Period Closing Voucher")
|
||||
qb.update(ppcv).set(ppcv.status, "Paused").where(ppcv.name.eq(docname)).run()
|
||||
|
||||
if queued_dates := frappe.db.get_all(
|
||||
"Process Period Closing Voucher Detail",
|
||||
filters={"parent": docname, "status": "Queued"},
|
||||
pluck="name",
|
||||
):
|
||||
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
||||
qb.update(ppcvd).set(ppcvd.status, "Paused").where(ppcvd.name.isin(queued_dates)).run()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def cancel_pcv_processing(docname: str):
|
||||
ppcv = qb.DocType("Process Period Closing Voucher")
|
||||
qb.update(ppcv).set(ppcv.status, "Cancelled").where(ppcv.name.eq(docname)).run()
|
||||
|
||||
if queued_dates := frappe.db.get_all(
|
||||
"Process Period Closing Voucher Detail",
|
||||
filters={"parent": docname, "status": "Queued"},
|
||||
pluck="name",
|
||||
):
|
||||
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
||||
qb.update(ppcvd).set(ppcvd.status, "Cancelled").where(ppcvd.name.isin(queued_dates)).run()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def resume_pcv_processing(docname: str):
|
||||
ppcv = qb.DocType("Process Period Closing Voucher")
|
||||
qb.update(ppcv).set(ppcv.status, "Running").where(ppcv.name.eq(docname)).run()
|
||||
|
||||
if paused_dates := frappe.db.get_all(
|
||||
"Process Period Closing Voucher Detail",
|
||||
filters={"parent": docname, "status": "Paused"},
|
||||
pluck="name",
|
||||
):
|
||||
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
||||
qb.update(ppcvd).set(ppcvd.status, "Queued").where(ppcvd.name.isin(paused_dates)).run()
|
||||
start_pcv_processing(docname)
|
||||
|
||||
|
||||
def update_default_dimensions(dimension_fields, gl_entry, dimension_values):
|
||||
for i, dimension in enumerate(dimension_fields):
|
||||
gl_entry[dimension] = dimension_values[i]
|
||||
|
||||
|
||||
def get_gle_for_pl_account(pcv, acc, balances, dimensions):
|
||||
balance_in_account_currency = flt(balances.debit_in_account_currency) - flt(
|
||||
balances.credit_in_account_currency
|
||||
)
|
||||
balance_in_company_currency = flt(balances.debit) - flt(balances.credit)
|
||||
gl_entry = frappe._dict(
|
||||
{
|
||||
"company": pcv.company,
|
||||
"posting_date": pcv.period_end_date,
|
||||
"account": acc,
|
||||
"account_currency": balances.account_currency,
|
||||
"debit_in_account_currency": abs(balance_in_account_currency)
|
||||
if balance_in_account_currency < 0
|
||||
else 0,
|
||||
"debit": abs(balance_in_company_currency) if balance_in_company_currency < 0 else 0,
|
||||
"credit_in_account_currency": abs(balance_in_account_currency)
|
||||
if balance_in_account_currency > 0
|
||||
else 0,
|
||||
"credit": abs(balance_in_company_currency) if balance_in_company_currency > 0 else 0,
|
||||
"is_period_closing_voucher_entry": 1,
|
||||
"voucher_type": "Period Closing Voucher",
|
||||
"voucher_no": pcv.name,
|
||||
"fiscal_year": pcv.fiscal_year,
|
||||
"remarks": pcv.remarks,
|
||||
"is_opening": "No",
|
||||
}
|
||||
)
|
||||
# update dimensions
|
||||
update_default_dimensions(get_dimensions(), gl_entry, dimensions)
|
||||
return gl_entry
|
||||
|
||||
|
||||
def get_gle_for_closing_account(pcv, dimension_balance, dimensions):
|
||||
balance_in_company_currency = flt(dimension_balance.balance_in_company_currency)
|
||||
debit = balance_in_company_currency if balance_in_company_currency > 0 else 0
|
||||
credit = abs(balance_in_company_currency) if balance_in_company_currency < 0 else 0
|
||||
|
||||
gl_entry = frappe._dict(
|
||||
{
|
||||
"company": pcv.company,
|
||||
"posting_date": pcv.period_end_date,
|
||||
"account": pcv.closing_account_head,
|
||||
"account_currency": frappe.db.get_value("Account", pcv.closing_account_head, "account_currency"),
|
||||
"debit_in_account_currency": debit,
|
||||
"debit": debit,
|
||||
"credit_in_account_currency": credit,
|
||||
"credit": credit,
|
||||
"is_period_closing_voucher_entry": 1,
|
||||
"voucher_type": "Period Closing Voucher",
|
||||
"voucher_no": pcv.name,
|
||||
"fiscal_year": pcv.fiscal_year,
|
||||
"remarks": pcv.remarks,
|
||||
"is_opening": "No",
|
||||
}
|
||||
)
|
||||
# update dimensions
|
||||
update_default_dimensions(get_dimensions(), gl_entry, dimensions)
|
||||
return gl_entry
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def schedule_next_date(docname: str):
|
||||
if to_process := frappe.db.get_all(
|
||||
"Process Period Closing Voucher Detail",
|
||||
filters={"parent": docname, "status": "Queued"},
|
||||
fields=["processing_date", "report_type", "parentfield"],
|
||||
order_by="parentfield, idx, processing_date",
|
||||
limit=1,
|
||||
):
|
||||
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,
|
||||
},
|
||||
"status",
|
||||
"Running",
|
||||
)
|
||||
frappe.enqueue(
|
||||
method="erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.process_individual_date",
|
||||
queue="long",
|
||||
timeout="3600",
|
||||
is_async=True,
|
||||
enqueue_after_commit=True,
|
||||
docname=docname,
|
||||
date=to_process[0].processing_date,
|
||||
report_type=to_process[0].report_type,
|
||||
parentfield=to_process[0].parentfield,
|
||||
)
|
||||
else:
|
||||
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
||||
total_no_of_dates = (
|
||||
qb.from_(ppcvd).select(Count(ppcvd.star)).where(ppcvd.parent.eq(docname)).run()[0][0]
|
||||
)
|
||||
completed = (
|
||||
qb.from_(ppcvd)
|
||||
.select(Count(ppcvd.star))
|
||||
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Completed"))
|
||||
.run()[0][0]
|
||||
)
|
||||
# Ensure both normal and opening balances are processed for all dates
|
||||
if total_no_of_dates == completed:
|
||||
summarize_and_post_ledger_entries(docname)
|
||||
|
||||
|
||||
def make_dict_json_compliant(dimension_wise_balance) -> dict:
|
||||
"""
|
||||
convert tuple -> str
|
||||
JSON doesn't support dictionary with tuple keys
|
||||
"""
|
||||
converted_dict = {}
|
||||
for k, v in dimension_wise_balance.items():
|
||||
str_key = [str(x) for x in k]
|
||||
str_key = ",".join(str_key)
|
||||
converted_dict[str_key] = v
|
||||
|
||||
return converted_dict
|
||||
|
||||
|
||||
def get_consolidated_gles(balances, report_type) -> list:
|
||||
gl_entries = []
|
||||
for x in balances:
|
||||
if x.report_type == report_type:
|
||||
closing_balances = [frappe._dict(gle) for gle in frappe.json.loads(x.closing_balance)]
|
||||
gl_entries.extend(closing_balances)
|
||||
return gl_entries
|
||||
|
||||
|
||||
def get_gl_entries(docname):
|
||||
"""
|
||||
Calculate total closing balance of all P&L accounts across PCV start and end date
|
||||
"""
|
||||
ppcv = frappe.get_doc("Process Period Closing Voucher", docname)
|
||||
|
||||
# calculate balance
|
||||
gl_entries = get_consolidated_gles(ppcv.normal_balances, "Profit and Loss")
|
||||
pl_dimension_wise_acc_balance = build_dimension_wise_balance_dict(gl_entries)
|
||||
|
||||
# save
|
||||
json_dict = make_dict_json_compliant(pl_dimension_wise_acc_balance)
|
||||
frappe.db.set_value(
|
||||
"Process Period Closing Voucher", docname, "p_l_closing_balance", frappe.json.dumps(json_dict)
|
||||
)
|
||||
|
||||
# build gl map
|
||||
pcv = frappe.get_doc("Period Closing Voucher", ppcv.parent_pcv)
|
||||
pl_accounts_reverse_gle = []
|
||||
closing_account_gle = []
|
||||
|
||||
for dimensions, account_balances in pl_dimension_wise_acc_balance.items():
|
||||
for acc, balances in account_balances.items():
|
||||
balance_in_company_currency = flt(balances.debit) - flt(balances.credit)
|
||||
if balance_in_company_currency:
|
||||
pl_accounts_reverse_gle.append(get_gle_for_pl_account(pcv, acc, balances, dimensions))
|
||||
|
||||
closing_account_gle.append(get_gle_for_closing_account(pcv, account_balances["balances"], dimensions))
|
||||
|
||||
return pl_accounts_reverse_gle, closing_account_gle
|
||||
|
||||
|
||||
def calculate_balance_sheet_balance(docname):
|
||||
"""
|
||||
Calculate total closing balance of all P&L accounts across PCV start and end date.
|
||||
If it is first PCV, opening entries are also considered
|
||||
"""
|
||||
ppcv = frappe.get_doc("Process Period Closing Voucher", docname)
|
||||
gl_entries = get_consolidated_gles(ppcv.normal_balances + ppcv.z_opening_balances, "Balance Sheet")
|
||||
|
||||
# build dimension wise dictionary from all GLE's
|
||||
bs_dimension_wise_acc_balance = build_dimension_wise_balance_dict(gl_entries)
|
||||
|
||||
# save
|
||||
json_dict = make_dict_json_compliant(bs_dimension_wise_acc_balance)
|
||||
frappe.db.set_value(
|
||||
"Process Period Closing Voucher", docname, "bs_closing_balance", frappe.json.dumps(json_dict)
|
||||
)
|
||||
return bs_dimension_wise_acc_balance
|
||||
|
||||
|
||||
def get_p_l_closing_entries(pl_gles, pcv):
|
||||
pl_closing_entries = copy.deepcopy(pl_gles)
|
||||
for d in pl_gles:
|
||||
# reverse debit and credit
|
||||
gle_copy = copy.deepcopy(d)
|
||||
gle_copy.debit = d.credit
|
||||
gle_copy.credit = d.debit
|
||||
gle_copy.debit_in_account_currency = d.credit_in_account_currency
|
||||
gle_copy.credit_in_account_currency = d.debit_in_account_currency
|
||||
gle_copy.is_period_closing_voucher_entry = 0
|
||||
gle_copy.period_closing_voucher = pcv.name
|
||||
pl_closing_entries.append(gle_copy)
|
||||
|
||||
return pl_closing_entries
|
||||
|
||||
|
||||
def get_bs_closing_entries(dimension_wise_balance, pcv):
|
||||
closing_entries = []
|
||||
for dimensions, account_balances in dimension_wise_balance.items():
|
||||
for acc, balances in account_balances.items():
|
||||
balance_in_company_currency = flt(balances.debit) - flt(balances.credit)
|
||||
if acc != "balances" and balance_in_company_currency:
|
||||
closing_entries.append(get_closing_entry(pcv, acc, balances, dimensions))
|
||||
|
||||
return closing_entries
|
||||
|
||||
|
||||
def get_closing_account_closing_entry(closing_account_gle, pcv):
|
||||
closing_entries_for_closing_account = copy.deepcopy(closing_account_gle)
|
||||
for d in closing_entries_for_closing_account:
|
||||
d.period_closing_voucher = pcv.name
|
||||
return closing_entries_for_closing_account
|
||||
|
||||
|
||||
def summarize_and_post_ledger_entries(docname):
|
||||
# P&L accounts
|
||||
pl_accounts_reverse_gle, closing_account_gle = get_gl_entries(docname)
|
||||
gl_entries = pl_accounts_reverse_gle + closing_account_gle
|
||||
from erpnext.accounts.general_ledger import make_gl_entries
|
||||
|
||||
if gl_entries:
|
||||
make_gl_entries(gl_entries, merge_entries=False)
|
||||
|
||||
pcv_name = frappe.db.get_value("Process Period Closing Voucher", docname, "parent_pcv")
|
||||
pcv = frappe.get_doc("Period Closing Voucher", pcv_name)
|
||||
|
||||
# Balance sheet accounts
|
||||
bs_dimension_wise_acc_balance = calculate_balance_sheet_balance(docname)
|
||||
|
||||
pl_closing_entries = get_p_l_closing_entries(pl_accounts_reverse_gle, pcv)
|
||||
bs_closing_entries = get_bs_closing_entries(bs_dimension_wise_acc_balance, pcv)
|
||||
closing_entries_for_closing_account = get_closing_account_closing_entry(closing_account_gle, pcv)
|
||||
closing_entries = pl_closing_entries + bs_closing_entries + closing_entries_for_closing_account
|
||||
|
||||
make_closing_entries(closing_entries, pcv.name, pcv.company, pcv.period_end_date)
|
||||
|
||||
frappe.db.set_value("Period Closing Voucher", pcv.name, "gle_processing_status", "Completed")
|
||||
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
|
||||
|
||||
|
||||
def get_closing_entry(pcv, account, balances, dimensions):
|
||||
closing_entry = frappe._dict(
|
||||
{
|
||||
"company": pcv.company,
|
||||
"closing_date": pcv.period_end_date,
|
||||
"period_closing_voucher": pcv.name,
|
||||
"account": account,
|
||||
"account_currency": balances.account_currency,
|
||||
"debit_in_account_currency": flt(balances.debit_in_account_currency),
|
||||
"debit": flt(balances.debit),
|
||||
"credit_in_account_currency": flt(balances.credit_in_account_currency),
|
||||
"credit": flt(balances.credit),
|
||||
"is_period_closing_voucher_entry": 0,
|
||||
}
|
||||
)
|
||||
# update dimensions
|
||||
update_default_dimensions(get_dimensions(), closing_entry, dimensions)
|
||||
return closing_entry
|
||||
|
||||
|
||||
def get_dimensions():
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
)
|
||||
|
||||
default_dimensions = ["cost_center", "finance_book", "project"]
|
||||
dimensions = default_dimensions + get_accounting_dimensions()
|
||||
return dimensions
|
||||
|
||||
|
||||
def get_dimension_key(res):
|
||||
return tuple([res.get(dimension) for dimension in get_dimensions()])
|
||||
|
||||
|
||||
def build_dimension_wise_balance_dict(gl_entries):
|
||||
dimension_balances = frappe._dict()
|
||||
for x in gl_entries:
|
||||
dimension_key = get_dimension_key(x)
|
||||
dimension_balances.setdefault(dimension_key, frappe._dict()).setdefault(
|
||||
x.account,
|
||||
frappe._dict(
|
||||
{
|
||||
"debit_in_account_currency": 0,
|
||||
"credit_in_account_currency": 0,
|
||||
"debit": 0,
|
||||
"credit": 0,
|
||||
"account_currency": x.account_currency,
|
||||
}
|
||||
),
|
||||
)
|
||||
dimension_balances[dimension_key][x.account].debit_in_account_currency += flt(
|
||||
x.debit_in_account_currency
|
||||
)
|
||||
dimension_balances[dimension_key][x.account].credit_in_account_currency += flt(
|
||||
x.credit_in_account_currency
|
||||
)
|
||||
dimension_balances[dimension_key][x.account].debit += flt(x.debit)
|
||||
dimension_balances[dimension_key][x.account].credit += flt(x.credit)
|
||||
|
||||
# dimension-wise total balances
|
||||
dimension_balances[dimension_key].setdefault(
|
||||
"balances",
|
||||
frappe._dict(
|
||||
{
|
||||
"balance_in_account_currency": 0,
|
||||
"balance_in_company_currency": 0,
|
||||
}
|
||||
),
|
||||
)
|
||||
balance_in_account_currency = flt(x.debit_in_account_currency) - flt(x.credit_in_account_currency)
|
||||
balance_in_company_currency = flt(x.debit) - flt(x.credit)
|
||||
dimension_balances[dimension_key][
|
||||
"balances"
|
||||
].balance_in_account_currency += balance_in_account_currency
|
||||
dimension_balances[dimension_key][
|
||||
"balances"
|
||||
].balance_in_company_currency += balance_in_company_currency
|
||||
|
||||
return dimension_balances
|
||||
|
||||
|
||||
def process_individual_date(docname: str, 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},
|
||||
"status",
|
||||
)
|
||||
if current_date_status != "Running":
|
||||
return
|
||||
|
||||
pcv_name = frappe.db.get_value("Process Period Closing Voucher", docname, "parent_pcv")
|
||||
company = frappe.db.get_value("Period Closing Voucher", pcv_name, "company")
|
||||
|
||||
dimensions = get_dimensions()
|
||||
|
||||
accounts = frappe.db.get_all(
|
||||
"Account", filters={"company": company, "report_type": report_type}, pluck="name"
|
||||
)
|
||||
|
||||
# summarize
|
||||
gle = qb.DocType("GL Entry")
|
||||
query = qb.from_(gle).select(gle.account)
|
||||
for dim in dimensions:
|
||||
query = query.select(gle[dim])
|
||||
query = query.select(
|
||||
Sum(gle.debit).as_("debit"),
|
||||
Sum(gle.credit).as_("credit"),
|
||||
Sum(gle.debit_in_account_currency).as_("debit_in_account_currency"),
|
||||
Sum(gle.credit_in_account_currency).as_("credit_in_account_currency"),
|
||||
gle.account_currency,
|
||||
).where(
|
||||
(gle.company.eq(company))
|
||||
& (gle.is_cancelled.eq(0))
|
||||
& (gle.posting_date.eq(date))
|
||||
& (gle.account.isin(accounts))
|
||||
)
|
||||
|
||||
if parentfield == "z_opening_balances":
|
||||
query = query.where(gle.is_opening.eq("Yes"))
|
||||
|
||||
query = query.groupby(gle.account)
|
||||
for dim in dimensions:
|
||||
query = query.groupby(gle[dim])
|
||||
res = query.run(as_dict=True)
|
||||
|
||||
# save results
|
||||
frappe.db.set_value(
|
||||
"Process Period Closing Voucher Detail",
|
||||
{"processing_date": date, "parent": docname, "report_type": report_type, "parentfield": parentfield},
|
||||
"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},
|
||||
"status",
|
||||
"Completed",
|
||||
)
|
||||
|
||||
# chain call
|
||||
schedule_next_date(docname)
|
||||
@@ -0,0 +1,4 @@
|
||||
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"creation": "2025-10-01 15:58:17.544153",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"processing_date",
|
||||
"report_type",
|
||||
"status",
|
||||
"closing_balance"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "processing_date",
|
||||
"fieldtype": "Date",
|
||||
"in_list_view": 1,
|
||||
"label": "Processing Date"
|
||||
},
|
||||
{
|
||||
"default": "Queued",
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Status",
|
||||
"options": "Queued\nRunning\nPaused\nCompleted\nCancelled"
|
||||
},
|
||||
{
|
||||
"fieldname": "closing_balance",
|
||||
"fieldtype": "JSON",
|
||||
"in_list_view": 1,
|
||||
"label": "Closing Balance"
|
||||
},
|
||||
{
|
||||
"default": "Profit and Loss",
|
||||
"fieldname": "report_type",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Report Type",
|
||||
"options": "Profit and Loss\nBalance Sheet"
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-10-20 12:03:59.106931",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Process Period Closing Voucher Detail",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"row_format": "Dynamic",
|
||||
"rows_threshold_for_grid_search": 20,
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class ProcessPeriodClosingVoucherDetail(Document):
|
||||
# begin: auto-generated types
|
||||
# This code is auto-generated. Do not modify anything in this block.
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from frappe.types import DF
|
||||
|
||||
closing_balance: DF.JSON | None
|
||||
parent: DF.Data
|
||||
parentfield: DF.Data
|
||||
parenttype: DF.Data
|
||||
processing_date: DF.Date | None
|
||||
report_type: DF.Literal["Profit and Loss", "Balance Sheet"]
|
||||
status: DF.Literal["Queued", "Running", "Paused", "Completed", "Cancelled"]
|
||||
# end: auto-generated types
|
||||
|
||||
pass
|
||||
@@ -12,6 +12,7 @@ erpnext.buying.setup_buying_controller();
|
||||
|
||||
erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.BuyingController {
|
||||
setup(doc) {
|
||||
this.setup_accounting_dimension_triggers();
|
||||
this.setup_posting_date_time_check();
|
||||
super.setup(doc);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends (
|
||||
erpnext.selling.SellingController
|
||||
) {
|
||||
setup(doc) {
|
||||
this.setup_accounting_dimension_triggers();
|
||||
this.setup_posting_date_time_check();
|
||||
super.setup(doc);
|
||||
this.frm.make_methods = {
|
||||
|
||||
@@ -648,6 +648,7 @@ def make_reverse_gl_entries(
|
||||
adv_adj=False,
|
||||
update_outstanding="Yes",
|
||||
partial_cancel=False,
|
||||
posting_date=None,
|
||||
):
|
||||
"""
|
||||
Get original gl entries of the voucher
|
||||
@@ -745,6 +746,8 @@ def make_reverse_gl_entries(
|
||||
if immutable_ledger_enabled:
|
||||
new_gle["is_cancelled"] = 0
|
||||
new_gle["posting_date"] = frappe.form_dict.get("posting_date") or getdate()
|
||||
elif posting_date:
|
||||
new_gle["posting_date"] = posting_date
|
||||
|
||||
if new_gle["debit"] or new_gle["credit"]:
|
||||
make_entry(new_gle, adv_adj, "Yes")
|
||||
|
||||
@@ -26,16 +26,13 @@ frappe.query_reports["Accounts Payable"] = {
|
||||
{
|
||||
fieldname: "cost_center",
|
||||
label: __("Cost Center"),
|
||||
fieldtype: "Link",
|
||||
options: "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value("company");
|
||||
return {
|
||||
filters: {
|
||||
company: company,
|
||||
},
|
||||
};
|
||||
fieldtype: "MultiSelectList",
|
||||
get_data: function (txt) {
|
||||
return frappe.db.get_link_options("Cost Center", txt, {
|
||||
company: frappe.query_report.get_filter_value("company"),
|
||||
});
|
||||
},
|
||||
options: "Cost Center",
|
||||
},
|
||||
{
|
||||
fieldname: "party_account",
|
||||
|
||||
@@ -45,16 +45,13 @@ frappe.query_reports["Accounts Payable Summary"] = {
|
||||
{
|
||||
fieldname: "cost_center",
|
||||
label: __("Cost Center"),
|
||||
fieldtype: "Link",
|
||||
options: "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value("company");
|
||||
return {
|
||||
filters: {
|
||||
company: company,
|
||||
},
|
||||
};
|
||||
fieldtype: "MultiSelectList",
|
||||
get_data: function (txt) {
|
||||
return frappe.db.get_link_options("Cost Center", txt, {
|
||||
company: frappe.query_report.get_filter_value("company"),
|
||||
});
|
||||
},
|
||||
options: "Cost Center",
|
||||
},
|
||||
{
|
||||
fieldname: "party_type",
|
||||
|
||||
@@ -28,16 +28,13 @@ frappe.query_reports["Accounts Receivable"] = {
|
||||
{
|
||||
fieldname: "cost_center",
|
||||
label: __("Cost Center"),
|
||||
fieldtype: "Link",
|
||||
options: "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value("company");
|
||||
return {
|
||||
filters: {
|
||||
company: company,
|
||||
},
|
||||
};
|
||||
fieldtype: "MultiSelectList",
|
||||
get_data: function (txt) {
|
||||
return frappe.db.get_link_options("Cost Center", txt, {
|
||||
company: frappe.query_report.get_filter_value("company"),
|
||||
});
|
||||
},
|
||||
options: "Cost Center",
|
||||
},
|
||||
{
|
||||
fieldname: "party_type",
|
||||
|
||||
@@ -15,6 +15,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
get_dimension_with_children,
|
||||
)
|
||||
from erpnext.accounts.report.financial_statements import get_cost_centers_with_children
|
||||
from erpnext.accounts.utils import (
|
||||
build_qb_match_conditions,
|
||||
get_advance_payment_doctypes,
|
||||
@@ -664,7 +665,16 @@ class ReceivablePayableReport:
|
||||
invoiced = d.base_payment_amount
|
||||
paid_amount = d.base_paid_amount
|
||||
|
||||
if company_currency == d.party_account_currency or self.filters.get("in_party_currency"):
|
||||
in_party_currency = self.filters.get("in_party_currency")
|
||||
# company, billing, and party account currencies are the same
|
||||
if company_currency == d.currency and company_currency == d.party_account_currency:
|
||||
in_party_currency = False
|
||||
|
||||
# When filtered by party currency and the billing currency not matches the party account currency
|
||||
if in_party_currency and d.currency != d.party_account_currency:
|
||||
in_party_currency = False
|
||||
|
||||
if in_party_currency:
|
||||
invoiced = d.payment_amount
|
||||
paid_amount = d.paid_amount
|
||||
|
||||
@@ -985,11 +995,7 @@ class ReceivablePayableReport:
|
||||
self.add_accounting_dimensions_filters()
|
||||
|
||||
def get_cost_center_conditions(self):
|
||||
lft, rgt = frappe.db.get_value("Cost Center", self.filters.cost_center, ["lft", "rgt"])
|
||||
cost_center_list = [
|
||||
center.name
|
||||
for center in frappe.get_list("Cost Center", filters={"lft": (">=", lft), "rgt": ("<=", rgt)})
|
||||
]
|
||||
cost_center_list = get_cost_centers_with_children(self.filters.cost_center)
|
||||
self.qb_selection_filter.append(self.ple.cost_center.isin(cost_center_list))
|
||||
|
||||
def add_common_filters(self):
|
||||
|
||||
@@ -199,6 +199,81 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
row = report[1]
|
||||
self.assertTrue(len(row) == 0)
|
||||
|
||||
@change_settings(
|
||||
"Accounts Settings",
|
||||
{"allow_multi_currency_invoices_against_single_party_account": 1},
|
||||
)
|
||||
def test_allow_multi_currency_invoices_against_single_party_account(self):
|
||||
filters = {
|
||||
"company": self.company,
|
||||
"based_on_payment_terms": 1,
|
||||
"report_date": today(),
|
||||
"range": "30, 60, 90, 120",
|
||||
"show_remarks": True,
|
||||
"in_party_currency": 1,
|
||||
}
|
||||
|
||||
# CASE 1: Company currency and party account currency are the same
|
||||
si = self.create_sales_invoice(qty=1, no_payment_schedule=True, do_not_submit=True)
|
||||
si.currency = "USD"
|
||||
si.conversion_rate = 80
|
||||
si.save().submit()
|
||||
|
||||
filters.update(
|
||||
{
|
||||
"party_type": "Customer",
|
||||
"party": [self.customer],
|
||||
}
|
||||
)
|
||||
report = execute(filters)
|
||||
row = report[1][0]
|
||||
|
||||
expected_data = [8000, 8000, "No Remarks"] # Data in company currency
|
||||
|
||||
self.assertEqual(expected_data, [row.invoice_grand_total, row.invoiced, row.remarks])
|
||||
|
||||
# CASE 2: Transaction currency and party account currency are the same
|
||||
self.create_customer(
|
||||
"USD Customer", currency="USD", default_account=self.debtors_usd, company=self.company
|
||||
)
|
||||
si = create_sales_invoice(
|
||||
item=self.item,
|
||||
company=self.company,
|
||||
customer=self.customer,
|
||||
debit_to=self.debtors_usd,
|
||||
posting_date=today(),
|
||||
parent_cost_center=self.cost_center,
|
||||
cost_center=self.cost_center,
|
||||
rate=100,
|
||||
currency="USD",
|
||||
conversion_rate=80,
|
||||
price_list_rate=100,
|
||||
do_not_save=1,
|
||||
)
|
||||
si.save().submit()
|
||||
|
||||
filters.update(
|
||||
{
|
||||
"party_type": "Customer",
|
||||
"party": [self.customer],
|
||||
}
|
||||
)
|
||||
report = execute(filters)
|
||||
row = report[1][0]
|
||||
|
||||
expected_data = [100, 100, "No Remarks"] # Data in Part Account Currency
|
||||
|
||||
self.assertEqual(expected_data, [row.invoice_grand_total, row.invoiced, row.remarks])
|
||||
|
||||
# View in Company currency
|
||||
filters.pop("in_party_currency")
|
||||
report = execute(filters)
|
||||
row = report[1][0]
|
||||
|
||||
expected_data = [8000, 8000, "No Remarks"] # Data in Company Currency
|
||||
|
||||
self.assertEqual(expected_data, [row.invoice_grand_total, row.invoiced, row.remarks])
|
||||
|
||||
def test_accounts_receivable_with_partial_payment(self):
|
||||
filters = {
|
||||
"company": self.company,
|
||||
|
||||
@@ -45,16 +45,13 @@ frappe.query_reports["Accounts Receivable Summary"] = {
|
||||
{
|
||||
fieldname: "cost_center",
|
||||
label: __("Cost Center"),
|
||||
fieldtype: "Link",
|
||||
options: "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value("company");
|
||||
return {
|
||||
filters: {
|
||||
company: company,
|
||||
},
|
||||
};
|
||||
fieldtype: "MultiSelectList",
|
||||
get_data: function (txt) {
|
||||
return frappe.db.get_link_options("Cost Center", txt, {
|
||||
company: frappe.query_report.get_filter_value("company"),
|
||||
});
|
||||
},
|
||||
options: "Cost Center",
|
||||
},
|
||||
{
|
||||
fieldname: "party_type",
|
||||
|
||||
@@ -119,6 +119,7 @@ def get_assets_details(assets):
|
||||
|
||||
fields = [
|
||||
"name as asset",
|
||||
"asset_name",
|
||||
"gross_purchase_amount",
|
||||
"opening_accumulated_depreciation",
|
||||
"asset_category",
|
||||
@@ -143,6 +144,12 @@ def get_columns():
|
||||
"options": "Asset",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Asset Name"),
|
||||
"fieldname": "asset_name",
|
||||
"fieldtype": "Data",
|
||||
"width": 140,
|
||||
},
|
||||
{
|
||||
"label": _("Depreciation Date"),
|
||||
"fieldname": "depreciation_date",
|
||||
|
||||
@@ -273,6 +273,7 @@ def get_asset_value_adjustment_map_by_category(filters):
|
||||
AND a.company = %(company)s
|
||||
AND a.purchase_date <= %(to_date)s
|
||||
AND gle.account = aca.fixed_asset_account
|
||||
AND gle.is_opening = 'No'
|
||||
GROUP BY a.asset_category
|
||||
""",
|
||||
{"from_date": filters.from_date, "to_date": filters.to_date, "company": filters.company},
|
||||
@@ -543,6 +544,7 @@ def get_asset_value_adjustment_map(filters):
|
||||
AND a.company = %(company)s
|
||||
AND a.purchase_date <= %(to_date)s
|
||||
AND gle.account = aca.fixed_asset_account
|
||||
AND gle.is_opening = 'No'
|
||||
GROUP BY a.name
|
||||
""",
|
||||
{"from_date": filters.from_date, "to_date": filters.to_date, "company": filters.company},
|
||||
|
||||
@@ -69,12 +69,18 @@ class PartyLedgerSummaryReport:
|
||||
party_type = self.filters.party_type
|
||||
|
||||
doctype = qb.DocType(party_type)
|
||||
|
||||
party_details_fields = [
|
||||
doctype.name.as_("party"),
|
||||
f"{scrub(party_type)}_name",
|
||||
f"{scrub(party_type)}_group",
|
||||
]
|
||||
|
||||
if party_type == "Customer":
|
||||
party_details_fields.append(doctype.territory)
|
||||
|
||||
conditions = self.get_party_conditions(doctype)
|
||||
query = (
|
||||
qb.from_(doctype)
|
||||
.select(doctype.name.as_("party"), f"{scrub(party_type)}_name")
|
||||
.where(Criterion.all(conditions))
|
||||
)
|
||||
query = qb.from_(doctype).select(*party_details_fields).where(Criterion.all(conditions))
|
||||
|
||||
from frappe.desk.reportview import build_match_conditions
|
||||
|
||||
@@ -153,6 +159,31 @@ class PartyLedgerSummaryReport:
|
||||
|
||||
credit_or_debit_note = "Credit Note" if self.filters.party_type == "Customer" else "Debit Note"
|
||||
|
||||
if self.filters.party_type == "Customer":
|
||||
columns += [
|
||||
{
|
||||
"label": _("Customer Group"),
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Customer Group",
|
||||
},
|
||||
{
|
||||
"label": _("Territory"),
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"options": "Territory",
|
||||
},
|
||||
]
|
||||
else:
|
||||
columns += [
|
||||
{
|
||||
"label": _("Supplier Group"),
|
||||
"fieldname": "supplier_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Supplier Group",
|
||||
}
|
||||
]
|
||||
|
||||
columns += [
|
||||
{
|
||||
"label": _("Opening Balance"),
|
||||
@@ -213,35 +244,6 @@ class PartyLedgerSummaryReport:
|
||||
},
|
||||
]
|
||||
|
||||
# Hidden columns for handling 'User Permissions'
|
||||
if self.filters.party_type == "Customer":
|
||||
columns += [
|
||||
{
|
||||
"label": _("Territory"),
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"options": "Territory",
|
||||
"hidden": 1,
|
||||
},
|
||||
{
|
||||
"label": _("Customer Group"),
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Customer Group",
|
||||
"hidden": 1,
|
||||
},
|
||||
]
|
||||
else:
|
||||
columns += [
|
||||
{
|
||||
"label": _("Supplier Group"),
|
||||
"fieldname": "supplier_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Supplier Group",
|
||||
"hidden": 1,
|
||||
}
|
||||
]
|
||||
|
||||
return columns
|
||||
|
||||
def get_data(self):
|
||||
|
||||
@@ -174,7 +174,7 @@ def add_solvency_ratios(
|
||||
return_on_equity_ratio = {"ratio": _("Return on Equity Ratio")}
|
||||
|
||||
for year in years:
|
||||
profit_after_tax = flt(total_income.get(year)) + flt(total_expense.get(year))
|
||||
profit_after_tax = flt(total_income.get(year)) - flt(total_expense.get(year))
|
||||
share_holder_fund = flt(total_asset.get(year)) - flt(total_liability.get(year))
|
||||
|
||||
debt_equity_ratio[year] = calculate_ratio(total_liability.get(year), share_holder_fund, precision)
|
||||
@@ -199,7 +199,7 @@ def add_turnover_ratios(data, years, period_list, filters, total_asset, net_sale
|
||||
|
||||
avg_data = {}
|
||||
for d in ["Receivable", "Payable", "Stock"]:
|
||||
avg_data[frappe.scrub(d)] = avg_ratio_balance("Receivable", period_list, precision, filters)
|
||||
avg_data[frappe.scrub(d)] = avg_ratio_balance(d, period_list, precision, filters)
|
||||
|
||||
avg_debtors, avg_creditors, avg_stock = (
|
||||
avg_data.get("receivable"),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"add_total_row": 1,
|
||||
"add_total_row": 0,
|
||||
"add_translate_data": 0,
|
||||
"columns": [],
|
||||
"creation": "2013-12-06 13:22:23",
|
||||
@@ -10,7 +10,7 @@
|
||||
"idx": 3,
|
||||
"is_standard": "Yes",
|
||||
"letterhead": null,
|
||||
"modified": "2025-08-13 12:47:27.645023",
|
||||
"modified": "2025-11-05 15:47:59.597853",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "General Ledger",
|
||||
|
||||
@@ -566,6 +566,13 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map, tot
|
||||
else:
|
||||
update_value_in_dict(consolidated_gle, key, gle)
|
||||
|
||||
if filters.get("include_dimensions"):
|
||||
dimensions = [*accounting_dimensions, "cost_center", "project"]
|
||||
|
||||
for dimension in dimensions:
|
||||
if val := gle.get(dimension):
|
||||
gle[dimension] = _(val)
|
||||
|
||||
for value in consolidated_gle.values():
|
||||
update_value_in_dict(totals, "total", value)
|
||||
update_value_in_dict(totals, "closing", value)
|
||||
|
||||
@@ -85,6 +85,12 @@ frappe.query_reports["Gross Profit"] = {
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldname: "include_returned_invoices",
|
||||
label: __("Include Returned Invoices (Stand-alone)"),
|
||||
fieldtype: "Check",
|
||||
default: 1,
|
||||
},
|
||||
],
|
||||
tree: true,
|
||||
name_field: "parent",
|
||||
|
||||
@@ -231,6 +231,15 @@ def get_data_when_not_grouped_by_invoice(gross_profit_data, filters, group_wise_
|
||||
|
||||
group_columns = group_wise_columns.get(scrub(filters.group_by))
|
||||
|
||||
# removing customer_name from group columns
|
||||
customer_master_name = frappe.db.get_single_value("Selling Settings", "cust_master_name")
|
||||
supplier_master_name = frappe.db.get_single_value("Buying Settings", "supp_master_name")
|
||||
|
||||
if "customer_name" in group_columns and (
|
||||
supplier_master_name == "Supplier Name" and customer_master_name == "Customer Name"
|
||||
):
|
||||
group_columns = [col for col in group_columns if col != "customer_name"]
|
||||
|
||||
for src in gross_profit_data.grouped_data:
|
||||
total_base_amount += src.base_amount or 0.00
|
||||
total_buying_amount += src.buying_amount or 0.00
|
||||
@@ -850,7 +859,10 @@ class GrossProfitGenerator:
|
||||
if self.filters.to_date:
|
||||
conditions += " and posting_date <= %(to_date)s"
|
||||
|
||||
conditions += " and (is_return = 0 or (is_return=1 and return_against is null))"
|
||||
if self.filters.include_returned_invoices:
|
||||
conditions += " and (is_return = 0 or (is_return=1 and return_against is null))"
|
||||
else:
|
||||
conditions += " and is_return = 0"
|
||||
|
||||
if self.filters.item_group:
|
||||
conditions += f" and {get_item_group_condition(self.filters.item_group)}"
|
||||
|
||||
@@ -442,7 +442,11 @@ class TestGrossProfit(FrappeTestCase):
|
||||
sinv = sinv.save().submit()
|
||||
|
||||
filters = frappe._dict(
|
||||
company=self.company, from_date=nowdate(), to_date=nowdate(), group_by="Invoice"
|
||||
company=self.company,
|
||||
from_date=nowdate(),
|
||||
to_date=nowdate(),
|
||||
group_by="Invoice",
|
||||
include_returned_invoices=1,
|
||||
)
|
||||
|
||||
columns, data = execute(filters=filters)
|
||||
|
||||
@@ -21,6 +21,7 @@ def get_ordered_to_be_billed_data(args, filters=None):
|
||||
|
||||
doctype = frappe.qb.DocType(doctype)
|
||||
child_doctype = frappe.qb.DocType(child_tab)
|
||||
item = frappe.qb.DocType("Item")
|
||||
|
||||
docname = filters.get(args.get("reference_field"), None)
|
||||
project_field = get_project_field(doctype, child_doctype, party)
|
||||
@@ -29,6 +30,8 @@ def get_ordered_to_be_billed_data(args, filters=None):
|
||||
frappe.qb.from_(doctype)
|
||||
.inner_join(child_doctype)
|
||||
.on(doctype.name == child_doctype.parent)
|
||||
.join(item)
|
||||
.on(item.name == child_doctype.item_code)
|
||||
.select(
|
||||
doctype.name,
|
||||
doctype[args.get("date")].as_("date"),
|
||||
@@ -54,6 +57,7 @@ def get_ordered_to_be_billed_data(args, filters=None):
|
||||
& (doctype.company == filters.get("company"))
|
||||
& (doctype.posting_date <= filters.get("posting_date"))
|
||||
& (child_doctype.amount > 0)
|
||||
& (item.is_stock_item == 1)
|
||||
& (
|
||||
child_doctype.base_amount
|
||||
- Round(child_doctype.billed_amt * IfNull(doctype.conversion_rate, 1), precision)
|
||||
|
||||
@@ -1,32 +1,37 @@
|
||||
{
|
||||
"add_total_row": 1,
|
||||
"apply_user_permissions": 1,
|
||||
"creation": "2013-06-13 18:46:55",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"idx": 3,
|
||||
"is_standard": "Yes",
|
||||
"modified": "2018-02-21 01:28:31.261299",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice Trends",
|
||||
"owner": "Administrator",
|
||||
"ref_doctype": "Purchase Invoice",
|
||||
"report_name": "Purchase Invoice Trends",
|
||||
"report_type": "Script Report",
|
||||
"add_total_row": 0,
|
||||
"add_translate_data": 0,
|
||||
"columns": [],
|
||||
"creation": "2013-06-13 18:46:55",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"filters": [],
|
||||
"idx": 3,
|
||||
"is_standard": "Yes",
|
||||
"letterhead": null,
|
||||
"modified": "2025-11-05 11:55:49.950442",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice Trends",
|
||||
"owner": "Administrator",
|
||||
"prepared_report": 0,
|
||||
"ref_doctype": "Purchase Invoice",
|
||||
"report_name": "Purchase Invoice Trends",
|
||||
"report_type": "Script Report",
|
||||
"roles": [
|
||||
{
|
||||
"role": "Accounts User"
|
||||
},
|
||||
},
|
||||
{
|
||||
"role": "Purchase User"
|
||||
},
|
||||
},
|
||||
{
|
||||
"role": "Accounts Manager"
|
||||
},
|
||||
},
|
||||
{
|
||||
"role": "Auditor"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"timeout": 0
|
||||
}
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
{
|
||||
"add_total_row": 1,
|
||||
"apply_user_permissions": 1,
|
||||
"creation": "2013-06-13 18:44:21",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"idx": 3,
|
||||
"is_standard": "Yes",
|
||||
"modified": "2018-02-21 01:28:03.622485",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice Trends",
|
||||
"owner": "Administrator",
|
||||
"ref_doctype": "Sales Invoice",
|
||||
"report_name": "Sales Invoice Trends",
|
||||
"report_type": "Script Report",
|
||||
"add_total_row": 0,
|
||||
"add_translate_data": 0,
|
||||
"columns": [],
|
||||
"creation": "2013-06-13 18:44:21",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"filters": [],
|
||||
"idx": 3,
|
||||
"is_standard": "Yes",
|
||||
"letterhead": null,
|
||||
"modified": "2025-11-05 11:55:50.070651",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice Trends",
|
||||
"owner": "Administrator",
|
||||
"prepared_report": 0,
|
||||
"ref_doctype": "Sales Invoice",
|
||||
"report_name": "Sales Invoice Trends",
|
||||
"report_type": "Script Report",
|
||||
"roles": [
|
||||
{
|
||||
"role": "Accounts Manager"
|
||||
},
|
||||
},
|
||||
{
|
||||
"role": "Accounts User"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"timeout": 0
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import getdate
|
||||
from frappe.utils import flt, getdate
|
||||
|
||||
from erpnext.accounts.utils import get_currency_precision
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@@ -43,6 +45,7 @@ def get_result(filters, tds_docs, tds_accounts, tax_category_map, journal_entry_
|
||||
party_map = get_party_pan_map(filters.get("party_type"))
|
||||
tax_rate_map = get_tax_rate_map(filters)
|
||||
gle_map = get_gle_map(tds_docs)
|
||||
precision = get_currency_precision()
|
||||
|
||||
out = []
|
||||
entries = {}
|
||||
@@ -72,17 +75,28 @@ def get_result(filters, tds_docs, tds_accounts, tax_category_map, journal_entry_
|
||||
tax_withholding_category = party_map.get(party, {}).get("tax_withholding_category")
|
||||
|
||||
rate = get_tax_withholding_rates(tax_rate_map.get(tax_withholding_category, []), posting_date)
|
||||
if net_total_map.get((voucher_type, name)):
|
||||
|
||||
values = net_total_map.get((voucher_type, name))
|
||||
|
||||
if values:
|
||||
if voucher_type == "Journal Entry" and tax_amount and rate:
|
||||
# back calcalute total amount from rate and tax_amount
|
||||
base_total = min(tax_amount / (rate / 100), net_total_map.get((voucher_type, name))[0])
|
||||
# back calculate total amount from rate and tax_amount
|
||||
base_total = min(flt(tax_amount / (rate / 100), precision=precision), values[0])
|
||||
total_amount = grand_total = base_total
|
||||
elif voucher_type == "Purchase Invoice":
|
||||
total_amount, grand_total, base_total, bill_no, bill_date = net_total_map.get(
|
||||
(voucher_type, name)
|
||||
)
|
||||
|
||||
else:
|
||||
total_amount, grand_total, base_total = net_total_map.get((voucher_type, name))
|
||||
if tax_amount and rate:
|
||||
# back calculate total amount from rate and tax_amount
|
||||
total_amount = flt((tax_amount * 100) / rate, precision=precision)
|
||||
else:
|
||||
total_amount = values[0]
|
||||
|
||||
grand_total = values[1]
|
||||
base_total = values[2]
|
||||
|
||||
if voucher_type == "Purchase Invoice":
|
||||
bill_no = values[3]
|
||||
bill_date = values[4]
|
||||
else:
|
||||
total_amount += entry.credit
|
||||
|
||||
|
||||
@@ -47,22 +47,23 @@ frappe.query_reports["Trial Balance"] = {
|
||||
{
|
||||
fieldname: "cost_center",
|
||||
label: __("Cost Center"),
|
||||
fieldtype: "Link",
|
||||
options: "Cost Center",
|
||||
get_query: function () {
|
||||
var company = frappe.query_report.get_filter_value("company");
|
||||
return {
|
||||
doctype: "Cost Center",
|
||||
filters: {
|
||||
company: company,
|
||||
},
|
||||
};
|
||||
fieldtype: "MultiSelectList",
|
||||
get_data: function (txt) {
|
||||
return frappe.db.get_link_options("Cost Center", txt, {
|
||||
company: frappe.query_report.get_filter_value("company"),
|
||||
});
|
||||
},
|
||||
options: "Cost Center",
|
||||
},
|
||||
{
|
||||
fieldname: "project",
|
||||
label: __("Project"),
|
||||
fieldtype: "Link",
|
||||
fieldtype: "MultiSelectList",
|
||||
get_data: function (txt) {
|
||||
return frappe.db.get_link_options("Project", txt, {
|
||||
company: frappe.query_report.get_filter_value("company"),
|
||||
});
|
||||
},
|
||||
options: "Project",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
from erpnext.accounts.report.financial_statements import (
|
||||
filter_accounts,
|
||||
filter_out_zero_value_rows,
|
||||
get_cost_centers_with_children,
|
||||
set_gl_entries_by_account,
|
||||
)
|
||||
from erpnext.accounts.report.utils import convert_to_presentation_currency, get_currency
|
||||
@@ -103,10 +104,6 @@ def get_data(filters):
|
||||
|
||||
opening_balances = get_opening_balances(filters, ignore_is_opening)
|
||||
|
||||
# add filter inside list so that the query in financial_statements.py doesn't break
|
||||
if filters.project:
|
||||
filters.project = [filters.project]
|
||||
|
||||
set_gl_entries_by_account(
|
||||
filters.company,
|
||||
filters.from_date,
|
||||
@@ -270,18 +267,12 @@ def get_opening_balance(
|
||||
opening_balance = opening_balance.where(closing_balance.voucher_type != "Period Closing Voucher")
|
||||
|
||||
if filters.cost_center:
|
||||
lft, rgt = frappe.db.get_value("Cost Center", filters.cost_center, ["lft", "rgt"])
|
||||
cost_center = frappe.qb.DocType("Cost Center")
|
||||
opening_balance = opening_balance.where(
|
||||
closing_balance.cost_center.isin(
|
||||
frappe.qb.from_(cost_center)
|
||||
.select("name")
|
||||
.where((cost_center.lft >= lft) & (cost_center.rgt <= rgt))
|
||||
)
|
||||
closing_balance.cost_center.isin(get_cost_centers_with_children(filters.get("cost_center")))
|
||||
)
|
||||
|
||||
if filters.project:
|
||||
opening_balance = opening_balance.where(closing_balance.project == filters.project)
|
||||
opening_balance = opening_balance.where(closing_balance.project.isin(filters.project))
|
||||
|
||||
if frappe.db.count("Finance Book"):
|
||||
if filters.get("include_default_book_entries"):
|
||||
|
||||
@@ -5,7 +5,9 @@ from erpnext.stock.doctype.item.test_item import create_item
|
||||
|
||||
|
||||
class AccountsTestMixin:
|
||||
def create_customer(self, customer_name="_Test Customer", currency=None):
|
||||
def create_customer(
|
||||
self, customer_name="_Test Customer", currency=None, default_account=None, company=None
|
||||
):
|
||||
if not frappe.db.exists("Customer", customer_name):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = customer_name
|
||||
@@ -13,9 +15,28 @@ class AccountsTestMixin:
|
||||
|
||||
if currency:
|
||||
customer.default_currency = currency
|
||||
if company and default_account:
|
||||
customer.append(
|
||||
"accounts",
|
||||
{
|
||||
"company": company,
|
||||
"account": default_account,
|
||||
},
|
||||
)
|
||||
customer.save()
|
||||
self.customer = customer.name
|
||||
else:
|
||||
if company and default_account:
|
||||
customer = frappe.get_doc("Customer", customer_name)
|
||||
customer.accounts = []
|
||||
customer.append(
|
||||
"accounts",
|
||||
{
|
||||
"company": company,
|
||||
"account": default_account,
|
||||
},
|
||||
)
|
||||
customer.save()
|
||||
self.customer = customer_name
|
||||
|
||||
def create_supplier(self, supplier_name="_Test Supplier", currency=None):
|
||||
|
||||
@@ -1755,24 +1755,22 @@ def check_and_delete_linked_reports(report):
|
||||
frappe.delete_doc("Desktop Icon", icon)
|
||||
|
||||
|
||||
def create_err_and_its_journals(companies: list | None = None) -> None:
|
||||
if companies:
|
||||
for company in companies:
|
||||
err = frappe.new_doc("Exchange Rate Revaluation")
|
||||
err.company = company.name
|
||||
err.posting_date = nowdate()
|
||||
err.rounding_loss_allowance = 0.0
|
||||
def create_err_and_its_journals(company: dict) -> None:
|
||||
err = frappe.new_doc("Exchange Rate Revaluation")
|
||||
err.company = company.name
|
||||
err.posting_date = nowdate()
|
||||
err.rounding_loss_allowance = 0.0
|
||||
|
||||
err.fetch_and_calculate_accounts_data()
|
||||
if err.accounts:
|
||||
err.save().submit()
|
||||
response = err.make_jv_entries()
|
||||
err.fetch_and_calculate_accounts_data()
|
||||
if err.accounts:
|
||||
err.save().submit()
|
||||
response = err.make_jv_entries()
|
||||
|
||||
if company.submit_err_jv:
|
||||
jv = response.get("revaluation_jv", None)
|
||||
jv and frappe.get_doc("Journal Entry", jv).submit()
|
||||
jv = response.get("zero_balance_jv", None)
|
||||
jv and frappe.get_doc("Journal Entry", jv).submit()
|
||||
if company.submit_err_jv:
|
||||
jv = response.get("revaluation_jv", None)
|
||||
jv and frappe.get_doc("Journal Entry", jv).submit()
|
||||
jv = response.get("zero_balance_jv", None)
|
||||
jv and frappe.get_doc("Journal Entry", jv).submit()
|
||||
|
||||
|
||||
def _auto_create_exchange_rate_revaluation_for(frequency: str) -> None:
|
||||
@@ -1785,7 +1783,14 @@ def _auto_create_exchange_rate_revaluation_for(frequency: str) -> None:
|
||||
filters={"auto_exchange_rate_revaluation": 1, "auto_err_frequency": frequency},
|
||||
fields=["name", "submit_err_jv"],
|
||||
)
|
||||
create_err_and_its_journals(companies)
|
||||
|
||||
if companies:
|
||||
for company in companies:
|
||||
frappe.enqueue(
|
||||
"erpnext.accounts.utils.create_err_and_its_journals",
|
||||
company=company,
|
||||
queue="long",
|
||||
)
|
||||
|
||||
|
||||
def auto_create_exchange_rate_revaluation_daily() -> None:
|
||||
|
||||
@@ -202,7 +202,7 @@ frappe.ui.form.on("Asset", {
|
||||
callback: function (r) {
|
||||
if (!r.message) {
|
||||
$(".primary-action").prop("hidden", true);
|
||||
$(".form-message").text("Capitalize this asset to confirm");
|
||||
$(".form-message").text(__("Capitalize this asset to confirm"));
|
||||
|
||||
frm.add_custom_button(__("Capitalize Asset"), function () {
|
||||
frm.trigger("create_asset_capitalization");
|
||||
|
||||
@@ -371,7 +371,6 @@
|
||||
"label": "Other Details"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"default": "Draft",
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
@@ -379,7 +378,7 @@
|
||||
"in_standard_filter": 1,
|
||||
"label": "Status",
|
||||
"no_copy": 1,
|
||||
"options": "Draft\nSubmitted\nPartially Depreciated\nFully Depreciated\nSold\nScrapped\nIn Maintenance\nOut of Order\nIssue\nReceipt\nCapitalized\nWork In Progress",
|
||||
"options": "Draft\nSubmitted\nCancelled\nPartially Depreciated\nFully Depreciated\nSold\nScrapped\nIn Maintenance\nOut of Order\nIssue\nReceipt\nCapitalized\nWork In Progress",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
@@ -518,6 +517,7 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.docstatus > 0",
|
||||
"fieldname": "additional_asset_cost",
|
||||
"fieldtype": "Currency",
|
||||
@@ -596,7 +596,7 @@
|
||||
"link_fieldname": "target_asset"
|
||||
}
|
||||
],
|
||||
"modified": "2025-05-20 00:44:06.229177",
|
||||
"modified": "2025-11-17 18:01:51.417942",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset",
|
||||
@@ -641,4 +641,4 @@
|
||||
"states": [],
|
||||
"title_field": "asset_name",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ class Asset(AccountsController):
|
||||
default_finance_book: DF.Link | None
|
||||
department: DF.Link | None
|
||||
depr_entry_posting_status: DF.Literal["", "Successful", "Failed"]
|
||||
depreciation_completed: DF.Check
|
||||
depreciation_method: DF.Literal["", "Straight Line", "Double Declining Balance", "Manual"]
|
||||
disposal_date: DF.Date | None
|
||||
finance_books: DF.Table[AssetFinanceBook]
|
||||
@@ -102,6 +103,7 @@ class Asset(AccountsController):
|
||||
status: DF.Literal[
|
||||
"Draft",
|
||||
"Submitted",
|
||||
"Cancelled",
|
||||
"Partially Depreciated",
|
||||
"Fully Depreciated",
|
||||
"Sold",
|
||||
@@ -152,7 +154,9 @@ class Asset(AccountsController):
|
||||
)
|
||||
self.validate_expected_value_after_useful_life()
|
||||
self.set_total_booked_depreciations()
|
||||
self.total_asset_cost = self.gross_purchase_amount
|
||||
|
||||
def before_save(self):
|
||||
self.total_asset_cost = self.gross_purchase_amount + self.additional_asset_cost
|
||||
self.status = self.get_status()
|
||||
|
||||
def on_submit(self):
|
||||
@@ -455,6 +459,7 @@ class Asset(AccountsController):
|
||||
"asset_name": self.asset_name,
|
||||
"target_location": self.location,
|
||||
"to_employee": self.custodian,
|
||||
"company": self.company,
|
||||
}
|
||||
]
|
||||
asset_movement = frappe.get_doc(
|
||||
@@ -936,7 +941,7 @@ def make_post_gl_entry():
|
||||
assets = frappe.db.sql_list(
|
||||
""" select name from `tabAsset`
|
||||
where asset_category = %s and ifnull(booked_fixed_asset, 0) = 0
|
||||
and available_for_use_date = %s""",
|
||||
and available_for_use_date = %s and docstatus = 1""",
|
||||
(asset_category.name, nowdate()),
|
||||
)
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Asset",
|
||||
"link_filters": "[[\"Asset\",\"status\",\"not in\",[\"Work In Progress\",\"Capitalized\",\"Fully Depreciated\",\"Sold\",\"Scrapped\",null]]]",
|
||||
"link_filters": "[[\"Asset\",\"status\",\"not in\",[\"Work In Progress\",\"Capitalized\",\"Fully Depreciated\",\"Sold\",\"Scrapped\",\"Cancelled\",null]]]",
|
||||
"options": "Asset",
|
||||
"reqd": 1
|
||||
},
|
||||
@@ -250,7 +250,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-07-29 15:14:34.044564",
|
||||
"modified": "2025-11-17 18:35:54.575265",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Repair",
|
||||
|
||||
@@ -60,6 +60,17 @@ class AssetRepair(AccountsController):
|
||||
if self.get("stock_items"):
|
||||
self.set_stock_items_cost()
|
||||
self.calculate_total_repair_cost()
|
||||
self.validate_purchase_invoice_status()
|
||||
|
||||
def validate_purchase_invoice_status(self):
|
||||
if self.purchase_invoice:
|
||||
docstatus = frappe.db.get_value("Purchase Invoice", self.purchase_invoice, "docstatus")
|
||||
if docstatus == 0:
|
||||
frappe.throw(
|
||||
_("{0} is still in Draft. Please submit it before saving the Asset Repair.").format(
|
||||
get_link_to_form("Purchase Invoice", self.purchase_invoice)
|
||||
)
|
||||
)
|
||||
|
||||
def validate_asset(self):
|
||||
if self.asset_doc.status in ("Sold", "Fully Depreciated", "Scrapped"):
|
||||
@@ -305,7 +316,6 @@ class AssetRepair(AccountsController):
|
||||
"cost_center": self.cost_center,
|
||||
"posting_date": self.completion_date,
|
||||
"against_voucher_type": "Purchase Invoice",
|
||||
"against_voucher": self.purchase_invoice,
|
||||
"company": self.company,
|
||||
},
|
||||
item=self,
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"backflush_raw_materials_of_subcontract_based_on",
|
||||
"column_break_11",
|
||||
"over_transfer_allowance",
|
||||
"validate_consumed_qty",
|
||||
"section_break_xcug",
|
||||
"auto_create_subcontracting_order",
|
||||
"column_break_izrr",
|
||||
@@ -270,6 +271,14 @@
|
||||
"label": "Fixed Outgoing Email Account",
|
||||
"link_filters": "[[\"Email Account\",\"enable_outgoing\",\"=\",1]]",
|
||||
"options": "Email Account"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.backflush_raw_materials_of_subcontract_based_on == \"Material Transferred for Subcontract\"",
|
||||
"description": "Raw materials consumed qty will be validated based on FG BOM required qty",
|
||||
"fieldname": "validate_consumed_qty",
|
||||
"fieldtype": "Check",
|
||||
"label": "Validate Consumed Qty (as per BOM)"
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
@@ -278,7 +287,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2025-08-20 22:13:38.506889",
|
||||
"modified": "2025-11-20 12:59:09.925862",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Buying Settings",
|
||||
|
||||
@@ -44,6 +44,7 @@ class BuyingSettings(Document):
|
||||
supp_master_name: DF.Literal["Supplier Name", "Naming Series", "Auto Name"]
|
||||
supplier_group: DF.Link | None
|
||||
use_transaction_date_exchange_rate: DF.Check
|
||||
validate_consumed_qty: DF.Check
|
||||
# end: auto-generated types
|
||||
|
||||
def validate(self):
|
||||
|
||||
@@ -303,6 +303,7 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends (
|
||||
erpnext.buying.BuyingController
|
||||
) {
|
||||
setup() {
|
||||
this.setup_accounting_dimension_triggers();
|
||||
this.frm.custom_make_buttons = {
|
||||
"Purchase Receipt": "Purchase Receipt",
|
||||
"Purchase Invoice": "Purchase Invoice",
|
||||
|
||||
@@ -76,6 +76,46 @@ class TestRequestforQuotation(FrappeTestCase):
|
||||
self.assertEqual(sq1.get("items")[0].item_code, "_Test Item")
|
||||
self.assertEqual(sq1.get("items")[0].qty, 5)
|
||||
|
||||
def test_make_supplier_quotation_with_taxes(self):
|
||||
"""Test automatic tax addition when supplier quotation is created from RFQ taxes_and_charges are set"""
|
||||
|
||||
# Create a Purchase Taxes and Charges Template for testing
|
||||
tax_template = frappe.new_doc("Purchase Taxes and Charges Template")
|
||||
tax_template.doctype = "Purchase Taxes and Charges Template"
|
||||
tax_template.title = "_Test Purchase Taxes Template for RFQ"
|
||||
tax_template.company = "_Test Company"
|
||||
tax_template.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": "_Test Account Service Tax - _TC",
|
||||
"description": "VAT",
|
||||
"rate": 10,
|
||||
},
|
||||
)
|
||||
tax_template.save()
|
||||
|
||||
rfq = make_request_for_quotation()
|
||||
supplier = rfq.get("suppliers")[0].supplier
|
||||
|
||||
tax_rule = frappe.new_doc("Tax Rule")
|
||||
tax_rule.company = "_Test Company"
|
||||
tax_rule.tax_type = "Purchase"
|
||||
tax_rule.supplier = supplier
|
||||
tax_rule.purchase_tax_template = tax_template.name
|
||||
tax_rule.save()
|
||||
|
||||
sq = make_supplier_quotation_from_rfq(rfq.name, for_supplier=supplier)
|
||||
|
||||
# Verify that taxes_and_charges is set from get_party_details
|
||||
self.assertEqual(sq.taxes_and_charges, tax_template.name)
|
||||
|
||||
# Verify that taxes are automatically added
|
||||
self.assertGreaterEqual(len(sq.get("taxes")), 1)
|
||||
|
||||
tax_rule.delete()
|
||||
tax_template.delete()
|
||||
|
||||
def test_make_supplier_quotation_with_special_characters(self):
|
||||
frappe.delete_doc_if_exists("Supplier", "_Test Supplier '1", force=1)
|
||||
supplier = frappe.new_doc("Supplier")
|
||||
|
||||
@@ -41,18 +41,20 @@ frappe.ui.form.on("Supplier", {
|
||||
|
||||
frm.set_query("supplier_primary_contact", function (doc) {
|
||||
return {
|
||||
query: "erpnext.buying.doctype.supplier.supplier.get_supplier_primary_contact",
|
||||
query: "erpnext.buying.doctype.supplier.supplier.get_supplier_primary",
|
||||
filters: {
|
||||
supplier: doc.name,
|
||||
type: "Contact",
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("supplier_primary_address", function (doc) {
|
||||
return {
|
||||
query: "erpnext.buying.doctype.supplier.supplier.get_supplier_primary",
|
||||
filters: {
|
||||
link_doctype: "Supplier",
|
||||
link_name: doc.name,
|
||||
supplier: doc.name,
|
||||
type: "Address",
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -215,19 +215,25 @@ class Supplier(TransactionBase):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_supplier_primary_contact(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_supplier_primary(doctype, txt, searchfield, start, page_len, filters):
|
||||
supplier = filters.get("supplier")
|
||||
contact = frappe.qb.DocType("Contact")
|
||||
type = filters.get("type")
|
||||
type_doctype = frappe.qb.DocType(type)
|
||||
dynamic_link = frappe.qb.DocType("Dynamic Link")
|
||||
|
||||
return (
|
||||
frappe.qb.from_(contact)
|
||||
query = (
|
||||
frappe.qb.from_(type_doctype)
|
||||
.join(dynamic_link)
|
||||
.on(contact.name == dynamic_link.parent)
|
||||
.select(contact.name, contact.email_id)
|
||||
.on(type_doctype.name == dynamic_link.parent)
|
||||
.select(type_doctype.name)
|
||||
.where(
|
||||
(dynamic_link.link_name == supplier)
|
||||
& (dynamic_link.link_doctype == "Supplier")
|
||||
& (contact.name.like(f"%{txt}%"))
|
||||
& (type_doctype.name.like(f"%{txt}%"))
|
||||
)
|
||||
).run(as_dict=False)
|
||||
)
|
||||
|
||||
if type == "Contact":
|
||||
query = query.select(type_doctype.email_id)
|
||||
|
||||
return query.run()
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
{
|
||||
"add_total_row": 1,
|
||||
"apply_user_permissions": 1,
|
||||
"creation": "2013-06-13 18:45:01",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"idx": 3,
|
||||
"is_standard": "Yes",
|
||||
"modified": "2018-02-21 01:28:37.416562",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Purchase Order Trends",
|
||||
"owner": "Administrator",
|
||||
"ref_doctype": "Purchase Order",
|
||||
"report_name": "Purchase Order Trends",
|
||||
"report_type": "Script Report",
|
||||
"add_total_row": 0,
|
||||
"add_translate_data": 0,
|
||||
"columns": [],
|
||||
"creation": "2013-06-13 18:45:01",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"filters": [],
|
||||
"idx": 3,
|
||||
"is_standard": "Yes",
|
||||
"letterhead": null,
|
||||
"modified": "2025-11-05 11:55:50.058154",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Purchase Order Trends",
|
||||
"owner": "Administrator",
|
||||
"prepared_report": 0,
|
||||
"ref_doctype": "Purchase Order",
|
||||
"report_name": "Purchase Order Trends",
|
||||
"report_type": "Script Report",
|
||||
"roles": [
|
||||
{
|
||||
"role": "Stock User"
|
||||
},
|
||||
},
|
||||
{
|
||||
"role": "Purchase Manager"
|
||||
},
|
||||
},
|
||||
{
|
||||
"role": "Purchase User"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"timeout": 0
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ from erpnext.accounts.doctype.pricing_rule.utils import (
|
||||
)
|
||||
from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center
|
||||
from erpnext.accounts.party import (
|
||||
PURCHASE_TRANSACTION_TYPES,
|
||||
SALES_TRANSACTION_TYPES,
|
||||
get_party_account,
|
||||
get_party_account_currency,
|
||||
get_party_gle_currency,
|
||||
@@ -2026,7 +2028,7 @@ class AccountsController(TransactionBase):
|
||||
discount_amount * self.get("conversion_rate"),
|
||||
item.precision("discount_amount"),
|
||||
),
|
||||
dr_or_cr + "_in_account_currency": flt(
|
||||
dr_or_cr + "_in_transaction_currency": flt(
|
||||
discount_amount, item.precision("discount_amount")
|
||||
),
|
||||
"cost_center": item.cost_center,
|
||||
@@ -2047,7 +2049,7 @@ class AccountsController(TransactionBase):
|
||||
discount_amount * self.get("conversion_rate"),
|
||||
item.precision("discount_amount"),
|
||||
),
|
||||
rev_dr_cr + "_in_account_currency": flt(
|
||||
rev_dr_cr + "_in_transaction_currency": flt(
|
||||
discount_amount, item.precision("discount_amount")
|
||||
),
|
||||
"cost_center": item.cost_center,
|
||||
@@ -2918,6 +2920,104 @@ class AccountsController(TransactionBase):
|
||||
x["transaction_currency"] = self.currency
|
||||
x["transaction_exchange_rate"] = self.get("conversion_rate") or 1
|
||||
|
||||
def after_mapping(self, source_doc):
|
||||
self.set_discount_amount_after_mapping(source_doc)
|
||||
|
||||
def set_discount_amount_after_mapping(self, source_doc):
|
||||
"""
|
||||
Ensures that Additional Discount Amount is not copied repeatedly
|
||||
for multiple mappings of a single source transaction.
|
||||
"""
|
||||
|
||||
# source and target doctypes should both be buying / selling
|
||||
for transaction_types in (PURCHASE_TRANSACTION_TYPES, SALES_TRANSACTION_TYPES):
|
||||
if self.doctype in transaction_types and source_doc.doctype in transaction_types:
|
||||
break
|
||||
|
||||
else:
|
||||
return
|
||||
|
||||
# ensure both doctypes have discount_amount field
|
||||
if not self.meta.get_field("discount_amount") or not source_doc.meta.get_field("discount_amount"):
|
||||
return
|
||||
|
||||
# ensure discount_amount is set in source doc
|
||||
if not source_doc.discount_amount:
|
||||
return
|
||||
|
||||
# ensure additional_discount_percentage is not set in the source doc
|
||||
if source_doc.get("additional_discount_percentage"):
|
||||
return
|
||||
|
||||
item_doctype = self.meta.get_field("items").options
|
||||
doctype_table = frappe.qb.DocType(self.doctype)
|
||||
item_table = frappe.qb.DocType(item_doctype)
|
||||
|
||||
is_same_doctype = self.doctype == source_doc.doctype
|
||||
is_return = self.get("is_return") and is_same_doctype
|
||||
|
||||
if is_same_doctype and not is_return:
|
||||
# should never happen
|
||||
# you don't map to the same doctype without it being a return
|
||||
return
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(doctype_table)
|
||||
.where(doctype_table.docstatus == 1)
|
||||
.where(doctype_table.discount_amount != 0)
|
||||
.select(Sum(doctype_table.discount_amount))
|
||||
)
|
||||
|
||||
if is_return:
|
||||
query = query.where(doctype_table.is_return == 1).where(
|
||||
doctype_table.return_against == source_doc.name
|
||||
)
|
||||
|
||||
else:
|
||||
item_meta = frappe.get_meta(item_doctype)
|
||||
reference_fieldname = next(
|
||||
(
|
||||
row.fieldname
|
||||
for row in item_meta.fields
|
||||
if row.fieldtype == "Link"
|
||||
and row.options == source_doc.doctype
|
||||
and not row.get("is_custom_field")
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
if not reference_fieldname:
|
||||
return
|
||||
|
||||
query = query.where(
|
||||
doctype_table.name.isin(
|
||||
frappe.qb.from_(item_table)
|
||||
.select(item_table.parent)
|
||||
.where(item_table[reference_fieldname] == source_doc.name)
|
||||
.distinct()
|
||||
)
|
||||
)
|
||||
|
||||
result = query.run()
|
||||
if not result:
|
||||
return
|
||||
|
||||
discount_already_applied = result[0][0]
|
||||
if not discount_already_applied:
|
||||
return
|
||||
|
||||
if is_return:
|
||||
# returns have negative discount
|
||||
discount_already_applied *= -1
|
||||
|
||||
discount_amount = max(source_doc.discount_amount - discount_already_applied, 0)
|
||||
if discount_amount and is_return:
|
||||
discount_amount *= -1
|
||||
|
||||
self.discount_amount = flt(discount_amount, self.precision("discount_amount"))
|
||||
|
||||
self.calculate_taxes_and_totals()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_tax_rate(account_head):
|
||||
@@ -3661,8 +3761,15 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil
|
||||
child_doctype = "Sales Order Item" if parent_doctype == "Sales Order" else "Purchase Order Item"
|
||||
return set_order_defaults(parent_doctype, parent_doctype_name, child_doctype, child_docname, item_row)
|
||||
|
||||
def is_allowed_zero_qty():
|
||||
if parent_doctype == "Sales Order":
|
||||
return frappe.db.get_single_value("Selling Settings", "allow_zero_qty_in_sales_order") or False
|
||||
elif parent_doctype == "Purchase Order":
|
||||
return frappe.db.get_single_value("Buying Settings", "allow_zero_qty_in_purchase_order") or False
|
||||
return False
|
||||
|
||||
def validate_quantity(child_item, new_data):
|
||||
if not flt(new_data.get("qty")):
|
||||
if not flt(new_data.get("qty")) and not is_allowed_zero_qty():
|
||||
frappe.throw(
|
||||
_("Row #{0}: Quantity for Item {1} cannot be zero.").format(
|
||||
new_data.get("idx"), frappe.bold(new_data.get("item_code"))
|
||||
@@ -3798,6 +3905,11 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil
|
||||
conv_fac_precision = child_item.precision("conversion_factor") or 2
|
||||
qty_precision = child_item.precision("qty") or 2
|
||||
|
||||
prev_rate, new_rate = flt(child_item.get("rate")), flt(d.get("rate"))
|
||||
rate_unchanged = prev_rate == new_rate
|
||||
if not rate_unchanged and not child_item.get("qty") and is_allowed_zero_qty():
|
||||
frappe.throw(_("Rate of '{}' items cannot be changed").format(frappe.bold(_("Unit Price"))))
|
||||
|
||||
# Amount cannot be lesser than billed amount, except for negative amounts
|
||||
row_rate = flt(d.get("rate"), rate_precision)
|
||||
amount_below_billed_amt = flt(child_item.billed_amt, rate_precision) > flt(
|
||||
|
||||
@@ -13,6 +13,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import g
|
||||
from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget
|
||||
from erpnext.accounts.party import get_party_details
|
||||
from erpnext.buying.utils import update_last_purchase_rate, validate_for_items
|
||||
from erpnext.controllers.accounts_controller import get_taxes_and_charges
|
||||
from erpnext.controllers.sales_and_purchase_return import get_rate_for_return
|
||||
from erpnext.controllers.subcontracting_controller import SubcontractingController
|
||||
from erpnext.stock.get_item_details import get_conversion_factor
|
||||
@@ -180,6 +181,12 @@ class BuyingController(SubcontractingController):
|
||||
|
||||
self.set_missing_item_details(for_validate)
|
||||
|
||||
if self.meta.get_field("taxes"):
|
||||
if self.get("taxes_and_charges") and not self.get("taxes") and not for_validate:
|
||||
taxes = get_taxes_and_charges("Purchase Taxes and Charges Template", self.taxes_and_charges)
|
||||
for tax in taxes:
|
||||
self.append("taxes", tax)
|
||||
|
||||
def set_supplier_from_item_default(self):
|
||||
if self.meta.get_field("supplier") and not self.supplier:
|
||||
for d in self.get("items"):
|
||||
@@ -878,6 +885,7 @@ class BuyingController(SubcontractingController):
|
||||
"asset_category": item_data.get("asset_category"),
|
||||
"location": row.asset_location,
|
||||
"company": self.company,
|
||||
"status": "Draft",
|
||||
"supplier": self.supplier,
|
||||
"purchase_date": self.posting_date,
|
||||
"calculate_depreciation": 0,
|
||||
|
||||
@@ -480,6 +480,13 @@ def make_return_doc(doctype: str, source_name: str, target_doc=None, return_agai
|
||||
target_doc.subcontracting_order_item = source_doc.subcontracting_order_item
|
||||
target_doc.rejected_warehouse = source_doc.rejected_warehouse
|
||||
target_doc.subcontracting_receipt_item = source_doc.name
|
||||
if return_against_rejected_qty:
|
||||
target_doc.qty = -1 * flt(source_doc.rejected_qty - (returned_qty_map.get("qty") or 0))
|
||||
target_doc.rejected_qty = 0.0
|
||||
target_doc.rejected_warehouse = ""
|
||||
target_doc.warehouse = source_doc.rejected_warehouse
|
||||
target_doc.received_qty = target_doc.qty
|
||||
target_doc.return_qty_from_rejected_warehouse = 1
|
||||
else:
|
||||
target_doc.purchase_order = source_doc.purchase_order
|
||||
target_doc.purchase_order_item = source_doc.purchase_order_item
|
||||
|
||||
@@ -95,6 +95,7 @@ class SellingController(StockController):
|
||||
# set contact and address details for customer, if they are not mentioned
|
||||
self.set_missing_lead_customer_details(for_validate=for_validate)
|
||||
self.set_price_list_and_item_details(for_validate=for_validate)
|
||||
self.set_company_contact_person()
|
||||
|
||||
def set_missing_lead_customer_details(self, for_validate=False):
|
||||
customer, lead = None, None
|
||||
@@ -137,6 +138,7 @@ class SellingController(StockController):
|
||||
lead,
|
||||
posting_date=self.get("transaction_date") or self.get("posting_date"),
|
||||
company=self.company,
|
||||
doctype=self.doctype,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -149,6 +151,13 @@ class SellingController(StockController):
|
||||
self.set_price_list_currency("Selling")
|
||||
self.set_missing_item_details(for_validate=for_validate)
|
||||
|
||||
def set_company_contact_person(self):
|
||||
"""Set the Company's Default Sales Contact as Company Contact Person."""
|
||||
if self.company and self.meta.has_field("company_contact_person") and not self.company_contact_person:
|
||||
self.company_contact_person = frappe.get_cached_value(
|
||||
"Company", self.company, "default_sales_contact"
|
||||
)
|
||||
|
||||
def remove_shipping_charge(self):
|
||||
if self.shipping_rule:
|
||||
shipping_rule = frappe.get_doc("Shipping Rule", self.shipping_rule)
|
||||
|
||||
@@ -93,6 +93,7 @@ status_map = {
|
||||
["Draft", None],
|
||||
["To Bill", "eval:self.per_billed == 0 and self.docstatus == 1"],
|
||||
["Partly Billed", "eval:self.per_billed > 0 and self.per_billed < 100 and self.docstatus == 1"],
|
||||
["Return", "eval:self.is_return == 1 and self.per_billed == 0 and self.docstatus == 1"],
|
||||
["Return Issued", "eval:self.per_returned == 100 and self.docstatus == 1"],
|
||||
[
|
||||
"Completed",
|
||||
|
||||
@@ -505,7 +505,7 @@ class SubcontractingController(StockController):
|
||||
if item.get("serial_and_batch_bundle"):
|
||||
frappe.delete_doc("Serial and Batch Bundle", item.serial_and_batch_bundle, force=True)
|
||||
|
||||
def __get_materials_from_bom(self, item_code, bom_no, exploded_item=0):
|
||||
def _get_materials_from_bom(self, item_code, bom_no, exploded_item=0):
|
||||
doctype = "BOM Item" if not exploded_item else "BOM Explosion Item"
|
||||
fields = [f"`tab{doctype}`.`stock_qty` / `tabBOM`.`quantity` as qty_consumed_per_unit"]
|
||||
|
||||
@@ -849,7 +849,7 @@ class SubcontractingController(StockController):
|
||||
if self.doctype == self.subcontract_data.order_doctype or (
|
||||
self.backflush_based_on == "BOM" or self.is_return
|
||||
):
|
||||
for bom_item in self.__get_materials_from_bom(
|
||||
for bom_item in self._get_materials_from_bom(
|
||||
row.item_code, row.bom, row.get("include_exploded_items")
|
||||
):
|
||||
qty = flt(bom_item.qty_consumed_per_unit) * flt(row.qty) * row.conversion_factor
|
||||
|
||||
@@ -682,6 +682,25 @@ class calculate_taxes_and_totals:
|
||||
self.doc.precision("discount_amount"),
|
||||
)
|
||||
|
||||
discount_amount = self.doc.discount_amount or 0
|
||||
grand_total = self.doc.grand_total
|
||||
|
||||
# validate that discount amount cannot exceed the total before discount
|
||||
if (
|
||||
(grand_total >= 0 and discount_amount > grand_total)
|
||||
or (grand_total < 0 and discount_amount < grand_total) # returns
|
||||
):
|
||||
frappe.throw(
|
||||
_(
|
||||
"Additional Discount Amount ({discount_amount}) cannot exceed "
|
||||
"the total before such discount ({total_before_discount})"
|
||||
).format(
|
||||
discount_amount=self.doc.get_formatted("discount_amount"),
|
||||
total_before_discount=self.doc.get_formatted("grand_total"),
|
||||
),
|
||||
title=_("Invalid Discount Amount"),
|
||||
)
|
||||
|
||||
def apply_discount_amount(self):
|
||||
if self.doc.discount_amount:
|
||||
if not self.doc.apply_discount_on:
|
||||
|
||||
@@ -2258,3 +2258,173 @@ class TestAccountsController(FrappeTestCase):
|
||||
self.assertRaises(frappe.ValidationError, si.save)
|
||||
si.contact_person = customer_contact.name
|
||||
si.save()
|
||||
|
||||
def test_discount_amount_not_mapped_repeatedly_for_sales_transactions(self):
|
||||
"""
|
||||
Test that additional discount amount is not copied repeatedly
|
||||
when creating multiple delivery notes from a single sales order with discount_amount set
|
||||
"""
|
||||
from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||
|
||||
# Create a sales order with discount amount
|
||||
so = make_sales_order(qty=10, rate=100, do_not_submit=True)
|
||||
so.apply_discount_on = "Net Total"
|
||||
so.discount_amount = 100
|
||||
so.save()
|
||||
so.submit()
|
||||
|
||||
# Create first delivery note from sales order (partial qty)
|
||||
dn1 = make_delivery_note(so.name)
|
||||
dn1.items[0].qty = 5
|
||||
dn1.save()
|
||||
dn1.submit()
|
||||
|
||||
# First delivery note should have full discount amount
|
||||
self.assertEqual(dn1.discount_amount, 100)
|
||||
self.assertEqual(dn1.grand_total, 400)
|
||||
|
||||
# Create second delivery note from the same sales order (remaining qty)
|
||||
dn2 = make_delivery_note(so.name)
|
||||
dn2.items[0].qty = 5
|
||||
dn2.save()
|
||||
dn2.submit()
|
||||
|
||||
# Second delivery note should have discount_amount set to 0
|
||||
# because discount was already fully applied in first delivery note
|
||||
self.assertEqual(dn2.discount_amount, 0)
|
||||
self.assertEqual(dn2.grand_total, 500)
|
||||
|
||||
def test_discount_amount_not_mapped_repeatedly_for_purchase_transactions(self):
|
||||
"""
|
||||
Test that additional discount amount is not copied repeatedly
|
||||
when creating multiple purchase receipts from a single purchase order with discount_amount set
|
||||
"""
|
||||
from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt
|
||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
||||
|
||||
# Create a purchase order with discount amount
|
||||
po = create_purchase_order(qty=10, rate=100, do_not_submit=True)
|
||||
po.apply_discount_on = "Net Total"
|
||||
po.discount_amount = 100
|
||||
po.save()
|
||||
po.submit()
|
||||
|
||||
# Create first purchase receipt from purchase order (partial qty)
|
||||
pr1 = make_purchase_receipt(po.name)
|
||||
pr1.items[0].qty = 5
|
||||
pr1.save()
|
||||
pr1.submit()
|
||||
|
||||
# First purchase receipt should have full discount amount
|
||||
self.assertEqual(pr1.discount_amount, 100)
|
||||
self.assertEqual(pr1.grand_total, 400)
|
||||
|
||||
# Create second purchase receipt from the same purchase order (remaining qty)
|
||||
pr2 = make_purchase_receipt(po.name)
|
||||
pr2.items[0].qty = 5
|
||||
pr2.save()
|
||||
pr2.submit()
|
||||
|
||||
# Second purchase receipt should have discount_amount set to 0
|
||||
# because discount was already fully applied in first purchase receipt
|
||||
self.assertEqual(pr2.discount_amount, 0)
|
||||
self.assertEqual(pr2.grand_total, 500)
|
||||
|
||||
def test_discount_amount_partial_application_in_mapped_transactions(self):
|
||||
"""
|
||||
Test that discount amount is partially applied when some discount
|
||||
has already been used in previous mapped transactions
|
||||
"""
|
||||
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||
|
||||
# Create a sales order with discount amount
|
||||
so = make_sales_order(qty=10, rate=100, do_not_submit=True)
|
||||
so.apply_discount_on = "Net Total"
|
||||
so.discount_amount = 200
|
||||
so.save()
|
||||
so.submit()
|
||||
|
||||
self.assertEqual(so.discount_amount, 200)
|
||||
self.assertEqual(so.grand_total, 800)
|
||||
|
||||
# Create first invoice with partial discount (manually set lower discount)
|
||||
si1 = make_sales_invoice(so.name)
|
||||
si1.items[0].qty = 5
|
||||
si1.discount_amount = 50 # Partial discount application
|
||||
si1.save()
|
||||
si1.submit()
|
||||
|
||||
self.assertEqual(si1.discount_amount, 50)
|
||||
self.assertEqual(si1.grand_total, 450)
|
||||
|
||||
# Create second invoice from the same sales order
|
||||
si2 = make_sales_invoice(so.name)
|
||||
si2.items[0].qty = 5
|
||||
si2.save()
|
||||
si2.submit()
|
||||
|
||||
# Second invoice should have remaining discount (200 - 50 = 150)
|
||||
self.assertEqual(si2.discount_amount, 150)
|
||||
self.assertEqual(si2.grand_total, 350)
|
||||
|
||||
def test_discount_amount_not_mapped_when_percentage_is_set(self):
|
||||
"""
|
||||
Test that discount amount is not adjusted when additional_discount_percentage
|
||||
is set in the source document (as it will be recalculated based on percentage)
|
||||
"""
|
||||
from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||
|
||||
# Create a sales order with discount percentage instead of amount
|
||||
so = make_sales_order(qty=10, rate=100, do_not_submit=True)
|
||||
so.apply_discount_on = "Net Total"
|
||||
so.additional_discount_percentage = 10 # 10% discount
|
||||
so.save()
|
||||
so.submit()
|
||||
|
||||
self.assertEqual(so.discount_amount, 100) # 10% of 1000
|
||||
self.assertEqual(so.grand_total, 900)
|
||||
|
||||
# Create delivery note from sales order
|
||||
dn = make_delivery_note(so.name)
|
||||
dn.items[0].qty = 5
|
||||
dn.save()
|
||||
|
||||
# Delivery note should have discount amount recalculated based on percentage
|
||||
# and not affected by the repeated mapping logic
|
||||
self.assertEqual(dn.additional_discount_percentage, 10)
|
||||
self.assertEqual(dn.discount_amount, 50) # 10% of 500
|
||||
|
||||
def test_discount_amount_for_multiple_returns(self):
|
||||
"""
|
||||
Test that discount amount is correctly adjusted when multiple return invoices
|
||||
are created against the same original invoice to prevent over-returning discount
|
||||
"""
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_sales_return
|
||||
|
||||
# Create original sales invoice with discount
|
||||
si = create_sales_invoice(qty=10, rate=100, do_not_submit=True)
|
||||
si.apply_discount_on = "Net Total"
|
||||
si.discount_amount = 100
|
||||
si.save()
|
||||
si.submit()
|
||||
|
||||
# Create first return - Frappe will copy full discount by default, we need to adjust it
|
||||
return_si_1 = make_sales_return(si.name)
|
||||
return_si_1.items[0].qty = -6 # Return 6 out of 10 items
|
||||
# Manually set discount to match the proportion (60% of discount)
|
||||
return_si_1.discount_amount = -60
|
||||
return_si_1.save()
|
||||
return_si_1.submit()
|
||||
|
||||
self.assertEqual(return_si_1.discount_amount, -60)
|
||||
|
||||
# Create second return for remaining items
|
||||
return_si_2 = make_sales_return(si.name)
|
||||
return_si_2.items[0].qty = -4 # Return remaining 4 out of 10 items
|
||||
return_si_2.save()
|
||||
|
||||
# Second return should only get remaining discount (100 - 60 = 40)
|
||||
self.assertEqual(return_si_2.discount_amount, -40)
|
||||
|
||||
@@ -191,6 +191,9 @@ def get_data(filters, conditions):
|
||||
des[j + inc] = row1[0][j]
|
||||
|
||||
data.append(des)
|
||||
|
||||
total_row = calculate_total_row(data1, conditions["columns"])
|
||||
data.append(total_row)
|
||||
else:
|
||||
data = frappe.db.sql(
|
||||
""" select {} from `tab{}` t1, `tab{} Item` t2 {}
|
||||
@@ -214,9 +217,32 @@ def get_data(filters, conditions):
|
||||
as_list=1,
|
||||
)
|
||||
|
||||
total_row = calculate_total_row(data, conditions["columns"])
|
||||
data.append(total_row)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def calculate_total_row(data, columns):
|
||||
def wrap_in_quotes(label):
|
||||
return f"'{label}'"
|
||||
|
||||
total_values = {}
|
||||
for i, col in enumerate(columns):
|
||||
if "Float" in col or "Currency/currency" in col:
|
||||
total_values[i] = 0
|
||||
|
||||
for row in data:
|
||||
for i in total_values.keys():
|
||||
total_values[i] += row[i] if row[i] is not None else 0
|
||||
|
||||
total_row = [wrap_in_quotes(_("Total"))]
|
||||
for i in range(1, len(columns)):
|
||||
total_row.append(total_values.get(i, None))
|
||||
|
||||
return total_row
|
||||
|
||||
|
||||
def get_mon(dt):
|
||||
return getdate(dt).strftime("%b")
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ def _set_missing_values(source, target):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_lead_details(lead, posting_date=None, company=None):
|
||||
def get_lead_details(lead, posting_date=None, company=None, doctype=None):
|
||||
if not lead:
|
||||
return {}
|
||||
|
||||
@@ -454,7 +454,7 @@ def get_lead_details(lead, posting_date=None, company=None):
|
||||
}
|
||||
)
|
||||
|
||||
set_address_details(out, lead, "Lead", company=company)
|
||||
set_address_details(out, lead, "Lead", doctype=doctype, company=company)
|
||||
|
||||
taxes_and_charges = set_taxes(
|
||||
None,
|
||||
|
||||
@@ -279,6 +279,7 @@
|
||||
"oldfieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 1,
|
||||
"fieldname": "items",
|
||||
"fieldtype": "Table",
|
||||
"label": "Items",
|
||||
@@ -547,12 +548,14 @@
|
||||
{
|
||||
"fieldname": "process_loss_percentage",
|
||||
"fieldtype": "Percent",
|
||||
"label": "% Process Loss"
|
||||
"label": "% Process Loss",
|
||||
"non_negative": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "process_loss_qty",
|
||||
"fieldtype": "Float",
|
||||
"label": "Process Loss Qty",
|
||||
"non_negative": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
@@ -638,7 +641,7 @@
|
||||
"image_field": "image",
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-06-16 16:13:22.497695",
|
||||
"modified": "2025-11-19 16:17:15.925156",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "BOM",
|
||||
|
||||
@@ -158,6 +158,7 @@ class BOM(WebsiteGenerator):
|
||||
show_operations: DF.Check
|
||||
thumbnail: DF.Data | None
|
||||
total_cost: DF.Currency
|
||||
track_semi_finished_goods: DF.Check
|
||||
transfer_material_against: DF.Literal["", "Work Order", "Job Card"]
|
||||
uom: DF.Link | None
|
||||
web_long_description: DF.TextEditor | None
|
||||
@@ -464,7 +465,7 @@ class BOM(WebsiteGenerator):
|
||||
)
|
||||
)
|
||||
|
||||
def get_rm_rate(self, arg):
|
||||
def get_rm_rate(self, arg, notify=True):
|
||||
"""Get raw material rate as per selected method, if bom exists takes bom cost"""
|
||||
rate = 0
|
||||
if not self.rm_cost_as_per:
|
||||
@@ -490,7 +491,7 @@ class BOM(WebsiteGenerator):
|
||||
),
|
||||
alert=True,
|
||||
)
|
||||
else:
|
||||
elif notify:
|
||||
frappe.msgprint(
|
||||
_("{0} not found for item {1}").format(self.rm_cost_as_per, arg["item_code"]),
|
||||
alert=True,
|
||||
@@ -795,11 +796,14 @@ class BOM(WebsiteGenerator):
|
||||
"stock_uom": d.stock_uom,
|
||||
"conversion_factor": d.conversion_factor,
|
||||
"sourced_by_supplier": d.sourced_by_supplier,
|
||||
}
|
||||
},
|
||||
notify=False,
|
||||
)
|
||||
|
||||
d.base_rate = flt(d.rate) * flt(self.conversion_rate)
|
||||
d.amount = flt(d.rate, d.precision("rate")) * flt(d.qty, d.precision("qty"))
|
||||
d.amount = flt(
|
||||
flt(d.rate, d.precision("rate")) * flt(d.qty, d.precision("qty")), d.precision("amount")
|
||||
)
|
||||
d.base_amount = d.amount * flt(self.conversion_rate)
|
||||
d.qty_consumed_per_unit = flt(d.stock_qty, d.precision("stock_qty")) / flt(
|
||||
self.quantity, self.precision("quantity")
|
||||
@@ -822,7 +826,10 @@ class BOM(WebsiteGenerator):
|
||||
d.base_rate = flt(d.rate, d.precision("rate")) * flt(
|
||||
self.conversion_rate, self.precision("conversion_rate")
|
||||
)
|
||||
d.amount = flt(d.rate, d.precision("rate")) * flt(d.stock_qty, d.precision("stock_qty"))
|
||||
d.amount = flt(
|
||||
flt(d.rate, d.precision("rate")) * flt(d.stock_qty, d.precision("stock_qty")),
|
||||
d.precision("amount"),
|
||||
)
|
||||
d.base_amount = flt(d.amount, d.precision("amount")) * flt(
|
||||
self.conversion_rate, self.precision("conversion_rate")
|
||||
)
|
||||
|
||||
@@ -38,6 +38,15 @@ frappe.ui.form.on("Job Card", {
|
||||
return doc.status === "Complete" ? "green" : "orange";
|
||||
}
|
||||
});
|
||||
|
||||
frm.set_query("employee", () => {
|
||||
return {
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
status: "Active",
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
@@ -408,7 +417,7 @@ frappe.ui.form.on("Job Card", {
|
||||
function updateStopwatch(increment) {
|
||||
var hours = Math.floor(increment / 3600);
|
||||
var minutes = Math.floor((increment - hours * 3600) / 60);
|
||||
var seconds = increment - hours * 3600 - minutes * 60;
|
||||
var seconds = Math.floor(increment - hours * 3600 - minutes * 60);
|
||||
|
||||
$(section)
|
||||
.find(".hours")
|
||||
@@ -431,7 +440,7 @@ frappe.ui.form.on("Job Card", {
|
||||
frm.dashboard.refresh();
|
||||
const timer = `
|
||||
<div class="stopwatch" style="font-weight:bold;margin:0px 13px 0px 2px;
|
||||
color:#545454;font-size:18px;display:inline-block;vertical-align:text-bottom;>
|
||||
color:#545454;font-size:18px;display:inline-block;vertical-align:text-bottom;">
|
||||
<span class="hours">00</span>
|
||||
<span class="colon">:</span>
|
||||
<span class="minutes">00</span>
|
||||
@@ -441,20 +450,34 @@ frappe.ui.form.on("Job Card", {
|
||||
|
||||
var section = frm.toolbar.page.add_inner_message(timer);
|
||||
|
||||
let currentIncrement = frm.doc.current_time || 0;
|
||||
let currentIncrement = frm.events.get_current_time(frm);
|
||||
if (frm.doc.started_time || frm.doc.current_time) {
|
||||
if (frm.doc.status == "On Hold") {
|
||||
updateStopwatch(currentIncrement);
|
||||
} else {
|
||||
currentIncrement += moment(frappe.datetime.now_datetime()).diff(
|
||||
moment(frm.doc.started_time),
|
||||
"seconds"
|
||||
);
|
||||
initialiseTimer();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get_current_time(frm) {
|
||||
let current_time = 0;
|
||||
|
||||
frm.doc.time_logs.forEach((d) => {
|
||||
if (d.to_time) {
|
||||
if (d.time_in_mins) {
|
||||
current_time += flt(d.time_in_mins, 2) * 60;
|
||||
} else {
|
||||
current_time += get_seconds_diff(d.to_time, d.from_time);
|
||||
}
|
||||
} else {
|
||||
current_time += get_seconds_diff(frappe.datetime.now_datetime(), d.from_time);
|
||||
}
|
||||
});
|
||||
|
||||
return current_time;
|
||||
},
|
||||
|
||||
hide_timer: function (frm) {
|
||||
frm.toolbar.page.inner_toolbar.find(".stopwatch").remove();
|
||||
},
|
||||
@@ -519,3 +542,7 @@ frappe.ui.form.on("Job Card Time Log", {
|
||||
frm.set_value("started_time", "");
|
||||
},
|
||||
});
|
||||
|
||||
function get_seconds_diff(d1, d2) {
|
||||
return moment(d1).diff(d2, "seconds");
|
||||
}
|
||||
|
||||
@@ -724,6 +724,9 @@ class ProductionPlan(Document):
|
||||
if not wo_list:
|
||||
frappe.msgprint(_("No Work Orders were created"))
|
||||
|
||||
if not po_list:
|
||||
frappe.msgprint(_("No Purchase Orders were created"))
|
||||
|
||||
def make_work_order_for_finished_goods(self, wo_list, default_warehouses):
|
||||
items_data = self.get_production_items()
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ def get_exploded_items(bom, data, indent=0, qty=1):
|
||||
)
|
||||
|
||||
for item in exploded_items:
|
||||
print(item.bom_no, indent)
|
||||
item["indent"] = indent
|
||||
data.append(
|
||||
{
|
||||
|
||||
@@ -151,10 +151,9 @@ def get_column(filters):
|
||||
},
|
||||
{
|
||||
"label": _("Document Type"),
|
||||
"fieldtype": "Link",
|
||||
"fieldtype": "Data",
|
||||
"fieldname": "document_type",
|
||||
"width": 150,
|
||||
"options": "DocType",
|
||||
},
|
||||
{
|
||||
"label": _("Document Name"),
|
||||
|
||||
@@ -318,7 +318,7 @@
|
||||
"type": "Link"
|
||||
}
|
||||
],
|
||||
"modified": "2024-10-21 14:13:38.777556",
|
||||
"modified": "2025-11-24 11:11:28.343568",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Manufacturing",
|
||||
@@ -336,7 +336,7 @@
|
||||
"doc_view": "List",
|
||||
"label": "Learn Manufacturing",
|
||||
"type": "URL",
|
||||
"url": "https://school.frappe.io/lms/courses/manufacturing?utm_source=in_app"
|
||||
"url": "https://school.frappe.io/lms/courses/production-planning-and-execution"
|
||||
},
|
||||
{
|
||||
"color": "Grey",
|
||||
|
||||
@@ -422,3 +422,8 @@ execute:frappe.db.set_single_value("Accounts Settings", "fetch_valuation_rate_fo
|
||||
erpnext.patches.v15_0.add_company_payment_gateway_account
|
||||
erpnext.patches.v15_0.update_uae_zero_rated_fetch
|
||||
erpnext.patches.v15_0.update_fieldname_in_accounting_dimension_filter
|
||||
erpnext.patches.v15_0.set_asset_status_if_not_already_set
|
||||
erpnext.patches.v15_0.toggle_legacy_controller_for_period_closing
|
||||
execute:frappe.db.set_single_value("Accounts Settings", "show_party_balance", 1)
|
||||
execute:frappe.db.set_single_value("Accounts Settings", "show_account_balance", 1)
|
||||
erpnext.patches.v16_0.update_currency_exchange_settings_for_frankfurter
|
||||
|
||||
13
erpnext/patches/v15_0/set_asset_status_if_not_already_set.py
Normal file
13
erpnext/patches/v15_0/set_asset_status_if_not_already_set.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import frappe
|
||||
from frappe.query_builder import DocType
|
||||
|
||||
|
||||
def execute():
|
||||
Asset = DocType("Asset")
|
||||
|
||||
query = (
|
||||
frappe.qb.update(Asset)
|
||||
.set(Asset.status, "Draft")
|
||||
.where((Asset.docstatus == 0) & ((Asset.status.isnull()) | (Asset.status == "")))
|
||||
)
|
||||
query.run()
|
||||
@@ -0,0 +1,9 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
"""
|
||||
Description:
|
||||
Enable Legacy controller for Period Closing Voucher
|
||||
"""
|
||||
frappe.db.set_single_value("Accounts Settings", "use_legacy_controller_for_pcv", 1)
|
||||
@@ -0,0 +1,12 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
settings = frappe.get_doc("Currency Exchange Settings")
|
||||
if settings.service_provider != "frankfurter.app":
|
||||
return
|
||||
|
||||
settings.service_provider = "frankfurter.dev"
|
||||
settings.set_parameters_and_result()
|
||||
settings.flags.ignore_validate = True
|
||||
settings.save()
|
||||
@@ -245,6 +245,7 @@
|
||||
"fieldname": "act_start_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "Actual Start Date (via Timesheet)",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "act_start_date",
|
||||
"oldfieldtype": "Date",
|
||||
"read_only": 1
|
||||
@@ -253,6 +254,7 @@
|
||||
"fieldname": "actual_time",
|
||||
"fieldtype": "Float",
|
||||
"label": "Actual Time in Hours (via Timesheet)",
|
||||
"no_copy": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
@@ -263,6 +265,7 @@
|
||||
"fieldname": "act_end_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "Actual End Date (via Timesheet)",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "act_end_date",
|
||||
"oldfieldtype": "Date",
|
||||
"read_only": 1
|
||||
@@ -277,6 +280,7 @@
|
||||
"fieldname": "total_costing_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Total Costing Amount (via Timesheet)",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "actual_budget",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
@@ -290,6 +294,7 @@
|
||||
"fieldname": "total_billing_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Total Billable Amount (via Timesheet)",
|
||||
"no_copy": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
@@ -399,7 +404,7 @@
|
||||
"is_tree": 1,
|
||||
"links": [],
|
||||
"max_attachments": 5,
|
||||
"modified": "2024-01-08 16:00:41.296203",
|
||||
"modified": "2025-10-16 08:39:12.214577",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Projects",
|
||||
"name": "Task",
|
||||
@@ -429,4 +434,4 @@
|
||||
"timeline_field": "project",
|
||||
"title_field": "subject",
|
||||
"track_seen": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ class CircularReferenceError(frappe.ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class ParentIsGroupError(frappe.ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class Task(NestedSet):
|
||||
# begin: auto-generated types
|
||||
# This code is auto-generated. Do not modify anything in this block.
|
||||
@@ -83,6 +87,7 @@ class Task(NestedSet):
|
||||
self.update_depends_on()
|
||||
self.validate_dependencies_for_template_task()
|
||||
self.validate_completed_on()
|
||||
self.validate_parent_is_group()
|
||||
|
||||
def validate_dates(self):
|
||||
self.validate_from_to_dates("exp_start_date", "exp_end_date")
|
||||
@@ -153,20 +158,36 @@ class Task(NestedSet):
|
||||
def validate_parent_template_task(self):
|
||||
if self.parent_task:
|
||||
if not frappe.db.get_value("Task", self.parent_task, "is_template"):
|
||||
parent_task_format = f"""<a href="/app/task/{self.parent_task}">{self.parent_task}</a>"""
|
||||
frappe.throw(_("Parent Task {0} is not a Template Task").format(parent_task_format))
|
||||
frappe.throw(
|
||||
_("Parent Task {0} is not a Template Task").format(
|
||||
get_link_to_form("Task", self.parent_task)
|
||||
)
|
||||
)
|
||||
|
||||
def validate_depends_on_tasks(self):
|
||||
if self.depends_on:
|
||||
for task in self.depends_on:
|
||||
if not frappe.db.get_value("Task", task.task, "is_template"):
|
||||
dependent_task_format = f"""<a href="/app/task/{task.task}">{task.task}</a>"""
|
||||
frappe.throw(_("Dependent Task {0} is not a Template Task").format(dependent_task_format))
|
||||
frappe.throw(
|
||||
_("Dependent Task {0} is not a Template Task").format(
|
||||
get_link_to_form("Task", task.task)
|
||||
)
|
||||
)
|
||||
|
||||
def validate_completed_on(self):
|
||||
if self.completed_on and getdate(self.completed_on) > getdate():
|
||||
frappe.throw(_("Completed On cannot be greater than Today"))
|
||||
|
||||
def validate_parent_is_group(self):
|
||||
if self.parent_task:
|
||||
if not frappe.db.get_value("Task", self.parent_task, "is_group"):
|
||||
frappe.throw(
|
||||
_("Parent Task {0} must be a Group Task").format(
|
||||
get_link_to_form("Task", self.parent_task)
|
||||
),
|
||||
ParentIsGroupError,
|
||||
)
|
||||
|
||||
def update_depends_on(self):
|
||||
depends_on_tasks = ""
|
||||
for d in self.depends_on:
|
||||
|
||||
@@ -6,7 +6,7 @@ import unittest
|
||||
import frappe
|
||||
from frappe.utils import add_days, getdate, nowdate
|
||||
|
||||
from erpnext.projects.doctype.task.task import CircularReferenceError
|
||||
from erpnext.projects.doctype.task.task import CircularReferenceError, ParentIsGroupError
|
||||
|
||||
|
||||
class TestTask(unittest.TestCase):
|
||||
@@ -109,6 +109,20 @@ class TestTask(unittest.TestCase):
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Task", task.name, "status"), "Overdue")
|
||||
|
||||
def test_parent_task_must_be_group(self):
|
||||
parent_task = create_task(
|
||||
subject="_Test Parent Task Non Group",
|
||||
is_group=0,
|
||||
)
|
||||
|
||||
child_task = create_task(
|
||||
subject="_Test Child Task",
|
||||
parent_task=parent_task.name,
|
||||
save=False,
|
||||
)
|
||||
|
||||
self.assertRaises(ParentIsGroupError, child_task.save)
|
||||
|
||||
|
||||
def create_task(
|
||||
subject,
|
||||
|
||||
@@ -21,6 +21,7 @@ frappe.ui.form.on("Timesheet", {
|
||||
filters: {
|
||||
project: child.project,
|
||||
status: ["!=", "Cancelled"],
|
||||
is_group: 0,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -285,7 +285,7 @@ class Timesheet(Document):
|
||||
if data.activity_type or data.is_billable:
|
||||
rate = get_activity_cost(self.employee, data.activity_type)
|
||||
hours = data.billing_hours or 0
|
||||
costing_hours = data.billing_hours or data.hours or 0
|
||||
costing_hours = data.hours or 0
|
||||
if rate:
|
||||
data.billing_rate = (
|
||||
flt(rate.get("billing_rate")) if flt(data.billing_rate) == 0 else data.billing_rate
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
|
||||
frappe.query_reports["Delayed Tasks Summary"] = {
|
||||
filters: [
|
||||
{
|
||||
fieldname: "project",
|
||||
label: __("Project"),
|
||||
fieldtype: "Link",
|
||||
options: "Project",
|
||||
},
|
||||
{
|
||||
fieldname: "from_date",
|
||||
label: __("From Date"),
|
||||
|
||||
@@ -23,6 +23,7 @@ def get_data(filters):
|
||||
fields=[
|
||||
"name",
|
||||
"subject",
|
||||
"project",
|
||||
"exp_start_date",
|
||||
"exp_end_date",
|
||||
"status",
|
||||
@@ -56,7 +57,7 @@ def get_data(filters):
|
||||
|
||||
def get_conditions(filters):
|
||||
conditions = frappe._dict()
|
||||
keys = ["priority", "status"]
|
||||
keys = ["priority", "status", "project"]
|
||||
for key in keys:
|
||||
if filters.get(key):
|
||||
conditions[key] = filters.get(key)
|
||||
@@ -89,6 +90,13 @@ def get_columns():
|
||||
columns = [
|
||||
{"fieldname": "name", "fieldtype": "Link", "label": _("Task"), "options": "Task", "width": 150},
|
||||
{"fieldname": "subject", "fieldtype": "Data", "label": _("Subject"), "width": 200},
|
||||
{
|
||||
"fieldname": "project",
|
||||
"fieldtype": "Link",
|
||||
"label": _("Project"),
|
||||
"options": "Project",
|
||||
"width": 150,
|
||||
},
|
||||
{"fieldname": "status", "fieldtype": "Data", "label": _("Status"), "width": 100},
|
||||
{"fieldname": "priority", "fieldtype": "Data", "label": _("Priority"), "width": 80},
|
||||
{"fieldname": "progress", "fieldtype": "Data", "label": _("Progress (%)"), "width": 120},
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user