[fixes] remover per_ordered field and update delivered qty from perchase order via delivered by supplier -1

This commit is contained in:
Saurabh 2015-10-23 10:40:32 +05:30
parent b0ab93f779
commit 6d64fe378d
7 changed files with 67 additions and 49 deletions

View File

@ -25,7 +25,11 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
cur_frm.add_custom_button(__('Stop'), this.stop_purchase_order);
cur_frm.add_custom_button(__('Close'), this.close_purchase_order);
if(doc.is_drop_ship && doc.status!="Delivered"){
cur_frm.add_custom_button(__('Delivered By Supplier'), this.delivered_by_supplier);
}
if(flt(doc.per_billed)==0) {
cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_bank_entry);
}
@ -166,6 +170,18 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
},
close_purchase_order: function(){
cur_frm.cscript.update_status('Close', 'Closed')
},
delivered_by_supplier: function(){
return frappe.call({
method: "erpnext.buying.doctype.purchase_order.purchase_order.delivered_by_supplier",
freez: true,
args:{
purchase_order: cur_frm.doc.name
},
callback:function(r){
cur_frm.refresh();
}
})
}
});

View File

@ -1684,7 +1684,7 @@
"no_copy": 1,
"oldfieldname": "status",
"oldfieldtype": "Select",
"options": "\nDraft\nTo Receive and Bill\nTo Bill\nTo Receive\nCompleted\nStopped\nCancelled\nClosed",
"options": "\nDraft\nTo Receive and Bill\nTo Bill\nTo Receive\nCompleted\nStopped\nCancelled\nClosed\nDelivered",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
@ -2238,8 +2238,8 @@
"is_submittable": 1,
"issingle": 0,
"istable": 0,
"modified": "2015-10-20 17:52:42.822372",
"modified_by": "saurabh@erpnext.com",
"modified": "2015-10-22 19:03:10.932738",
"modified_by": "Administrator",
"module": "Buying",
"name": "Purchase Order",
"owner": "Administrator",

View File

@ -223,11 +223,10 @@ class PurchaseOrder(BuyingController):
def update_status_updater(self):
self.status_updater[0].update({
"target_parent_dt": "Sales Order",
"target_parent_field": "per_ordered",
"target_dt": "Sales Order Item",
'target_field': 'ordered_qty'
})
@frappe.whitelist()
def stop_or_unstop_purchase_orders(names, status):
if not frappe.has_permission("Purchase Order", "write"):
@ -344,4 +343,36 @@ def make_stock_entry(purchase_order, item_code):
def update_status(status, name):
po = frappe.get_doc("Purchase Order", name)
po.update_status(status)
return
return
@frappe.whitelist()
def delivered_by_supplier(purchase_order):
po = frappe.get_doc("Purchase Order", purchase_order)
update_delivered_qty(po)
po.update_status("Delivered")
return po.as_dict()
def update_delivered_qty(purchase_order):
sales_order_list = []
for item in purchase_order.items:
if item.prevdoc_doctype == "Sales Order":
frappe.db.sql(""" update `tabSales Order Item`
set delivered_qty = (ifnull(delivered_qty, 0) + %(qty)s)
where item_code='%(item_code)s' and parent = '%(name)s'
"""%{"qty": item.qty, "item_code": item.item_code, "name": item.prevdoc_docname})
sales_order_list.append(item.prevdoc_docname)
update_per_delivery(sales_order_list)
def update_per_delivery(sales_order_list):
for so in sales_order_list:
frappe.db.sql("""update `tabSales Order`
set per_delivered = (select
sum(if(qty > ifnull(delivered_qty, 0), delivered_qty, qty))/ sum(qty)*100
from `tabSales Order Item` where parent="%(name)s") where name = "%(name)s" """%{"name":so})
so = frappe.get_doc("Sales Order", so)
so.set_status(update=True)
so.notify_update()

View File

@ -6,7 +6,9 @@ frappe.listview_settings['Purchase Order'] = {
return [__("Stopped"), "darkgrey", "status,=,Stopped"];
} else if(doc.status==="Closed"){
return [__("Closed"), "green", "status,=,Closed"];
} else if(flt(doc.per_received, 2) < 100 && doc.status!=="Stopped") {
} else if (doc.status==="Delivered") {
return [__("Delivered"), "green", "status,=,Closed"];
}else if(flt(doc.per_received, 2) < 100 && doc.status!=="Stopped") {
if(flt(doc.per_billed, 2) < 100) {
return [__("To Receive and Bill"), "orange",
"per_received,<,100|per_billed,<,100|status,!=,Stopped"];

View File

@ -45,6 +45,7 @@ status_map = {
["To Bill", "eval:self.per_received == 100 and self.per_billed < 100 and self.docstatus == 1"],
["To Receive", "eval:self.per_received < 100 and self.per_billed == 100 and self.docstatus == 1"],
["Completed", "eval:self.per_received == 100 and self.per_billed == 100 and self.docstatus == 1"],
["Delivered", "eval:self.status=='Delivered'"],
["Stopped", "eval:self.status=='Stopped'"],
["Cancelled", "eval:self.docstatus==2"],
["Closed", "eval:self.status=='Closed'"],
@ -170,11 +171,12 @@ class StatusUpdater(Document):
else:
args['cond'] = ' and parent!="%s"' % self.name.replace('"', '\"')
args['set_modified'] = ''
if change_modified:
args['set_modified'] = ', modified = now(), modified_by = "{0}"'\
.format(frappe.db.escape(frappe.session.user))
args["drop_ship_cond"] = ''
self._update_children(args)
if "percent_join_field" in args:
@ -212,16 +214,6 @@ class StatusUpdater(Document):
def _update_percent_field(self, args):
"""Update percent field in parent transaction"""
unique_transactions = set([d.get(args['percent_join_field']) for d in self.get_all_children(args['source_dt'])])
args["drop_ship_cond"] = ''
if getattr(self, "is_drop_ship", None):
if self.is_drop_ship == 1:
args["drop_ship_cond"] = " and is_drop_ship=1 "
else:
if self.doctype=="Delivery Note":
args["drop_ship_cond"] = " and is_drop_ship!=1 and supplier = '' "
for name in unique_transactions:
if not name:
@ -235,7 +227,7 @@ class StatusUpdater(Document):
set %(target_parent_field)s = round((select sum(if(%(target_ref_field)s >
ifnull(%(target_field)s, 0), %(target_field)s,
%(target_ref_field)s))/sum(%(target_ref_field)s)*100
from `tab%(target_dt)s` where parent="%(name)s" %(drop_ship_cond)s), 2) %(set_modified)s
from `tab%(target_dt)s` where parent="%(name)s"), 2) %(set_modified)s
where name='%(name)s'""" % args)
# update field

View File

@ -2038,29 +2038,6 @@
"unique": 0,
"width": "100px"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "per_ordered",
"fieldtype": "Percent",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 1,
"in_list_view": 1,
"label": "% Ordered",
"no_copy": 1,
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "100px"
},
{
"allow_on_submit": 0,
"bold": 0,
@ -2578,7 +2555,7 @@
"is_submittable": 1,
"issingle": 0,
"istable": 0,
"modified": "2015-10-21 19:02:58.591057",
"modified": "2015-10-22 16:32:34.339835",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order",

View File

@ -325,8 +325,8 @@ class TestSalesOrder(unittest.TestCase):
}
]
existing_ordered_qty, existing_reserved_qty = frappe.db.get_value("Bin", {"item_code": po_item.item_code,
"warehouse": "_Test Warehouse - _TC"}, ["ordered_qty", "reserved_qty"])
existing_ordered_qty, existing_reserved_qty = frappe.db.get_value("Bin",
{"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"}, ["ordered_qty", "reserved_qty"])
so = make_sales_order(item_list=so_items, do_not_submit=True)
so.submit()
@ -344,8 +344,8 @@ class TestSalesOrder(unittest.TestCase):
self.assertEquals(dn.items[0].item_code, dn_item.item_code)
#test ordered_qty and reserved_qty
ordered_qty, reserved_qty = frappe.db.get_value("Bin", {"item_code": po_item.item_code,
"warehouse": "_Test Warehouse - _TC"}, ["ordered_qty", "reserved_qty"])
ordered_qty, reserved_qty = frappe.db.get_value("Bin",
{"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"}, ["ordered_qty", "reserved_qty"])
self.assertEquals(abs(ordered_qty), (existing_ordered_qty + so_items[0]['qty']))
self.assertEquals(abs(reserved_qty), (existing_reserved_qty + so_items[0]['qty']))