fix: last purchase rate greater than selling price (#19617)
This commit is contained in:
parent
24cde55e28
commit
290253fdd0
@ -313,7 +313,7 @@ def item_last_purchase_rate(name, conversion_rate, item_code, conversion_factor=
|
||||
|
||||
last_purchase_details = get_last_purchase_details(item_code, name)
|
||||
if last_purchase_details:
|
||||
last_purchase_rate = (last_purchase_details['base_rate'] * (flt(conversion_factor) or 1.0)) / conversion_rate
|
||||
last_purchase_rate = (last_purchase_details['base_net_rate'] * (flt(conversion_factor) or 1.0)) / conversion_rate
|
||||
return last_purchase_rate
|
||||
else:
|
||||
item_last_purchase_rate = frappe.get_cached_value("Item", item_code, "last_purchase_rate")
|
||||
|
@ -24,12 +24,12 @@ def update_last_purchase_rate(doc, is_submit):
|
||||
last_purchase_rate = None
|
||||
if last_purchase_details and \
|
||||
(last_purchase_details.purchase_date > this_purchase_date):
|
||||
last_purchase_rate = last_purchase_details['base_rate']
|
||||
last_purchase_rate = last_purchase_details['base_net_rate']
|
||||
elif is_submit == 1:
|
||||
# even if this transaction is the latest one, it should be submitted
|
||||
# for it to be considered for latest purchase rate
|
||||
if flt(d.conversion_factor):
|
||||
last_purchase_rate = flt(d.base_rate) / flt(d.conversion_factor)
|
||||
last_purchase_rate = flt(d.base_net_rate) / flt(d.conversion_factor)
|
||||
# Check if item code is present
|
||||
# Conversion factor should not be mandatory for non itemized items
|
||||
elif d.item_code:
|
||||
|
@ -645,7 +645,7 @@ class Item(WebsiteGenerator):
|
||||
json.dumps(item_wise_tax_detail), update_modified=False)
|
||||
|
||||
def set_last_purchase_rate(self, new_name):
|
||||
last_purchase_rate = get_last_purchase_details(new_name).get("base_rate", 0)
|
||||
last_purchase_rate = get_last_purchase_details(new_name).get("base_net_rate", 0)
|
||||
frappe.db.set_value("Item", new_name, "last_purchase_rate", last_purchase_rate)
|
||||
|
||||
def recalculate_bin_qty(self, new_name):
|
||||
@ -942,7 +942,7 @@ def get_last_purchase_details(item_code, doc_name=None, conversion_rate=1.0):
|
||||
last_purchase_order = frappe.db.sql("""\
|
||||
select po.name, po.transaction_date, po.conversion_rate,
|
||||
po_item.conversion_factor, po_item.base_price_list_rate,
|
||||
po_item.discount_percentage, po_item.base_rate
|
||||
po_item.discount_percentage, po_item.base_rate, po_item.base_net_rate
|
||||
from `tabPurchase Order` po, `tabPurchase Order Item` po_item
|
||||
where po.docstatus = 1 and po_item.item_code = %s and po.name != %s and
|
||||
po.name = po_item.parent
|
||||
@ -953,7 +953,7 @@ def get_last_purchase_details(item_code, doc_name=None, conversion_rate=1.0):
|
||||
last_purchase_receipt = frappe.db.sql("""\
|
||||
select pr.name, pr.posting_date, pr.posting_time, pr.conversion_rate,
|
||||
pr_item.conversion_factor, pr_item.base_price_list_rate, pr_item.discount_percentage,
|
||||
pr_item.base_rate
|
||||
pr_item.base_rate, pr_item.base_net_rate
|
||||
from `tabPurchase Receipt` pr, `tabPurchase Receipt Item` pr_item
|
||||
where pr.docstatus = 1 and pr_item.item_code = %s and pr.name != %s and
|
||||
pr.name = pr_item.parent
|
||||
@ -984,6 +984,7 @@ def get_last_purchase_details(item_code, doc_name=None, conversion_rate=1.0):
|
||||
out = frappe._dict({
|
||||
"base_price_list_rate": flt(last_purchase.base_price_list_rate) / conversion_factor,
|
||||
"base_rate": flt(last_purchase.base_rate) / conversion_factor,
|
||||
"base_net_rate": flt(last_purchase.net_rate) / conversion_factor,
|
||||
"discount_percentage": flt(last_purchase.discount_percentage),
|
||||
"purchase_date": purchase_date
|
||||
})
|
||||
@ -992,7 +993,8 @@ def get_last_purchase_details(item_code, doc_name=None, conversion_rate=1.0):
|
||||
out.update({
|
||||
"price_list_rate": out.base_price_list_rate / conversion_rate,
|
||||
"rate": out.base_rate / conversion_rate,
|
||||
"base_rate": out.base_rate
|
||||
"base_rate": out.base_rate,
|
||||
"base_net_rate": out.base_net_rate
|
||||
})
|
||||
|
||||
return out
|
||||
|
Loading…
x
Reference in New Issue
Block a user