Getting last purchase price of an item (#10897)
* Added a column last purchase rate * Removed button last purchase rate * Get last purchase rate on adding an item * Added test case for last purchase rate * Replaced cur_frm with frm * Update purchase_order.js
This commit is contained in:
parent
1b61dfd9ea
commit
b79c4a9ff6
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
@ -24,6 +25,18 @@ frappe.ui.form.on("Purchase Order", {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frappe.ui.form.on("Purchase Order Item", {
|
||||||
|
item_code: function(frm) {
|
||||||
|
frappe.call({
|
||||||
|
method: "get_last_purchase_rate",
|
||||||
|
doc: frm.doc,
|
||||||
|
callback: function(r, rt) {
|
||||||
|
frm.trigger('calculate_taxes_and_totals');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
|
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
|
||||||
refresh: function(doc, cdt, cdn) {
|
refresh: function(doc, cdt, cdn) {
|
||||||
var me = this;
|
var me = this;
|
||||||
@ -214,17 +227,6 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
|||||||
|
|
||||||
delivered_by_supplier: function(){
|
delivered_by_supplier: function(){
|
||||||
cur_frm.cscript.update_status('Deliver', 'Delivered')
|
cur_frm.cscript.update_status('Deliver', 'Delivered')
|
||||||
},
|
|
||||||
|
|
||||||
get_last_purchase_rate: function() {
|
|
||||||
frappe.call({
|
|
||||||
"method": "get_last_purchase_rate",
|
|
||||||
"doc": cur_frm.doc,
|
|
||||||
callback: function(r, rt) {
|
|
||||||
cur_frm.dirty();
|
|
||||||
cur_frm.cscript.calculate_taxes_and_totals();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1206,37 +1206,6 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"depends_on": "eval:doc.docstatus===0 && (doc.items && doc.items.length)",
|
|
||||||
"fieldname": "get_last_purchase_rate",
|
|
||||||
"fieldtype": "Button",
|
|
||||||
"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": "Get last purchase rate",
|
|
||||||
"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_bulk_edit": 0,
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
@ -3458,7 +3427,7 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2017-09-19 11:22:30.190589",
|
"modified": "2017-09-22 16:11:49.856808",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Purchase Order",
|
"name": "Purchase Order",
|
||||||
|
@ -116,14 +116,13 @@ class PurchaseOrder(BuyingController):
|
|||||||
d.discount_percentage = last_purchase_details['discount_percentage']
|
d.discount_percentage = last_purchase_details['discount_percentage']
|
||||||
d.base_rate = last_purchase_details['base_rate'] * (flt(d.conversion_factor) or 1.0)
|
d.base_rate = last_purchase_details['base_rate'] * (flt(d.conversion_factor) or 1.0)
|
||||||
d.price_list_rate = d.base_price_list_rate / conversion_rate
|
d.price_list_rate = d.base_price_list_rate / conversion_rate
|
||||||
d.rate = d.base_rate / conversion_rate
|
d.last_purchase_rate = d.base_rate / conversion_rate
|
||||||
else:
|
else:
|
||||||
msgprint(_("Last purchase rate not found"))
|
|
||||||
|
|
||||||
item_last_purchase_rate = frappe.db.get_value("Item", d.item_code, "last_purchase_rate")
|
item_last_purchase_rate = frappe.db.get_value("Item", d.item_code, "last_purchase_rate")
|
||||||
if item_last_purchase_rate:
|
if item_last_purchase_rate:
|
||||||
d.base_price_list_rate = d.base_rate = d.price_list_rate \
|
d.base_price_list_rate = d.base_rate = d.price_list_rate \
|
||||||
= d.rate = item_last_purchase_rate
|
= d.last_purchase_rate = item_last_purchase_rate
|
||||||
|
|
||||||
# Check for Closed status
|
# Check for Closed status
|
||||||
def check_for_closed_status(self):
|
def check_for_closed_status(self):
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
QUnit.module('Buying');
|
||||||
|
|
||||||
|
QUnit.test("test: purchase order with last purchase rate", function(assert) {
|
||||||
|
assert.expect(5);
|
||||||
|
let done = assert.async();
|
||||||
|
|
||||||
|
frappe.run_serially([
|
||||||
|
() => {
|
||||||
|
return frappe.tests.make('Purchase Order', [
|
||||||
|
{supplier: 'Test Supplier'},
|
||||||
|
{is_subcontracted: 'No'},
|
||||||
|
{currency: 'INR'},
|
||||||
|
{items: [
|
||||||
|
[
|
||||||
|
{"item_code": 'Test Product 4'},
|
||||||
|
{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
|
||||||
|
{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
|
||||||
|
{"qty": 1},
|
||||||
|
{"rate": 800},
|
||||||
|
{"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{"item_code": 'Test Product 1'},
|
||||||
|
{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
|
||||||
|
{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
|
||||||
|
{"qty": 1},
|
||||||
|
{"rate": 400},
|
||||||
|
{"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))}
|
||||||
|
]
|
||||||
|
]}
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
|
() => {
|
||||||
|
// Get item details
|
||||||
|
assert.ok(cur_frm.doc.items[0].item_name == 'Test Product 4', "Item 1 name correct");
|
||||||
|
assert.ok(cur_frm.doc.items[1].item_name == 'Test Product 1', "Item 2 name correct");
|
||||||
|
},
|
||||||
|
|
||||||
|
() => frappe.timeout(1),
|
||||||
|
|
||||||
|
() => frappe.tests.click_button('Submit'),
|
||||||
|
() => frappe.tests.click_button('Yes'),
|
||||||
|
() => frappe.timeout(3),
|
||||||
|
|
||||||
|
() => frappe.tests.click_button('Close'),
|
||||||
|
() => frappe.timeout(1),
|
||||||
|
|
||||||
|
() => {
|
||||||
|
return frappe.tests.make('Purchase Order', [
|
||||||
|
{supplier: 'Test Supplier'},
|
||||||
|
{is_subcontracted: 'No'},
|
||||||
|
{currency: 'INR'},
|
||||||
|
{items: [
|
||||||
|
[
|
||||||
|
{"item_code": 'Test Product 4'},
|
||||||
|
{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
|
||||||
|
{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
|
||||||
|
{"qty": 1},
|
||||||
|
{"rate": 600},
|
||||||
|
{"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{"item_code": 'Test Product 1'},
|
||||||
|
{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
|
||||||
|
{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
|
||||||
|
{"qty": 1},
|
||||||
|
{"rate": 200},
|
||||||
|
{"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))}
|
||||||
|
]
|
||||||
|
]}
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
|
() => frappe.timeout(2),
|
||||||
|
|
||||||
|
// Get the last purchase rate of items
|
||||||
|
() => {
|
||||||
|
assert.ok(cur_frm.doc.items[0].last_purchase_rate == 800, "Last purchase rate of item 1 correct");
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
assert.ok(cur_frm.doc.items[1].last_purchase_rate == 400, "Last purchase rate of item 2 correct");
|
||||||
|
},
|
||||||
|
|
||||||
|
() => frappe.tests.click_button('Submit'),
|
||||||
|
() => frappe.tests.click_button('Yes'),
|
||||||
|
() => frappe.timeout(3),
|
||||||
|
|
||||||
|
() => frappe.tests.click_button('Close'),
|
||||||
|
|
||||||
|
() => frappe.timeout(1),
|
||||||
|
|
||||||
|
() => {
|
||||||
|
assert.ok(cur_frm.doc.status == 'To Receive and Bill', "Submitted successfully");
|
||||||
|
},
|
||||||
|
|
||||||
|
() => done()
|
||||||
|
]);
|
||||||
|
});
|
@ -655,6 +655,37 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_bulk_edit": 0,
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"fieldname": "last_purchase_rate",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"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": "Last Purchase Rate",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"options": "currency",
|
||||||
|
"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_bulk_edit": 0,
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
@ -1714,7 +1745,7 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2017-08-02 22:15:47.411235",
|
"modified": "2017-09-22 16:47:08.783546",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Purchase Order Item",
|
"name": "Purchase Order Item",
|
||||||
|
@ -128,3 +128,4 @@ erpnext/stock/doctype/stock_entry/tests/test_stock_entry_for_material_issue_with
|
|||||||
erpnext/stock/doctype/stock_entry/tests/test_stock_entry_for_repack.js
|
erpnext/stock/doctype/stock_entry/tests/test_stock_entry_for_repack.js
|
||||||
erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_serialize_item.js
|
erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_serialize_item.js
|
||||||
erpnext/accounts/doctype/payment_entry/tests/test_payment_against_invoice.js
|
erpnext/accounts/doctype/payment_entry/tests/test_payment_against_invoice.js
|
||||||
|
erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_last_purchase_rate.js
|
Loading…
x
Reference in New Issue
Block a user