mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-15 15:45:01 +00:00
fix: set landed cost based on purchase invoice rate
(cherry picked from commit 75ab5f2bd0)
# Conflicts:
# erpnext/patches.txt
This commit is contained in:
@@ -395,9 +395,13 @@ execute:frappe.db.set_single_value("Accounts Settings", "exchange_gain_loss_post
|
||||
erpnext.patches.v14_0.disable_add_row_in_gross_profit
|
||||
erpnext.patches.v15_0.set_difference_amount_in_asset_value_adjustment
|
||||
erpnext.patches.v14_0.update_posting_datetime
|
||||
<<<<<<< HEAD
|
||||
erpnext.stock.doctype.stock_ledger_entry.patches.ensure_sle_indexes
|
||||
erpnext.patches.v15_0.update_query_report
|
||||
erpnext.patches.v15_0.rename_field_from_rate_difference_to_amount_difference
|
||||
=======
|
||||
erpnext.patches.v15_0.rename_field_from_rate_difference_to_amount_difference #2025-03-18
|
||||
>>>>>>> 75ab5f2bd0 (fix: set landed cost based on purchase invoice rate)
|
||||
erpnext.patches.v15_0.recalculate_amount_difference_field
|
||||
erpnext.patches.v15_0.rename_sla_fields #2025-03-12
|
||||
erpnext.patches.v15_0.set_purchase_receipt_row_item_to_capitalization_stock_item
|
||||
|
||||
@@ -1102,16 +1102,10 @@ def update_billing_percentage(pr_doc, update_modified=True, adjust_incoming_rate
|
||||
|
||||
if adjust_incoming_rate:
|
||||
adjusted_amt = 0.0
|
||||
item_wise_billed_qty = get_billed_qty_against_purchase_receipt(pr_doc)
|
||||
billed_qty = get_billed_qty_against_item(item.name)
|
||||
|
||||
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
|
||||
if item.billed_amt is not None and item.amount is not None and billed_qty:
|
||||
adjusted_amt = (flt(item.billed_amt / billed_qty) - flt(item.rate)) * item.qty
|
||||
|
||||
adjusted_amt = flt(adjusted_amt * flt(pr_doc.conversion_rate), item.precision("amount"))
|
||||
item.db_set("amount_difference_with_purchase_invoice", adjusted_amt, update_modified=False)
|
||||
@@ -1127,19 +1121,14 @@ def update_billing_percentage(pr_doc, update_modified=True, adjust_incoming_rate
|
||||
adjust_incoming_rate_for_pr(pr_doc)
|
||||
|
||||
|
||||
def get_billed_qty_against_purchase_receipt(pr_doc):
|
||||
pr_names = [d.name for d in pr_doc.items]
|
||||
def get_billed_qty_against_item(name):
|
||||
table = frappe.qb.DocType("Purchase Invoice Item")
|
||||
query = (
|
||||
frappe.qb.from_(table)
|
||||
.select(table.pr_detail, fn.Sum(table.qty).as_("qty"))
|
||||
.where((table.pr_detail.isin(pr_names)) & (table.docstatus == 1))
|
||||
.select(fn.Sum(table.qty).as_("qty"))
|
||||
.where((table.pr_detail == name) & (table.docstatus == 1))
|
||||
)
|
||||
invoice_data = query.run(as_list=1)
|
||||
|
||||
if not invoice_data:
|
||||
return frappe._dict()
|
||||
return frappe._dict(invoice_data)
|
||||
return query.run(as_dict=True)[0].get("qty", 0)
|
||||
|
||||
|
||||
def adjust_incoming_rate_for_pr(doc):
|
||||
|
||||
Reference in New Issue
Block a user