mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 14:09:19 +00:00
Merge pull request #42330 from ruthra-kumar/fix_gross_profit_valuation_rate_for_diff_warehouse
fix: incorrect valuation rate for items from different warehouses in Gross Profit
This commit is contained in:
@@ -713,7 +713,8 @@ class GrossProfitGenerator:
|
|||||||
|
|
||||||
def get_average_buying_rate(self, row, item_code):
|
def get_average_buying_rate(self, row, item_code):
|
||||||
args = row
|
args = row
|
||||||
if item_code not in self.average_buying_rate:
|
key = (item_code, row.warehouse)
|
||||||
|
if key not in self.average_buying_rate:
|
||||||
args.update(
|
args.update(
|
||||||
{
|
{
|
||||||
"voucher_type": row.parenttype,
|
"voucher_type": row.parenttype,
|
||||||
@@ -727,9 +728,9 @@ class GrossProfitGenerator:
|
|||||||
args.update({"serial_and_batch_bundle": row.serial_and_batch_bundle})
|
args.update({"serial_and_batch_bundle": row.serial_and_batch_bundle})
|
||||||
|
|
||||||
average_buying_rate = get_incoming_rate(args)
|
average_buying_rate = get_incoming_rate(args)
|
||||||
self.average_buying_rate[item_code] = flt(average_buying_rate)
|
self.average_buying_rate[key] = flt(average_buying_rate)
|
||||||
|
|
||||||
return self.average_buying_rate[item_code]
|
return self.average_buying_rate[key]
|
||||||
|
|
||||||
def get_last_purchase_rate(self, item_code, row):
|
def get_last_purchase_rate(self, item_code, row):
|
||||||
purchase_invoice = frappe.qb.DocType("Purchase Invoice")
|
purchase_invoice = frappe.qb.DocType("Purchase Invoice")
|
||||||
|
|||||||
@@ -558,3 +558,50 @@ class TestGrossProfit(FrappeTestCase):
|
|||||||
}
|
}
|
||||||
gp_entry = [x for x in data if x.parent_invoice == sinv.name]
|
gp_entry = [x for x in data if x.parent_invoice == sinv.name]
|
||||||
self.assertEqual(gp_entry[0], gp_entry[0] | expected_entry)
|
self.assertEqual(gp_entry[0], gp_entry[0] | expected_entry)
|
||||||
|
|
||||||
|
def test_valuation_rate_without_previous_sle(self):
|
||||||
|
"""
|
||||||
|
Test Valuation rate calculation when stock ledger is empty and invoices are against different warehouses
|
||||||
|
"""
|
||||||
|
stock_settings = frappe.get_doc("Stock Settings")
|
||||||
|
stock_settings.valuation_method = "FIFO"
|
||||||
|
stock_settings.save()
|
||||||
|
|
||||||
|
item = create_item(
|
||||||
|
item_code="_Test Wirebound Notebook",
|
||||||
|
is_stock_item=1,
|
||||||
|
)
|
||||||
|
item.allow_negative_stock = True
|
||||||
|
item.save()
|
||||||
|
self.item = item.item_code
|
||||||
|
|
||||||
|
item.reload()
|
||||||
|
item.valuation_rate = 1900
|
||||||
|
item.save()
|
||||||
|
sinv1 = self.create_sales_invoice(qty=1, rate=2000, posting_date=nowdate(), do_not_submit=True)
|
||||||
|
sinv1.update_stock = 1
|
||||||
|
sinv1.set_warehouse = self.warehouse
|
||||||
|
sinv1.items[0].warehouse = self.warehouse
|
||||||
|
sinv1.save().submit()
|
||||||
|
|
||||||
|
item.reload()
|
||||||
|
item.valuation_rate = 1800
|
||||||
|
item.save()
|
||||||
|
sinv2 = self.create_sales_invoice(qty=1, rate=2000, posting_date=nowdate(), do_not_submit=True)
|
||||||
|
sinv2.update_stock = 1
|
||||||
|
sinv2.set_warehouse = self.finished_warehouse
|
||||||
|
sinv2.items[0].warehouse = self.finished_warehouse
|
||||||
|
sinv2.save().submit()
|
||||||
|
|
||||||
|
filters = frappe._dict(
|
||||||
|
company=self.company, from_date=nowdate(), to_date=nowdate(), group_by="Invoice"
|
||||||
|
)
|
||||||
|
columns, data = execute(filters=filters)
|
||||||
|
|
||||||
|
item_from_sinv1 = [x for x in data if x.parent_invoice == sinv1.name]
|
||||||
|
self.assertEqual(len(item_from_sinv1), 1)
|
||||||
|
self.assertEqual(1900, item_from_sinv1[0].valuation_rate)
|
||||||
|
|
||||||
|
item_from_sinv2 = [x for x in data if x.parent_invoice == sinv2.name]
|
||||||
|
self.assertEqual(len(item_from_sinv2), 1)
|
||||||
|
self.assertEqual(1800, item_from_sinv2[0].valuation_rate)
|
||||||
|
|||||||
Reference in New Issue
Block a user