diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index 1d5e77b73e3..d3ceb09eaa0 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@ import frappe
from erpnext.hooks import regional_overrides
from frappe.utils import getdate
-__version__ = '11.1.51'
+__version__ = '11.1.52'
def get_default_company(user=None):
'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index df1dae34f35..8914afcba9f 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();
@@ -131,16 +135,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 00000000000..e69de29bb2d
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 00000000000..889b7f71aa5
--- /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 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 00000000000..352b5498e67
--- /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 ebf51104bf2..be25d56129f 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -58,7 +58,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 a1972aa16de..34677ebc3e3 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -76,7 +76,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 29769464f3e..737cc92dded 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -91,7 +91,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);
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 5bd381ba200..e6806784cda 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -753,13 +753,13 @@ class StockEntry(StockController):
self.add_to_stock_entry_detail(item_dict)
- if self.purpose != "Subcontract":
- scrap_item_dict = self.get_bom_scrap_material(self.fg_completed_qty)
- for item in itervalues(scrap_item_dict):
- if self.pro_doc and self.pro_doc.scrap_warehouse:
- item["to_warehouse"] = self.pro_doc.scrap_warehouse
+ if self.purpose != "Subcontract" and self.purpose == "Manufacture":
+ scrap_item_dict = self.get_bom_scrap_material(self.fg_completed_qty)
+ for item in itervalues(scrap_item_dict):
+ if self.pro_doc and self.pro_doc.scrap_warehouse:
+ item["to_warehouse"] = self.pro_doc.scrap_warehouse
- self.add_to_stock_entry_detail(scrap_item_dict, bom_no=self.bom_no)
+ self.add_to_stock_entry_detail(scrap_item_dict, bom_no=self.bom_no)
# fetch the serial_no of the first stock entry for the second stock entry
if self.work_order and self.purpose == "Manufacture":
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index 0ef2afa4a81..9517cd495b4 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -360,8 +360,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"""