Skip to content

Commit

Permalink
feat: Dialog to select alternative item before creating Sales order
Browse files Browse the repository at this point in the history
- Users can leave the row blank in the dialog if original item is to be used
- Else users can select an alternative item against an original item
- In the document, users must check `Is Alternative Item` if needed and also specify which item it is an altenrative to since there are no documented mappings
  • Loading branch information
marination committed Jan 26, 2023
1 parent f19eada commit cef7dfd
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
2 changes: 1 addition & 1 deletion erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, doc: Document):

def filter_rows(self):
"""Exclude rows, that do not fulfill the filter criteria, from totals computation."""
items = list(filter(lambda item: not item.get("is_alternative_item"), self.doc.get("items")))
items = list(filter(lambda item: not item.get("is_alternative"), self.doc.get("items")))
return items

def calculate(self):
Expand Down
2 changes: 1 addition & 1 deletion erpnext/public/js/controllers/taxes_and_totals.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,6 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
}

filtered_items() {
return this.frm.doc.items.filter(item => !item["is_alternative_item"]);
return this.frm.doc.items.filter(item => !item["is_alternative"]);
}
};
79 changes: 78 additions & 1 deletion erpnext/selling/doctype/quotation/quotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ erpnext.selling.QuotationController = class QuotationController extends erpnext.
if (doc.docstatus == 1 && !["Lost", "Ordered"].includes(doc.status)) {
this.frm.add_custom_button(
__("Sales Order"),
this.frm.cscript["Make Sales Order"],
() => this.make_sales_order(),
__("Create")
);

Expand Down Expand Up @@ -141,6 +141,20 @@ erpnext.selling.QuotationController = class QuotationController extends erpnext.

}

make_sales_order() {
var me = this;

let has_alternative_item = this.frm.doc.items.some((item) => item.is_alternative);
if (has_alternative_item) {
this.show_alternative_item_dialog();
} else {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.quotation.quotation.make_sales_order",
frm: me.frm
});
}
}

set_dynamic_field_label(){
if (this.frm.doc.quotation_to == "Customer")
{
Expand Down Expand Up @@ -216,6 +230,69 @@ erpnext.selling.QuotationController = class QuotationController extends erpnext.
}
})
}

show_alternative_item_dialog() {
// Create a `{original item: [alternate items]}` map
const item_alt_map = {};
this.frm.doc.items.filter(
(item) => item.is_alternative
).forEach((item) =>
(item_alt_map[item.alternative_to] ??= []).push(item.item_code)
)

const fields = [{
fieldtype:"Link",
fieldname:"original_item",
options: "Item",
label: __("Original Item"),
read_only: 1,
in_list_view: 1,
},
{
fieldtype:"Link",
fieldname:"alternative_item",
options: "Item",
label: __("Alternative Item"),
in_list_view: 1,
get_query: (row, cdt, cdn) => {
return {
filters: {
"item_code": ["in", item_alt_map[row.original_item]]
}
}
},
}];

this.data = Object.keys(item_alt_map).map((item) => {
return {"original_item": item}
});

const dialog = new frappe.ui.Dialog({
title: __("Select Alternatives for Sales Order"),
fields: [
{
fieldname: "alternative_items",
fieldtype: "Table",
label: "Items with Alternatives",
cannot_add_rows: true,
in_place_edit: true,
reqd: 1,
data: this.data,
description: __("Select an alternative to be used in the Sales Order or leave it blank to use the original item."),
get_data: () => {
return this.data;
},
fields: fields
},
],
primary_action: function() {
this.hide();
},
primary_action_label: __('Continue')
});

dialog.show();
}
};

cur_frm.script_manager.make(erpnext.selling.QuotationController);
Expand Down
18 changes: 14 additions & 4 deletions erpnext/selling/doctype/quotation_item/quotation_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"pricing_rules",
"stock_uom_rate",
"is_free_item",
"is_alternative_item",
"is_alternative",
"alternative_to",
"section_break_43",
"valuation_rate",
"column_break_45",
Expand Down Expand Up @@ -647,16 +648,25 @@
},
{
"default": "0",
"fieldname": "is_alternative_item",
"fieldname": "is_alternative",
"fieldtype": "Check",
"label": "Is Alternative Item",
"label": "Is Alternative",
"print_hide": 1
},
{
"depends_on": "is_alternative",
"fieldname": "alternative_to",
"fieldtype": "Link",
"label": "Alternative To",
"mandatory_depends_on": "is_alternative",
"options": "Item",
"print_hide": 1
}
],
"idx": 1,
"istable": 1,
"links": [],
"modified": "2023-01-24 08:48:06.290335",
"modified": "2023-01-26 07:32:02.768197",
"modified_by": "Administrator",
"module": "Selling",
"name": "Quotation Item",
Expand Down

0 comments on commit cef7dfd

Please sign in to comment.