[get_query] to server side

This commit is contained in:
Saurabh
2013-07-09 10:08:18 +05:30
61 changed files with 478 additions and 1531 deletions

View File

@@ -231,16 +231,6 @@ class DocType(BuyingController):
else:
chk_dupl_itm.append(f)
def validate_reference_value(self, obj):
ref_doc = []
for d in getlist(obj.doclist, obj.fname):
if d.prevdoc_doctype and d.prevdoc_docname and d.prevdoc_doctype not in ref_doc:
mapper_name = d.prevdoc_doctype + '-' + obj.doc.doctype
get_obj('DocType Mapper', mapper_name, with_children = 1).\
validate_reference_value(obj, obj.doc.name)
ref_doc.append(d.prevdoc_doctype)
# Check for Stopped status
def check_for_stopped_status(self, doctype, docname):
stopped = sql("select name from `tab%s` where name = '%s' and status = 'Stopped'" %
@@ -248,7 +238,10 @@ class DocType(BuyingController):
if stopped:
msgprint("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
( doctype, docname), raise_exception=1)
def validate_reference_value(self, obj=None):
pass
# Check Docstatus of Next DocType on Cancel AND of Previous DocType on Submit
def check_docstatus(self, check, doctype, docname , detail_doctype = ''):

View File

@@ -27,8 +27,15 @@ wn.require('app/buying/doctype/purchase_common/purchase_common.js');
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
refresh: function(doc, cdt, cdn) {
this._super();
this.frm.dashboard.reset();
if(doc.docstatus == 1 && doc.status != 'Stopped'){
cur_frm.dashboard.add_progress(cint(doc.per_received) + wn._("% Received"),
doc.per_received);
cur_frm.dashboard.add_progress(cint(doc.per_billed) + wn._("% Billed"),
doc.per_billed);
cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']);
if(flt(doc.per_received, 2) < 100)
cur_frm.add_custom_button('Make Purchase Receipt', this.make_purchase_receipt);
@@ -36,20 +43,15 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
cur_frm.add_custom_button('Make Invoice', this.make_purchase_invoice);
if(flt(doc.per_billed, 2) < 100 || doc.per_received < 100)
cur_frm.add_custom_button('Stop', cur_frm.cscript['Stop Purchase Order']);
} else if(doc.docstatus===0) {
cur_frm.cscript.add_from_mappers();
}
if(doc.docstatus == 1 && doc.status == 'Stopped')
cur_frm.add_custom_button('Unstop Purchase Order',
cur_frm.cscript['Unstop Purchase Order']);
},
get_items: function() {
wn.model.map_current_doc({
method: "stock.doctype.material_request.material_request.make_purchase_order",
source_name: cur_frm.doc.indent_no,
})
},
make_purchase_receipt: function() {
wn.model.open_mapped_doc({
method: "buying.doctype.purchase_order.purchase_order.make_purchase_receipt",
@@ -64,12 +66,40 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
})
},
get_supplier_quotation_items: function() {
wn.model.map_current_doc({
method: "buying.doctype.supplier_quotation.supplier_quotation.make_purchase_order",
source_name: cur_frm.doc.supplier_quotation,
})
}
add_from_mappers: function() {
cur_frm.add_custom_button(wn._('From Material Request'),
function() {
wn.model.map_current_doc({
method: "stock.doctype.material_request.material_request.make_purchase_order",
source_doctype: "Material Request",
get_query_filters: {
material_request_type: "Purchase",
docstatus: 1,
status: ["!=", "Stopped"],
per_ordered: ["<", 99.99],
company: cur_frm.doc.company
}
})
});
cur_frm.add_custom_button(wn._('From Supplier Quotation'),
function() {
wn.model.map_current_doc({
method: "buying.doctype.supplier_quotation.supplier_quotation.make_purchase_order",
source_doctype: "Supplier Quotation",
get_query_filters: {
docstatus: 1,
status: ["!=", "Stopped"],
company: cur_frm.doc.company
}
})
});
},
tc_name: function() {
this.get_terms();
},
});
// for backward compatibility: combine new and previous states

View File

@@ -44,23 +44,13 @@ class DocType(BuyingController):
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
"Cancelled"])
# Step 2:=> get Purchase Common Obj
pc_obj = get_obj(dt='Purchase Common')
# Step 4:=> validate for items
pc_obj.validate_for_items(self)
# Get po date
pc_obj.get_prevdoc_date(self)
# validate_doc
self.validate_doc(pc_obj)
# Check for stopped status
self.check_for_stopped_status(pc_obj)
# sub-contracting
self.validate_for_subcontracting()
self.update_raw_materials_supplied("po_raw_material_details")
@@ -244,7 +234,6 @@ def make_purchase_receipt(source_name, target_doclist=None):
def make_purchase_invoice(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def set_missing_values(source, target):
bean = webnotes.bean(target)
bean.run_method("set_missing_values")
@@ -254,7 +243,8 @@ def make_purchase_invoice(source_name, target_doclist=None):
target.conversion_factor = 1
target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt)
target.amount = target.import_amount / flt(source_parent.conversion_rate)
target.qty = target.amount / flt(obj.purchase_rate)
if flt(obj.purchase_rate):
target.qty = target.amount / flt(obj.purchase_rate)
doclist = get_mapped_doclist("Purchase Order", source_name, {
"Purchase Order": {

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-05-21 16:16:39",
"docstatus": 0,
"modified": "2013-07-05 14:51:59",
"modified": "2013-07-08 17:49:29",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -183,59 +183,6 @@
"label": "Re-Calculate Values",
"oldfieldtype": "Button"
},
{
"doctype": "DocField",
"fieldname": "section_break0",
"fieldtype": "Section Break"
},
{
"description": "You can make a purchase order from multiple Material Requests. Select Material Requests one by one and click on the button below.",
"doctype": "DocField",
"fieldname": "indent_no",
"fieldtype": "Link",
"hidden": 0,
"label": "Select Material Request",
"no_copy": 1,
"oldfieldname": "indent_no",
"oldfieldtype": "Link",
"options": "Material Request",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "get_items",
"fieldtype": "Button",
"hidden": 0,
"label": "Get Items",
"no_copy": 0,
"oldfieldtype": "Button",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "column_break3",
"fieldtype": "Column Break",
"print_width": "50%",
"width": "50%"
},
{
"description": "You can make a purchase order from multiple Supplier Quotations. Select Supplier Quotations one by one and click on the button below.",
"doctype": "DocField",
"fieldname": "supplier_quotation",
"fieldtype": "Link",
"label": "Select Supplier Quotation",
"no_copy": 1,
"options": "Supplier Quotation",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "get_supplier_quotation_items",
"fieldtype": "Button",
"label": "Get Items",
"options": "get_supplier_quotation_items",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "price_list_and_currency",
@@ -269,7 +216,7 @@
"fieldtype": "Float",
"hidden": 0,
"label": "Exchange Rate",
"no_copy": 0,
"no_copy": 1,
"oldfieldname": "conversion_rate",
"oldfieldtype": "Currency",
"print_hide": 1,
@@ -541,13 +488,6 @@
"options": "Terms and Conditions",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "get_terms",
"fieldtype": "Button",
"label": "Get Terms and Conditions",
"oldfieldtype": "Button"
},
{
"doctype": "DocField",
"fieldname": "terms",

View File

@@ -32,10 +32,13 @@ class TestPurchaseOrder(unittest.TestCase):
po = webnotes.bean("Purchase Order", po.doc.name)
po.submit()
pr = make_purchase_receipt(po.doc.name)
pr[0]["supplier_warehouse"] = "_Test Warehouse 1"
self.assertEquals(pr[0]["doctype"], "Purchase Receipt")
self.assertEquals(len(pr), len(test_records[0]))
webnotes.bean(pr).insert()
def test_make_purchase_invocie(self):
from buying.doctype.purchase_order.purchase_order import make_purchase_invoice
@@ -50,10 +53,12 @@ class TestPurchaseOrder(unittest.TestCase):
self.assertEquals(pi[0]["doctype"], "Purchase Invoice")
self.assertEquals(len(pi), len(test_records[0]))
webnotes.bean(pi).insert()
def test_subcontracting(self):
po = webnotes.bean(copy=test_records[0])
po.insert()
po.insert()
self.assertEquals(len(po.doclist.get({"parentfield": "po_raw_material_details"})), 2)
def test_warehouse_company_validation(self):

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:06",
"docstatus": 0,
"modified": "2013-05-31 14:26:22",
"modified": "2013-07-08 13:51:42",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -32,7 +32,7 @@
"hidden": 0,
"in_filter": 1,
"label": "Reqd By Date",
"no_copy": 1,
"no_copy": 0,
"oldfieldname": "schedule_date",
"oldfieldtype": "Date",
"print_hide": 1,
@@ -121,7 +121,7 @@
"doctype": "DocField",
"fieldname": "import_ref_rate",
"fieldtype": "Currency",
"label": "Ref Rate ",
"label": "Price List Rate",
"options": "currency",
"print_hide": 1,
"read_only": 0

View File

@@ -29,16 +29,25 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
if (this.frm.doc.docstatus === 1) {
cur_frm.add_custom_button("Make Purchase Order", this.make_purchase_order);
}
else if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(wn._('From Material Request'),
function() {
wn.model.map_current_doc({
method: "stock.doctype.material_request.material_request.make_supplier_quotation",
source_doctype: "Material Request",
get_query_filters: {
material_request_type: "Purchase",
docstatus: 1,
status: ["!=", "Stopped"],
per_ordered: ["<", 99.99],
company: cur_frm.doc.company
}
})
});
}
},
get_items: function() {
wn.model.map_current_doc({
method: "stock.doctype.material_request.material_request.make_supplier_quotation",
source_name: cur_frm.doc.indent_no,
})
},
make_purchase_order: function() {
wn.model.open_mapped_doc({
method: "buying.doctype.supplier_quotation.supplier_quotation.make_purchase_order",

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-05-21 16:16:45",
"docstatus": 0,
"modified": "2013-07-05 14:57:12",
"modified": "2013-07-08 15:14:48",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -168,32 +168,6 @@
"label": "Re-Calculate Values",
"oldfieldtype": "Button"
},
{
"doctype": "DocField",
"fieldname": "section_break_14",
"fieldtype": "Section Break"
},
{
"description": "You can make a purchase order from multiple Material Requests. Select Material Requests one by one and click on the button below.",
"doctype": "DocField",
"fieldname": "indent_no",
"fieldtype": "Link",
"hidden": 0,
"label": "Select Material Request",
"no_copy": 1,
"oldfieldname": "indent_no",
"oldfieldtype": "Link",
"options": "Material Request",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "get_items",
"fieldtype": "Button",
"hidden": 0,
"label": "Get Items",
"oldfieldtype": "Button"
},
{
"doctype": "DocField",
"fieldname": "currency_price_list",

View File

@@ -36,6 +36,8 @@ class TestPurchaseOrder(unittest.TestCase):
self.assertEquals(po[0]["doctype"], "Purchase Order")
self.assertEquals(len(po), len(sq.doclist))
webnotes.bean(po).insert()
test_records = [
[
{
@@ -45,7 +47,7 @@ test_records = [
"doctype": "Supplier Quotation",
"fiscal_year": "_Test Fiscal Year 2013",
"transaction_date": "2013-02-12",
"is_subcontracted": "Yes",
"is_subcontracted": "No",
"supplier": "_Test Supplier",
"supplier_name": "_Test Supplier",
"net_total": 5000.0,

View File

@@ -85,7 +85,8 @@ def _get_basic_details(args, item_bean):
"item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
item_bean.doclist.get({"parentfield": "item_tax"})))),
"batch_no": None,
"expense_head": item.purchase_account,
"expense_head": item.purchase_account \
or webnotes.conn.get_value("Company", args.company, "default_expense_account"),
"cost_center": item.cost_center
})