-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: company wise deferred accounting fields in item (#37023)
* fix: move deferred accounts in accounting section * fix: move deferred check boxes in item accounting * fix: show company wise acc in filters * fix: fetch item deferred account from child table * fix: tests using deferred acc * refactor: use cached value * fix: cached value call * feat: patch to migrate deferred acc * fix: hardcode education module doctypes in patch * chore: resolve conflicts --------- Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
- Loading branch information
1 parent
34bb64e
commit 099468e
Showing
11 changed files
with
117 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
erpnext/patches/v14_0/migrate_deferred_accounts_to_item_defaults.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import frappe | ||
|
||
|
||
def execute(): | ||
try: | ||
item_dict = get_deferred_accounts() | ||
add_to_item_defaults(item_dict) | ||
except Exception: | ||
frappe.db.rollback() | ||
frappe.log_error("Failed to migrate deferred accounts in Item Defaults.") | ||
|
||
|
||
def get_deferred_accounts(): | ||
item = frappe.qb.DocType("Item") | ||
return ( | ||
frappe.qb.from_(item) | ||
.select(item.name, item.deferred_expense_account, item.deferred_revenue_account) | ||
.where((item.enable_deferred_expense == 1) | (item.enable_deferred_revenue == 1)) | ||
.run(as_dict=True) | ||
) | ||
|
||
|
||
def add_to_item_defaults(item_dict): | ||
for item in item_dict: | ||
add_company_wise_item_default(item, "deferred_expense_account") | ||
add_company_wise_item_default(item, "deferred_revenue_account") | ||
|
||
|
||
def add_company_wise_item_default(item, account_type): | ||
company = frappe.get_cached_value("Account", item[account_type], "company") | ||
if company and item[account_type]: | ||
item_defaults = frappe.get_cached_value("Item", item["name"], "item_defaults") | ||
for item_row in item_defaults: | ||
if item_row.company == company: | ||
frappe.set_value("Item Default", item_row.name, account_type, item[account_type]) | ||
break | ||
else: | ||
item_defaults.append({"company": company, account_type: item[account_type]}) | ||
frappe.set_value("Item", item["name"], "item_defaults", item_defaults) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters