From e3a3306b309f4a355b9469d4bfbd70ade679794c Mon Sep 17 00:00:00 2001 From: Rohan Bansal Date: Wed, 12 Jun 2019 17:42:24 +0530 Subject: [PATCH 1/5] feat(customer): Add report to show item prices per Customer --- .../customer_wise_item_price/__init__.py | 0 .../customer_wise_item_price.js | 27 +++++ .../customer_wise_item_price.json | 43 ++++++++ .../customer_wise_item_price.py | 101 ++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 erpnext/selling/report/customer_wise_item_price/__init__.py create mode 100644 erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.js create mode 100644 erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.json create mode 100644 erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.py diff --git a/erpnext/selling/report/customer_wise_item_price/__init__.py b/erpnext/selling/report/customer_wise_item_price/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.js b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.js new file mode 100644 index 0000000000..d333c8be65 --- /dev/null +++ b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.js @@ -0,0 +1,27 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +/* eslint-disable */ + +frappe.query_reports["Customer-wise Item Price"] = { + "filters": [ + { + "label": __("Customer"), + "fieldname": "customer", + "fieldtype": "Link", + "options": "Customer", + "reqd": 1 + }, + { + "label": __("Item"), + "fieldname": "item", + "fieldtype": "Link", + "options": "Item", + "get_query": () => { + return { + query: "erpnext.controllers.queries.item_query", + filters: { 'is_sales_item': 1 } + } + } + } + ] +} diff --git a/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.json b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.json new file mode 100644 index 0000000000..998ba94a8b --- /dev/null +++ b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.json @@ -0,0 +1,43 @@ +{ + "add_total_row": 0, + "creation": "2019-06-12 03:25:36.263179", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "idx": 0, + "is_standard": "Yes", + "letter_head": "Delta9", + "modified": "2019-06-12 03:25:36.263179", + "modified_by": "Administrator", + "module": "Selling", + "name": "Customer-wise Item Price", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Customer", + "report_name": "Customer-wise Item Price", + "report_type": "Script Report", + "roles": [ + { + "role": "Sales User" + }, + { + "role": "Stock Manager" + }, + { + "role": "Accounts User" + }, + { + "role": "Accounts Manager" + }, + { + "role": "Sales Manager" + }, + { + "role": "Sales Master Manager" + }, + { + "role": "Stock User" + } + ] +} \ No newline at end of file diff --git a/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.py b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.py new file mode 100644 index 0000000000..bdd39229df --- /dev/null +++ b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.py @@ -0,0 +1,101 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +import frappe +from erpnext import get_default_company +from erpnext.accounts.party import get_party_details +from erpnext.stock.get_item_details import get_price_list_rate_for +from frappe import _ + + +def execute(filters=None): + if not filters: + filters = {} + + if not filters.get("customer"): + frappe.throw(_("Please select a Customer")) + + columns = get_columns(filters) + data = get_data(filters) + + return columns, data + + +def get_columns(filters=None): + return [ + { + "label": _("Item Code"), + "fieldname": "item_code", + "fieldtype": "Link", + "options": "Item", + "width": 150 + }, + { + "label": _("Item Name"), + "fieldname": "item_name", + "fieldtype": "Data", + "width": 200 + }, + { + "label": _("Selling Rate"), + "fieldname": "selling_rate", + "fieldtype": "Currency" + }, + { + "label": _("Available Stock"), + "fieldname": "available_stock", + "fieldtype": "Float", + "width": 150 + }, + { + "label": _("Price List"), + "fieldname": "price_list", + "fieldtype": "Link", + "options": "Price List", + "width": 120 + } + ] + + +def get_data(filters=None): + data = [] + customer_details = get_customer_details(filters) + items = get_selling_items(filters) + + for item in items: + price_list_rate = get_price_list_rate_for(customer_details, item.item_code) or 0.0 + available_stock = frappe.db.sql("SELECT sum(actual_qty) FROM `tabBin` WHERE item_code = %s", item.item_code) + available_stock = available_stock[0][0] if available_stock else None + + data.append({ + "item_code": item.item_code, + "item_name": item.item_name, + "selling_rate": price_list_rate, + "price_list": customer_details.get("price_list"), + "available_stock": available_stock, + }) + + return data + + +def get_customer_details(filters): + customer_details = get_party_details(party=filters.get("customer"), party_type="Customer") + customer_details.update({ + "company": get_default_company(), + "price_list": customer_details.get("selling_price_list") + }) + + return customer_details + + +def get_selling_items(filters): + if filters.get("item"): + item_filters = {"item_code": filters.get("item"), "is_sales_item": 1, "disabled": 0} + else: + item_filters = {"is_sales_item": 1, "disabled": 0} + + items = frappe.get_all("Item", filters=item_filters, fields=["item_code", "item_name"], order_by="item_name") + + return items \ No newline at end of file From 0426636a3270f23c6cccaa9ea519c850798c95fc Mon Sep 17 00:00:00 2001 From: Rohan Bansal Date: Mon, 17 Jun 2019 12:11:04 +0530 Subject: [PATCH 2/5] fix(customer): Improve performance by reducing queries --- .../customer_wise_item_price/customer_wise_item_price.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.py b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.py index bdd39229df..eb9273a562 100644 --- a/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.py +++ b/erpnext/selling/report/customer_wise_item_price/customer_wise_item_price.py @@ -62,12 +62,14 @@ def get_columns(filters=None): def get_data(filters=None): data = [] customer_details = get_customer_details(filters) + items = get_selling_items(filters) + item_stock_map = frappe.get_all("Bin", fields=["item_code", "sum(actual_qty) AS available"], group_by="item_code") + item_stock_map = {item.item_code: item.available for item in item_stock_map} for item in items: price_list_rate = get_price_list_rate_for(customer_details, item.item_code) or 0.0 - available_stock = frappe.db.sql("SELECT sum(actual_qty) FROM `tabBin` WHERE item_code = %s", item.item_code) - available_stock = available_stock[0][0] if available_stock else None + available_stock = item_stock_map.get(item.item_code) data.append({ "item_code": item.item_code, @@ -98,4 +100,4 @@ def get_selling_items(filters): items = frappe.get_all("Item", filters=item_filters, fields=["item_code", "item_name"], order_by="item_name") - return items \ No newline at end of file + return items From f9c0ef3eb3c3755b1e892c1078e3497c3c8d59bc Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Tue, 30 Jul 2019 18:49:19 +0530 Subject: [PATCH 3/5] fix: Check zero valuation rate only for valid doctypes --- erpnext/stock/stock_ledger.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index ff5b026695..5fda2a4007 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -363,8 +363,17 @@ class update_entries_after(object): self.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.valuation_rate]) def check_if_allow_zero_valuation_rate(self, voucher_type, voucher_detail_no): - ref_item_dt = voucher_type + (" Detail" if voucher_type == "Stock Entry" else " Item") - return frappe.db.get_value(ref_item_dt, voucher_detail_no, "allow_zero_valuation_rate") + ref_item_dt = "" + + if voucher_type == "Stock Entry": + ref_item_dt = voucher_type + " Detail" + elif voucher_type in ["Purchase Invoice", "Sales Invoice", "Delivery Note", "Purchase Receipt"]: + ref_item_dt = voucher_type + " Item" + + if ref_item_dt: + return frappe.db.get_value(ref_item_dt, voucher_detail_no, "allow_zero_valuation_rate") + else: + return 0 def get_sle_before_datetime(self): """get previous stock ledger entry before current time-bucket""" From d301d26fda50b85b79fd56c6883f865d6ff65f4c Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Wed, 31 Jul 2019 15:58:19 +0530 Subject: [PATCH 4/5] fix: Enhancement in credit note (#18511) * fix: Credit note enhancement * Fix: Print format for Sales Invoice Return * fix: Zero quantity validation fix for credit note --- .../doctype/sales_invoice/sales_invoice.js | 14 +- .../sales_invoice_return/__init__.py | 0 .../sales_invoice_return.html | 129 ++++++++++++++++++ .../sales_invoice_return.json | 24 ++++ erpnext/controllers/accounts_controller.py | 4 +- erpnext/controllers/taxes_and_totals.py | 7 +- .../public/js/controllers/taxes_and_totals.js | 8 +- 7 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 erpnext/accounts/print_format/sales_invoice_return/__init__.py create mode 100644 erpnext/accounts/print_format/sales_invoice_return/sales_invoice_return.html create mode 100644 erpnext/accounts/print_format/sales_invoice_return/sales_invoice_return.json diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 1fe6895601..74e9186e37 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -44,6 +44,10 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte this.frm.toggle_reqd("due_date", !this.frm.doc.is_return); + if (this.frm.doc.is_return) { + this.frm.return_print_format = "Sales Invoice Return"; + } + this.show_general_ledger(); if(doc.update_stock) this.show_stock_ledger(); @@ -148,16 +152,24 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte }, set_default_print_format: function() { - // set default print format to POS type + // set default print format to POS type or Credit Note if(cur_frm.doc.is_pos) { if(cur_frm.pos_print_format) { cur_frm.meta._default_print_format = cur_frm.meta.default_print_format; cur_frm.meta.default_print_format = cur_frm.pos_print_format; } + } else if(cur_frm.doc.is_return) { + if(cur_frm.return_print_format) { + cur_frm.meta._default_print_format = cur_frm.meta.default_print_format; + cur_frm.meta.default_print_format = cur_frm.return_print_format; + } } else { if(cur_frm.meta._default_print_format) { cur_frm.meta.default_print_format = cur_frm.meta._default_print_format; cur_frm.meta._default_print_format = null; + } else if(in_list([cur_frm.pos_print_format, cur_frm.return_print_format], cur_frm.meta.default_print_format)) { + cur_frm.meta.default_print_format = null; + cur_frm.meta._default_print_format = null; } } }, diff --git a/erpnext/accounts/print_format/sales_invoice_return/__init__.py b/erpnext/accounts/print_format/sales_invoice_return/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/print_format/sales_invoice_return/sales_invoice_return.html b/erpnext/accounts/print_format/sales_invoice_return/sales_invoice_return.html new file mode 100644 index 0000000000..889b7f71aa --- /dev/null +++ b/erpnext/accounts/print_format/sales_invoice_return/sales_invoice_return.html @@ -0,0 +1,129 @@ +{%- from "templates/print_formats/standard_macros.html" import add_header, render_field, print_value, fieldmeta, + get_width, get_align_class -%} + +{%- macro render_currency(df, doc) -%} +
+
+ +
+
+ {% if doc.get(df.fieldname) != None -%} + {{ frappe.utils.fmt_money((doc[df.fieldname])|int|abs, currency=doc.currency) }} + {% endif %} +
+
+{%- endmacro -%} + +{%- macro render_taxes(df, doc) -%} + {%- set data = doc.get(df.fieldname)[df.start:df.end] -%} +
+
+
+ {%- for charge in data -%} + {%- if (charge.tax_amount or doc.flags.print_taxes_with_zero_amount) and (not charge.included_in_print_rate or doc.flags.show_inclusive_tax_in_print) -%} +
+
+
+
+ {{ frappe.utils.fmt_money((charge.tax_amount)|int|abs, currency=doc.currency) }} +
+
+ {%- endif -%} + {%- endfor -%} +
+
+{%- endmacro -%} + +{%- macro render_table(df, doc) -%} + {%- set table_meta = frappe.get_meta(df.options) -%} + {%- set data = doc.get(df.fieldname)[df.start:df.end] -%} + {%- if doc.print_templates and + doc.print_templates.get(df.fieldname) -%} + {% include doc.print_templates[df.fieldname] %} + {%- else -%} + {%- if data -%} + {%- set visible_columns = get_visible_columns(doc.get(df.fieldname), + table_meta, df) -%} +
+ + + + + {% for tdf in visible_columns %} + {% if (data and not data[0].flags.compact_item_print) or tdf.fieldname in doc.get(df.fieldname)[0].flags.compact_item_fields %} + + {% endif %} + {% endfor %} + + + + {% for d in data %} + + + {% for tdf in visible_columns %} + {% if not d.flags.compact_item_print or tdf.fieldname in doc.get(df.fieldname)[0].flags.compact_item_fields %} + + {% else %} +
{{ print_value(tdf, d, doc, visible_columns) }}
+ {% endif %} + {% endif %} + {% endfor %} + + {% endfor %} + +
{{ _("Sr") }} + {{ _(tdf.label) }}
{{ d.idx }} + {% if tdf.fieldtype == 'Currency' %} +
{{ frappe.utils.fmt_money((d[tdf.fieldname])|int|abs, currency=doc.currency) }}
+
+ {%- endif -%} + {%- endif -%} +{%- endmacro -%} + +{% for page in layout %} +
+
+ {{ add_header(loop.index, layout|len, doc, letter_head, no_letterhead, footer, print_settings) }} +
+ + {% if print_settings.repeat_header_footer %} + + {% endif %} + + {% for section in page %} +
+ {% if section.columns.fields %} + {%- if doc._line_breaks and loop.index != 1 -%}
{%- endif -%} + {%- if doc._show_section_headings and section.label and section.has_data -%} +

{{ _(section.label) }}

+ {% endif %} + {%- endif -%} + {% for column in section.columns %} +
+ {% for df in column.fields %} + {% if df.fieldname == 'taxes' %} + {{ render_taxes(df, doc) }} + {% elif df.fieldtype == 'Currency' %} + {{ render_currency(df, doc) }} + {% elif df.fieldtype =='Table' %} + {{ render_table(df, doc)}} + {% elif doc[df.fieldname] %} + {{ render_field(df, doc) }} + {% endif %} + {% endfor %} +
+ {% endfor %} +
+ {% endfor %} +
+{% endfor %} diff --git a/erpnext/accounts/print_format/sales_invoice_return/sales_invoice_return.json b/erpnext/accounts/print_format/sales_invoice_return/sales_invoice_return.json new file mode 100644 index 0000000000..352b5498e6 --- /dev/null +++ b/erpnext/accounts/print_format/sales_invoice_return/sales_invoice_return.json @@ -0,0 +1,24 @@ +{ + "align_labels_right": 1, + "creation": "2019-07-24 20:13:30.259953", + "custom_format": 0, + "default_print_language": "en-US", + "disabled": 0, + "doc_type": "Sales Invoice", + "docstatus": 0, + "doctype": "Print Format", + "font": "Default", + "html": "", + "idx": 0, + "line_breaks": 1, + "modified": "2019-07-24 20:13:30.259953", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Sales Invoice Return", + "owner": "Administrator", + "print_format_builder": 0, + "print_format_type": "Jinja", + "raw_printing": 0, + "show_section_headings": 1, + "standard": "Yes" +} \ No newline at end of file diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index ca59a396b8..288aa082c5 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -60,7 +60,9 @@ class AccountsController(TransactionBase): def validate(self): - self.validate_qty_is_not_zero() + if not self.get('is_return'): + self.validate_qty_is_not_zero() + if self.get("_action") and self._action != "update_after_submit": self.set_missing_values(for_validate=True) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 8d24e7a316..b774037266 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -81,7 +81,12 @@ class calculate_taxes_and_totals(object): item.discount_amount = item.price_list_rate - item.rate item.net_rate = item.rate - item.amount = flt(item.rate * item.qty, item.precision("amount")) + + if not item.qty and self.doc.is_return: + item.amount = flt(-1 * item.rate, item.precision("amount")) + else: + item.amount = flt(item.rate * item.qty, item.precision("amount")) + item.net_amount = item.amount self._set_in_company_currency(item, ["price_list_rate", "rate", "net_rate", "amount", "net_amount"]) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 91800cd9a9..7cf2181e42 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -92,7 +92,13 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ $.each(this.frm.doc["items"] || [], function(i, item) { frappe.model.round_floats_in(item); item.net_rate = item.rate; - item.amount = flt(item.rate * item.qty, precision("amount", item)); + + if ((!item.qty) && me.frm.doc.is_return) { + item.amount = flt(item.rate * -1, precision("amount", item)); + } else { + item.amount = flt(item.rate * item.qty, precision("amount", item)); + } + item.net_amount = item.amount; item.item_tax_amount = 0.0; item.total_weight = flt(item.weight_per_unit * item.stock_qty); From 8704bc6f39bc829a5ce334788ae56ffa2a6cb338 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Thu, 1 Aug 2019 13:24:48 +0530 Subject: [PATCH 5/5] fix: Payment Order link fix in bank dashboard --- erpnext/accounts/doctype/bank/bank_dashboard.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/accounts/doctype/bank/bank_dashboard.py b/erpnext/accounts/doctype/bank/bank_dashboard.py index 432404155d..e047b9aad0 100644 --- a/erpnext/accounts/doctype/bank/bank_dashboard.py +++ b/erpnext/accounts/doctype/bank/bank_dashboard.py @@ -6,6 +6,9 @@ from frappe import _ def get_data(): return { 'fieldname': 'bank', + 'non_standard_fieldnames': { + 'Paymnet Order': 'company_bank' + }, 'transactions': [ { 'label': _('Bank Deatils'),