Removed Sales/Purchase Return option from Stock Entry
diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py
index bac5441..4521821 100644
--- a/erpnext/stock/doctype/serial_no/serial_no.py
+++ b/erpnext/stock/doctype/serial_no/serial_no.py
@@ -81,20 +81,19 @@
def set_status(self, last_sle):
if last_sle:
if last_sle.voucher_type == "Stock Entry":
- document_type = frappe.db.get_value("Stock Entry", last_sle.voucher_no,
- "purpose")
+ document_type = frappe.db.get_value("Stock Entry", last_sle.voucher_no, "purpose")
else:
document_type = last_sle.voucher_type
if last_sle.actual_qty > 0:
- if document_type == "Sales Return":
+ if document_type in ("Delivery Note", "Sales Invoice", "Sales Return"):
self.status = "Sales Returned"
else:
self.status = "Available"
else:
- if document_type == "Purchase Return":
+ if document_type in ("Purchase Receipt", "Purchase Invoice", "Purchase Return"):
self.status = "Purchase Returned"
- elif last_sle.voucher_type in ("Delivery Note", "Sales Invoice"):
+ elif document_type in ("Delivery Note", "Sales Invoice"):
self.status = "Delivered"
else:
self.status = "Not Available"
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 6958ea0..8526117 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -7,20 +7,7 @@
erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
setup: function() {
var me = this;
-
- this.frm.fields_dict.delivery_note_no.get_query = function() {
- return { query: "erpnext.stock.doctype.stock_entry.stock_entry.query_sales_return_doc" };
- };
-
- this.frm.fields_dict.sales_invoice_no.get_query =
- this.frm.fields_dict.delivery_note_no.get_query;
-
- this.frm.fields_dict.purchase_receipt_no.get_query = function() {
- return {
- filters:{ 'docstatus': 1 }
- };
- };
-
+
this.frm.fields_dict.bom_no.get_query = function() {
return {
filters:{ 'docstatus': 1 }
@@ -28,20 +15,7 @@
};
this.frm.fields_dict.items.grid.get_field('item_code').get_query = function() {
- if(in_list(["Sales Return", "Purchase Return"], me.frm.doc.purpose) &&
- me.get_doctype_docname()) {
- return {
- query: "erpnext.stock.doctype.stock_entry.stock_entry.query_return_item",
- filters: {
- purpose: me.frm.doc.purpose,
- delivery_note_no: me.frm.doc.delivery_note_no,
- sales_invoice_no: me.frm.doc.sales_invoice_no,
- purchase_receipt_no: me.frm.doc.purchase_receipt_no
- }
- };
- } else {
- return erpnext.queries.item({is_stock_item: "Yes"});
- }
+ return erpnext.queries.item({is_stock_item: "Yes"});
};
this.frm.set_query("purchase_order", function() {
@@ -84,19 +58,6 @@
this.toggle_enable_bom();
this.show_stock_ledger();
this.show_general_ledger();
-
- if(this.frm.doc.docstatus === 1 && frappe.boot.user.can_create.indexOf("Journal Entry")!==-1
- && this.frm.doc.__onload.credit_debit_note_exists == 0 ) {
- if(this.frm.doc.purpose === "Sales Return") {
- this.frm.add_custom_button(__("Make Credit Note"),
- function() { me.make_return_jv(); }, frappe.boot.doctype_icons["Journal Entry"]);
- this.add_excise_button();
- } else if(this.frm.doc.purpose === "Purchase Return") {
- this.frm.add_custom_button(__("Make Debit Note"),
- function() { me.make_return_jv(); }, frappe.boot.doctype_icons["Journal Entry"]);
- this.add_excise_button();
- }
- }
},
on_submit: function() {
@@ -111,15 +72,10 @@
var me = this;
if(cint(frappe.defaults.get_default("auto_accounting_for_stock")) && this.frm.doc.company) {
- var account_for = "stock_adjustment_account";
-
- if (this.frm.doc.purpose == "Purchase Return")
- account_for = "stock_received_but_not_billed";
-
return this.frm.call({
method: "erpnext.accounts.utils.get_company_default",
args: {
- "fieldname": account_for,
+ "fieldname": "stock_adjustment_account",
"company": this.frm.doc.company
},
callback: function(r) {
@@ -192,35 +148,6 @@
this.frm.toggle_enable("bom_no", !in_list(["Manufacture", "Material Transfer for Manufacture"], this.frm.doc.purpose));
},
- get_doctype_docname: function() {
- if(this.frm.doc.purpose === "Sales Return") {
- if(this.frm.doc.delivery_note_no && this.frm.doc.sales_invoice_no) {
- // both specified
- msgprint(__("You can not enter both Delivery Note No and Sales Invoice No. Please enter any one."));
-
- } else if(!(this.frm.doc.delivery_note_no || this.frm.doc.sales_invoice_no)) {
- // none specified
- msgprint(__("Please enter Delivery Note No or Sales Invoice No to proceed"));
-
- } else if(this.frm.doc.delivery_note_no) {
- return {doctype: "Delivery Note", docname: this.frm.doc.delivery_note_no};
-
- } else if(this.frm.doc.sales_invoice_no) {
- return {doctype: "Sales Invoice", docname: this.frm.doc.sales_invoice_no};
-
- }
- } else if(this.frm.doc.purpose === "Purchase Return") {
- if(this.frm.doc.purchase_receipt_no) {
- return {doctype: "Purchase Receipt", docname: this.frm.doc.purchase_receipt_no};
-
- } else {
- // not specified
- msgprint(__("Please enter Purchase Receipt No to proceed"));
-
- }
- }
- },
-
add_excise_button: function() {
if(frappe.boot.sysdefaults.country === "India")
this.frm.add_custom_button(__("Make Excise Invoice"), function() {
@@ -231,37 +158,16 @@
}, frappe.boot.doctype_icons["Journal Entry"], "btn-default");
},
- make_return_jv: function() {
- if(this.get_doctype_docname()) {
- return this.frm.call({
- method: "make_return_jv",
- args: {
- stock_entry: this.frm.doc.name
- },
- callback: function(r) {
- if(!r.exc) {
- var doclist = frappe.model.sync(r.message);
- frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
-
- }
- }
- });
- }
- },
-
items_add: function(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
- this.frm.script_manager.copy_from_first_row("items", row,
- ["expense_account", "cost_center"]);
+ this.frm.script_manager.copy_from_first_row("items", row, ["expense_account", "cost_center"]);
if(!row.s_warehouse) row.s_warehouse = this.frm.doc.from_warehouse;
if(!row.t_warehouse) row.t_warehouse = this.frm.doc.to_warehouse;
},
- source_mandatory: ["Material Issue", "Material Transfer", "Purchase Return", "Subcontract",
- "Material Transfer for Manufacture"],
- target_mandatory: ["Material Receipt", "Material Transfer", "Sales Return", "Subcontract",
- "Material Transfer for Manufacture"],
+ source_mandatory: ["Material Issue", "Material Transfer", "Subcontract", "Material Transfer for Manufacture"],
+ target_mandatory: ["Material Receipt", "Material Transfer", "Subcontract", "Material Transfer for Manufacture"],
from_warehouse: function(doc) {
var me = this;
@@ -295,92 +201,21 @@
items_on_form_rendered: function(doc, grid_row) {
erpnext.setup_serial_no();
- },
-
- customer: function() {
- this.get_party_details({
- party: this.frm.doc.customer,
- party_type:"Customer",
- doctype: this.frm.doc.doctype
- });
- },
-
- supplier: function() {
- this.get_party_details({
- party: this.frm.doc.supplier,
- party_type:"Supplier",
- doctype: this.frm.doc.doctype
- });
- },
-
- get_party_details: function(args) {
- var me = this;
- frappe.call({
- method: "erpnext.accounts.party.get_party_details",
- args: args,
- callback: function(r) {
- if(r.message) {
- me.frm.set_value({
- "customer_name": r.message["customer_name"],
- "customer_address": r.message["address_display"]
- });
- }
- }
- });
- },
-
- delivery_note_no: function() {
- this.get_party_details_from_against_voucher({
- ref_dt: "Delivery Note",
- ref_dn: this.frm.doc.delivery_note_no
- })
- },
-
- sales_invoice_no: function() {
- this.get_party_details_from_against_voucher({
- ref_dt: "Sales Invoice",
- ref_dn: this.frm.doc.sales_invoice_no
- })
- },
-
- purchase_receipt_no: function() {
- this.get_party_details_from_against_voucher({
- ref_dt: "Purchase Receipt",
- ref_dn: this.frm.doc.purchase_receipt_no
- })
- },
-
- get_party_details_from_against_voucher: function(args) {
- return this.frm.call({
- method: "erpnext.stock.doctype.stock_entry.stock_entry.get_party_details",
- args: args,
- })
}
-
});
cur_frm.script_manager.make(erpnext.stock.StockEntry);
cur_frm.cscript.toggle_related_fields = function(doc) {
- disable_from_warehouse = inList(["Material Receipt", "Sales Return"], doc.purpose);
- disable_to_warehouse = inList(["Material Issue", "Purchase Return"], doc.purpose);
+ cur_frm.toggle_enable("from_warehouse", doc.purpose!='Material Receipt');
+ cur_frm.toggle_enable("to_warehouse", doc.purpose!='Material Issue');
- cur_frm.toggle_enable("from_warehouse", !disable_from_warehouse);
- cur_frm.toggle_enable("to_warehouse", !disable_to_warehouse);
-
- cur_frm.fields_dict["items"].grid.set_column_disp("s_warehouse", !disable_from_warehouse);
- cur_frm.fields_dict["items"].grid.set_column_disp("t_warehouse", !disable_to_warehouse);
+ cur_frm.fields_dict["items"].grid.set_column_disp("s_warehouse", doc.purpose!='Material Receipt');
+ cur_frm.fields_dict["items"].grid.set_column_disp("t_warehouse", doc.purpose!='Material Issue');
cur_frm.cscript.toggle_enable_bom();
- if(doc.purpose == 'Purchase Return') {
- doc.customer = doc.customer_name = doc.customer_address =
- doc.delivery_note_no = doc.sales_invoice_no = null;
- doc.bom_no = doc.production_order = doc.fg_completed_qty = null;
- } else if(doc.purpose == 'Sales Return') {
- doc.supplier=doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no=null;
- doc.bom_no = doc.production_order = doc.fg_completed_qty = null;
- } else if (doc.purpose == 'Subcontract') {
+ if (doc.purpose == 'Subcontract') {
doc.customer = doc.customer_name = doc.customer_address =
doc.delivery_note_no = doc.sales_invoice_no = null;
} else {
@@ -388,7 +223,7 @@
doc.delivery_note_no = doc.sales_invoice_no = doc.supplier =
doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no = null;
}
- if(in_list(["Material Receipt", "Sales Return", "Purchase Return"], doc.purpose)) {
+ if(doc.purpose == "Material Receipt") {
cur_frm.set_value("from_bom", 0);
}
}
@@ -505,8 +340,6 @@
}
cur_frm.cscript.validate = function(doc, cdt, cdn) {
- if($.inArray(cur_frm.doc.purpose, ["Purchase Return", "Sales Return"])!==-1)
- validated = cur_frm.cscript.get_doctype_docname() ? true : false;
cur_frm.cscript.validate_items(doc);
}
@@ -526,14 +359,6 @@
erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "cost_center");
}
-cur_frm.fields_dict.customer.get_query = function(doc, cdt, cdn) {
- return { query: "erpnext.controllers.queries.customer_query" }
-}
-
-cur_frm.fields_dict.supplier.get_query = function(doc, cdt, cdn) {
- return { query: "erpnext.controllers.queries.supplier_query" }
-}
-
cur_frm.cscript.company = function(doc, cdt, cdn) {
if(doc.company) {
erpnext.get_fiscal_year(doc.company, doc.posting_date, function() {
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json
index 06dec58..ca84db9 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.json
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.json
@@ -54,7 +54,7 @@
"no_copy": 0,
"oldfieldname": "purpose",
"oldfieldtype": "Select",
- "options": "Material Issue\nMaterial Receipt\nMaterial Transfer\nMaterial Transfer for Manufacture\nManufacture\nRepack\nSubcontract\nSales Return\nPurchase Return",
+ "options": "Material Issue\nMaterial Receipt\nMaterial Transfer\nMaterial Transfer for Manufacture\nManufacture\nRepack\nSubcontract",
"permlevel": 0,
"print_hide": 0,
"read_only": 0,
@@ -678,7 +678,7 @@
"is_submittable": 1,
"issingle": 0,
"max_attachments": 0,
- "modified": "2015-07-13 05:28:26.085266",
+ "modified": "2015-07-17 15:41:00.980883",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Entry",
@@ -695,7 +695,7 @@
"print": 1,
"read": 1,
"report": 1,
- "role": "Stock User",
+ "role": "Material User",
"share": 1,
"submit": 1,
"write": 1
@@ -741,7 +741,7 @@
"print": 1,
"read": 1,
"report": 1,
- "role": "Stock Manager",
+ "role": "Material Manager",
"share": 1,
"submit": 1,
"write": 1
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index fb1ec3d..78e1038 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -4,10 +4,8 @@
from __future__ import unicode_literals
import frappe
import frappe.defaults
-
-from frappe.utils import cstr, cint, flt, comma_or, get_datetime, getdate
-
from frappe import _
+from frappe.utils import cstr, cint, flt, comma_or, get_datetime, getdate
from erpnext.stock.utils import get_incoming_rate
from erpnext.stock.stock_ledger import get_previous_sle, NegativeStockError
from erpnext.controllers.queries import get_match_cond
@@ -16,7 +14,6 @@
from erpnext.accounts.utils import validate_fiscal_year
class NotUpdateStockError(frappe.ValidationError): pass
-class StockOverReturnError(frappe.ValidationError): pass
class IncorrectValuationRateError(frappe.ValidationError): pass
class DuplicateEntryForProductionOrderError(frappe.ValidationError): pass
class OperationsNotCompleteError(frappe.ValidationError): pass
@@ -37,13 +34,6 @@
item.update(get_available_qty(item.item_code,
item.s_warehouse))
- count = frappe.db.exists({
- "doctype": "Journal Entry",
- "stock_entry":self.name,
- "docstatus":1
- })
- self.get("__onload").credit_debit_note_exists = 1 if count else 0
-
def validate(self):
self.pro_doc = None
if self.production_order:
@@ -84,16 +74,13 @@
def validate_purpose(self):
valid_purposes = ["Material Issue", "Material Receipt", "Material Transfer", "Material Transfer for Manufacture",
- "Manufacture", "Repack", "Subcontract", "Sales Return", "Purchase Return"]
+ "Manufacture", "Repack", "Subcontract"]
if self.purpose not in valid_purposes:
frappe.throw(_("Purpose must be one of {0}").format(comma_or(valid_purposes)))
- if self.purpose in ("Manufacture", "Repack", "Sales Return") and not self.difference_account:
+ if self.purpose in ("Manufacture", "Repack") and not self.difference_account:
self.difference_account = frappe.db.get_value("Company", self.company, "default_expense_account")
- if self.purpose in ("Purchase Return") and not self.difference_account:
- frappe.throw(_("Difference Account mandatory for purpose '{0}'").format(self.purpose))
-
def set_transfer_qty(self):
for item in self.get("items"):
if not flt(item.qty):
@@ -122,7 +109,7 @@
if not item.transfer_qty:
item.transfer_qty = item.qty * item.conversion_factor
- if (self.purpose in ("Material Transfer", "Sales Return", "Purchase Return", "Material Transfer for Manufacture")
+ if (self.purpose in ("Material Transfer", "Material Transfer for Manufacture")
and not item.serial_no
and item.item_code in serialized_items):
frappe.throw(_("Row #{0}: Please specify Serial No for Item {1}").format(item.idx, item.item_code),
@@ -131,8 +118,8 @@
def validate_warehouse(self):
"""perform various (sometimes conditional) validations on warehouse"""
- source_mandatory = ["Material Issue", "Material Transfer", "Purchase Return", "Subcontract", "Material Transfer for Manufacture"]
- target_mandatory = ["Material Receipt", "Material Transfer", "Sales Return", "Subcontract", "Material Transfer for Manufacture"]
+ source_mandatory = ["Material Issue", "Material Transfer", "Subcontract", "Material Transfer for Manufacture"]
+ target_mandatory = ["Material Receipt", "Material Transfer", "Subcontract", "Material Transfer for Manufacture"]
validate_for_manufacture_repack = any([d.bom_no for d in self.get("items")])
@@ -291,8 +278,8 @@
# get incoming rate
if not d.bom_no:
- if not flt(d.incoming_rate) or d.s_warehouse or self.purpose == "Sales Return" or force:
- incoming_rate = flt(self.get_incoming_rate(args), self.precision("incoming_rate", d))
+ if not flt(d.incoming_rate) or d.s_warehouse or force:
+ incoming_rate = flt(get_incoming_rate(args), self.precision("incoming_rate", d))
if incoming_rate > 0:
d.incoming_rate = incoming_rate
@@ -336,27 +323,6 @@
return operation_cost_per_unit + (flt(self.additional_operating_cost) / flt(qty))
- def get_incoming_rate(self, args):
- incoming_rate = 0
- if self.purpose == "Sales Return":
- incoming_rate = self.get_incoming_rate_for_sales_return(args)
- else:
- incoming_rate = get_incoming_rate(args)
-
- return incoming_rate
-
- def get_incoming_rate_for_sales_return(self, args):
- incoming_rate = 0.0
- if (self.delivery_note_no or self.sales_invoice_no) and args.get("item_code"):
- incoming_rate = frappe.db.sql("""select abs(ifnull(stock_value_difference, 0) / actual_qty)
- from `tabStock Ledger Entry`
- where voucher_type = %s and voucher_no = %s and item_code = %s limit 1""",
- ((self.delivery_note_no and "Delivery Note" or "Sales Invoice"),
- self.delivery_note_no or self.sales_invoice_no, args.item_code))
- incoming_rate = incoming_rate[0][0] if incoming_rate else 0.0
-
- return incoming_rate
-
def validate_purchase_order(self):
"""Throw exception if more raw material is transferred against Purchase Order than in
the raw materials supplied table"""
@@ -403,55 +369,6 @@
frappe.throw(_("Finished Item {0} must be entered for Manufacture type entry")
.format(production_item))
- def validate_return_reference_doc(self):
- """validate item with reference doc"""
- ref = get_return_doc_and_details(self)
-
- if ref.doc:
- # validate docstatus
- if ref.doc.docstatus != 1:
- frappe.throw(_("{0} {1} must be submitted").format(ref.doc.doctype, ref.doc.name),
- frappe.InvalidStatusError)
-
- # update stock check
- if ref.doc.doctype == "Sales Invoice" and cint(ref.doc.update_stock) != 1:
- frappe.throw(_("'Update Stock' for Sales Invoice {0} must be set").format(ref.doc.name), NotUpdateStockError)
-
- # posting date check
- ref_posting_datetime = "%s %s" % (ref.doc.posting_date, ref.doc.posting_time or "00:00:00")
-
- if get_datetime(ref_posting_datetime) < get_datetime(ref_posting_datetime):
- from frappe.utils.dateutils import datetime_in_user_format
- frappe.throw(_("Posting timestamp must be after {0}")
- .format(datetime_in_user_format(ref_posting_datetime)))
-
- stock_items = get_stock_items_for_return(ref.doc, ref.parentfields)
- already_returned_item_qty = self.get_already_returned_item_qty(ref.fieldname)
-
- for item in self.get("items"):
- # validate if item exists in the ref doc and that it is a stock item
- if item.item_code not in stock_items:
- frappe.throw(_("Item {0} does not exist in {1} {2}").format(item.item_code, ref.doc.doctype, ref.doc.name),
- frappe.DoesNotExistError)
-
- # validate quantity <= ref item's qty - qty already returned
- if self.purpose == "Purchase Return":
- ref_item_qty = sum([flt(d.qty)*flt(d.conversion_factor) for d in ref.doc.get({"item_code": item.item_code})])
- elif self.purpose == "Sales Return":
- ref_item_qty = sum([flt(d.qty) for d in ref.doc.get({"item_code": item.item_code})])
- returnable_qty = ref_item_qty - flt(already_returned_item_qty.get(item.item_code))
- if not returnable_qty:
- frappe.throw(_("Item {0} has already been returned").format(item.item_code), StockOverReturnError)
- elif item.transfer_qty > returnable_qty:
- frappe.throw(_("Cannot return more than {0} for Item {1}").format(returnable_qty, item.item_code),
- StockOverReturnError)
-
- def get_already_returned_item_qty(self, ref_fieldname):
- return dict(frappe.db.sql("""select item_code, sum(transfer_qty) as qty
- from `tabStock Entry Detail` where parent in (
- select name from `tabStock Entry` where `%s`=%s and docstatus=1)
- group by item_code""" % (ref_fieldname, "%s"), (self.get(ref_fieldname),)))
-
def update_stock_ledger(self):
sl_entries = []
for d in self.get('items'):
@@ -514,6 +431,7 @@
(args.get('item_code')), as_dict = 1)
if not item:
frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code")))
+
item = item[0]
ret = {
@@ -561,7 +479,7 @@
ret = {
"actual_qty" : get_previous_sle(args).get("qty_after_transaction") or 0,
- "incoming_rate" : self.get_incoming_rate(args)
+ "incoming_rate" : get_incoming_rate(args)
}
return ret
@@ -738,15 +656,6 @@
if getdate(self.posting_date) > getdate(expiry_date):
frappe.throw(_("Batch {0} of Item {1} has expired.").format(item.batch_no, item.item_code))
-@frappe.whitelist()
-def get_party_details(ref_dt, ref_dn):
- if ref_dt in ["Delivery Note", "Sales Invoice"]:
- res = frappe.db.get_value(ref_dt, ref_dn,
- ["customer", "customer_name", "address_display as customer_address"], as_dict=1)
- else:
- res = frappe.db.get_value(ref_dt, ref_dn,
- ["supplier", "supplier_name", "address_display as supplier_address"], as_dict=1)
- return res or {}
@frappe.whitelist()
def get_production_order_details(production_order):
@@ -756,264 +665,3 @@
from `tabProduction Order` where name = %s""", production_order, as_dict=1)
return res and res[0] or {}
-
-def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters):
- conditions = ""
- if doctype == "Sales Invoice":
- conditions = "and update_stock=1"
-
- return frappe.db.sql("""select name, customer, customer_name
- from `tab%s` where docstatus = 1
- and (`%s` like %%(txt)s
- or `customer` like %%(txt)s) %s %s
- order by name, customer, customer_name
- limit %s""" % (doctype, searchfield, conditions,
- get_match_cond(doctype), "%(start)s, %(page_len)s"),
- {"txt": "%%%s%%" % txt, "start": start, "page_len": page_len},
- as_list=True)
-
-def query_purchase_return_doc(doctype, txt, searchfield, start, page_len, filters):
- return frappe.db.sql("""select name, supplier, supplier_name
- from `tab%s` where docstatus = 1
- and (`%s` like %%(txt)s
- or `supplier` like %%(txt)s) %s
- order by name, supplier, supplier_name
- limit %s""" % (doctype, searchfield, get_match_cond(doctype),
- "%(start)s, %(page_len)s"), {"txt": "%%%s%%" % txt, "start":
- start, "page_len": page_len}, as_list=True)
-
-def query_return_item(doctype, txt, searchfield, start, page_len, filters):
- txt = txt.replace("%", "")
-
- ref = get_return_doc_and_details(filters)
-
- stock_items = get_stock_items_for_return(ref.doc, ref.parentfields)
-
- result = []
- for item in ref.doc.get_all_children():
- if getattr(item, "item_code", None) in stock_items:
- item.item_name = cstr(item.item_name)
- item.description = cstr(item.description)
- if (txt in item.item_code) or (txt in item.item_name) or (txt in item.description):
- val = [
- item.item_code,
- (len(item.item_name) > 40) and (item.item_name[:40] + "...") or item.item_name,
- (len(item.description) > 40) and (item.description[:40] + "...") or \
- item.description
- ]
- if val not in result:
- result.append(val)
-
- return result[start:start+page_len]
-
-def get_stock_items_for_return(ref_doc, parentfields):
- """return item codes filtered from doc, which are stock items"""
- if isinstance(parentfields, basestring):
- parentfields = [parentfields]
-
- all_items = list(set([d.item_code for d in
- ref_doc.get_all_children() if d.get("item_code")]))
- stock_items = frappe.db.sql_list("""select name from `tabItem`
- where is_stock_item='Yes' and name in (%s)""" % (", ".join(["%s"] * len(all_items))),
- tuple(all_items))
-
- return stock_items
-
-def get_return_doc_and_details(args):
- ref = frappe._dict()
-
- # get ref_doc
- if args.get("purpose") in return_map:
- for fieldname, val in return_map[args.get("purpose")].items():
- if args.get(fieldname):
- ref.fieldname = fieldname
- ref.doc = frappe.get_doc(val[0], args.get(fieldname))
- ref.parentfields = val[1]
- break
-
- return ref
-
-return_map = {
- "Sales Return": {
- # [Ref DocType, [Item tables' parentfields]]
- "delivery_note_no": ["Delivery Note", ["items", "packed_items"]],
- "sales_invoice_no": ["Sales Invoice", ["items", "packed_items"]]
- },
- "Purchase Return": {
- "purchase_receipt_no": ["Purchase Receipt", ["items"]]
- }
-}
-
-@frappe.whitelist()
-def make_return_jv(stock_entry):
- se = frappe.get_doc("Stock Entry", stock_entry)
- if not se.purpose in ["Sales Return", "Purchase Return"]:
- return
-
- ref = get_return_doc_and_details(se)
-
- if ref.doc.doctype == "Delivery Note":
- result = make_return_jv_from_delivery_note(se, ref)
- elif ref.doc.doctype == "Sales Invoice":
- result = make_return_jv_from_sales_invoice(se, ref)
- elif ref.doc.doctype == "Purchase Receipt":
- result = make_return_jv_from_purchase_receipt(se, ref)
-
- # create jv doc and fetch balance for each unique row item
- jv = frappe.new_doc("Journal Entry")
- jv.update({
- "posting_date": se.posting_date,
- "voucher_type": se.purpose == "Sales Return" and "Credit Note" or "Debit Note",
- "fiscal_year": se.fiscal_year,
- "company": se.company,
- "stock_entry": se.name
- })
-
- from erpnext.accounts.utils import get_balance_on
- for r in result:
- jv.append("accounts", {
- "account": r.get("account"),
- "party_type": r.get("party_type"),
- "party": r.get("party"),
- "balance": get_balance_on(r.get("account"), se.posting_date) if r.get("account") else 0
- })
-
- return jv
-
-def make_return_jv_from_sales_invoice(se, ref):
- # customer account entry
- parent = {
- "account": ref.doc.debit_to,
- "party_type": "Customer",
- "party": ref.doc.customer
- }
-
- # income account entries
- children = []
- for se_item in se.get("items"):
- # find item in ref.doc
- ref_item = ref.doc.get({"item_code": se_item.item_code})[0]
-
- account = get_sales_account_from_item(ref.doc, ref_item)
-
- if account not in children:
- children.append(account)
-
- return [parent] + [{"account": account} for account in children]
-
-def get_sales_account_from_item(doc, ref_item):
- account = None
- if not getattr(ref_item, "income_account", None):
- if ref_item.parent_item:
- parent_item = doc.get("items", {"item_code": ref_item.parent_item})[0]
- account = parent_item.income_account
- else:
- account = ref_item.income_account
-
- return account
-
-def make_return_jv_from_delivery_note(se, ref):
- invoices_against_delivery = get_invoice_list("Sales Invoice Item", "delivery_note",
- ref.doc.name)
-
- if not invoices_against_delivery:
- sales_orders_against_delivery = [d.against_sales_order for d in ref.doc.get_all_children() if getattr(d, "against_sales_order", None)]
-
- if sales_orders_against_delivery:
- invoices_against_delivery = get_invoice_list("Sales Invoice Item", "sales_order",
- sales_orders_against_delivery)
-
- if not invoices_against_delivery:
- return []
-
- packing_item_parent_map = dict([[d.item_code, d.parent_item] for d in ref.doc.get(ref.parentfields[1])])
-
- parent = {}
- children = []
-
- for se_item in se.get("items"):
- for sales_invoice in invoices_against_delivery:
- si = frappe.get_doc("Sales Invoice", sales_invoice)
-
- if se_item.item_code in packing_item_parent_map:
- ref_item = si.get({"item_code": packing_item_parent_map[se_item.item_code]})
- else:
- ref_item = si.get({"item_code": se_item.item_code})
-
- if not ref_item:
- continue
-
- ref_item = ref_item[0]
-
- account = get_sales_account_from_item(si, ref_item)
-
- if account not in children:
- children.append(account)
-
- if not parent:
- parent = {
- "account": si.debit_to,
- "party_type": "Customer",
- "party": si.customer
- }
-
- break
-
- result = [parent] + [{"account": account} for account in children]
-
- return result
-
-def get_invoice_list(doctype, link_field, value):
- if isinstance(value, basestring):
- value = [value]
-
- return frappe.db.sql_list("""select distinct parent from `tab%s`
- where docstatus = 1 and `%s` in (%s)""" % (doctype, link_field,
- ", ".join(["%s"]*len(value))), tuple(value))
-
-def make_return_jv_from_purchase_receipt(se, ref):
- invoice_against_receipt = get_invoice_list("Purchase Invoice Item", "purchase_receipt",
- ref.doc.name)
-
- if not invoice_against_receipt:
- purchase_orders_against_receipt = [d.prevdoc_docname for d in
- ref.doc.get("items", {"prevdoc_doctype": "Purchase Order"})
- if getattr(d, "prevdoc_docname", None)]
-
- if purchase_orders_against_receipt:
- invoice_against_receipt = get_invoice_list("Purchase Invoice Item", "purchase_order",
- purchase_orders_against_receipt)
-
- if not invoice_against_receipt:
- return []
-
- parent = {}
- children = []
-
- for se_item in se.get("items"):
- for purchase_invoice in invoice_against_receipt:
- pi = frappe.get_doc("Purchase Invoice", purchase_invoice)
- ref_item = pi.get({"item_code": se_item.item_code})
-
- if not ref_item:
- continue
-
- ref_item = ref_item[0]
-
- account = ref_item.expense_account
-
- if account not in children:
- children.append(account)
-
- if not parent:
- parent = {
- "account": pi.credit_to,
- "party_type": "Supplier",
- "party": pi.supplier
- }
-
- break
-
- result = [parent] + [{"account": account} for account in children]
-
- return result
diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
index 70d6413..5406bdc 100644
--- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
@@ -303,262 +303,262 @@
self.assertEquals(expected_gl_entries[i][1], gle[1])
self.assertEquals(expected_gl_entries[i][2], gle[2])
- def _test_sales_invoice_return(self, item_code, delivered_qty, returned_qty):
- from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
-
- si = create_sales_invoice(item_code=item_code, qty=delivered_qty)
-
- se = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=returned_qty,
- purpose="Sales Return", sales_invoice_no=si.name, do_not_save=True)
- self.assertRaises(NotUpdateStockError, se.insert)
-
- make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=200, incoming_rate=100)
-
- # check currency available qty in bin
- actual_qty_0 = get_qty_after_transaction()
-
- # insert a pos invoice with update stock
- si = create_sales_invoice(update_stock=1, item_code=item_code, qty=5)
-
- # check available bin qty after invoice submission
- actual_qty_1 = get_qty_after_transaction()
-
- self.assertEquals(actual_qty_0 - delivered_qty, actual_qty_1)
-
- # check if item is validated
- se = make_stock_entry(item_code="_Test Item Home Desktop 200", target="_Test Warehouse - _TC",
- qty=returned_qty, purpose="Sales Return", sales_invoice_no=si.name, do_not_save=True)
-
- self.assertRaises(frappe.DoesNotExistError, se.insert)
-
- # try again
- se = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
- qty=returned_qty, purpose="Sales Return", sales_invoice_no=si.name)
-
- # check if available qty is increased
- actual_qty_2 = get_qty_after_transaction()
-
- self.assertEquals(actual_qty_1 + returned_qty, actual_qty_2)
-
- return se
-
- def test_sales_invoice_return_of_non_packing_item(self):
- self._test_sales_invoice_return("_Test Item", 5, 2)
-
- def test_sales_invoice_return_of_packing_item(self):
- self._test_sales_invoice_return("_Test Product Bundle Item", 25, 20)
-
- def _test_delivery_note_return(self, item_code, delivered_qty, returned_qty):
- from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
-
- from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice
-
- make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, incoming_rate=100)
-
- actual_qty_0 = get_qty_after_transaction()
- # make a delivery note based on this invoice
- dn = create_delivery_note(item_code="_Test Item",
- warehouse="_Test Warehouse - _TC", qty=delivered_qty)
-
- actual_qty_1 = get_qty_after_transaction()
-
- self.assertEquals(actual_qty_0 - delivered_qty, actual_qty_1)
-
- si = make_sales_invoice(dn.name)
- si.insert()
- si.submit()
-
- # insert and submit stock entry for sales return
- se = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
- qty=returned_qty, purpose="Sales Return", delivery_note_no=dn.name)
-
- actual_qty_2 = get_qty_after_transaction()
- self.assertEquals(actual_qty_1 + returned_qty, actual_qty_2)
-
- return se
-
- def test_delivery_note_return_of_non_packing_item(self):
- self._test_delivery_note_return("_Test Item", 5, 2)
-
- def test_delivery_note_return_of_packing_item(self):
- self._test_delivery_note_return("_Test Product Bundle Item", 25, 20)
-
- def _test_sales_return_jv(self, se):
- jv = make_return_jv(se.name)
-
- self.assertEqual(len(jv.get("accounts")), 2)
- self.assertEqual(jv.get("voucher_type"), "Credit Note")
- self.assertEqual(jv.get("posting_date"), getdate(se.posting_date))
- self.assertEqual(jv.get("accounts")[0].get("account"), "Debtors - _TC")
- self.assertEqual(jv.get("accounts")[0].get("party_type"), "Customer")
- self.assertEqual(jv.get("accounts")[0].get("party"), "_Test Customer")
- self.assertEqual(jv.get("accounts")[1].get("account"), "Sales - _TC")
-
- def test_make_return_jv_for_sales_invoice_non_packing_item(self):
- se = self._test_sales_invoice_return("_Test Item", 5, 2)
- self._test_sales_return_jv(se)
-
- def test_make_return_jv_for_sales_invoice_packing_item(self):
- se = self._test_sales_invoice_return("_Test Product Bundle Item", 25, 20)
- self._test_sales_return_jv(se)
-
- def test_make_return_jv_for_delivery_note_non_packing_item(self):
- se = self._test_delivery_note_return("_Test Item", 5, 2)
- self._test_sales_return_jv(se)
-
- se = self._test_delivery_note_return_against_sales_order("_Test Item", 5, 2)
- self._test_sales_return_jv(se)
-
- def test_make_return_jv_for_delivery_note_packing_item(self):
- se = self._test_delivery_note_return("_Test Product Bundle Item", 25, 20)
- self._test_sales_return_jv(se)
-
- se = self._test_delivery_note_return_against_sales_order("_Test Product Bundle Item", 25, 20)
- self._test_sales_return_jv(se)
-
- def _test_delivery_note_return_against_sales_order(self, item_code, delivered_qty, returned_qty):
- from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
-
- actual_qty_0 = get_qty_after_transaction()
-
- so = make_sales_order(qty=50)
-
- dn = create_dn_against_so(so.name, delivered_qty)
-
- actual_qty_1 = get_qty_after_transaction()
- self.assertEquals(actual_qty_0 - delivered_qty, actual_qty_1)
-
- si = make_sales_invoice(so.name)
- si.insert()
- si.submit()
-
- # insert and submit stock entry for sales return
- se = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
- qty=returned_qty, purpose="Sales Return", delivery_note_no=dn.name)
-
- actual_qty_2 = get_qty_after_transaction()
- self.assertEquals(actual_qty_1 + returned_qty, actual_qty_2)
-
- return se
-
- def test_purchase_receipt_return(self):
- actual_qty_0 = get_qty_after_transaction()
-
- # submit purchase receipt
- pr = make_purchase_receipt(item_code="_Test Item", warehouse="_Test Warehouse - _TC", qty=5)
-
- actual_qty_1 = get_qty_after_transaction()
-
- self.assertEquals(actual_qty_0 + 5, actual_qty_1)
-
- pi_doc = make_purchase_invoice(pr.name)
-
- pi = frappe.get_doc(pi_doc)
- pi.posting_date = pr.posting_date
- pi.credit_to = "_Test Payable - _TC"
- for d in pi.get("items"):
- d.expense_account = "_Test Account Cost for Goods Sold - _TC"
- d.cost_center = "_Test Cost Center - _TC"
-
- for d in pi.get("taxes"):
- d.cost_center = "_Test Cost Center - _TC"
-
- pi.insert()
- pi.submit()
-
- # submit purchase return
- se = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
- qty=5, purpose="Purchase Return", purchase_receipt_no=pr.name)
-
- actual_qty_2 = get_qty_after_transaction()
-
- self.assertEquals(actual_qty_1 - 5, actual_qty_2)
-
- return se, pr.name
-
- def test_over_stock_return(self):
- from erpnext.stock.doctype.stock_entry.stock_entry import StockOverReturnError
-
- # out of 10, 5 gets returned
- prev_se, pr_docname = self.test_purchase_receipt_return()
-
- se = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
- qty=6, purpose="Purchase Return", purchase_receipt_no=pr_docname, do_not_save=True)
-
- self.assertRaises(StockOverReturnError, se.insert)
-
- def _test_purchase_return_jv(self, se):
- jv = make_return_jv(se.name)
-
- self.assertEqual(len(jv.get("accounts")), 2)
- self.assertEqual(jv.get("voucher_type"), "Debit Note")
- self.assertEqual(jv.get("posting_date"), getdate(se.posting_date))
- self.assertEqual(jv.get("accounts")[0].get("account"), "_Test Payable - _TC")
- self.assertEqual(jv.get("accounts")[0].get("party"), "_Test Supplier")
- self.assertEqual(jv.get("accounts")[1].get("account"), "_Test Account Cost for Goods Sold - _TC")
-
- def test_make_return_jv_for_purchase_receipt(self):
- se, pr_name = self.test_purchase_receipt_return()
- self._test_purchase_return_jv(se)
-
- se, pr_name = self._test_purchase_return_return_against_purchase_order()
- self._test_purchase_return_jv(se)
-
- def _test_purchase_return_return_against_purchase_order(self):
-
- actual_qty_0 = get_qty_after_transaction()
-
- from erpnext.buying.doctype.purchase_order.test_purchase_order \
- import test_records as purchase_order_test_records
-
- from erpnext.buying.doctype.purchase_order.purchase_order import \
- make_purchase_receipt, make_purchase_invoice
-
- # submit purchase receipt
- po = frappe.copy_doc(purchase_order_test_records[0])
- po.transaction_date = nowdate()
- po.is_subcontracted = None
- po.get("items")[0].item_code = "_Test Item"
- po.get("items")[0].rate = 50
- po.insert()
- po.submit()
-
- pr_doc = make_purchase_receipt(po.name)
-
- pr = frappe.get_doc(pr_doc)
- pr.posting_date = po.transaction_date
- pr.insert()
- pr.submit()
-
- actual_qty_1 = get_qty_after_transaction()
-
- self.assertEquals(actual_qty_0 + 10, actual_qty_1)
-
- pi_doc = make_purchase_invoice(po.name)
-
- pi = frappe.get_doc(pi_doc)
- pi.posting_date = pr.posting_date
- pi.credit_to = "_Test Payable - _TC"
- for d in pi.get("items"):
- d.expense_account = "_Test Account Cost for Goods Sold - _TC"
- d.cost_center = "_Test Cost Center - _TC"
- for d in pi.get("taxes"):
- d.cost_center = "_Test Cost Center - _TC"
-
- pi.run_method("calculate_taxes_and_totals")
- pi.bill_no = "NA"
- pi.insert()
- pi.submit()
-
- # submit purchase return
- se = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
- qty=5, purpose="Purchase Return", purchase_receipt_no=pr.name)
-
- actual_qty_2 = get_qty_after_transaction()
-
- self.assertEquals(actual_qty_1 - 5, actual_qty_2)
-
- return se, pr.name
+ # def _test_sales_invoice_return(self, item_code, delivered_qty, returned_qty):
+ # from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
+ #
+ # si = create_sales_invoice(item_code=item_code, qty=delivered_qty)
+ #
+ # se = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=returned_qty,
+ # purpose="Sales Return", sales_invoice_no=si.name, do_not_save=True)
+ # self.assertRaises(NotUpdateStockError, se.insert)
+ #
+ # make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=200, incoming_rate=100)
+ #
+ # # check currency available qty in bin
+ # actual_qty_0 = get_qty_after_transaction()
+ #
+ # # insert a pos invoice with update stock
+ # si = create_sales_invoice(update_stock=1, item_code=item_code, qty=5)
+ #
+ # # check available bin qty after invoice submission
+ # actual_qty_1 = get_qty_after_transaction()
+ #
+ # self.assertEquals(actual_qty_0 - delivered_qty, actual_qty_1)
+ #
+ # # check if item is validated
+ # se = make_stock_entry(item_code="_Test Item Home Desktop 200", target="_Test Warehouse - _TC",
+ # qty=returned_qty, purpose="Sales Return", sales_invoice_no=si.name, do_not_save=True)
+ #
+ # self.assertRaises(frappe.DoesNotExistError, se.insert)
+ #
+ # # try again
+ # se = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
+ # qty=returned_qty, purpose="Sales Return", sales_invoice_no=si.name)
+ #
+ # # check if available qty is increased
+ # actual_qty_2 = get_qty_after_transaction()
+ #
+ # self.assertEquals(actual_qty_1 + returned_qty, actual_qty_2)
+ #
+ # return se
+ #
+ # def test_sales_invoice_return_of_non_packing_item(self):
+ # self._test_sales_invoice_return("_Test Item", 5, 2)
+ #
+ # def test_sales_invoice_return_of_packing_item(self):
+ # self._test_sales_invoice_return("_Test Product Bundle Item", 25, 20)
+ #
+ # def _test_delivery_note_return(self, item_code, delivered_qty, returned_qty):
+ # from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
+ #
+ # from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice
+ #
+ # make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, incoming_rate=100)
+ #
+ # actual_qty_0 = get_qty_after_transaction()
+ # # make a delivery note based on this invoice
+ # dn = create_delivery_note(item_code="_Test Item",
+ # warehouse="_Test Warehouse - _TC", qty=delivered_qty)
+ #
+ # actual_qty_1 = get_qty_after_transaction()
+ #
+ # self.assertEquals(actual_qty_0 - delivered_qty, actual_qty_1)
+ #
+ # si = make_sales_invoice(dn.name)
+ # si.insert()
+ # si.submit()
+ #
+ # # insert and submit stock entry for sales return
+ # se = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
+ # qty=returned_qty, purpose="Sales Return", delivery_note_no=dn.name)
+ #
+ # actual_qty_2 = get_qty_after_transaction()
+ # self.assertEquals(actual_qty_1 + returned_qty, actual_qty_2)
+ #
+ # return se
+ #
+ # def test_delivery_note_return_of_non_packing_item(self):
+ # self._test_delivery_note_return("_Test Item", 5, 2)
+ #
+ # def test_delivery_note_return_of_packing_item(self):
+ # self._test_delivery_note_return("_Test Product Bundle Item", 25, 20)
+ #
+ # def _test_sales_return_jv(self, se):
+ # jv = make_return_jv(se.name)
+ #
+ # self.assertEqual(len(jv.get("accounts")), 2)
+ # self.assertEqual(jv.get("voucher_type"), "Credit Note")
+ # self.assertEqual(jv.get("posting_date"), getdate(se.posting_date))
+ # self.assertEqual(jv.get("accounts")[0].get("account"), "Debtors - _TC")
+ # self.assertEqual(jv.get("accounts")[0].get("party_type"), "Customer")
+ # self.assertEqual(jv.get("accounts")[0].get("party"), "_Test Customer")
+ # self.assertEqual(jv.get("accounts")[1].get("account"), "Sales - _TC")
+ #
+ # def test_make_return_jv_for_sales_invoice_non_packing_item(self):
+ # se = self._test_sales_invoice_return("_Test Item", 5, 2)
+ # self._test_sales_return_jv(se)
+ #
+ # def test_make_return_jv_for_sales_invoice_packing_item(self):
+ # se = self._test_sales_invoice_return("_Test Product Bundle Item", 25, 20)
+ # self._test_sales_return_jv(se)
+ #
+ # def test_make_return_jv_for_delivery_note_non_packing_item(self):
+ # se = self._test_delivery_note_return("_Test Item", 5, 2)
+ # self._test_sales_return_jv(se)
+ #
+ # se = self._test_delivery_note_return_against_sales_order("_Test Item", 5, 2)
+ # self._test_sales_return_jv(se)
+ #
+ # def test_make_return_jv_for_delivery_note_packing_item(self):
+ # se = self._test_delivery_note_return("_Test Product Bundle Item", 25, 20)
+ # self._test_sales_return_jv(se)
+ #
+ # se = self._test_delivery_note_return_against_sales_order("_Test Product Bundle Item", 25, 20)
+ # self._test_sales_return_jv(se)
+ #
+ # def _test_delivery_note_return_against_sales_order(self, item_code, delivered_qty, returned_qty):
+ # from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
+ #
+ # actual_qty_0 = get_qty_after_transaction()
+ #
+ # so = make_sales_order(qty=50)
+ #
+ # dn = create_dn_against_so(so.name, delivered_qty)
+ #
+ # actual_qty_1 = get_qty_after_transaction()
+ # self.assertEquals(actual_qty_0 - delivered_qty, actual_qty_1)
+ #
+ # si = make_sales_invoice(so.name)
+ # si.insert()
+ # si.submit()
+ #
+ # # insert and submit stock entry for sales return
+ # se = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC",
+ # qty=returned_qty, purpose="Sales Return", delivery_note_no=dn.name)
+ #
+ # actual_qty_2 = get_qty_after_transaction()
+ # self.assertEquals(actual_qty_1 + returned_qty, actual_qty_2)
+ #
+ # return se
+ #
+ # def test_purchase_receipt_return(self):
+ # actual_qty_0 = get_qty_after_transaction()
+ #
+ # # submit purchase receipt
+ # pr = make_purchase_receipt(item_code="_Test Item", warehouse="_Test Warehouse - _TC", qty=5)
+ #
+ # actual_qty_1 = get_qty_after_transaction()
+ #
+ # self.assertEquals(actual_qty_0 + 5, actual_qty_1)
+ #
+ # pi_doc = make_purchase_invoice(pr.name)
+ #
+ # pi = frappe.get_doc(pi_doc)
+ # pi.posting_date = pr.posting_date
+ # pi.credit_to = "_Test Payable - _TC"
+ # for d in pi.get("items"):
+ # d.expense_account = "_Test Account Cost for Goods Sold - _TC"
+ # d.cost_center = "_Test Cost Center - _TC"
+ #
+ # for d in pi.get("taxes"):
+ # d.cost_center = "_Test Cost Center - _TC"
+ #
+ # pi.insert()
+ # pi.submit()
+ #
+ # # submit purchase return
+ # se = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
+ # qty=5, purpose="Purchase Return", purchase_receipt_no=pr.name)
+ #
+ # actual_qty_2 = get_qty_after_transaction()
+ #
+ # self.assertEquals(actual_qty_1 - 5, actual_qty_2)
+ #
+ # return se, pr.name
+ #
+ # def test_over_stock_return(self):
+ # from erpnext.stock.doctype.stock_entry.stock_entry import StockOverReturnError
+ #
+ # # out of 10, 5 gets returned
+ # prev_se, pr_docname = self.test_purchase_receipt_return()
+ #
+ # se = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
+ # qty=6, purpose="Purchase Return", purchase_receipt_no=pr_docname, do_not_save=True)
+ #
+ # self.assertRaises(StockOverReturnError, se.insert)
+ #
+ # def _test_purchase_return_jv(self, se):
+ # jv = make_return_jv(se.name)
+ #
+ # self.assertEqual(len(jv.get("accounts")), 2)
+ # self.assertEqual(jv.get("voucher_type"), "Debit Note")
+ # self.assertEqual(jv.get("posting_date"), getdate(se.posting_date))
+ # self.assertEqual(jv.get("accounts")[0].get("account"), "_Test Payable - _TC")
+ # self.assertEqual(jv.get("accounts")[0].get("party"), "_Test Supplier")
+ # self.assertEqual(jv.get("accounts")[1].get("account"), "_Test Account Cost for Goods Sold - _TC")
+ #
+ # def test_make_return_jv_for_purchase_receipt(self):
+ # se, pr_name = self.test_purchase_receipt_return()
+ # self._test_purchase_return_jv(se)
+ #
+ # se, pr_name = self._test_purchase_return_return_against_purchase_order()
+ # self._test_purchase_return_jv(se)
+ #
+ # def _test_purchase_return_return_against_purchase_order(self):
+ #
+ # actual_qty_0 = get_qty_after_transaction()
+ #
+ # from erpnext.buying.doctype.purchase_order.test_purchase_order \
+ # import test_records as purchase_order_test_records
+ #
+ # from erpnext.buying.doctype.purchase_order.purchase_order import \
+ # make_purchase_receipt, make_purchase_invoice
+ #
+ # # submit purchase receipt
+ # po = frappe.copy_doc(purchase_order_test_records[0])
+ # po.transaction_date = nowdate()
+ # po.is_subcontracted = None
+ # po.get("items")[0].item_code = "_Test Item"
+ # po.get("items")[0].rate = 50
+ # po.insert()
+ # po.submit()
+ #
+ # pr_doc = make_purchase_receipt(po.name)
+ #
+ # pr = frappe.get_doc(pr_doc)
+ # pr.posting_date = po.transaction_date
+ # pr.insert()
+ # pr.submit()
+ #
+ # actual_qty_1 = get_qty_after_transaction()
+ #
+ # self.assertEquals(actual_qty_0 + 10, actual_qty_1)
+ #
+ # pi_doc = make_purchase_invoice(po.name)
+ #
+ # pi = frappe.get_doc(pi_doc)
+ # pi.posting_date = pr.posting_date
+ # pi.credit_to = "_Test Payable - _TC"
+ # for d in pi.get("items"):
+ # d.expense_account = "_Test Account Cost for Goods Sold - _TC"
+ # d.cost_center = "_Test Cost Center - _TC"
+ # for d in pi.get("taxes"):
+ # d.cost_center = "_Test Cost Center - _TC"
+ #
+ # pi.run_method("calculate_taxes_and_totals")
+ # pi.bill_no = "NA"
+ # pi.insert()
+ # pi.submit()
+ #
+ # # submit purchase return
+ # se = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
+ # qty=5, purpose="Purchase Return", purchase_receipt_no=pr.name)
+ #
+ # actual_qty_2 = get_qty_after_transaction()
+ #
+ # self.assertEquals(actual_qty_1 - 5, actual_qty_2)
+ #
+ # return se, pr.name
def test_serial_no_not_reqd(self):
se = frappe.copy_doc(test_records[0])