Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rounding of percentage fields #36167

Merged
merged 1 commit into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions erpnext/buying/doctype/purchase_order/purchase_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ frappe.ui.form.on("Purchase Order", {
get_materials_from_supplier: function(frm) {
let po_details = [];

if (frm.doc.supplied_items && (frm.doc.per_received == 100 || frm.doc.status === 'Closed')) {
if (frm.doc.supplied_items && (flt(frm.doc.per_received, 2) == 100 || frm.doc.status === 'Closed')) {
frm.doc.supplied_items.forEach(d => {
if (d.total_supplied_qty && d.total_supplied_qty != d.consumed_qty) {
po_details.push(d.name)
Expand Down Expand Up @@ -181,7 +181,7 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e
}

if(!in_list(["Closed", "Delivered"], doc.status)) {
if(this.frm.doc.status !== 'Closed' && flt(this.frm.doc.per_received) < 100 && flt(this.frm.doc.per_billed) < 100) {
if(this.frm.doc.status !== 'Closed' && flt(this.frm.doc.per_received, 2) < 100 && flt(this.frm.doc.per_billed, 2) < 100) {
// Don't add Update Items button if the PO is following the new subcontracting flow.
if (!(this.frm.doc.is_subcontracted && !this.frm.doc.is_old_subcontracting_flow)) {
this.frm.add_custom_button(__('Update Items'), () => {
Expand All @@ -195,7 +195,7 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e
}
}
if (this.frm.has_perm("submit")) {
if(flt(doc.per_billed, 6) < 100 || flt(doc.per_received, 6) < 100) {
if(flt(doc.per_billed, 2) < 100 || flt(doc.per_received, 2) < 100) {
if (doc.status != "On Hold") {
this.frm.add_custom_button(__('Hold'), () => this.hold_purchase_order(), __("Status"));
} else{
Expand All @@ -218,7 +218,7 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e
}
if(doc.status != "Closed") {
if (doc.status != "On Hold") {
if(flt(doc.per_received) < 100 && allow_receipt) {
if(flt(doc.per_received, 2) < 100 && allow_receipt) {
cur_frm.add_custom_button(__('Purchase Receipt'), this.make_purchase_receipt, __('Create'));
if (doc.is_subcontracted) {
if (doc.is_old_subcontracting_flow) {
Expand All @@ -231,19 +231,19 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e
}
}
}
if(flt(doc.per_billed) < 100)
if(flt(doc.per_billed, 2) < 100)
cur_frm.add_custom_button(__('Purchase Invoice'),
this.make_purchase_invoice, __('Create'));

if(flt(doc.per_billed) < 100 && doc.status != "Delivered") {
if(flt(doc.per_billed, 2) < 100 && doc.status != "Delivered") {
this.frm.add_custom_button(
__('Payment'),
() => this.make_payment_entry(),
__('Create')
);
}

if(flt(doc.per_billed) < 100) {
if(flt(doc.per_billed, 2) < 100) {
this.frm.add_custom_button(__('Payment Request'),
function() { me.make_payment_request() }, __('Create'));
}
Expand Down
6 changes: 4 additions & 2 deletions erpnext/controllers/website_list_for_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ def post_process(doctype, data):
)

if doc.get("per_delivered"):
doc.status_percent += flt(doc.per_delivered)
doc.status_percent += flt(doc.per_delivered, 2)
doc.status_display.append(
_("Delivered") if doc.per_delivered == 100 else _("{0}% Delivered").format(doc.per_delivered)
_("Delivered")
if flt(doc.per_delivered, 2) == 100
else _("{0}% Delivered").format(doc.per_delivered)
)

if hasattr(doc, "set_indicator"):
Expand Down
4 changes: 3 additions & 1 deletion erpnext/patches/v12_0/update_bom_in_so_mr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ def execute():
frappe.reload_doc("selling", "doctype", "sales_order_item")

for doctype in ["Sales Order", "Material Request"]:
condition = " and child_doc.stock_qty > child_doc.produced_qty and doc.per_delivered < 100"
condition = (
" and child_doc.stock_qty > child_doc.produced_qty and ROUND(doc.per_delivered, 2) < 100"
)
if doctype == "Material Request":
condition = " and doc.per_ordered < 100 and doc.material_request_type = 'Manufacture'"

Expand Down
14 changes: 7 additions & 7 deletions erpnext/selling/doctype/sales_order/sales_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ frappe.ui.form.on("Sales Order", {

refresh: function(frm) {
if(frm.doc.docstatus === 1) {
if (frm.doc.status !== 'Closed' && flt(frm.doc.per_delivered, 6) < 100 && flt(frm.doc.per_billed, 6) < 100) {
if (frm.doc.status !== 'Closed' && flt(frm.doc.per_delivered, 2) < 100 && flt(frm.doc.per_billed, 2) < 100) {
frm.add_custom_button(__('Update Items'), () => {
erpnext.utils.update_child_items({
frm: frm,
Expand Down Expand Up @@ -307,7 +307,7 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
me.frm.cscript.update_status('Resume', 'Draft')
}, __("Status"));

if(flt(doc.per_delivered, 6) < 100 || flt(doc.per_billed) < 100) {
if(flt(doc.per_delivered, 2) < 100 || flt(doc.per_billed, 2) < 100) {
// close
this.frm.add_custom_button(__('Close'), () => this.close_sales_order(), __("Status"))
}
Expand All @@ -325,15 +325,15 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
&& !this.frm.doc.skip_delivery_note

if (this.frm.has_perm("submit")) {
if(flt(doc.per_delivered, 6) < 100 || flt(doc.per_billed) < 100) {
if(flt(doc.per_delivered, 2) < 100 || flt(doc.per_billed, 2) < 100) {
// hold
this.frm.add_custom_button(__('Hold'), () => this.hold_sales_order(), __("Status"))
// close
this.frm.add_custom_button(__('Close'), () => this.close_sales_order(), __("Status"))
}
}

if (flt(doc.per_picked, 6) < 100 && flt(doc.per_delivered, 6) < 100) {
if (flt(doc.per_picked, 2) < 100 && flt(doc.per_delivered, 2) < 100) {
this.frm.add_custom_button(__('Pick List'), () => this.create_pick_list(), __('Create'));
}

Expand All @@ -343,18 +343,18 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
const order_is_a_custom_sale = ["Sales", "Shopping Cart", "Maintenance"].indexOf(doc.order_type) === -1;

// delivery note
if(flt(doc.per_delivered, 6) < 100 && (order_is_a_sale || order_is_a_custom_sale) && allow_delivery) {
if(flt(doc.per_delivered, 2) < 100 && (order_is_a_sale || order_is_a_custom_sale) && allow_delivery) {
this.frm.add_custom_button(__('Delivery Note'), () => this.make_delivery_note_based_on_delivery_date(), __('Create'));
this.frm.add_custom_button(__('Work Order'), () => this.make_work_order(), __('Create'));
}

// sales invoice
if(flt(doc.per_billed, 6) < 100) {
if(flt(doc.per_billed, 2) < 100) {
this.frm.add_custom_button(__('Sales Invoice'), () => me.make_sales_invoice(), __('Create'));
}

// material request
if(!doc.order_type || (order_is_a_sale || order_is_a_custom_sale) && flt(doc.per_delivered, 6) < 100) {
if(!doc.order_type || (order_is_a_sale || order_is_a_custom_sale) && flt(doc.per_delivered, 2) < 100) {
this.frm.add_custom_button(__('Material Request'), () => this.make_material_request(), __('Create'));
this.frm.add_custom_button(__('Request for Raw Materials'), () => this.make_raw_material_request(), __('Create'));
}
Expand Down
10 changes: 5 additions & 5 deletions erpnext/selling/doctype/sales_order/sales_order_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ frappe.listview_settings['Sales Order'] = {
return [__("On Hold"), "orange", "status,=,On Hold"];
} else if (doc.status === "Completed") {
return [__("Completed"), "green", "status,=,Completed"];
} else if (!doc.skip_delivery_note && flt(doc.per_delivered, 6) < 100) {
} else if (!doc.skip_delivery_note && flt(doc.per_delivered, 2) < 100) {
if (frappe.datetime.get_diff(doc.delivery_date) < 0) {
// not delivered & overdue
return [__("Overdue"), "red",
Expand All @@ -19,7 +19,7 @@ frappe.listview_settings['Sales Order'] = {
// not delivered (zeroount order)
return [__("To Deliver"), "orange",
"per_delivered,<,100|grand_total,=,0|status,!=,Closed"];
} else if (flt(doc.per_billed, 6) < 100) {
} else if (flt(doc.per_billed, 2) < 100) {
// not delivered & not billed
return [__("To Deliver and Bill"), "orange",
"per_delivered,<,100|per_billed,<,100|status,!=,Closed"];
Expand All @@ -28,12 +28,12 @@ frappe.listview_settings['Sales Order'] = {
return [__("To Deliver"), "orange",
"per_delivered,<,100|per_billed,=,100|status,!=,Closed"];
}
} else if ((flt(doc.per_delivered, 6) === 100) && flt(doc.grand_total) !== 0
&& flt(doc.per_billed, 6) < 100) {
} else if ((flt(doc.per_delivered, 2) === 100) && flt(doc.grand_total) !== 0
&& flt(doc.per_billed, 2) < 100) {
// to bill
return [__("To Bill"), "orange",
"per_delivered,=,100|per_billed,<,100|status,!=,Closed"];
} else if (doc.skip_delivery_note && flt(doc.per_billed, 6) < 100){
} else if (doc.skip_delivery_note && flt(doc.per_billed, 2) < 100){
return [__("To Bill"), "orange", "per_billed,<,100|status,!=,Closed"];
}
},
Expand Down
2 changes: 1 addition & 1 deletion erpnext/templates/form_grid/item_grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
title = "Warehouse",
actual_qty = (frm.doc.doctype==="Sales Order"
? doc.projected_qty : doc.actual_qty);
if(flt(frm.doc.per_delivered) < 100
if(flt(frm.doc.per_delivered, 2) < 100
&& in_list(["Sales Order Item", "Delivery Note Item"], doc.doctype)) {
if(actual_qty != undefined) {
if(actual_qty >= doc.qty) {
Expand Down