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>
This commit is contained in:
maharshivpatel 2022-05-31 19:48:30 +05:30 committed by GitHub
parent a1b7a7983a
commit b3ccc4bfb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -783,6 +783,7 @@ class TestSalesOrder(FrappeTestCase):
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(
@ -804,6 +805,25 @@ class TestSalesOrder(FrappeTestCase):
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)
@ -1659,7 +1679,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,
},
)

View File

@ -353,6 +353,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,
@ -365,7 +366,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"]
@ -823,7 +824,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(
@ -849,6 +852,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()