Merge branch 'develop' into enable-discount-accounting
diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
index 703e93c..49a2afe 100644
--- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
+++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
@@ -19,6 +19,7 @@
"book_asset_depreciation_entry_automatically",
"unlink_advance_payment_on_cancelation_of_order",
"post_change_gl_entries",
+ "enable_discount_accounting",
"tax_settings_section",
"determine_address_tax_category_from",
"column_break_19",
@@ -261,6 +262,13 @@
"fieldname": "post_change_gl_entries",
"fieldtype": "Check",
"label": "Create Ledger Entries for Change Amount"
+ },
+ {
+ "default": "0",
+ "description": "If enabled, additional ledger entries will be made for discounts in a separate Discount Account",
+ "fieldname": "enable_discount_accounting",
+ "fieldtype": "Check",
+ "label": "Enable Discount Accounting"
}
],
"icon": "icon-cog",
@@ -268,7 +276,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2021-06-17 20:26:03.721202",
+ "modified": "2021-07-12 18:54:29.084958",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounts Settings",
diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
index ac4a2d6..24b0ec4 100644
--- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
+++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
@@ -21,6 +21,7 @@
self.validate_stale_days()
self.enable_payment_schedule_in_print()
+ self.toggle_discount_accounting_fields()
def validate_stale_days(self):
if not self.allow_stale and cint(self.stale_days) <= 0:
@@ -33,3 +34,14 @@
for doctype in ("Sales Order", "Sales Invoice", "Purchase Order", "Purchase Invoice"):
make_property_setter(doctype, "due_date", "print_hide", show_in_print, "Check", validate_fields_for_doctype=False)
make_property_setter(doctype, "payment_schedule", "print_hide", 0 if show_in_print else 1, "Check", validate_fields_for_doctype=False)
+
+ def toggle_discount_accounting_fields(self):
+ enable_discount_accounting = cint(self.enable_discount_accounting)
+
+ for doctype in ["Sales Invoice Item", "Purchase Invoice Item"]:
+ make_property_setter(doctype, "discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
+
+ for doctype in ["Sales Invoice", "Purchase Invoice"]:
+ make_property_setter(doctype, "additional_discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
+
+ make_property_setter("Item", "default_discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index 7562418..435fc1e 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -365,7 +365,7 @@
items_add(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
this.frm.script_manager.copy_from_first_row("items", row,
- ["expense_account", "cost_center", "project"]);
+ ["expense_account", "discount_account", "cost_center", "project"]);
}
on_submit() {
@@ -499,6 +499,16 @@
'Payment Entry': 'Payment'
}
+ frm.set_query("additional_discount_account", function() {
+ return {
+ filters: {
+ company: frm.doc.company,
+ is_group: 0,
+ root_type: "Profit and Loss",
+ }
+ };
+ });
+
frm.fields_dict['items'].grid.get_field('deferred_expense_account').get_query = function(doc) {
return {
filters: {
@@ -508,6 +518,16 @@
}
}
}
+
+ frm.fields_dict['items'].grid.get_field('discount_account').get_query = function(doc) {
+ return {
+ filters: {
+ 'report_type': 'Profit and Loss',
+ 'company': doc.company,
+ "is_group": 0
+ }
+ }
+ }
},
refresh: function(frm) {
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index 00ef7d5..96ae828 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -96,6 +96,7 @@
"section_break_44",
"apply_discount_on",
"base_discount_amount",
+ "additional_discount_account",
"column_break_46",
"additional_discount_percentage",
"discount_amount",
@@ -1377,13 +1378,19 @@
"no_copy": 1,
"print_hide": 1,
"read_only": 1
+ },
+ {
+ "fieldname": "additional_discount_account",
+ "fieldtype": "Link",
+ "label": "Additional Discount Account",
+ "options": "Account"
}
],
"icon": "fa fa-file-text",
"idx": 204,
"is_submittable": 1,
"links": [],
- "modified": "2021-06-15 18:20:56.806195",
+ "modified": "2021-07-17 17:37:50.570595",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice",
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index b99d75e..95ad653 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -446,6 +446,7 @@
self.make_supplier_gl_entry(gl_entries)
self.make_item_gl_entries(gl_entries)
+ self.make_discount_gl_entries(gl_entries)
if self.check_asset_cwip_enabled():
self.get_asset_gl_entry(gl_entries)
@@ -917,6 +918,11 @@
"remarks": self.remarks or "Accounting Entry for Stock"
}, item=tax))
+ enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting'))
+
+ if enable_discount_accounting and self.get('discount_amount') and self.get('additional_discount_account'):
+ self.make_gle_for_additional_discount_applied_on_taxes(gl_entries)
+
def make_internal_transfer_gl_entries(self, gl_entries):
if self.is_internal_transfer() and flt(self.base_total_taxes_and_charges):
account_currency = get_account_currency(self.unrealized_profit_loss_account)
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index db6f143..87bdb7c 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -251,6 +251,52 @@
self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount)
+ def test_purchase_invoice_with_discount_accounting_enabled(self):
+ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import check_gl_entries
+
+ enable_discount_accounting()
+
+ discount_account = create_account(account_name="Discount Account",
+ parent_account="Indirect Expenses - _TC", company="_Test Company")
+ pi = make_purchase_invoice(discount_account=discount_account, discount_amount=100)
+
+ expected_gle = [
+ ["Discount Account - _TC", 0.0, 100.0, nowdate()],
+ ["_Test Account Cost for Goods Sold - _TC", 350.0, 0.0, nowdate()],
+ ["Creditors - _TC", 0.0, 250.0, nowdate()]
+ ]
+
+ check_gl_entries(self, pi.name, expected_gle, nowdate())
+
+ def test_additional_discount_for_purchase_invoice_with_discount_accounting_enabled(self):
+ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import check_gl_entries
+
+ enable_discount_accounting()
+ additional_discount_account = create_account(account_name="Discount Account",
+ parent_account="Indirect Expenses - _TC", company="_Test Company")
+
+ pi = make_purchase_invoice(qty=1, rate=75000, do_not_save=1)
+ pi.apply_discount_on = "Grand Total"
+ pi.additional_discount_account = additional_discount_account
+ pi.additional_discount_percentage = 10
+ pi.append("taxes", {
+ "charge_type": "On Net Total",
+ "account_head": "CGST - _TC",
+ "cost_center": "Main - _TC",
+ "description": "CGST @ 9.0",
+ "rate": 9
+ })
+ pi.submit()
+
+ expected_gle = [
+ ["Discount Account - _TC", 0.0, 675.0, nowdate()],
+ ["CGST - _TC", 6750.0, 0.0, nowdate()],
+ ["_Test Account Cost for Goods Sold - _TC", 67500.0, 0.0, nowdate()],
+ ["Creditors - _TC", 0.0, 73575.0, nowdate()]
+ ]
+
+ check_gl_entries(self, pi.name, expected_gle, nowdate())
+
def test_purchase_invoice_change_naming_series(self):
pi = frappe.copy_doc(test_records[1])
pi.insert()
@@ -1191,6 +1237,11 @@
accounts_settings.unlink_payment_on_cancellation_of_invoice = enable
accounts_settings.save()
+def enable_discount_accounting(enable=1):
+ accounts_settings = frappe.get_doc("Accounts Settings")
+ accounts_settings.enable_discount_accounting = enable
+ accounts_settings.save()
+
def make_purchase_invoice(**args):
pi = frappe.new_doc("Purchase Invoice")
args = frappe._dict(args)
@@ -1213,6 +1264,7 @@
pi.return_against = args.return_against
pi.is_subcontracted = args.is_subcontracted or "No"
pi.supplier_warehouse = args.supplier_warehouse or "_Test Warehouse 1 - _TC"
+ pi.cost_center = args.cost_center or "_Test Cost Center - _TC"
pi.append("items", {
"item_code": args.item or args.item_code or "_Test Item",
@@ -1221,7 +1273,9 @@
"received_qty": args.received_qty or 0,
"rejected_qty": args.rejected_qty or 0,
"rate": args.rate or 50,
- 'expense_account': args.expense_account or '_Test Account Cost for Goods Sold - _TC',
+ "expense_account": args.expense_account or '_Test Account Cost for Goods Sold - _TC',
+ "discount_account": args.discount_account or None,
+ "discount_amount": args.discount_amount or 0,
"conversion_factor": 1.0,
"serial_no": args.serial_no,
"stock_uom": args.uom or "_Test UOM",
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index b39022d..922b567 100644
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -73,6 +73,7 @@
"manufacturer_part_no",
"accounting",
"expense_account",
+ "discount_account",
"col_break5",
"is_fixed_asset",
"asset_location",
@@ -849,12 +850,18 @@
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
+ },
+ {
+ "fieldname": "discount_account",
+ "fieldtype": "Link",
+ "label": "Discount Account",
+ "options": "Account"
}
],
"idx": 1,
"istable": 1,
"links": [],
- "modified": "2021-06-16 19:43:51.099386",
+ "modified": "2021-07-13 02:04:37.787882",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index bb55651..3fb20d9 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -347,7 +347,7 @@
items_add(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
- this.frm.script_manager.copy_from_first_row("items", row, ["income_account", "cost_center"]);
+ this.frm.script_manager.copy_from_first_row("items", row, ["income_account", "discount_account", "cost_center"]);
}
set_dynamic_labels() {
@@ -510,7 +510,6 @@
}
});
-
// Cost Center in Details Table
// -----------------------------
cur_frm.fields_dict["items"].grid.get_field("cost_center").get_query = function(doc) {
@@ -592,6 +591,16 @@
};
});
+ frm.set_query("additional_discount_account", function() {
+ return {
+ filters: {
+ company: frm.doc.company,
+ is_group: 0,
+ root_type: "Profit and Loss",
+ }
+ };
+ });
+
frm.custom_make_buttons = {
'Delivery Note': 'Delivery',
'Sales Invoice': 'Return / Credit Note',
@@ -618,6 +627,17 @@
}
}
+ // discount account
+ frm.fields_dict['items'].grid.get_field('discount_account').get_query = function(doc) {
+ return {
+ filters: {
+ 'report_type': 'Profit and Loss',
+ 'company': doc.company,
+ "is_group": 0
+ }
+ }
+ }
+
frm.fields_dict['items'].grid.get_field('deferred_revenue_account').get_query = function(doc) {
return {
filters: {
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index e7dd6b8..5c09b71 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -104,6 +104,7 @@
"section_break_49",
"apply_discount_on",
"base_discount_amount",
+ "additional_discount_account",
"column_break_51",
"additional_discount_percentage",
"discount_amount",
@@ -1966,6 +1967,12 @@
"fieldname": "disable_rounded_total",
"fieldtype": "Check",
"label": "Disable Rounded Total"
+ },
+ {
+ "fieldname": "additional_discount_account",
+ "fieldtype": "Link",
+ "label": "Additional Discount Account",
+ "options": "Account"
}
],
"icon": "fa fa-file-text",
@@ -1978,7 +1985,7 @@
"link_fieldname": "consolidated_invoice"
}
],
- "modified": "2021-05-20 22:48:33.988881",
+ "modified": "2021-07-15 21:57:17.544279",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 8889913..955f223 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -846,6 +846,7 @@
self.allocate_advance_taxes(gl_entries)
self.make_item_gl_entries(gl_entries)
+ self.make_discount_gl_entries(gl_entries)
# merge gl entries before adding pos entries
gl_entries = merge_similar_entries(gl_entries)
@@ -901,6 +902,11 @@
}, account_currency, item=tax)
)
+ enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting'))
+
+ if enable_discount_accounting and self.get('discount_amount') and self.get('additional_discount_account'):
+ self.make_gle_for_additional_discount_applied_on_taxes(gl_entries)
+
def make_internal_transfer_gl_entries(self, gl_entries):
if self.is_internal_transfer() and flt(self.base_total_taxes_and_charges):
account_currency = get_account_currency(self.unrealized_profit_loss_account)
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 6dc2767..00831fe 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -2015,6 +2015,52 @@
sales_invoice.save()
self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 10 - _TC")
+ def test_sales_invoice_with_discount_accounting_enabled(self):
+ from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import enable_discount_accounting
+
+ enable_discount_accounting()
+
+ discount_account = create_account(account_name="Discount Account",
+ parent_account="Indirect Expenses - _TC", company="_Test Company")
+ si = create_sales_invoice(discount_account=discount_account, discount_amount=100)
+
+ expected_gle = [
+ ["Discount Account - _TC", 100.0, 0.0, nowdate()],
+ ["Sales - _TC", 0.0, 200.0, nowdate()],
+ ["Debtors - _TC", 100.0, 0.0, nowdate()]
+ ]
+
+ check_gl_entries(self, si.name, expected_gle, nowdate())
+
+ def test_additional_discount_for_sales_invoice_with_discount_accounting_enabled(self):
+ from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import enable_discount_accounting
+
+ enable_discount_accounting()
+ additional_discount_account = create_account(account_name="Discount Account",
+ parent_account="Indirect Expenses - _TC", company="_Test Company")
+
+ si = create_sales_invoice(rate=75000, do_not_save=1)
+ si.apply_discount_on = "Grand Total"
+ si.additional_discount_account = additional_discount_account
+ si.additional_discount_percentage = 10
+ si.append("taxes", {
+ "charge_type": "On Net Total",
+ "account_head": "CGST - _TC",
+ "cost_center": "Main - _TC",
+ "description": "CGST @ 9.0",
+ "rate": 9
+ })
+ si.submit()
+
+ expected_gle = [
+ ["Sales - _TC", 0.0, 67500.0, nowdate()],
+ ["Discount Account - _TC", 675.0, 0.0, nowdate()],
+ ["CGST - _TC", 0.0, 6750.0, nowdate()],
+ ["Debtors - _TC", 73575.0, 0.0, nowdate()]
+ ]
+
+ check_gl_entries(self, si.name, expected_gle, nowdate())
+
def get_sales_invoice_for_e_invoice():
si = make_sales_invoice_for_ewaybill()
si.naming_series = 'INV-2020-.#####'
@@ -2182,6 +2228,7 @@
si.currency=args.currency or "INR"
si.conversion_rate = args.conversion_rate or 1
si.naming_series = args.naming_series or "T-SINV-"
+ si.cost_center = args.cost_center or "_Test Cost Center - _TC"
si.append("items", {
"item_code": args.item or args.item_code or "_Test Item",
@@ -2195,6 +2242,8 @@
"rate": args.rate if args.get("rate") is not None else 100,
"income_account": args.income_account or "Sales - _TC",
"expense_account": args.expense_account or "Cost of Goods Sold - _TC",
+ "discount_account": args.discount_account or None,
+ "discount_amount": args.discount_amount or 0,
"asset": args.asset or None,
"cost_center": args.cost_center or "_Test Cost Center - _TC",
"serial_no": args.serial_no,
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index 6690bda..0da439e 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -63,6 +63,7 @@
"finance_book",
"col_break4",
"expense_account",
+ "discount_account",
"deferred_revenue",
"deferred_revenue_account",
"service_stop_date",
@@ -820,12 +821,18 @@
"no_copy": 1,
"options": "currency",
"read_only": 1
+ },
+ {
+ "fieldname": "discount_account",
+ "fieldtype": "Link",
+ "label": "Discount Account",
+ "options": "Account"
}
],
"idx": 1,
"istable": 1,
"links": [],
- "modified": "2021-06-21 23:03:11.599901",
+ "modified": "2021-07-05 15:07:22.857128",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 4c313c4..aa2fe29 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -808,6 +808,91 @@
tax_map[tax.account_head] -= allocated_amount
allocated_tax_map[tax.account_head] -= allocated_amount
+ def make_discount_gl_entries(self, gl_entries):
+ enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting'))
+
+ if enable_discount_accounting:
+ for item in self.get("items"):
+ if item.get('discount_amount') and item.get('discount_account'):
+ if self.doctype == "Purchase Invoice":
+ dr_or_cr = "credit"
+ rev_dr_cr = "debit"
+ supplier_or_customer = self.supplier
+ income_or_expense_account = (item.expense_account
+ if (not item.enable_deferred_expense or self.is_return)
+ else item.deferred_expense_account)
+ else:
+ dr_or_cr = "debit"
+ rev_dr_cr = "credit"
+ supplier_or_customer = self.customer
+ income_or_expense_account = (item.income_account
+ if (not item.enable_deferred_revenue or self.is_return)
+ else item.deferred_revenue_account)
+
+ account_currency = get_account_currency(item.discount_account)
+ gl_entries.append(
+ self.get_gl_dict({
+ "account": item.discount_account,
+ "against": supplier_or_customer,
+ dr_or_cr: flt(item.discount_amount),
+ dr_or_cr + "_in_account_currency": flt(item.discount_amount),
+ "cost_center": self.cost_center,
+ "project": self.project
+ }, account_currency, item=self)
+ )
+
+ account_currency = get_account_currency(income_or_expense_account)
+ gl_entries.append(
+ self.get_gl_dict({
+ "account": income_or_expense_account,
+ "against": supplier_or_customer,
+ rev_dr_cr: flt(item.discount_amount),
+ rev_dr_cr + "_in_account_currency": flt(item.discount_amount),
+ "cost_center": item.cost_center,
+ "project": item.project or self.project
+ }, account_currency, item=item)
+ )
+
+ def make_gle_for_additional_discount_applied_on_taxes(self, gl_entries):
+ for tax in self.get("taxes"):
+ if flt(tax.base_tax_amount_after_discount_amount) and flt(tax.base_tax_amount):
+ account_currency = get_account_currency(tax.account_head)
+ additional_discount_applied_on_taxes = flt(tax.base_tax_amount) - flt(tax.base_tax_amount_after_discount_amount)
+ if self.doctype == 'Purchase Invoice':
+ against = self.supplier
+ dr_or_cr = "debit"
+ rev_dr_cr = "credit"
+ else:
+ against = self.customer
+ dr_or_cr = "credit"
+ rev_dr_cr = "debit"
+
+ gl_entries.append(
+ self.get_gl_dict({
+ "account": tax.account_head,
+ "against": against,
+ dr_or_cr: flt(additional_discount_applied_on_taxes,
+ tax.precision("tax_amount_after_discount_amount")),
+ dr_or_cr + "_in_account_currency": (flt(additional_discount_applied_on_taxes,
+ tax.precision("base_tax_amount_after_discount_amount")) if account_currency==self.company_currency else
+ flt(additional_discount_applied_on_taxes, tax.precision("tax_amount_after_discount_amount"))),
+ "cost_center": tax.cost_center
+ }, account_currency, item=tax)
+ )
+
+ gl_entries.append(
+ self.get_gl_dict({
+ "account": self.additional_discount_account,
+ "against": against,
+ rev_dr_cr: flt(additional_discount_applied_on_taxes,
+ tax.precision("tax_amount_after_discount_amount")),
+ rev_dr_cr + "_in_account_currency": (flt(additional_discount_applied_on_taxes,
+ tax.precision("base_tax_amount_after_discount_amount")) if account_currency==self.company_currency else
+ flt(additional_discount_applied_on_taxes, tax.precision("tax_amount_after_discount_amount"))),
+ "cost_center": tax.cost_center
+ }, account_currency, item=tax)
+ )
+
def allocate_advance_taxes(self, gl_entries):
tax_map = self.get_tax_map()
for pe in self.get("advances"):
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index 568f0ef..c68cd01 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -275,6 +275,17 @@
}
}
+ frm.fields_dict["item_defaults"].grid.get_field("default_discount_account").get_query = function(doc, cdt, cdn) {
+ const row = locals[cdt][cdn];
+ return {
+ filters: {
+ 'report_type': 'Profit and Loss',
+ 'company': row.company,
+ "is_group": 0
+ }
+ };
+ };
+
frm.fields_dict["item_defaults"].grid.get_field("buying_cost_center").get_query = function(doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index 6fed9ef..f662bbd 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -1067,7 +1067,7 @@
"index_web_pages_for_search": 1,
"links": [],
"max_attachments": 1,
- "modified": "2021-03-18 14:04:38.575519",
+ "modified": "2021-07-13 01:29:06.071827",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item",
@@ -1138,4 +1138,4 @@
"sort_order": "DESC",
"title_field": "item_name",
"track_changes": 1
-}
+}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item_default/item_default.json b/erpnext/stock/doctype/item_default/item_default.json
index 96b5dfd..bc17160 100644
--- a/erpnext/stock/doctype/item_default/item_default.json
+++ b/erpnext/stock/doctype/item_default/item_default.json
@@ -1,464 +1,118 @@
{
- "allow_copy": 0,
- "allow_events_in_timeline": 0,
- "allow_guest_to_view": 0,
- "allow_import": 0,
- "allow_rename": 0,
- "beta": 0,
- "creation": "2018-05-03 02:29:24.444341",
- "custom": 0,
- "docstatus": 0,
- "doctype": "DocType",
- "document_type": "",
- "editable_grid": 1,
- "engine": "InnoDB",
+ "actions": [],
+ "creation": "2018-05-03 02:29:24.444341",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+ "company",
+ "default_warehouse",
+ "column_break_3",
+ "default_price_list",
+ "default_discount_account",
+ "purchase_defaults",
+ "buying_cost_center",
+ "default_supplier",
+ "column_break_8",
+ "expense_account",
+ "selling_defaults",
+ "selling_cost_center",
+ "column_break_12",
+ "income_account"
+ ],
"fields": [
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "company",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 1,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Company",
- "length": 0,
- "no_copy": 0,
- "options": "Company",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "company",
+ "fieldtype": "Link",
+ "ignore_user_permissions": 1,
+ "in_list_view": 1,
+ "label": "Company",
+ "options": "Company",
+ "reqd": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "default_warehouse",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Default Warehouse",
- "length": 0,
- "no_copy": 0,
- "options": "Warehouse",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "default_warehouse",
+ "fieldtype": "Link",
+ "in_list_view": 1,
+ "label": "Default Warehouse",
+ "options": "Warehouse"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "column_break_3",
- "fieldtype": "Column Break",
- "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,
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "column_break_3",
+ "fieldtype": "Column Break"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "default_price_list",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Default Price List",
- "length": 0,
- "no_copy": 0,
- "options": "Price List",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "default_price_list",
+ "fieldtype": "Link",
+ "in_list_view": 1,
+ "label": "Default Price List",
+ "options": "Price List"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "purchase_defaults",
- "fieldtype": "Section Break",
- "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": "Purchase Defaults",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "purchase_defaults",
+ "fieldtype": "Section Break",
+ "label": "Purchase Defaults"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "buying_cost_center",
- "fieldtype": "Link",
- "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": "Default Buying Cost Center",
- "length": 0,
- "no_copy": 0,
- "options": "Cost Center",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "buying_cost_center",
+ "fieldtype": "Link",
+ "label": "Default Buying Cost Center",
+ "options": "Cost Center"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "default_supplier",
- "fieldtype": "Link",
- "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": "Default Supplier",
- "length": 0,
- "no_copy": 0,
- "options": "Supplier",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "default_supplier",
+ "fieldtype": "Link",
+ "label": "Default Supplier",
+ "options": "Supplier"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "column_break_8",
- "fieldtype": "Column Break",
- "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,
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "column_break_8",
+ "fieldtype": "Column Break"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "expense_account",
- "fieldtype": "Link",
- "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": "Default Expense Account",
- "length": 0,
- "no_copy": 0,
- "options": "Account",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "expense_account",
+ "fieldtype": "Link",
+ "label": "Default Expense Account",
+ "options": "Account"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "selling_defaults",
- "fieldtype": "Section Break",
- "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": "Sales Defaults",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "selling_defaults",
+ "fieldtype": "Section Break",
+ "label": "Sales Defaults"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "selling_cost_center",
- "fieldtype": "Link",
- "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": "Default Selling Cost Center",
- "length": 0,
- "no_copy": 0,
- "options": "Cost Center",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "selling_cost_center",
+ "fieldtype": "Link",
+ "label": "Default Selling Cost Center",
+ "options": "Cost Center"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "column_break_12",
- "fieldtype": "Column Break",
- "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,
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "column_break_12",
+ "fieldtype": "Column Break"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "income_account",
- "fieldtype": "Link",
- "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": "Default Income Account",
- "length": 0,
- "no_copy": 0,
- "options": "Account",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
+ "fieldname": "income_account",
+ "fieldtype": "Link",
+ "label": "Default Income Account",
+ "options": "Account"
+ },
+ {
+ "fieldname": "default_discount_account",
+ "fieldtype": "Link",
+ "label": "Default Discount Account",
+ "options": "Account"
}
- ],
- "has_web_view": 0,
- "hide_heading": 0,
- "hide_toolbar": 0,
- "idx": 0,
- "image_view": 0,
- "in_create": 0,
- "is_submittable": 0,
- "issingle": 0,
- "istable": 1,
- "max_attachments": 0,
- "modified": "2018-12-07 11:48:07.638935",
- "modified_by": "Administrator",
- "module": "Stock",
- "name": "Item Default",
- "name_case": "",
- "owner": "Administrator",
- "permissions": [],
- "quick_entry": 1,
- "read_only": 0,
- "read_only_onload": 0,
- "show_name_in_global_search": 0,
- "sort_field": "modified",
- "sort_order": "DESC",
- "track_changes": 1,
- "track_seen": 0,
- "track_views": 0
+ ],
+ "istable": 1,
+ "links": [],
+ "modified": "2021-07-13 01:26:03.860065",
+ "modified_by": "Administrator",
+ "module": "Stock",
+ "name": "Item Default",
+ "owner": "Administrator",
+ "permissions": [],
+ "quick_entry": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
}
\ No newline at end of file
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 4657700..06d0f7e 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -288,6 +288,7 @@
"warehouse": warehouse,
"income_account": get_default_income_account(args, item_defaults, item_group_defaults, brand_defaults),
"expense_account": expense_account or get_default_expense_account(args, item_defaults, item_group_defaults, brand_defaults) ,
+ "discount_account": None or get_default_discount_account(args, item_defaults),
"cost_center": get_default_cost_center(args, item_defaults, item_group_defaults, brand_defaults),
'has_serial_no': item.has_serial_no,
'has_batch_no': item.has_batch_no,
@@ -590,6 +591,10 @@
or brand.get("expense_account")
or args.expense_account)
+def get_default_discount_account(args, item):
+ return (item.get("default_discount_account")
+ or args.discount_account)
+
def get_default_deferred_account(args, item, fieldname=None):
if item.get("enable_deferred_revenue") or item.get("enable_deferred_expense"):
return (item.get(fieldname)