Checkbox in Price list for Price not UOM dependant (#11836)
* checkbox price not uom dependant
* change price list rate on uom dependancy condition
* test case
* Update get_item_details.py
diff --git a/erpnext/stock/doctype/price_list/price_list.json b/erpnext/stock/doctype/price_list/price_list.json
index be6673e..d160f8a 100644
--- a/erpnext/stock/doctype/price_list/price_list.json
+++ b/erpnext/stock/doctype/price_list/price_list.json
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
+ "allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 1,
"autoname": "field:price_list_name",
@@ -14,6 +15,7 @@
"engine": "InnoDB",
"fields": [
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -43,6 +45,7 @@
"unique": 0
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -70,6 +73,7 @@
"unique": 0
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -100,6 +104,7 @@
"unique": 0
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -129,6 +134,7 @@
"unique": 0
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -157,6 +163,7 @@
"unique": 0
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -185,6 +192,37 @@
"unique": 0
},
{
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "price_not_uom_dependant",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Price Not UOM Dependant",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -212,6 +250,7 @@
"unique": 0
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -242,18 +281,18 @@
"unique": 0
}
],
+ "has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"icon": "fa fa-tags",
"idx": 1,
"image_view": 0,
"in_create": 0,
- "in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 1,
- "modified": "2017-02-20 13:27:30.431064",
+ "modified": "2017-12-01 16:55:00.243382",
"modified_by": "Administrator",
"module": "Stock",
"name": "Price List",
diff --git a/erpnext/stock/doctype/price_list/test_price_list.js b/erpnext/stock/doctype/price_list/test_price_list.js
new file mode 100644
index 0000000..fe4e07b
--- /dev/null
+++ b/erpnext/stock/doctype/price_list/test_price_list.js
@@ -0,0 +1,23 @@
+/* eslint-disable */
+// rename this file from _test_[name] to test_[name] to activate
+// and remove above this line
+
+QUnit.test("test: Price List", function (assert) {
+ let done = assert.async();
+
+ // number of asserts
+ assert.expect(1);
+
+ frappe.run_serially([
+ // insert a new Price List
+ () => frappe.tests.make('Price List', [
+ // values to be set
+ {key: 'value'}
+ ]),
+ () => {
+ assert.equal(cur_frm.doc.key, 'value');
+ },
+ () => done()
+ ]);
+
+});
diff --git a/erpnext/stock/doctype/price_list/test_price_list_uom.js b/erpnext/stock/doctype/price_list/test_price_list_uom.js
new file mode 100644
index 0000000..526d0da
--- /dev/null
+++ b/erpnext/stock/doctype/price_list/test_price_list_uom.js
@@ -0,0 +1,58 @@
+QUnit.module('Price List');
+
+QUnit.test("test price list with uom dependancy", function(assert) {
+ assert.expect(2);
+ let done = assert.async();
+ frappe.run_serially([
+
+ () => frappe.set_route('Form', 'Price List', 'Standard Buying'),
+ () => {
+ cur_frm.set_value('price_not_uom_dependant','1');
+ frappe.timeout(1);
+ },
+ () => cur_frm.save(),
+
+ () => frappe.timeout(1),
+
+ () => {
+ return frappe.tests.make('Item Price', [
+ {price_list:'Standard Buying'},
+ {item_code: 'Test Product 3'},
+ {price_list_rate: 200}
+ ]);
+ },
+
+ () => cur_frm.save(),
+
+ () => {
+ return frappe.tests.make('Purchase Order', [
+ {supplier: 'Test Supplier'},
+ {currency: 'INR'},
+ {buying_price_list: 'Standard Buying'},
+ {items: [
+ [
+ {"item_code": 'Test Product 3'},
+ {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 2)},
+ {"uom": 'Nos'},
+ {"conversion_factor": 3}
+ ]
+ ]},
+
+ ]);
+ },
+
+ () => cur_frm.save(),
+ () => frappe.timeout(0.3),
+
+ () => {
+ assert.ok(cur_frm.doc.items[0].item_name == 'Test Product 3', "Item code correct");
+ assert.ok(cur_frm.doc.items[0].price_list_rate == 200, "Price list rate correct");
+ },
+
+ () => frappe.tests.click_button('Submit'),
+ () => frappe.tests.click_button('Yes'),
+ () => frappe.timeout(1),
+
+ () => done()
+ ]);
+});
\ No newline at end of file
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 790be71..2ceed97 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -155,6 +155,7 @@
"conversion_rate": 1.0,
"selling_price_list": None,
"price_list_currency": None,
+ "price_list_uom_dependant": None,
"plc_conversion_rate": 1.0,
"doctype": "",
"name": "",
@@ -311,8 +312,8 @@
out.price_list_rate = flt(price_list_rate) * flt(args.plc_conversion_rate) \
/ flt(args.conversion_rate)
-
- out.price_list_rate = flt(out.price_list_rate * (args.conversion_factor or 1.0))
+ if args.price_list_uom_dependant == 0:
+ out.price_list_rate = flt(out.price_list_rate * (args.conversion_factor or 1.0))
if not out.price_list_rate and args.transaction_type=="buying":
from erpnext.stock.doctype.item.item import get_last_purchase_details
@@ -504,6 +505,7 @@
"conversion_rate": 1.0,
"selling_price_list": None,
"price_list_currency": None,
+ "price_list_uom_dependant": None,
"plc_conversion_rate": 1.0,
"doctype": "",
"name": "",
@@ -530,7 +532,7 @@
children.append(item_details)
if as_doc:
- args.price_list_currency = parent.price_list_currency
+ args.price_list_currency = parent.price_list_currency,
args.plc_conversion_rate = parent.plc_conversion_rate
if args.get('items'):
for i, item in enumerate(args.get('items')):
@@ -565,11 +567,23 @@
return result.currency
+def get_price_list_uom_dependant(price_list):
+ if price_list:
+ result = frappe.db.get_value("Price List", {"name": price_list,
+ "enabled": 1}, ["name", "price_not_uom_dependant"], as_dict=True)
+
+ if not result:
+ throw(_("Price List {0} is disabled or does not exist").format(price_list))
+
+ return result.price_not_uom_dependant
+
+
def get_price_list_currency_and_exchange_rate(args):
if not args.price_list:
return {}
price_list_currency = get_price_list_currency(args.price_list)
+ price_list_uom_dependant = get_price_list_uom_dependant(args.price_list)
plc_conversion_rate = args.plc_conversion_rate
if (not plc_conversion_rate) or (price_list_currency and args.price_list_currency \
@@ -580,6 +594,7 @@
return frappe._dict({
"price_list_currency": price_list_currency,
+ "price_list_uom_dependant": price_list_uom_dependant,
"plc_conversion_rate": plc_conversion_rate
})
diff --git a/erpnext/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt
index 3c3a8ac..6a0399c 100644
--- a/erpnext/tests/ui/tests.txt
+++ b/erpnext/tests/ui/tests.txt
@@ -140,6 +140,7 @@
erpnext/selling/doctype/sales_order/tests/test_sales_order_with_margin.js
erpnext/selling/doctype/quotation/tests/test_quotation_with_margin.js
erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_margin.js
+erpnext/stock/doctype/price_list/test_price_list_uom.js
erpnext/agriculture/doctype/land_unit/test_land_unit.js
erpnext/agriculture/doctype/fertilizer/test_fertilizer.js
erpnext/agriculture/doctype/water_analysis/test_water_analysis.js
@@ -153,4 +154,4 @@
erpnext/non_profit/doctype/volunteer/test_volunteer.js
erpnext/non_profit/doctype/donor_type/test_donor_type.js
erpnext/non_profit/doctype/donor/test_donor.js
-erpnext/non_profit/doctype/grant_application/test_grant_application.js
\ No newline at end of file
+erpnext/non_profit/doctype/grant_application/test_grant_application.js