[fixes] remover per_ordered field and update delivered qty from perchase order via delivered by supplier -1
This commit is contained in:
parent
b0ab93f779
commit
6d64fe378d
@ -26,6 +26,10 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
|||||||
|
|
||||||
cur_frm.add_custom_button(__('Close'), this.close_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) {
|
if(flt(doc.per_billed)==0) {
|
||||||
cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_bank_entry);
|
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(){
|
close_purchase_order: function(){
|
||||||
cur_frm.cscript.update_status('Close', 'Closed')
|
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();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1684,7 +1684,7 @@
|
|||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"oldfieldname": "status",
|
"oldfieldname": "status",
|
||||||
"oldfieldtype": "Select",
|
"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,
|
"permlevel": 0,
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
@ -2238,8 +2238,8 @@
|
|||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"modified": "2015-10-20 17:52:42.822372",
|
"modified": "2015-10-22 19:03:10.932738",
|
||||||
"modified_by": "saurabh@erpnext.com",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Purchase Order",
|
"name": "Purchase Order",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
|
@ -223,7 +223,6 @@ class PurchaseOrder(BuyingController):
|
|||||||
def update_status_updater(self):
|
def update_status_updater(self):
|
||||||
self.status_updater[0].update({
|
self.status_updater[0].update({
|
||||||
"target_parent_dt": "Sales Order",
|
"target_parent_dt": "Sales Order",
|
||||||
"target_parent_field": "per_ordered",
|
|
||||||
"target_dt": "Sales Order Item",
|
"target_dt": "Sales Order Item",
|
||||||
'target_field': 'ordered_qty'
|
'target_field': 'ordered_qty'
|
||||||
})
|
})
|
||||||
@ -345,3 +344,35 @@ def update_status(status, name):
|
|||||||
po = frappe.get_doc("Purchase Order", name)
|
po = frappe.get_doc("Purchase Order", name)
|
||||||
po.update_status(status)
|
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()
|
||||||
|
|
@ -6,7 +6,9 @@ frappe.listview_settings['Purchase Order'] = {
|
|||||||
return [__("Stopped"), "darkgrey", "status,=,Stopped"];
|
return [__("Stopped"), "darkgrey", "status,=,Stopped"];
|
||||||
} else if(doc.status==="Closed"){
|
} else if(doc.status==="Closed"){
|
||||||
return [__("Closed"), "green", "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) {
|
if(flt(doc.per_billed, 2) < 100) {
|
||||||
return [__("To Receive and Bill"), "orange",
|
return [__("To Receive and Bill"), "orange",
|
||||||
"per_received,<,100|per_billed,<,100|status,!=,Stopped"];
|
"per_received,<,100|per_billed,<,100|status,!=,Stopped"];
|
||||||
|
@ -45,6 +45,7 @@ status_map = {
|
|||||||
["To Bill", "eval:self.per_received == 100 and self.per_billed < 100 and self.docstatus == 1"],
|
["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"],
|
["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"],
|
["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'"],
|
["Stopped", "eval:self.status=='Stopped'"],
|
||||||
["Cancelled", "eval:self.docstatus==2"],
|
["Cancelled", "eval:self.docstatus==2"],
|
||||||
["Closed", "eval:self.status=='Closed'"],
|
["Closed", "eval:self.status=='Closed'"],
|
||||||
@ -170,11 +171,12 @@ class StatusUpdater(Document):
|
|||||||
else:
|
else:
|
||||||
args['cond'] = ' and parent!="%s"' % self.name.replace('"', '\"')
|
args['cond'] = ' and parent!="%s"' % self.name.replace('"', '\"')
|
||||||
|
|
||||||
args['set_modified'] = ''
|
|
||||||
if change_modified:
|
if change_modified:
|
||||||
args['set_modified'] = ', modified = now(), modified_by = "{0}"'\
|
args['set_modified'] = ', modified = now(), modified_by = "{0}"'\
|
||||||
.format(frappe.db.escape(frappe.session.user))
|
.format(frappe.db.escape(frappe.session.user))
|
||||||
|
|
||||||
|
args["drop_ship_cond"] = ''
|
||||||
|
|
||||||
self._update_children(args)
|
self._update_children(args)
|
||||||
|
|
||||||
if "percent_join_field" in args:
|
if "percent_join_field" in args:
|
||||||
@ -213,16 +215,6 @@ class StatusUpdater(Document):
|
|||||||
"""Update percent field in parent transaction"""
|
"""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'])])
|
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:
|
for name in unique_transactions:
|
||||||
if not name:
|
if not name:
|
||||||
continue
|
continue
|
||||||
@ -235,7 +227,7 @@ class StatusUpdater(Document):
|
|||||||
set %(target_parent_field)s = round((select sum(if(%(target_ref_field)s >
|
set %(target_parent_field)s = round((select sum(if(%(target_ref_field)s >
|
||||||
ifnull(%(target_field)s, 0), %(target_field)s,
|
ifnull(%(target_field)s, 0), %(target_field)s,
|
||||||
%(target_ref_field)s))/sum(%(target_ref_field)s)*100
|
%(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)
|
where name='%(name)s'""" % args)
|
||||||
|
|
||||||
# update field
|
# update field
|
||||||
|
@ -2038,29 +2038,6 @@
|
|||||||
"unique": 0,
|
"unique": 0,
|
||||||
"width": "100px"
|
"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,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -2578,7 +2555,7 @@
|
|||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"modified": "2015-10-21 19:02:58.591057",
|
"modified": "2015-10-22 16:32:34.339835",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Sales Order",
|
"name": "Sales Order",
|
||||||
|
@ -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,
|
existing_ordered_qty, existing_reserved_qty = frappe.db.get_value("Bin",
|
||||||
"warehouse": "_Test Warehouse - _TC"}, ["ordered_qty", "reserved_qty"])
|
{"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 = make_sales_order(item_list=so_items, do_not_submit=True)
|
||||||
so.submit()
|
so.submit()
|
||||||
@ -344,8 +344,8 @@ class TestSalesOrder(unittest.TestCase):
|
|||||||
self.assertEquals(dn.items[0].item_code, dn_item.item_code)
|
self.assertEquals(dn.items[0].item_code, dn_item.item_code)
|
||||||
|
|
||||||
#test ordered_qty and reserved_qty
|
#test ordered_qty and reserved_qty
|
||||||
ordered_qty, reserved_qty = frappe.db.get_value("Bin", {"item_code": po_item.item_code,
|
ordered_qty, reserved_qty = frappe.db.get_value("Bin",
|
||||||
"warehouse": "_Test Warehouse - _TC"}, ["ordered_qty", "reserved_qty"])
|
{"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(ordered_qty), (existing_ordered_qty + so_items[0]['qty']))
|
||||||
self.assertEquals(abs(reserved_qty), (existing_reserved_qty + so_items[0]['qty']))
|
self.assertEquals(abs(reserved_qty), (existing_reserved_qty + so_items[0]['qty']))
|
||||||
|
Loading…
Reference in New Issue
Block a user