Skip to content

Commit

Permalink
feat: bulkdiscount (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahilk25 authored Jul 16, 2021
1 parent ab0d5c4 commit f8ba055
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 46 deletions.
Empty file.
84 changes: 84 additions & 0 deletions erpnext/selling/doctype/bulk_discount/bulk_discount.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"creation": "2021-06-29 23:42:47.804616",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"minimum_qty",
"maximum_qty",
"column_break_3",
"discount_type",
"discount_percentage",
"discount_amount",
"amended_from"
],
"fields": [
{
"fieldname": "minimum_qty",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Minimum Qty"
},
{
"fieldname": "maximum_qty",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Maximum Qty"
},
{
"fieldname": "column_break_3",
"fieldtype": "Column Break"
},
{
"fieldname": "discount_type",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Discount type",
"options": "\nPercentage\nAmount"
},
{
"depends_on": "eval:doc.discount_type==\"Percentage\"",
"fieldname": "discount_percentage",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "Discount Percentage"
},
{
"depends_on": "eval:doc.discount_type==\"Amount\"",
"fieldname": "discount_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Discount Amount"
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Bulk Discount",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Bulk Discount",
"print_hide": 1,
"read_only": 1
}
],
"is_submittable": 1,
"istable": 1,
"modified": "2021-06-30 01:01:34.307743",
"modified_by": "Administrator",
"module": "Selling",
"name": "Bulk Discount",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
10 changes: 10 additions & 0 deletions erpnext/selling/doctype/bulk_discount/bulk_discount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document

class BulkDiscount(Document):
pass
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

frappe.ui.form.on('Bulk Discount Scheme', {
// refresh: function(frm) {

// }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"autoname": "field:scheme_name",
"creation": "2021-06-29 23:42:53.901998",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"scheme_name",
"bulk_disount",
"amended_from"
],
"fields": [
{
"fieldname": "bulk_disount",
"fieldtype": "Table",
"label": "Bulk Disount",
"options": "Bulk Discount"
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Bulk Discount Scheme",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "scheme_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Name",
"reqd": 1,
"unique": 1
}
],
"is_submittable": 1,
"modified": "2021-06-29 23:53:29.887064",
"modified_by": "Administrator",
"module": "Selling",
"name": "Bulk Discount Scheme",
"name_case": "UPPER CASE",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"submit": 1,
"write": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document

class BulkDiscountScheme(Document):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

# import frappe
import unittest

class TestBulkDiscountScheme(unittest.TestCase):
pass
89 changes: 84 additions & 5 deletions erpnext/selling/doctype/quoting_sheet/quoting_sheet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,72 @@
// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Quoting Sheet', {
item_code: function (frm) {
if (frm.doc.currency == frappe.sys_defaults.currency) {
frm.set_value("conversion_rate", 1.0);
onload: (frm) => {
frm.set_query("quote_to", function() {
return{
"filters": {
"name": ["in", ["Customer", "Lead"]],
}
};
});

frm.set_query("bom", () => {
if (frm.doc.item_code) {
return {
filters: {
"item": frm.doc.item_code
}
};
}
});
},

refresh:(frm) => {
frm.trigger('set_dynamic_field_label');
},

quote_to:(frm) => {
frm.trigger('set_dynamic_field_label');
},

set_dynamic_field_label: function(frm){
if (frm.doc.quote_to == "Customer")
{
frm.set_df_property("party_name", "label", "Customer");
frm.fields_dict.party_name.get_query = null;
}

if (frm.doc.quote_to == "Lead")
{
frm.set_df_property("party_name", "label", "Lead");

frm.fields_dict.party_name.get_query = function() {
return{ query: "erpnext.controllers.queries.lead_query" };
};
}
},

bom: function (frm) {
if (frm.doc.bom) {
frappe.call({
method: "get_raw_materials",
doc: frm.doc,
callback: () => {
frm.refresh_field("raw_material_items");
frm.refresh_field("rm_cost");
},
});
}
},
bulk_discount_scheme: function (frm) {
if (frm.doc.bulk_discount_scheme) {
frappe.call({
method: "get_bulk_discount",
doc: frm.doc,
callback: () => {
frm.refresh_field("bulk_discount");
},
});
}
},

Expand All @@ -17,13 +80,27 @@ frappe.ui.form.on('Quoting Sheet', {
frm.reload_doc();
},
});
}
},

calculate_total_raw_material_cost: function (frm) {
frappe.call({
method: "calculate_total_raw_material_cost",
doc: frm.doc,
callback: (res) => {
if (res.message) {
frm.set_value("rm_cost", res.message);
frm.refresh_field("rm_cost");
}

}
});
},
});

frappe.ui.form.on("Quoting Sheet Item", {
item_code: function (frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (!row.item_code) {return;}
if (!row.item_code) { return; }
frappe.call({
method: "erpnext.selling.doctype.quoting_sheet.quoting_sheet.get_item_details_quoting_sheet",
args: {
Expand All @@ -42,6 +119,7 @@ frappe.ui.form.on("Quoting Sheet Item", {
if (row.qty && row.rate) {
let amount = row.qty * row.rate;
frappe.model.set_value(cdt, cdn, "amount", amount);
frm.trigger("calculate_total_raw_material_cost");
}
},

Expand All @@ -50,6 +128,7 @@ frappe.ui.form.on("Quoting Sheet Item", {
if (row.qty && row.rate) {
let amount = row.qty * row.rate;
frappe.model.set_value(cdt, cdn, "amount", amount);
frm.trigger("calculate_total_raw_material_cost");
}
},

Expand Down
Loading

0 comments on commit f8ba055

Please sign in to comment.