Skip to content

Commit

Permalink
fix: Auto Insert Item Price If Missing when discount & blank UOM (bac…
Browse files Browse the repository at this point in the history
…kport #31168) (#31267)

fix: Auto Insert Item Price If Missing when discount & blank UOM (#31168)

* fix: Auto Insert Item Price If Missing when discount and blank UOM

fixes wrong item price insert when discount is used and adds uom=stock_uom instead of blank as price is converted to stock uom

* unit tests added for item with discount

I have added test  for auto_insert_price where discount is used.

* unit test issue fixed

fixed make_sales_order as some of the test that depended on it were failing due to passing of incorrect parameters.

Co-authored-by: Ankush Menat <me@ankush.dev>
(cherry picked from commit b3ccc4b)

Co-authored-by: maharshivpatel <39730881+maharshivpatel@users.noreply.github.com>
  • Loading branch information
mergify[bot] and maharshivpatel authored Jun 7, 2022
1 parent 0e53edf commit e69bff0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
24 changes: 23 additions & 1 deletion erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ def test_mix_type_product_bundle(self):

def test_auto_insert_price(self):
make_item("_Test Item for Auto Price List", {"is_stock_item": 0})
make_item("_Test Item for Auto Price List with Discount Percentage", {"is_stock_item": 0})
frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 1)

item_price = frappe.db.get_value(
Expand All @@ -798,6 +799,25 @@ def test_auto_insert_price(self):
100,
)

make_sales_order(
item_code="_Test Item for Auto Price List with Discount Percentage",
selling_price_list="_Test Price List",
price_list_rate=200,
discount_percentage=20,
)

self.assertEqual(
frappe.db.get_value(
"Item Price",
{
"price_list": "_Test Price List",
"item_code": "_Test Item for Auto Price List with Discount Percentage",
},
"price_list_rate",
),
200,
)

# do not update price list
frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 0)

Expand Down Expand Up @@ -1587,7 +1607,9 @@ def make_sales_order(**args):
"warehouse": args.warehouse,
"qty": args.qty or 10,
"uom": args.uom or None,
"rate": args.rate or 100,
"price_list_rate": args.price_list_rate or None,
"discount_percentage": args.discount_percentage or None,
"rate": args.rate or (None if args.price_list_rate else 100),
"against_blanket_order": args.against_blanket_order,
},
)
Expand Down
8 changes: 6 additions & 2 deletions erpnext/stock/get_item_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def get_basic_details(args, item, overwrite_warehouse=True):
"has_batch_no": item.has_batch_no,
"batch_no": args.get("batch_no"),
"uom": args.uom,
"stock_uom": item.stock_uom,
"min_order_qty": flt(item.min_order_qty) if args.doctype == "Material Request" else "",
"qty": flt(args.qty) or 1.0,
"stock_qty": flt(args.qty) or 1.0,
Expand All @@ -355,7 +356,7 @@ def get_basic_details(args, item, overwrite_warehouse=True):
"net_rate": 0.0,
"net_amount": 0.0,
"discount_percentage": 0.0,
"discount_amount": 0.0,
"discount_amount": flt(args.discount_amount) or 0.0,
"supplier": get_default_supplier(args, item_defaults, item_group_defaults, brand_defaults),
"update_stock": args.get("update_stock")
if args.get("doctype") in ["Sales Invoice", "Purchase Invoice"]
Expand Down Expand Up @@ -813,7 +814,9 @@ def insert_item_price(args):
):
if frappe.has_permission("Item Price", "write"):
price_list_rate = (
args.rate / args.get("conversion_factor") if args.get("conversion_factor") else args.rate
(args.rate + args.discount_amount) / args.get("conversion_factor")
if args.get("conversion_factor")
else (args.rate + args.discount_amount)
)

item_price = frappe.db.get_value(
Expand All @@ -839,6 +842,7 @@ def insert_item_price(args):
"item_code": args.item_code,
"currency": args.currency,
"price_list_rate": price_list_rate,
"uom": args.stock_uom,
}
)
item_price.insert()
Expand Down

0 comments on commit e69bff0

Please sign in to comment.