clean code
This commit is contained in:
parent
0d91d3f572
commit
bf68611567
@ -15,8 +15,6 @@ frappe.ui.form.on("Purchase Order", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
set_schedule_date(frm);
|
|
||||||
|
|
||||||
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
||||||
return erpnext.queries.warehouse(frm.doc);
|
return erpnext.queries.warehouse(frm.doc);
|
||||||
});
|
});
|
||||||
@ -109,7 +107,12 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
|||||||
},
|
},
|
||||||
|
|
||||||
validate: function() {
|
validate: function() {
|
||||||
set_schedule_date(cur_frm);
|
// set default schedule date as today if missing.
|
||||||
|
(this.frm.doc.items || []).forEach(function(d) {
|
||||||
|
if(!d.schedule_date) {
|
||||||
|
d.schedule_date = frappe.datetime.nowdate();
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
make_stock_entry: function() {
|
make_stock_entry: function() {
|
||||||
@ -198,10 +201,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
|||||||
|
|
||||||
items_add: function(doc, cdt, cdn) {
|
items_add: function(doc, cdt, cdn) {
|
||||||
var row = frappe.get_doc(cdt, cdn);
|
var row = frappe.get_doc(cdt, cdn);
|
||||||
if(doc.schedule_date) {
|
this.frm.script_manager.copy_from_first_row("items", row, ["schedule_date"]);
|
||||||
row.schedule_date = doc.schedule_date;
|
|
||||||
refresh_field("schedule_date", cdn, "items");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
unclose_purchase_order: function(){
|
unclose_purchase_order: function(){
|
||||||
@ -225,9 +225,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
|||||||
cur_frm.cscript.calculate_taxes_and_totals();
|
cur_frm.cscript.calculate_taxes_and_totals();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
|
|
||||||
items_on_form_rendered: set_schedule_date(cur_frm),
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -270,18 +268,8 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_schedule_date(frm) {
|
|
||||||
if(!frm.doc.schedule_date){
|
|
||||||
frm.doc.schedule_date = frappe.datetime.add_days(frappe.datetime.now_date(), 1);
|
|
||||||
}
|
|
||||||
erpnext.utils.copy_value_in_all_row(frm.doc, frm.doc.doctype, frm.doc.name, "items", "schedule_date");
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.schedule_date = function(doc, cdt, cdn) {
|
cur_frm.cscript.schedule_date = function(doc, cdt, cdn) {
|
||||||
var row = frappe.get_doc(cdt, cdn);
|
erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "schedule_date");
|
||||||
if(row.schedule_date){
|
|
||||||
set_schedule_date(cur_frm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frappe.provide("erpnext.buying");
|
frappe.provide("erpnext.buying");
|
||||||
|
|||||||
@ -292,37 +292,6 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_on_submit": 1,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"default": "",
|
|
||||||
"fieldname": "schedule_date",
|
|
||||||
"fieldtype": "Date",
|
|
||||||
"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": "Reqd By Date",
|
|
||||||
"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": 1,
|
|
||||||
"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,
|
||||||
|
|||||||
@ -13,18 +13,9 @@ QUnit.test("test: purchase order", function(assert) {
|
|||||||
{items: [
|
{items: [
|
||||||
[
|
[
|
||||||
{"item_code": 'Test Product 4'},
|
{"item_code": 'Test Product 4'},
|
||||||
{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 2)},
|
|
||||||
{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
|
|
||||||
{"qty": 5},
|
|
||||||
{"uom": 'Unit'},
|
|
||||||
{"rate": 100},
|
|
||||||
{"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)},
|
{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
|
||||||
{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
|
{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
|
||||||
{"qty": 2},
|
{"qty": 5},
|
||||||
{"uom": 'Unit'},
|
{"uom": 'Unit'},
|
||||||
{"rate": 100},
|
{"rate": 100},
|
||||||
{"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))}
|
{"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default("Company"))}
|
||||||
@ -39,19 +30,12 @@ QUnit.test("test: purchase order", function(assert) {
|
|||||||
() => {
|
() => {
|
||||||
// Get supplier details
|
// Get supplier details
|
||||||
assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct");
|
assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct");
|
||||||
assert.ok(cur_frm.doc.schedule_date == frappe.datetime.add_days(frappe.datetime.now_date(), 1), "Schedule Date correct");
|
|
||||||
assert.ok($('div.control-value.like-disabled-input.for-description').text().includes('Contact 3'), "Contact display correct");
|
assert.ok($('div.control-value.like-disabled-input.for-description').text().includes('Contact 3'), "Contact display correct");
|
||||||
assert.ok(cur_frm.doc.contact_email == 'test@supplier.com', "Contact email correct");
|
assert.ok(cur_frm.doc.contact_email == 'test@supplier.com', "Contact email correct");
|
||||||
// Get item details
|
// Get item details
|
||||||
assert.ok(cur_frm.doc.items[0].item_name == 'Test Product 4', "Item name correct");
|
assert.ok(cur_frm.doc.items[0].item_name == 'Test Product 4', "Item name correct");
|
||||||
assert.ok(cur_frm.doc.items[0].description == 'Test Product 4', "Description correct");
|
assert.ok(cur_frm.doc.items[0].description == 'Test Product 4', "Description correct");
|
||||||
assert.ok(cur_frm.doc.items[0].qty == 5, "Quantity correct");
|
assert.ok(cur_frm.doc.items[0].qty == 5, "Quantity correct");
|
||||||
assert.ok(cur_frm.doc.items[0].schedule_date == frappe.datetime.add_days(frappe.datetime.now_date(), 2), "Schedule Date correct");
|
|
||||||
|
|
||||||
assert.ok(cur_frm.doc.items[1].item_name == 'Test Product 1', "Item name correct");
|
|
||||||
assert.ok(cur_frm.doc.items[1].description == 'Test Product 1', "Description correct");
|
|
||||||
assert.ok(cur_frm.doc.items[1].qty == 2, "Quantity correct");
|
|
||||||
assert.ok(cur_frm.doc.items[1].schedule_date == cur_frm.doc.schedule_date, "Schedule Date correct");
|
|
||||||
// Calculate total
|
// Calculate total
|
||||||
assert.ok(cur_frm.doc.total == 500, "Total correct");
|
assert.ok(cur_frm.doc.total == 500, "Total correct");
|
||||||
// Get terms
|
// Get terms
|
||||||
|
|||||||
@ -148,7 +148,7 @@
|
|||||||
"ignore_xss_filter": 0,
|
"ignore_xss_filter": 0,
|
||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
"in_global_search": 0,
|
"in_global_search": 0,
|
||||||
"in_list_view": 1,
|
"in_list_view": 0,
|
||||||
"in_standard_filter": 0,
|
"in_standard_filter": 0,
|
||||||
"label": "Reqd By Date",
|
"label": "Reqd By Date",
|
||||||
"length": 0,
|
"length": 0,
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
# Copyright (c) 2017, Frappe and Contributors
|
|
||||||
# License: GNU General Public License v3. See license.txt
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
import frappe
|
|
||||||
|
|
||||||
def execute():
|
|
||||||
frappe.reload_doctype("Purchase Order")
|
|
||||||
frappe.reload_doctype("Purchase Order Item")
|
|
||||||
|
|
||||||
if not frappe.db.has_column("Purchase Order", "schedule_date"):
|
|
||||||
return
|
|
||||||
|
|
||||||
#Update only submitted PO
|
|
||||||
for po in frappe.get_all("Purchase Order", filters= [["docstatus", "=", 1]], fields=["name"]):
|
|
||||||
purchase_order = frappe.get_doc("Purchase Order", po)
|
|
||||||
if purchase_order.items:
|
|
||||||
if not purchase_order.schedule_date:
|
|
||||||
purchase_order.schedule_date = purchase_order.items[0].schedule_date
|
|
||||||
purchase_order.save()
|
|
||||||
Loading…
x
Reference in New Issue
Block a user