Merge pull request #42455 from frappe/mergify/bp/version-14-hotfix/pr-42390

refactor: cleaning up stale code related to reposting (backport #42390)
This commit is contained in:
ruthra kumar
2024-07-24 17:35:24 +05:30
committed by GitHub
10 changed files with 37 additions and 98 deletions

View File

@@ -557,7 +557,7 @@
"table_fieldname": "payment_entries" "table_fieldname": "payment_entries"
} }
], ],
"modified": "2023-11-23 12:11:04.128015", "modified": "2024-07-18 15:32:29.413598",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Journal Entry", "name": "Journal Entry",

View File

@@ -59,25 +59,6 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.
this.show_stock_ledger(); this.show_stock_ledger();
} }
if (this.frm.doc.repost_required && this.frm.doc.docstatus===1) {
this.frm.set_intro(__("Accounting entries for this invoice need to be reposted. Please click on 'Repost' button to update."));
this.frm.add_custom_button(__('Repost Accounting Entries'),
() => {
this.frm.call({
doc: this.frm.doc,
method: 'repost_accounting_entries',
freeze: true,
freeze_message: __('Reposting...'),
callback: (r) => {
if (!r.exc) {
frappe.msgprint(__('Accounting Entries are reposted.'));
me.frm.refresh();
}
}
});
}).removeClass('btn-default').addClass('btn-warning');
}
if(!doc.is_return && doc.docstatus == 1 && doc.outstanding_amount != 0){ if(!doc.is_return && doc.docstatus == 1 && doc.outstanding_amount != 0){
if(doc.on_hold) { if(doc.on_hold) {
this.frm.add_custom_button( this.frm.add_custom_button(

View File

@@ -170,7 +170,6 @@
"against_expense_account", "against_expense_account",
"column_break_63", "column_break_63",
"unrealized_profit_loss_account", "unrealized_profit_loss_account",
"repost_required",
"subscription_section", "subscription_section",
"auto_repeat", "auto_repeat",
"update_auto_repeat_reference", "update_auto_repeat_reference",
@@ -1590,15 +1589,6 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "Use Company Default Round Off Cost Center" "label": "Use Company Default Round Off Cost Center"
}, },
{
"default": "0",
"fieldname": "repost_required",
"fieldtype": "Check",
"hidden": 1,
"label": "Repost Required",
"options": "Account",
"read_only": 1
},
{ {
"default": "0", "default": "0",
"fieldname": "use_transaction_date_exchange_rate", "fieldname": "use_transaction_date_exchange_rate",
@@ -1619,7 +1609,7 @@
"idx": 204, "idx": 204,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2024-03-20 15:57:00.736868", "modified": "2024-07-18 15:31:49.488566",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Purchase Invoice", "name": "Purchase Invoice",

View File

@@ -590,18 +590,17 @@ class PurchaseInvoice(BuyingController):
self.process_common_party_accounting() self.process_common_party_accounting()
def on_update_after_submit(self): def on_update_after_submit(self):
if hasattr(self, "repost_required"): fields_to_check = [
fields_to_check = [ "cash_bank_account",
"cash_bank_account", "write_off_account",
"write_off_account", "unrealized_profit_loss_account",
"unrealized_profit_loss_account", "is_opening",
] ]
child_tables = {"items": ("expense_account",), "taxes": ("account_head",)} child_tables = {"items": ("expense_account",), "taxes": ("account_head",)}
self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables) self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables)
if self.needs_repost: if self.needs_repost:
self.validate_for_repost() self.validate_for_repost()
self.db_set("repost_required", self.needs_repost) self.repost_accounting_entries()
self.repost_accounting_entries()
def make_gl_entries(self, gl_entries=None, from_repost=False): def make_gl_entries(self, gl_entries=None, from_repost=False):
update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes" update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"

View File

@@ -1917,8 +1917,6 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
["Service - _TC", 1000, 0.0, nowdate()], ["Service - _TC", 1000, 0.0, nowdate()],
] ]
check_gl_entries(self, pi.name, expected_gle, nowdate()) check_gl_entries(self, pi.name, expected_gle, nowdate())
pi.load_from_db()
self.assertFalse(pi.repost_required)
def test_default_cost_center_for_purchase(self): def test_default_cost_center_for_purchase(self):
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center

View File

@@ -49,25 +49,6 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
this.frm.toggle_reqd("due_date", !this.frm.doc.is_return); this.frm.toggle_reqd("due_date", !this.frm.doc.is_return);
if (this.frm.doc.repost_required && this.frm.doc.docstatus===1) {
this.frm.set_intro(__("Accounting entries for this invoice needs to be reposted. Please click on 'Repost' button to update."));
this.frm.add_custom_button(__('Repost Accounting Entries'),
() => {
this.frm.call({
doc: this.frm.doc,
method: 'repost_accounting_entries',
freeze: true,
freeze_message: __('Reposting...'),
callback: (r) => {
if (!r.exc) {
frappe.msgprint(__('Accounting Entries are reposted'));
me.frm.refresh();
}
}
});
}).removeClass('btn-default').addClass('btn-warning');
}
if (this.frm.doc.is_return) { if (this.frm.doc.is_return) {
this.frm.return_print_format = "Sales Invoice Return"; this.frm.return_print_format = "Sales Invoice Return";
} }

View File

@@ -213,7 +213,6 @@
"is_internal_customer", "is_internal_customer",
"is_discounted", "is_discounted",
"remarks", "remarks",
"repost_required",
"connections_tab" "connections_tab"
], ],
"fields": [ "fields": [
@@ -2184,7 +2183,7 @@
"link_fieldname": "consolidated_invoice" "link_fieldname": "consolidated_invoice"
} }
], ],
"modified": "2024-05-08 18:02:28.549041", "modified": "2024-07-18 15:30:39.428519",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Sales Invoice", "name": "Sales Invoice",

View File

@@ -385,7 +385,6 @@ class SalesInvoice(SellingController):
self.repost_future_sle_and_gle() self.repost_future_sle_and_gle()
self.db_set("status", "Cancelled") self.db_set("status", "Cancelled")
self.db_set("repost_required", 0)
if frappe.db.get_single_value("Selling Settings", "sales_update_frequency") == "Each Transaction": if frappe.db.get_single_value("Selling Settings", "sales_update_frequency") == "Each Transaction":
update_company_current_month_sales(self.company) update_company_current_month_sales(self.company)
@@ -532,24 +531,23 @@ class SalesInvoice(SellingController):
data.sales_invoice = sales_invoice data.sales_invoice = sales_invoice
def on_update_after_submit(self): def on_update_after_submit(self):
if hasattr(self, "repost_required"): fields_to_check = [
fields_to_check = [ "additional_discount_account",
"additional_discount_account", "cash_bank_account",
"cash_bank_account", "account_for_change_amount",
"account_for_change_amount", "write_off_account",
"write_off_account", "loyalty_redemption_account",
"loyalty_redemption_account", "unrealized_profit_loss_account",
"unrealized_profit_loss_account", "is_opening",
] ]
child_tables = { child_tables = {
"items": ("income_account", "expense_account", "discount_account"), "items": ("income_account", "expense_account", "discount_account"),
"taxes": ("account_head",), "taxes": ("account_head",),
} }
self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables) self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables)
if self.needs_repost: if self.needs_repost:
self.validate_for_repost() self.validate_for_repost()
self.db_set("repost_required", self.needs_repost) self.repost_accounting_entries()
self.repost_accounting_entries()
def set_paid_amount(self): def set_paid_amount(self):
paid_amount = 0.0 paid_amount = 0.0

View File

@@ -2896,9 +2896,6 @@ class TestSalesInvoice(FrappeTestCase):
check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1)) check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1))
si.load_from_db()
self.assertFalse(si.repost_required)
def test_asset_depreciation_on_sale_with_pro_rata(self): def test_asset_depreciation_on_sale_with_pro_rata(self):
""" """
Tests if an Asset set to depreciate yearly on June 30, that gets sold on Sept 30, creates an additional depreciation entry on its date of sale. Tests if an Asset set to depreciate yearly on June 30, that gets sold on Sept 30, creates an additional depreciation entry on its date of sale.

View File

@@ -2376,16 +2376,12 @@ class AccountsController(TransactionBase):
@frappe.whitelist() @frappe.whitelist()
def repost_accounting_entries(self): def repost_accounting_entries(self):
if self.repost_required: repost_ledger = frappe.new_doc("Repost Accounting Ledger")
repost_ledger = frappe.new_doc("Repost Accounting Ledger") repost_ledger.company = self.company
repost_ledger.company = self.company repost_ledger.append("vouchers", {"voucher_type": self.doctype, "voucher_no": self.name})
repost_ledger.append("vouchers", {"voucher_type": self.doctype, "voucher_no": self.name}) repost_ledger.flags.ignore_permissions = True
repost_ledger.flags.ignore_permissions = True repost_ledger.insert()
repost_ledger.insert() repost_ledger.submit()
repost_ledger.submit()
self.db_set("repost_required", 0)
else:
frappe.throw(_("No updates pending for reposting"))
@frappe.whitelist() @frappe.whitelist()