From a09c57f0d1429d737a2819cd5b6ea87b44843fbb Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Mon, 17 Feb 2025 20:20:17 +0530 Subject: [PATCH] fix: revert last commit (cherry picked from commit 154e9813c4f27c2a7d51b133fd89cdfbaa1f1477) # Conflicts: # erpnext/patches.txt --- erpnext/patches.txt | 8 ++++ .../recalculate_amount_difference_field.py | 45 ++++++++++--------- ...om_rate_difference_to_amount_difference.py | 1 - 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 34794556022..604f0ff6141 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -262,10 +262,13 @@ erpnext.patches.v14_0.clear_reconciliation_values_from_singles execute:frappe.rename_doc("Report", "TDS Payable Monthly", "Tax Withholding Details", force=True) erpnext.patches.v14_0.update_proprietorship_to_individual <<<<<<< HEAD +<<<<<<< HEAD erpnext.patches.v15_0.rename_subcontracting_fields ======= erpnext.stock.doctype.purchase_receipt_item.patches.rename_field_from_rate_difference_to_amount_difference >>>>>>> 17d415b105 (fix: set landed cost based on purchase invoice rate) +======= +>>>>>>> 154e9813c4 (fix: revert last commit) [post_model_sync] erpnext.patches.v15_0.create_asset_depreciation_schedules_from_assets @@ -398,6 +401,7 @@ erpnext.patches.v15_0.sync_auto_reconcile_config execute:frappe.db.set_single_value("Accounts Settings", "exchange_gain_loss_posting_date", "Payment") erpnext.patches.v14_0.disable_add_row_in_gross_profit <<<<<<< HEAD +<<<<<<< HEAD erpnext.patches.v15_0.set_difference_amount_in_asset_value_adjustment erpnext.patches.v14_0.update_posting_datetime erpnext.stock.doctype.stock_ledger_entry.patches.ensure_sle_indexes @@ -406,3 +410,7 @@ erpnext.patches.v15_0.update_query_report ======= erpnext.stock.doctype.purchase_receipt_item.patches.recalculate_amount_difference_field >>>>>>> 17d415b105 (fix: set landed cost based on purchase invoice rate) +======= +erpnext.stock.doctype.purchase_receipt_item.patches.rename_field_from_rate_difference_to_amount_difference +erpnext.stock.doctype.purchase_receipt_item.patches.recalculate_amount_difference_field +>>>>>>> 154e9813c4 (fix: revert last commit) diff --git a/erpnext/stock/doctype/purchase_receipt_item/patches/recalculate_amount_difference_field.py b/erpnext/stock/doctype/purchase_receipt_item/patches/recalculate_amount_difference_field.py index 0222388d270..fc904baa927 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/patches/recalculate_amount_difference_field.py +++ b/erpnext/stock/doctype/purchase_receipt_item/patches/recalculate_amount_difference_field.py @@ -27,30 +27,35 @@ def execute(): ) if fiscal_year_dates := get_fiscal_year(frappe.utils.datetime.date.today(), raise_on_missing=False): query.where(parent.posting_date.between(fiscal_year_dates[1], fiscal_year_dates[2])) - result = query.run(as_dict=True) - item_wise_billed_qty = get_billed_qty_against_purchase_receipt([item.name for item in result]) + if result := query.run(as_dict=True): + item_wise_billed_qty = get_billed_qty_against_purchase_receipt([item.name for item in result]) - for item in result: - adjusted_amt = 0.0 + for item in result: + adjusted_amt = 0.0 - if item.billed_amt is not None and item.amount is not None and item_wise_billed_qty.get(item.name): - adjusted_amt = ( - flt(item.billed_amt / item_wise_billed_qty.get(item.name)) - flt(item.rate) - ) * item.qty - adjusted_amt = flt( - adjusted_amt * flt(item.conversion_rate), frappe.get_precision("Purchase Receipt Item", "amount") - ) - - if adjusted_amt != item.amount_difference_with_purchase_invoice: - frappe.db.set_value( - "Purchase Receipt Item", - item.name, - "amount_difference_with_purchase_invoice", - adjusted_amt, - update_modified=False, + if ( + item.billed_amt is not None + and item.amount is not None + and item_wise_billed_qty.get(item.name) + ): + adjusted_amt = ( + flt(item.billed_amt / item_wise_billed_qty.get(item.name)) - flt(item.rate) + ) * item.qty + adjusted_amt = flt( + adjusted_amt * flt(item.conversion_rate), + frappe.get_precision("Purchase Receipt Item", "amount"), ) - adjust_incoming_rate_for_pr(frappe.get_doc("Purchase Receipt", item.parent)) + + if adjusted_amt != item.amount_difference_with_purchase_invoice: + frappe.db.set_value( + "Purchase Receipt Item", + item.name, + "amount_difference_with_purchase_invoice", + adjusted_amt, + update_modified=False, + ) + adjust_incoming_rate_for_pr(frappe.get_doc("Purchase Receipt", item.parent)) def get_billed_qty_against_purchase_receipt(pr_names): diff --git a/erpnext/stock/doctype/purchase_receipt_item/patches/rename_field_from_rate_difference_to_amount_difference.py b/erpnext/stock/doctype/purchase_receipt_item/patches/rename_field_from_rate_difference_to_amount_difference.py index ce802b029da..44c8c49cba8 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/patches/rename_field_from_rate_difference_to_amount_difference.py +++ b/erpnext/stock/doctype/purchase_receipt_item/patches/rename_field_from_rate_difference_to_amount_difference.py @@ -13,6 +13,5 @@ def execute(): "Purchase Receipt Item", "rate_difference_with_purchase_invoice", "amount_difference_with_purchase_invoice", - validate=False, ) frappe.clear_cache(doctype="Purchase Receipt Item")