feat(Selling): Gross Profit In Quotation (#21795)
* added valuation rate and gross_profit in quotation item table
* modified code to not fetch valuation_rate manually, used set_gross_profit from selling controller
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 1e0a48c..b696ac3 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -361,7 +361,7 @@
self.po_no = ', '.join(list(set([d.po_no for d in po_nos if d.po_no])))
def set_gross_profit(self):
- if self.doctype == "Sales Order":
+ if self.doctype in ["Sales Order", "Quotation"]:
for item in self.items:
item.gross_profit = flt(((item.base_rate - item.valuation_rate) * item.stock_qty), self.precision("amount", item))
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 637d3b3..524a958 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -1711,7 +1711,7 @@
},
set_gross_profit: function(item) {
- if (this.frm.doc.doctype == "Sales Order" && item.valuation_rate) {
+ if (["Sales Order", "Quotation"].includes(this.frm.doc.doctype) && item.valuation_rate) {
var rate = flt(item.rate) * flt(this.frm.doc.conversion_rate || 1);
item.gross_profit = flt(((rate - item.valuation_rate) * item.stock_qty), precision("amount", item));
}
diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index 7cfec5a..0e771c3 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -197,9 +197,9 @@
cond = "qo.docstatus = 1 and qo.status != 'Expired' and qo.valid_till < %s"
# check if those QUO have SO against it
so_against_quo = """
- SELECT
+ SELECT
so.name FROM `tabSales Order` so, `tabSales Order Item` so_item
- WHERE
+ WHERE
so_item.docstatus = 1 and so.docstatus = 1
and so_item.parent = so.name
and so_item.prevdoc_docname = qo.name"""
diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json
index d50397c..59ae7b2 100644
--- a/erpnext/selling/doctype/quotation_item/quotation_item.json
+++ b/erpnext/selling/doctype/quotation_item/quotation_item.json
@@ -48,6 +48,10 @@
"base_net_amount",
"pricing_rules",
"is_free_item",
+ "section_break_43",
+ "valuation_rate",
+ "column_break_45",
+ "gross_profit",
"item_weight_details",
"weight_per_unit",
"total_weight",
@@ -602,12 +606,40 @@
"label": "Against Blanket Order",
"no_copy": 1,
"print_hide": 1
+ },
+ {
+ "fieldname": "section_break_43",
+ "fieldtype": "Section Break"
+ },
+ {
+ "fieldname": "valuation_rate",
+ "fieldtype": "Currency",
+ "label": "Valuation Rate",
+ "no_copy": 1,
+ "options": "Company:company:default_currency",
+ "print_hide": 1,
+ "read_only": 1,
+ "report_hide": 1
+ },
+ {
+ "fieldname": "column_break_45",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "gross_profit",
+ "fieldtype": "Currency",
+ "label": "Gross Profit",
+ "no_copy": 1,
+ "options": "Company:company:default_currency",
+ "print_hide": 1,
+ "read_only": 1,
+ "report_hide": 1
}
],
"idx": 1,
"istable": 1,
"links": [],
- "modified": "2020-03-30 18:40:28.782720",
+ "modified": "2020-05-19 20:48:43.222229",
"modified_by": "Administrator",
"module": "Selling",
"name": "Quotation Item",