Discount amount field in all transactions' child tables (#15124)

* Add discount_amount and base_discount_amount in Sales Invoice Item

* Add patch for existing documents

* Discount amount field in all child tables of Purchase and Selling

* Remove console statements
This commit is contained in:
Shreya Shah 2018-08-14 10:51:48 +05:30 committed by Nabin Hait
parent 88b0a1305f
commit 0631aed3d9
13 changed files with 2544 additions and 2222 deletions

View File

@ -585,6 +585,38 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "discount_percentage",
"fieldname": "discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Discount Amount",
"length": 0,
"no_copy": 0,
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -2156,7 +2188,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-11-30 14:21:00.962126",
"modified": "2018-08-06 05:17:38.205356",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",

View File

@ -629,6 +629,38 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "discount_percentage",
"fieldname": "discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Discount Amount",
"length": 0,
"no_copy": 0,
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -1897,7 +1929,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2018-07-18 07:53:54.677844",
"modified": "2018-08-06 05:16:58.258276",
"modified_by": "Administrator",
"module": "Buying",
"name": "Purchase Order Item",

View File

@ -470,6 +470,38 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "discount_percentage",
"fieldname": "discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Discount Amount",
"length": 0,
"no_copy": 0,
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -1645,7 +1677,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2018-01-25 15:04:40.171617",
"modified": "2018-08-06 05:33:07.404385",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier Quotation Item",

View File

@ -502,4 +502,5 @@ erpnext.patches.v10_0.taxes_issue_with_pos
erpnext.patches.v10_0.set_qty_in_transactions_based_on_serial_no_input
erpnext.patches.v10_0.show_leaves_of_all_department_members_in_calendar
erpnext.patches.v10_0.update_status_in_purchase_receipt
erpnext.patches.v10_0.update_address_template_for_india
erpnext.patches.v10_0.update_address_template_for_india
erpnext.patches.v10_0.set_discount_amount

View File

@ -0,0 +1,56 @@
import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "sales_invoice_item")
frappe.reload_doc('accounts', 'doctype', 'purchase_invoice_item')
frappe.reload_doc('buying', 'doctype', 'purchase_order_item')
frappe.reload_doc('buying', 'doctype', 'supplier_quotation_item')
frappe.reload_doc('selling', 'doctype', 'sales_order_item')
frappe.reload_doc('selling', 'doctype', 'quotation_item')
frappe.reload_doc('stock', 'doctype', 'delivery_note_item')
frappe.reload_doc('stock', 'doctype', 'purchase_receipt_item')
selling_doctypes = ["Sales Order Item", "Sales Invoice Item", "Delivery Note Item", "Quotation Item"]
buying_doctypes = ["Purchase Order Item", "Purchase Invoice Item", "Purchase Receipt Item", "Supplier Quotation Item"]
for doctype in selling_doctypes:
values = frappe.db.sql('''
SELECT
discount_percentage, rate_with_margin, price_list_rate, name
FROM
`tab%s`
WHERE
ifnull(discount_percentage, 0) > 0
''' % (doctype), as_dict=True)
calculate_discount(doctype, values)
for doctype in buying_doctypes:
values = frappe.db.sql('''
SELECT
discount_percentage, price_list_rate, name
FROM
`tab%s`
WHERE
discount_percentage > 0
''' % (doctype), as_dict=True)
calculate_discount(doctype, values)
def calculate_discount(doctype, values):
rate = None
if not values: return
for d in values:
if d.rate_with_margin and d.rate_with_margin > 0:
rate = d.rate_with_margin
else:
rate = d.price_list_rate
discount_value = rate * d.get('discount_percentage') / 100
frappe.db.sql('''
UPDATE
`tab%s`
SET
discount_amount = %s
WHERE
name = '%s'
''' % (doctype, discount_value, d.get('name')))

View File

@ -113,8 +113,8 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["price_list_rate", "discount_percentage"]);
item.rate = flt(item.price_list_rate * (1 - item.discount_percentage / 100.0),
precision("rate", item));
item.discount_amount = flt(item.price_list_rate) * flt(item.discount_percentage) / 100;
item.rate = flt((item.price_list_rate) - (item.discount_amount), precision('rate', item));
this.calculate_taxes_and_totals();
},

View File

@ -16,8 +16,8 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
item.rate = flt(item.rate_with_margin , precision("rate", item));
if(item.discount_percentage){
var discount_value = flt(item.rate_with_margin) * flt(item.discount_percentage) / 100;
item.rate = flt((item.rate_with_margin) - (discount_value), precision('rate', item));
item.discount_amount = flt(item.rate_with_margin) * flt(item.discount_percentage) / 100;
item.rate = flt((item.rate_with_margin) - (item.discount_amount), precision('rate', item));
}
},

View File

@ -790,6 +790,38 @@
"unique": 0,
"width": "100px"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "discount_percentage",
"fieldname": "discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Discount Amount",
"length": 0,
"no_copy": 0,
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -1766,7 +1798,7 @@
"istable": 1,
"max_attachments": 0,
"menu_index": 0,
"modified": "2017-12-14 09:39:17.180709",
"modified": "2018-08-06 05:18:38.135668",
"modified_by": "Administrator",
"module": "Selling",
"name": "Quotation Item",

View File

@ -820,6 +820,38 @@
"unique": 0,
"width": "70px"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "discount_percentage",
"fieldname": "discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Discount Amount",
"length": 0,
"no_copy": 0,
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -2146,7 +2178,7 @@
"istable": 1,
"max_attachments": 0,
"menu_index": 0,
"modified": "2017-11-30 14:05:39.173834",
"modified": "2018-08-06 05:17:51.297862",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order Item",

View File

@ -145,6 +145,15 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
this.set_gross_profit(item);
},
discount_amount: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
if(!item.price_list_rate) {
item.discount_amount = 0.0;
} else {
this.price_list_rate(doc, cdt, cdn);
}
},
commission_rate: function() {
this.calculate_commission();
refresh_field("total_commission");

View File

@ -819,6 +819,38 @@
"unique": 0,
"width": "100px"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "discount_percentage",
"fieldname": "discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Discount Amount",
"length": 0,
"no_copy": 0,
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -2139,7 +2171,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-11-30 14:07:12.217563",
"modified": "2018-08-06 05:18:26.132899",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note Item",

View File

@ -759,6 +759,38 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "discount_percentage",
"fieldname": "discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Discount Amount",
"length": 0,
"no_copy": 0,
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -2290,7 +2322,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-12-06 13:50:08.201145",
"modified": "2018-08-06 05:16:48.590787",
"modified_by": "Administrator",
"module": "Stock",
"name": "Purchase Receipt Item",