Skip to content

Commit

Permalink
fix: Update Existing Price List Rate not working (backport #40333) (#…
Browse files Browse the repository at this point in the history
…40526)

* fix: Update Existing Price List Rate not working (#40333)

(cherry picked from commit 09ea7ed)

# Conflicts:
#	erpnext/selling/doctype/sales_order/test_sales_order.py
#	erpnext/setup/demo_data/item.json

* chore: fix conflicts

---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Mar 19, 2024
1 parent b197c19 commit 64f1844
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
34 changes: 34 additions & 0 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,40 @@ def test_pick_list_without_rejected_materials(self):
self.assertFalse(row.warehouse == rejected_warehouse)
self.assertTrue(row.warehouse == warehouse)

def test_auto_update_price_list(self):
item = make_item(
"_Test Auto Update Price List Item",
)

frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 1)
so = make_sales_order(
item_code=item.name, currency="USD", qty=1, rate=100, price_list_rate=100, do_not_submit=True
)
so.save()

item_price = frappe.db.get_value("Item Price", {"item_code": item.name}, "price_list_rate")
self.assertEqual(item_price, 100)

so = make_sales_order(
item_code=item.name, currency="USD", qty=1, rate=200, price_list_rate=100, do_not_submit=True
)
so.save()

item_price = frappe.db.get_value("Item Price", {"item_code": item.name}, "price_list_rate")
self.assertEqual(item_price, 100)

frappe.db.set_single_value("Stock Settings", "update_existing_price_list_rate", 1)
so = make_sales_order(
item_code=item.name, currency="USD", qty=1, rate=200, price_list_rate=200, do_not_submit=True
)
so.save()

item_price = frappe.db.get_value("Item Price", {"item_code": item.name}, "price_list_rate")
self.assertEqual(item_price, 200)

frappe.db.set_single_value("Stock Settings", "update_existing_price_list_rate", 0)
frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 0)


def automatically_fetch_payment_terms(enable=1):
accounts_settings = frappe.get_doc("Accounts Settings")
Expand Down
92 changes: 92 additions & 0 deletions erpnext/setup/demo_data/item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU001",
"item_name": "T-shirt",
"valuation_rate": 400.0,
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/1484808/pexels-photo-1484808.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU002",
"valuation_rate": 300.0,
"item_name": "Laptop",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/3999538/pexels-photo-3999538.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU003",
"valuation_rate": 523.0,
"item_name": "Book",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/2422178/pexels-photo-2422178.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU004",
"valuation_rate": 725.0,
"item_name": "Smartphone",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/1647976/pexels-photo-1647976.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU005",
"valuation_rate": 222.0,
"item_name": "Sneakers",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/1598505/pexels-photo-1598505.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU006",
"valuation_rate": 420.0,
"item_name": "Coffee Mug",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/585753/pexels-photo-585753.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU007",
"valuation_rate": 375.0,
"item_name": "Television",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/8059376/pexels-photo-8059376.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU008",
"valuation_rate": 333.0,
"item_name": "Backpack",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/3731256/pexels-photo-3731256.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU009",
"valuation_rate": 700.0,
"item_name": "Headphones",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/3587478/pexels-photo-3587478.jpeg"
},
{
"doctype": "Item",
"item_group": "Demo Item Group",
"item_code": "SKU010",
"valuation_rate": 500.0,
"item_name": "Camera",
"gst_hsn_code": "999512",
"image": "https://images.pexels.com/photos/51383/photo-camera-subject-photographer-51383.jpeg"
}
]
4 changes: 3 additions & 1 deletion erpnext/stock/get_item_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,9 @@ def get_price_list_rate(args, item_doc, out=None):
price_list_rate = get_price_list_rate_for(args, item_doc.variant_of)

# insert in database
if price_list_rate is None:
if price_list_rate is None or frappe.db.get_single_value(
"Stock Settings", "update_existing_price_list_rate"
):
if args.price_list and args.rate:
insert_item_price(args)
return out
Expand Down

0 comments on commit 64f1844

Please sign in to comment.