Removed tname and fname from code

This commit is contained in:
Nabin Hait 2014-12-26 13:15:21 +05:30
parent 79f091e2fe
commit dd38a266b8
37 changed files with 168 additions and 279 deletions

View File

@ -1,10 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
cur_frm.cscript.tname = "Purchase Invoice Item";
cur_frm.cscript.fname = "items";
cur_frm.cscript.other_fname = "taxes";
frappe.provide("erpnext.accounts"); frappe.provide("erpnext.accounts");
{% include 'buying/doctype/purchase_common/purchase_common.js' %}; {% include 'buying/doctype/purchase_common/purchase_common.js' %};
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %} {% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}

View File

@ -16,9 +16,6 @@ form_grid_templates = {
} }
class PurchaseInvoice(BuyingController): class PurchaseInvoice(BuyingController):
tname = 'Purchase Invoice Item'
fname = 'items'
def __init__(self, arg1, arg2=None): def __init__(self, arg1, arg2=None):
super(PurchaseInvoice, self).__init__(arg1, arg2) super(PurchaseInvoice, self).__init__(arg1, arg2)
self.status_updater = [{ self.status_updater = [{
@ -107,7 +104,7 @@ class PurchaseInvoice(BuyingController):
throw(_("Purchase Order {0} is 'Stopped'").format(d.purchase_order)) throw(_("Purchase Order {0} is 'Stopped'").format(d.purchase_order))
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(PurchaseInvoice, self).validate_with_previous_doc(self.tname, { super(PurchaseInvoice, self).validate_with_previous_doc({
"Purchase Order": { "Purchase Order": {
"ref_dn_field": "purchase_order", "ref_dn_field": "purchase_order",
"compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]], "compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]],
@ -130,7 +127,7 @@ class PurchaseInvoice(BuyingController):
}) })
if cint(frappe.defaults.get_global_default('maintain_same_rate')): if cint(frappe.defaults.get_global_default('maintain_same_rate')):
super(PurchaseInvoice, self).validate_with_previous_doc(self.tname, { super(PurchaseInvoice, self).validate_with_previous_doc({
"Purchase Order Item": { "Purchase Order Item": {
"ref_dn_field": "po_detail", "ref_dn_field": "po_detail",
"compare_fields": [["rate", "="]], "compare_fields": [["rate", "="]],

View File

@ -293,7 +293,7 @@ erpnext.POS = Class.extend({
// check whether the item is already added // check whether the item is already added
if (no_of_items != 0) { if (no_of_items != 0) {
$.each(this.frm.doc[this.frm.cscript.fname] || [], function(i, d) { $.each(this.frm.doc["items"] || [], function(i, d) {
if (d.item_code == item_code) { if (d.item_code == item_code) {
caught = true; caught = true;
if (serial_no) if (serial_no)
@ -314,8 +314,7 @@ erpnext.POS = Class.extend({
add_new_item_to_grid: function(item_code, serial_no) { add_new_item_to_grid: function(item_code, serial_no) {
var me = this; var me = this;
var child = frappe.model.add_child(me.frm.doc, this.frm.doctype + " Item", var child = frappe.model.add_child(me.frm.doc, this.frm.doctype + " Item", "items");
this.frm.cscript.fname);
child.item_code = item_code; child.item_code = item_code;
if (serial_no) if (serial_no)
@ -334,7 +333,7 @@ erpnext.POS = Class.extend({
}, },
update_qty: function(item_code, qty) { update_qty: function(item_code, qty) {
var me = this; var me = this;
$.each(this.frm.doc[this.frm.cscript.fname] || [], function(i, d) { $.each(this.frm.doc["items"] || [], function(i, d) {
if (d.item_code == item_code) { if (d.item_code == item_code) {
if (qty == 0) { if (qty == 0) {
frappe.model.clear_doc(d.doctype, d.name); frappe.model.clear_doc(d.doctype, d.name);
@ -383,7 +382,7 @@ erpnext.POS = Class.extend({
var me = this; var me = this;
var $items = this.wrapper.find("#cart tbody").empty(); var $items = this.wrapper.find("#cart tbody").empty();
$.each(this.frm.doc[this.frm.cscript.fname] || [], function(i, d) { $.each(this.frm.doc["items"] || [], function(i, d) {
$(repl('<tr id="%(item_code)s" data-selected="false">\ $(repl('<tr id="%(item_code)s" data-selected="false">\
<td>%(item_code)s%(item_name)s</td>\ <td>%(item_code)s%(item_name)s</td>\
@ -425,7 +424,7 @@ erpnext.POS = Class.extend({
}, },
show_taxes: function() { show_taxes: function() {
var me = this; var me = this;
var taxes = this.frm.doc[this.frm.cscript.other_fname] || []; var taxes = this.frm.doc["taxes"] || [];
$(this.wrapper).find(".tax-table") $(this.wrapper).find(".tax-table")
.toggle((taxes && taxes.length) ? true : false) .toggle((taxes && taxes.length) ? true : false)
.find("tbody").empty(); .find("tbody").empty();
@ -550,7 +549,7 @@ erpnext.POS = Class.extend({
} }
} }
var child = this.frm.doc[this.frm.cscript.fname] || []; var child = this.frm.doc["items"] || [];
$.each(child, function(i, d) { $.each(child, function(i, d) {
for (var i in selected_items) { for (var i in selected_items) {
@ -564,7 +563,7 @@ erpnext.POS = Class.extend({
}, },
refresh_grid: function() { refresh_grid: function() {
this.frm.dirty(); this.frm.dirty();
this.frm.fields_dict[this.frm.cscript.fname].grid.refresh(); this.frm.fields_dict["items"].grid.refresh();
this.frm.script_manager.trigger("calculate_taxes_and_totals"); this.frm.script_manager.trigger("calculate_taxes_and_totals");
this.refresh(); this.refresh();
}, },

View File

@ -1,11 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
cur_frm.cscript.tname = "Sales Invoice Item";
cur_frm.cscript.fname = "items";
cur_frm.cscript.other_fname = "taxes";
cur_frm.cscript.sales_team_fname = "sales_team";
// print heading // print heading
cur_frm.pformat.print_heading = 'Invoice'; cur_frm.pformat.print_heading = 'Invoice';

View File

@ -17,9 +17,6 @@ form_grid_templates = {
} }
class SalesInvoice(SellingController): class SalesInvoice(SellingController):
tname = 'Sales Invoice Item'
fname = 'items'
def __init__(self, arg1, arg2=None): def __init__(self, arg1, arg2=None):
super(SalesInvoice, self).__init__(arg1, arg2) super(SalesInvoice, self).__init__(arg1, arg2)
self.status_updater = [{ self.status_updater = [{
@ -151,7 +148,7 @@ class SalesInvoice(SellingController):
super(SalesInvoice, self).set_missing_values(for_validate) super(SalesInvoice, self).set_missing_values(for_validate)
def update_time_log_batch(self, sales_invoice): def update_time_log_batch(self, sales_invoice):
for d in self.get(self.fname): for d in self.get("items"):
if d.time_log_batch: if d.time_log_batch:
tlb = frappe.get_doc("Time Log Batch", d.time_log_batch) tlb = frappe.get_doc("Time Log Batch", d.time_log_batch)
tlb.sales_invoice = sales_invoice tlb.sales_invoice = sales_invoice
@ -159,7 +156,7 @@ class SalesInvoice(SellingController):
tlb.save() tlb.save()
def validate_time_logs_are_submitted(self): def validate_time_logs_are_submitted(self):
for d in self.get(self.fname): for d in self.get("items"):
if d.time_log_batch: if d.time_log_batch:
status = frappe.db.get_value("Time Log Batch", d.time_log_batch, "status") status = frappe.db.get_value("Time Log Batch", d.time_log_batch, "status")
if status!="Submitted": if status!="Submitted":
@ -258,7 +255,7 @@ class SalesInvoice(SellingController):
msgprint(_("Account {0} must be of type 'Fixed Asset' as Item {1} is an Asset Item").format(acc[0][0], d.item_code), raise_exception=True) msgprint(_("Account {0} must be of type 'Fixed Asset' as Item {1} is an Asset Item").format(acc[0][0], d.item_code), raise_exception=True)
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(SalesInvoice, self).validate_with_previous_doc(self.tname, { super(SalesInvoice, self).validate_with_previous_doc({
"Sales Order": { "Sales Order": {
"ref_dn_field": "sales_order", "ref_dn_field": "sales_order",
"compare_fields": [["customer", "="], ["company", "="], ["project_name", "="], "compare_fields": [["customer", "="], ["company", "="], ["project_name", "="],
@ -272,7 +269,7 @@ class SalesInvoice(SellingController):
}) })
if cint(frappe.defaults.get_global_default('maintain_same_sales_rate')): if cint(frappe.defaults.get_global_default('maintain_same_sales_rate')):
super(SalesInvoice, self).validate_with_previous_doc(self.tname, { super(SalesInvoice, self).validate_with_previous_doc({
"Sales Order Item": { "Sales Order Item": {
"ref_dn_field": "so_detail", "ref_dn_field": "so_detail",
"compare_fields": [["rate", "="]], "compare_fields": [["rate", "="]],

View File

@ -1,11 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// Preset
// ------
// cur_frm.cscript.tname - Details table name
// cur_frm.cscript.fname - Details fieldname
frappe.provide("erpnext.buying"); frappe.provide("erpnext.buying");
frappe.require("assets/erpnext/js/transaction.js"); frappe.require("assets/erpnext/js/transaction.js");
{% include "public/js/controllers/accounts.js" %} {% include "public/js/controllers/accounts.js" %}
@ -42,7 +37,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
return{ query: "erpnext.controllers.queries.supplier_query" }}); return{ query: "erpnext.controllers.queries.supplier_query" }});
} }
this.frm.set_query("item_code", this.frm.cscript.fname, function() { this.frm.set_query("item_code", "items", function() {
if(me.frm.doc.is_subcontracted == "Yes") { if(me.frm.doc.is_subcontracted == "Yes") {
return{ return{
query: "erpnext.controllers.queries.item_query", query: "erpnext.controllers.queries.item_query",
@ -159,7 +154,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
project_name: function(doc, cdt, cdn) { project_name: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn); var item = frappe.get_doc(cdt, cdn);
if(item.project_name) { if(item.project_name) {
$.each(this.frm.doc[this.fname], $.each(this.frm.doc["items"],
function(i, other_item) { function(i, other_item) {
if(!other_item.project_name) { if(!other_item.project_name) {
other_item.project_name = item.project_name; other_item.project_name = item.project_name;
@ -359,13 +354,12 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}; };
setup_field_label_map(["base_rate", "base_price_list_rate", "base_amount", "base_rate"], setup_field_label_map(["base_rate", "base_price_list_rate", "base_amount", "base_rate"],
company_currency, this.fname); company_currency, "items");
setup_field_label_map(["rate", "price_list_rate", "amount"], setup_field_label_map(["rate", "price_list_rate", "amount"], this.frm.doc.currency, "items");
this.frm.doc.currency, this.fname);
if(this.frm.fields_dict[this.other_fname]) { if(this.frm.fields_dict["taxes"]) {
setup_field_label_map(["tax_amount", "total"], company_currency, this.other_fname); setup_field_label_map(["tax_amount", "total"], company_currency, "taxes");
} }
if(this.frm.fields_dict["advances"]) { if(this.frm.fields_dict["advances"]) {
@ -374,7 +368,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
} }
// toggle columns // toggle columns
var item_grid = this.frm.fields_dict[this.fname].grid; var item_grid = this.frm.fields_dict["items"].grid;
var fieldnames = $.map(["base_rate", "base_price_list_rate", "base_amount", "base_rate"], function(fname) { var fieldnames = $.map(["base_rate", "base_price_list_rate", "base_amount", "base_rate"], function(fname) {
return frappe.meta.get_docfield(item_grid.doctype, fname, me.frm.docname) ? fname : null; return frappe.meta.get_docfield(item_grid.doctype, fname, me.frm.docname) ? fname : null;
}); });
@ -391,7 +385,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
cur_frm.add_fetch('project_name', 'cost_center', 'cost_center'); cur_frm.add_fetch('project_name', 'cost_center', 'cost_center');
erpnext.buying.get_default_bom = function(frm) { erpnext.buying.get_default_bom = function(frm) {
$.each(frm.doc[frm.cscript.fname] || [], function(i, d) { $.each(frm.doc["items"] || [], function(i, d) {
if (d.item_code && d.bom === "") { if (d.item_code && d.bom === "") {
return frappe.call({ return frappe.call({
type: "GET", type: "GET",

View File

@ -16,7 +16,7 @@ class PurchaseCommon(BuyingController):
import frappe.utils import frappe.utils
this_purchase_date = frappe.utils.getdate(obj.get('posting_date') or obj.get('transaction_date')) this_purchase_date = frappe.utils.getdate(obj.get('posting_date') or obj.get('transaction_date'))
for d in obj.get(obj.fname): for d in obj.get("items"):
# get last purchase details # get last purchase details
last_purchase_details = get_last_purchase_details(d.item_code, obj.name) last_purchase_details = get_last_purchase_details(d.item_code, obj.name)
@ -38,34 +38,9 @@ class PurchaseCommon(BuyingController):
frappe.db.sql("""update `tabItem` set last_purchase_rate = %s where name = %s""", frappe.db.sql("""update `tabItem` set last_purchase_rate = %s where name = %s""",
(flt(last_purchase_rate), d.item_code)) (flt(last_purchase_rate), d.item_code))
def get_last_purchase_rate(self, obj):
"""get last purchase rates for all items"""
doc_name = obj.name
conversion_rate = flt(obj.get('conversion_rate')) or 1.0
for d in obj.get(obj.fname):
if d.item_code:
last_purchase_details = get_last_purchase_details(d.item_code, doc_name)
if last_purchase_details:
d.base_price_list_rate = last_purchase_details['base_price_list_rate'] * (flt(d.conversion_factor) or 1.0)
d.discount_percentage = last_purchase_details['discount_percentage']
d.base_rate = last_purchase_details['base_rate'] * (flt(d.conversion_factor) or 1.0)
d.price_list_rate = d.base_price_list_rate / conversion_rate
d.rate = d.base_rate / conversion_rate
else:
# if no last purchase found, reset all values to 0
d.base_price_list_rate = d.base_rate = d.price_list_rate = d.rate = d.discount_percentage = 0
item_last_purchase_rate = frappe.db.get_value("Item",
d.item_code, "last_purchase_rate")
if item_last_purchase_rate:
d.base_price_list_rate = d.base_rate = d.price_list_rate \
= d.rate = item_last_purchase_rate
def validate_for_items(self, obj): def validate_for_items(self, obj):
check_list, chk_dupl_itm=[],[] check_list, chk_dupl_itm=[],[]
for d in obj.get(obj.fname): for d in obj.get("items"):
# validation for valid qty # validation for valid qty
if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)): if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)):
frappe.throw(_("Please enter quantity for Item {0}").format(d.item_code)) frappe.throw(_("Please enter quantity for Item {0}").format(d.item_code))

View File

@ -3,10 +3,6 @@
frappe.provide("erpnext.buying"); frappe.provide("erpnext.buying");
cur_frm.cscript.tname = "Purchase Order Item";
cur_frm.cscript.fname = "items";
cur_frm.cscript.other_fname = "taxes";
{% include 'buying/doctype/purchase_common/purchase_common.js' %}; {% include 'buying/doctype/purchase_common/purchase_common.js' %};
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %} {% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
{% include 'accounts/doctype/sales_invoice/pos.js' %} {% include 'accounts/doctype/sales_invoice/pos.js' %}
@ -147,7 +143,7 @@ cur_frm.fields_dict['items'].grid.get_field('bom').get_query = function(doc, cdt
cur_frm.cscript.get_last_purchase_rate = function(doc, cdt, cdn){ cur_frm.cscript.get_last_purchase_rate = function(doc, cdt, cdn){
return $c_obj(doc, 'get_last_purchase_rate', '', function(r, rt) { return $c_obj(doc, 'get_last_purchase_rate', '', function(r, rt) {
refresh_field(cur_frm.cscript.fname); refresh_field("items");
var doc = locals[cdt][cdn]; var doc = locals[cdt][cdn];
cur_frm.cscript.calc_amount( doc, 2); cur_frm.cscript.calc_amount( doc, 2);
}); });

View File

@ -7,15 +7,14 @@ from frappe.utils import cstr, flt
from frappe import msgprint, _, throw from frappe import msgprint, _, throw
from frappe.model.mapper import get_mapped_doc from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
from erpnext.stock.doctype.item.item import get_last_purchase_details
form_grid_templates = { form_grid_templates = {
"items": "templates/form_grid/item_grid.html" "items": "templates/form_grid/item_grid.html"
} }
class PurchaseOrder(BuyingController): class PurchaseOrder(BuyingController):
tname = 'Purchase Order Item'
fname = 'items'
def __init__(self, arg1, arg2=None): def __init__(self, arg1, arg2=None):
super(PurchaseOrder, self).__init__(arg1, arg2) super(PurchaseOrder, self).__init__(arg1, arg2)
self.status_updater = [{ self.status_updater = [{
@ -54,7 +53,7 @@ class PurchaseOrder(BuyingController):
self.create_raw_materials_supplied("supplied_items") self.create_raw_materials_supplied("supplied_items")
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(PurchaseOrder, self).validate_with_previous_doc(self.tname, { super(PurchaseOrder, self).validate_with_previous_doc({
"Supplier Quotation": { "Supplier Quotation": {
"ref_dn_field": "supplier_quotation", "ref_dn_field": "supplier_quotation",
"compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]], "compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]],
@ -86,7 +85,27 @@ class PurchaseOrder(BuyingController):
d.prevdoc_detail_docname, "schedule_date") d.prevdoc_detail_docname, "schedule_date")
def get_last_purchase_rate(self): def get_last_purchase_rate(self):
frappe.get_doc('Purchase Common').get_last_purchase_rate(self) """get last purchase rates for all items"""
conversion_rate = flt(self.get('conversion_rate')) or 1.0
for d in self.get("items"):
if d.item_code:
last_purchase_details = get_last_purchase_details(d.item_code, self.name)
if last_purchase_details:
d.base_price_list_rate = last_purchase_details['base_price_list_rate'] * (flt(d.conversion_factor) or 1.0)
d.discount_percentage = last_purchase_details['discount_percentage']
d.base_rate = last_purchase_details['base_rate'] * (flt(d.conversion_factor) or 1.0)
d.price_list_rate = d.base_price_list_rate / conversion_rate
d.rate = d.base_rate / conversion_rate
else:
# if no last purchase found, reset all values to 0
d.base_price_list_rate = d.base_rate = d.price_list_rate = d.rate = d.discount_percentage = 0
item_last_purchase_rate = frappe.db.get_value("Item", d.item_code, "last_purchase_rate")
if item_last_purchase_rate:
d.base_price_list_rate = d.base_rate = d.price_list_rate \
= d.rate = item_last_purchase_rate
# Check for Stopped status # Check for Stopped status
def check_for_stopped_status(self, pc_obj): def check_for_stopped_status(self, pc_obj):

View File

@ -1,11 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// define defaults for purchase common
cur_frm.cscript.tname = "Supplier Quotation Item";
cur_frm.cscript.fname = "items";
cur_frm.cscript.other_fname = "taxes";
// attach required files // attach required files
{% include 'buying/doctype/purchase_common/purchase_common.js' %}; {% include 'buying/doctype/purchase_common/purchase_common.js' %};
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %} {% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}

View File

@ -12,9 +12,6 @@ form_grid_templates = {
} }
class SupplierQuotation(BuyingController): class SupplierQuotation(BuyingController):
tname = "Supplier Quotation Item"
fname = "items"
def validate(self): def validate(self):
super(SupplierQuotation, self).validate() super(SupplierQuotation, self).validate()
@ -39,7 +36,7 @@ class SupplierQuotation(BuyingController):
pass pass
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(SupplierQuotation, self).validate_with_previous_doc(self.tname, { super(SupplierQuotation, self).validate_with_previous_doc({
"Material Request": { "Material Request": {
"ref_dn_field": "prevdoc_docname", "ref_dn_field": "prevdoc_docname",
"compare_fields": [["company", "="]], "compare_fields": [["company", "="]],

View File

@ -102,12 +102,12 @@ class AccountsController(TransactionBase):
def set_missing_item_details(self): def set_missing_item_details(self):
"""set missing item values""" """set missing item values"""
from erpnext.stock.get_item_details import get_item_details from erpnext.stock.get_item_details import get_item_details
if hasattr(self, "fname"): if hasattr(self, "items"):
parent_dict = {} parent_dict = {}
for fieldname in self.meta.get_valid_columns(): for fieldname in self.meta.get_valid_columns():
parent_dict[fieldname] = self.get(fieldname) parent_dict[fieldname] = self.get(fieldname)
for item in self.get(self.fname): for item in self.get("items"):
if item.get("item_code"): if item.get("item_code"):
args = parent_dict.copy() args = parent_dict.copy()
args.update(item.as_dict()) args.update(item.as_dict())
@ -166,8 +166,6 @@ class AccountsController(TransactionBase):
self.meta.get_label("conversion_rate"), self.company) self.meta.get_label("conversion_rate"), self.company)
self.conversion_rate = flt(self.conversion_rate) self.conversion_rate = flt(self.conversion_rate)
self.item_doclist = self.get(self.fname)
self.tax_doclist = self.get(self.other_fname)
self.calculate_item_values() self.calculate_item_values()
self.initialize_taxes() self.initialize_taxes()
@ -181,7 +179,7 @@ class AccountsController(TransactionBase):
self._cleanup() self._cleanup()
def initialize_taxes(self): def initialize_taxes(self):
for tax in self.tax_doclist: for tax in self.get("taxes"):
tax.item_wise_tax_detail = {} tax.item_wise_tax_detail = {}
tax_fields = ["total", "tax_amount_after_discount_amount", tax_fields = ["total", "tax_amount_after_discount_amount",
"tax_amount_for_current_item", "grand_total_for_current_item", "tax_amount_for_current_item", "grand_total_for_current_item",
@ -216,30 +214,30 @@ class AccountsController(TransactionBase):
# inclusive tax cannot be of type Actual # inclusive tax cannot be of type Actual
throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate").format(tax.idx)) throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate").format(tax.idx))
elif tax.charge_type == "On Previous Row Amount" and \ elif tax.charge_type == "On Previous Row Amount" and \
not cint(self.tax_doclist[cint(tax.row_id) - 1].included_in_print_rate): not cint(self.get("taxes")[cint(tax.row_id) - 1].included_in_print_rate):
# referred row should also be inclusive # referred row should also be inclusive
_on_previous_row_error(tax.row_id) _on_previous_row_error(tax.row_id)
elif tax.charge_type == "On Previous Row Total" and \ elif tax.charge_type == "On Previous Row Total" and \
not all([cint(t.included_in_print_rate) for t in self.tax_doclist[:cint(tax.row_id) - 1]]): not all([cint(t.included_in_print_rate) for t in self.get("taxes")[:cint(tax.row_id) - 1]]):
# all rows about the reffered tax should be inclusive # all rows about the reffered tax should be inclusive
_on_previous_row_error("1 - %d" % (tax.row_id,)) _on_previous_row_error("1 - %d" % (tax.row_id,))
def calculate_taxes(self): def calculate_taxes(self):
# maintain actual tax rate based on idx # maintain actual tax rate based on idx
actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.precision("tax_amount", tax))] for tax in self.tax_doclist actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.precision("tax_amount", tax))] for tax in self.get("taxes")
if tax.charge_type == "Actual"]) if tax.charge_type == "Actual"])
for n, item in enumerate(self.item_doclist): for n, item in enumerate(self.get("items")):
item_tax_map = self._load_item_tax_rate(item.item_tax_rate) item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
for i, tax in enumerate(self.tax_doclist): for i, tax in enumerate(self.get("taxes")):
# tax_amount represents the amount of tax for the current step # tax_amount represents the amount of tax for the current step
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map) current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
# Adjust divisional loss to the last item # Adjust divisional loss to the last item
if tax.charge_type == "Actual": if tax.charge_type == "Actual":
actual_tax_dict[tax.idx] -= current_tax_amount actual_tax_dict[tax.idx] -= current_tax_amount
if n == len(self.item_doclist) - 1: if n == len(self.get("items")) - 1:
current_tax_amount += actual_tax_dict[tax.idx] current_tax_amount += actual_tax_dict[tax.idx]
# store tax_amount for current item as it will be used for # store tax_amount for current item as it will be used for
@ -268,18 +266,18 @@ class AccountsController(TransactionBase):
self.precision("total", tax)) self.precision("total", tax))
else: else:
tax.grand_total_for_current_item = \ tax.grand_total_for_current_item = \
flt(self.tax_doclist[i-1].grand_total_for_current_item + flt(self.get("taxes")[i-1].grand_total_for_current_item +
current_tax_amount, self.precision("total", tax)) current_tax_amount, self.precision("total", tax))
# in tax.total, accumulate grand total of each item # in tax.total, accumulate grand total of each item
tax.total += tax.grand_total_for_current_item tax.total += tax.grand_total_for_current_item
# set precision in the last item iteration # set precision in the last item iteration
if n == len(self.item_doclist) - 1: if n == len(self.get("items")) - 1:
self.round_off_totals(tax) self.round_off_totals(tax)
# adjust Discount Amount loss in last tax iteration # adjust Discount Amount loss in last tax iteration
if i == (len(self.tax_doclist) - 1) and self.discount_amount_applied: if i == (len(self.get("taxes")) - 1) and self.discount_amount_applied:
self.adjust_discount_amount_loss(tax) self.adjust_discount_amount_loss(tax)
def round_off_totals(self, tax): def round_off_totals(self, tax):
@ -308,10 +306,10 @@ class AccountsController(TransactionBase):
current_tax_amount = (tax_rate / 100.0) * item.base_amount current_tax_amount = (tax_rate / 100.0) * item.base_amount
elif tax.charge_type == "On Previous Row Amount": elif tax.charge_type == "On Previous Row Amount":
current_tax_amount = (tax_rate / 100.0) * \ current_tax_amount = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].tax_amount_for_current_item self.get("taxes")[cint(tax.row_id) - 1].tax_amount_for_current_item
elif tax.charge_type == "On Previous Row Total": elif tax.charge_type == "On Previous Row Total":
current_tax_amount = (tax_rate / 100.0) * \ current_tax_amount = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].grand_total_for_current_item self.get("taxes")[cint(tax.row_id) - 1].grand_total_for_current_item
current_tax_amount = flt(current_tax_amount, self.precision("tax_amount", tax)) current_tax_amount = flt(current_tax_amount, self.precision("tax_amount", tax))
@ -335,7 +333,7 @@ class AccountsController(TransactionBase):
return tax.rate return tax.rate
def _cleanup(self): def _cleanup(self):
for tax in self.tax_doclist: for tax in self.get("taxes"):
tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail, separators=(',', ':')) tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail, separators=(',', ':'))
def _set_in_company_currency(self, item, print_field, base_field): def _set_in_company_currency(self, item, print_field, base_field):
@ -461,7 +459,7 @@ class AccountsController(TransactionBase):
else: else:
already_billed = frappe.db.sql("""select sum(%s) from `tab%s` already_billed = frappe.db.sql("""select sum(%s) from `tab%s`
where %s=%s and docstatus=1 and parent != %s""" % where %s=%s and docstatus=1 and parent != %s""" %
(based_on, self.tname, item_ref_dn, '%s', '%s'), (based_on, self.doctype + " Item", item_ref_dn, '%s', '%s'),
(item.get(item_ref_dn), self.name))[0][0] (item.get(item_ref_dn), self.name))[0][0]
total_billed_amt = flt(flt(already_billed) + flt(item.get(based_on)), total_billed_amt = flt(flt(already_billed) + flt(item.get(based_on)),
@ -481,7 +479,7 @@ class AccountsController(TransactionBase):
def get_stock_items(self): def get_stock_items(self):
stock_items = [] stock_items = []
item_codes = list(set(item.item_code for item in self.get(self.fname))) item_codes = list(set(item.item_code for item in self.get("items")))
if item_codes: if item_codes:
stock_items = [r[0] for r in frappe.db.sql("""select name stock_items = [r[0] for r in frappe.db.sql("""select name
from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \ from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \

View File

@ -14,9 +14,9 @@ from erpnext.controllers.stock_controller import StockController
class BuyingController(StockController): class BuyingController(StockController):
def __setup__(self): def __setup__(self):
if hasattr(self, "fname"): if hasattr(self, "items"):
self.table_print_templates = { self.table_print_templates = {
self.fname: "templates/print_formats/includes/item_grid.html", "items": "templates/print_formats/includes/item_grid.html",
"taxes": "templates/print_formats/includes/taxes.html", "taxes": "templates/print_formats/includes/taxes.html",
} }
@ -50,7 +50,7 @@ class BuyingController(StockController):
def set_supplier_from_item_default(self): def set_supplier_from_item_default(self):
if self.meta.get_field("supplier") and not self.supplier: if self.meta.get_field("supplier") and not self.supplier:
for d in self.get(self.fname): for d in self.get("items"):
supplier = frappe.db.get_value("Item", d.item_code, "default_supplier") supplier = frappe.db.get_value("Item", d.item_code, "default_supplier")
if supplier: if supplier:
self.supplier = supplier self.supplier = supplier
@ -60,7 +60,7 @@ class BuyingController(StockController):
from erpnext.stock.utils import validate_warehouse_company from erpnext.stock.utils import validate_warehouse_company
warehouses = list(set([d.warehouse for d in warehouses = list(set([d.warehouse for d in
self.get(self.fname) if getattr(d, "warehouse", None)])) self.get("items") if getattr(d, "warehouse", None)]))
for w in warehouses: for w in warehouses:
validate_warehouse_company(w, self.company) validate_warehouse_company(w, self.company)
@ -82,12 +82,11 @@ class BuyingController(StockController):
self.currency) self.currency)
def calculate_taxes_and_totals(self): def calculate_taxes_and_totals(self):
self.other_fname = "taxes"
super(BuyingController, self).calculate_taxes_and_totals() super(BuyingController, self).calculate_taxes_and_totals()
self.calculate_total_advance("Purchase Invoice", "advances") self.calculate_total_advance("Purchase Invoice", "advances")
def calculate_item_values(self): def calculate_item_values(self):
for item in self.item_doclist: for item in self.get("items"):
self.round_floats_in(item) self.round_floats_in(item)
if item.discount_percentage == 100.0: if item.discount_percentage == 100.0:
@ -108,14 +107,14 @@ class BuyingController(StockController):
def calculate_net_total(self): def calculate_net_total(self):
self.net_total = self.net_total_import = 0.0 self.net_total = self.net_total_import = 0.0
for item in self.item_doclist: for item in self.get("items"):
self.net_total += item.base_amount self.net_total += item.base_amount
self.net_total_import += item.amount self.net_total_import += item.amount
self.round_floats_in(self, ["net_total", "net_total_import"]) self.round_floats_in(self, ["net_total", "net_total_import"])
def calculate_totals(self): def calculate_totals(self):
self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist else self.net_total) self.grand_total = flt(self.get("taxes")[-1].total if self.get("taxes") else self.net_total)
self.grand_total_import = flt(self.grand_total / self.conversion_rate) self.grand_total_import = flt(self.grand_total / self.conversion_rate)
self.total_tax = flt(self.grand_total - self.net_total, self.precision("total_tax")) self.total_tax = flt(self.grand_total - self.net_total, self.precision("total_tax"))
@ -130,12 +129,12 @@ class BuyingController(StockController):
self.rounded_total_import = rounded(self.grand_total_import) self.rounded_total_import = rounded(self.grand_total_import)
if self.meta.get_field("other_charges_added"): if self.meta.get_field("other_charges_added"):
self.other_charges_added = flt(sum([flt(d.tax_amount) for d in self.tax_doclist self.other_charges_added = flt(sum([flt(d.tax_amount) for d in self.get("taxes")
if d.add_deduct_tax=="Add" and d.category in ["Valuation and Total", "Total"]]), if d.add_deduct_tax=="Add" and d.category in ["Valuation and Total", "Total"]]),
self.precision("other_charges_added")) self.precision("other_charges_added"))
if self.meta.get_field("other_charges_deducted"): if self.meta.get_field("other_charges_deducted"):
self.other_charges_deducted = flt(sum([flt(d.tax_amount) for d in self.tax_doclist self.other_charges_deducted = flt(sum([flt(d.tax_amount) for d in self.get("taxes")
if d.add_deduct_tax=="Deduct" and d.category in ["Valuation and Total", "Total"]]), if d.add_deduct_tax=="Deduct" and d.category in ["Valuation and Total", "Total"]]),
self.precision("other_charges_deducted")) self.precision("other_charges_deducted"))
@ -216,12 +215,12 @@ class BuyingController(StockController):
if self.doctype == "Purchase Receipt" and not self.supplier_warehouse: if self.doctype == "Purchase Receipt" and not self.supplier_warehouse:
frappe.throw(_("Supplier Warehouse mandatory for sub-contracted Purchase Receipt")) frappe.throw(_("Supplier Warehouse mandatory for sub-contracted Purchase Receipt"))
for item in self.get(self.fname): for item in self.get("items"):
if item in self.sub_contracted_items and not item.bom: if item in self.sub_contracted_items and not item.bom:
frappe.throw(_("Please select BOM in BOM field for Item {0}").format(item.item_code)) frappe.throw(_("Please select BOM in BOM field for Item {0}").format(item.item_code))
else: else:
for item in self.get(self.fname): for item in self.get("items"):
if item.bom: if item.bom:
item.bom = None item.bom = None
@ -229,7 +228,7 @@ class BuyingController(StockController):
if self.is_subcontracted=="Yes": if self.is_subcontracted=="Yes":
parent_items = [] parent_items = []
rm_supplied_idx = 0 rm_supplied_idx = 0
for item in self.get(self.fname): for item in self.get("items"):
if self.doctype == "Purchase Receipt": if self.doctype == "Purchase Receipt":
item.rm_supp_cost = 0.0 item.rm_supp_cost = 0.0
if item.item_code in self.sub_contracted_items: if item.item_code in self.sub_contracted_items:
@ -241,7 +240,7 @@ class BuyingController(StockController):
self.cleanup_raw_materials_supplied(parent_items, raw_material_table) self.cleanup_raw_materials_supplied(parent_items, raw_material_table)
elif self.doctype == "Purchase Receipt": elif self.doctype == "Purchase Receipt":
for item in self.get(self.fname): for item in self.get("items"):
item.rm_supp_cost = 0.0 item.rm_supp_cost = 0.0
def update_raw_materials_supplied(self, item, raw_material_table, rm_supplied_idx): def update_raw_materials_supplied(self, item, raw_material_table, rm_supplied_idx):
@ -336,7 +335,7 @@ class BuyingController(StockController):
if not hasattr(self, "_sub_contracted_items"): if not hasattr(self, "_sub_contracted_items"):
self._sub_contracted_items = [] self._sub_contracted_items = []
item_codes = list(set(item.item_code for item in item_codes = list(set(item.item_code for item in
self.get(self.fname))) self.get("items")))
if item_codes: if item_codes:
self._sub_contracted_items = [r[0] for r in frappe.db.sql("""select name self._sub_contracted_items = [r[0] for r in frappe.db.sql("""select name
from `tabItem` where name in (%s) and is_sub_contracted_item='Yes'""" % \ from `tabItem` where name in (%s) and is_sub_contracted_item='Yes'""" % \
@ -349,7 +348,7 @@ class BuyingController(StockController):
if not hasattr(self, "_purchase_items"): if not hasattr(self, "_purchase_items"):
self._purchase_items = [] self._purchase_items = []
item_codes = list(set(item.item_code for item in item_codes = list(set(item.item_code for item in
self.get(self.fname))) self.get("items")))
if item_codes: if item_codes:
self._purchase_items = [r[0] for r in frappe.db.sql("""select name self._purchase_items = [r[0] for r in frappe.db.sql("""select name
from `tabItem` where name in (%s) and is_purchase_item='Yes'""" % \ from `tabItem` where name in (%s) and is_purchase_item='Yes'""" % \
@ -359,11 +358,11 @@ class BuyingController(StockController):
def is_item_table_empty(self): def is_item_table_empty(self):
if not len(self.get(self.fname)): if not len(self.get("items")):
frappe.throw(_("Item table can not be blank")) frappe.throw(_("Item table can not be blank"))
def set_qty_as_per_stock_uom(self): def set_qty_as_per_stock_uom(self):
for d in self.get(self.fname): for d in self.get("items"):
if d.meta.get_field("stock_qty") and not d.stock_qty: if d.meta.get_field("stock_qty") and not d.stock_qty:
if not d.conversion_factor: if not d.conversion_factor:
frappe.throw(_("Row {0}: Conversion Factor is mandatory")) frappe.throw(_("Row {0}: Conversion Factor is mandatory"))

View File

@ -12,9 +12,9 @@ from erpnext.controllers.stock_controller import StockController
class SellingController(StockController): class SellingController(StockController):
def __setup__(self): def __setup__(self):
if hasattr(self, "fname"): if hasattr(self, "items"):
self.table_print_templates = { self.table_print_templates = {
self.fname: "templates/print_formats/includes/item_grid.html", "items": "templates/print_formats/includes/item_grid.html",
"taxes": "templates/print_formats/includes/taxes.html", "taxes": "templates/print_formats/includes/taxes.html",
} }
@ -24,7 +24,7 @@ class SellingController(StockController):
def onload(self): def onload(self):
if self.doctype in ("Sales Order", "Delivery Note", "Sales Invoice"): if self.doctype in ("Sales Order", "Delivery Note", "Sales Invoice"):
for item in self.get(self.fname): for item in self.get("items"):
item.update(get_available_qty(item.item_code, item.update(get_available_qty(item.item_code,
item.warehouse)) item.warehouse))
@ -124,8 +124,6 @@ class SellingController(StockController):
self.grand_total_export or self.rounded_total_export, self.currency) self.grand_total_export or self.rounded_total_export, self.currency)
def calculate_taxes_and_totals(self): def calculate_taxes_and_totals(self):
self.other_fname = "taxes"
super(SellingController, self).calculate_taxes_and_totals() super(SellingController, self).calculate_taxes_and_totals()
self.calculate_total_advance("Sales Invoice", "advances") self.calculate_total_advance("Sales Invoice", "advances")
@ -133,21 +131,21 @@ class SellingController(StockController):
self.calculate_contribution() self.calculate_contribution()
def determine_exclusive_rate(self): def determine_exclusive_rate(self):
if not any((cint(tax.included_in_print_rate) for tax in self.tax_doclist)): if not any((cint(tax.included_in_print_rate) for tax in self.get("taxes"))):
# no inclusive tax # no inclusive tax
return return
for item in self.item_doclist: for item in self.get("items"):
item_tax_map = self._load_item_tax_rate(item.item_tax_rate) item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
cumulated_tax_fraction = 0 cumulated_tax_fraction = 0
for i, tax in enumerate(self.tax_doclist): for i, tax in enumerate(self.get("taxes")):
tax.tax_fraction_for_current_item = self.get_current_tax_fraction(tax, item_tax_map) tax.tax_fraction_for_current_item = self.get_current_tax_fraction(tax, item_tax_map)
if i==0: if i==0:
tax.grand_total_fraction_for_current_item = 1 + tax.tax_fraction_for_current_item tax.grand_total_fraction_for_current_item = 1 + tax.tax_fraction_for_current_item
else: else:
tax.grand_total_fraction_for_current_item = \ tax.grand_total_fraction_for_current_item = \
self.tax_doclist[i-1].grand_total_fraction_for_current_item \ self.get("taxes")[i-1].grand_total_fraction_for_current_item \
+ tax.tax_fraction_for_current_item + tax.tax_fraction_for_current_item
cumulated_tax_fraction += tax.tax_fraction_for_current_item cumulated_tax_fraction += tax.tax_fraction_for_current_item
@ -181,17 +179,17 @@ class SellingController(StockController):
elif tax.charge_type == "On Previous Row Amount": elif tax.charge_type == "On Previous Row Amount":
current_tax_fraction = (tax_rate / 100.0) * \ current_tax_fraction = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].tax_fraction_for_current_item self.get("taxes")[cint(tax.row_id) - 1].tax_fraction_for_current_item
elif tax.charge_type == "On Previous Row Total": elif tax.charge_type == "On Previous Row Total":
current_tax_fraction = (tax_rate / 100.0) * \ current_tax_fraction = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].grand_total_fraction_for_current_item self.get("taxes")[cint(tax.row_id) - 1].grand_total_fraction_for_current_item
return current_tax_fraction return current_tax_fraction
def calculate_item_values(self): def calculate_item_values(self):
if not self.discount_amount_applied: if not self.discount_amount_applied:
for item in self.item_doclist: for item in self.get("items"):
self.round_floats_in(item) self.round_floats_in(item)
if item.discount_percentage == 100: if item.discount_percentage == 100:
@ -210,14 +208,14 @@ class SellingController(StockController):
def calculate_net_total(self): def calculate_net_total(self):
self.net_total = self.net_total_export = 0.0 self.net_total = self.net_total_export = 0.0
for item in self.item_doclist: for item in self.get("items"):
self.net_total += item.base_amount self.net_total += item.base_amount
self.net_total_export += item.amount self.net_total_export += item.amount
self.round_floats_in(self, ["net_total", "net_total_export"]) self.round_floats_in(self, ["net_total", "net_total_export"])
def calculate_totals(self): def calculate_totals(self):
self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist else self.net_total) self.grand_total = flt(self.get("taxes")[-1].total if self.get("taxes") else self.net_total)
self.grand_total_export = flt(self.grand_total / self.conversion_rate) self.grand_total_export = flt(self.grand_total / self.conversion_rate)
@ -238,7 +236,7 @@ class SellingController(StockController):
if grand_total_for_discount_amount: if grand_total_for_discount_amount:
# calculate item amount after Discount Amount # calculate item amount after Discount Amount
for item in self.item_doclist: for item in self.get("items"):
distributed_amount = flt(self.discount_amount) * item.base_amount / grand_total_for_discount_amount distributed_amount = flt(self.discount_amount) * item.base_amount / grand_total_for_discount_amount
item.base_amount = flt(item.base_amount - distributed_amount, self.precision("base_amount", item)) item.base_amount = flt(item.base_amount - distributed_amount, self.precision("base_amount", item))
@ -248,7 +246,7 @@ class SellingController(StockController):
def get_grand_total_for_discount_amount(self): def get_grand_total_for_discount_amount(self):
actual_taxes_dict = {} actual_taxes_dict = {}
for tax in self.tax_doclist: for tax in self.get("taxes"):
if tax.charge_type == "Actual": if tax.charge_type == "Actual":
actual_taxes_dict.setdefault(tax.idx, tax.tax_amount) actual_taxes_dict.setdefault(tax.idx, tax.tax_amount)
elif tax.row_id in actual_taxes_dict: elif tax.row_id in actual_taxes_dict:
@ -306,7 +304,7 @@ class SellingController(StockController):
throw(_("Order Type must be one of {0}").format(comma_or(valid_types))) throw(_("Order Type must be one of {0}").format(comma_or(valid_types)))
def validate_max_discount(self): def validate_max_discount(self):
for d in self.get(self.fname): for d in self.get("items"):
discount = flt(frappe.db.get_value("Item", d.item_code, "max_discount")) discount = flt(frappe.db.get_value("Item", d.item_code, "max_discount"))
if discount and flt(d.discount_percentage) > discount: if discount and flt(d.discount_percentage) > discount:
@ -314,7 +312,7 @@ class SellingController(StockController):
def get_item_list(self): def get_item_list(self):
il = [] il = []
for d in self.get(self.fname): for d in self.get("items"):
reserved_warehouse = "" reserved_warehouse = ""
reserved_qty_for_main_item = 0 reserved_qty_for_main_item = 0
@ -390,14 +388,14 @@ class SellingController(StockController):
return so_qty, so_warehouse return so_qty, so_warehouse
def check_stop_sales_order(self, ref_fieldname): def check_stop_sales_order(self, ref_fieldname):
for d in self.get(self.fname): for d in self.get("items"):
if d.get(ref_fieldname): if d.get(ref_fieldname):
status = frappe.db.get_value("Sales Order", d.get(ref_fieldname), "status") status = frappe.db.get_value("Sales Order", d.get(ref_fieldname), "status")
if status == "Stopped": if status == "Stopped":
frappe.throw(_("Sales Order {0} is stopped").format(d.get(ref_fieldname))) frappe.throw(_("Sales Order {0} is stopped").format(d.get(ref_fieldname)))
def check_active_sales_items(obj): def check_active_sales_items(obj):
for d in obj.get(obj.fname): for d in obj.get("items"):
if d.item_code: if d.item_code:
item = frappe.db.sql("""select docstatus, is_sales_item, item = frappe.db.sql("""select docstatus, is_sales_item,
is_service_item, income_account from tabItem where name = %s""", is_service_item, income_account from tabItem where name = %s""",

View File

@ -77,7 +77,7 @@ class StockController(AccountsController):
return [frappe._dict({ "name": voucher_detail_no, "expense_account": default_expense_account, return [frappe._dict({ "name": voucher_detail_no, "expense_account": default_expense_account,
"cost_center": default_cost_center }) for voucher_detail_no, sle in sle_map.items()] "cost_center": default_cost_center }) for voucher_detail_no, sle in sle_map.items()]
else: else:
details = self.get(self.fname) details = self.get("items")
if default_expense_account or default_cost_center: if default_expense_account or default_cost_center:
for d in details: for d in details:
@ -91,8 +91,8 @@ class StockController(AccountsController):
def get_items_and_warehouses(self): def get_items_and_warehouses(self):
items, warehouses = [], [] items, warehouses = [], []
if hasattr(self, "fname"): if hasattr(self, "items"):
item_doclist = self.get(self.fname) item_doclist = self.get("items")
elif self.doctype == "Stock Reconciliation": elif self.doctype == "Stock Reconciliation":
import json import json
item_doclist = [] item_doclist = []
@ -208,7 +208,7 @@ class StockController(AccountsController):
def get_serialized_items(self): def get_serialized_items(self):
serialized_items = [] serialized_items = []
item_codes = list(set([d.item_code for d in self.get(self.fname)])) item_codes = list(set([d.item_code for d in self.get("items")]))
if item_codes: if item_codes:
serialized_items = frappe.db.sql_list("""select name from `tabItem` serialized_items = frappe.db.sql_list("""select name from `tabItem`
where has_serial_no='Yes' and name in ({})""".format(", ".join(["%s"]*len(item_codes))), where has_serial_no='Yes' and name in ({})""".format(", ".join(["%s"]*len(item_codes))),

View File

@ -75,11 +75,11 @@ erpnext.stock.StockController = frappe.ui.form.Controller.extend({
copy_account_in_all_row: function(doc, dt, dn, fieldname) { copy_account_in_all_row: function(doc, dt, dn, fieldname) {
var d = locals[dt][dn]; var d = locals[dt][dn];
if(d[fieldname]){ if(d[fieldname]){
var cl = doc[this.frm.cscript.fname] || []; var cl = doc["items"] || [];
for(var i = 0; i < cl.length; i++) { for(var i = 0; i < cl.length; i++) {
if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname];
} }
} }
refresh_field(this.frm.cscript.fname); refresh_field("items");
} }
}); });

View File

@ -33,22 +33,22 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
} }
} }
if(this.other_fname) { if(this.frm.fields_dict["taxes"]) {
this[this.other_fname + "_remove"] = this.calculate_taxes_and_totals; this["taxes_remove"] = this.calculate_taxes_and_totals;
} }
if(this.fname) { if(this.frm.fields_dict["items"]) {
this[this.fname + "_remove"] = this.calculate_taxes_and_totals; this["items_remove"] = this.calculate_taxes_and_totals;
} }
}, },
onload_post_render: function() { onload_post_render: function() {
var me = this; var me = this;
if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc[this.fname] && !this.frm.doc.is_pos) { if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] && !this.frm.doc.is_pos) {
this.calculate_taxes_and_totals(); this.calculate_taxes_and_totals();
} }
if(frappe.meta.get_docfield(this.tname, "item_code")) { if(frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "item_code")) {
cur_frm.get_field(this.fname).grid.set_multiple_add("item_code", "qty"); cur_frm.get_field("items").grid.set_multiple_add("item_code", "qty");
} }
}, },
@ -125,7 +125,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
var item = frappe.get_doc(cdt, cdn); var item = frappe.get_doc(cdt, cdn);
if(item.item_code || item.barcode || item.serial_no) { if(item.item_code || item.barcode || item.serial_no) {
if(!this.validate_company_and_party()) { if(!this.validate_company_and_party()) {
cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove(); cur_frm.fields_dict["items"].grid.grid_rows[item.idx - 1].remove();
} else { } else {
return this.frm.call({ return this.frm.call({
method: "erpnext.stock.get_item_details.get_item_details", method: "erpnext.stock.get_item_details.get_item_details",
@ -593,11 +593,11 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
}, },
get_item_doclist: function() { get_item_doclist: function() {
return this.frm.doc[this.fname] || []; return this.frm.doc["items"] || [];
}, },
get_tax_doclist: function() { get_tax_doclist: function() {
return this.frm.doc[this.other_fname] || []; return this.frm.doc["taxes"] || [];
}, },
validate_conversion_rate: function() { validate_conversion_rate: function() {
@ -828,11 +828,11 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
"master_doctype": frappe.meta.get_docfield(this.frm.doc.doctype, "taxes_and_charges", "master_doctype": frappe.meta.get_docfield(this.frm.doc.doctype, "taxes_and_charges",
this.frm.doc.name).options, this.frm.doc.name).options,
"master_name": this.frm.doc.taxes_and_charges, "master_name": this.frm.doc.taxes_and_charges,
"tax_parentfield": this.other_fname "tax_parentfield": "taxes"
}, },
callback: function(r) { callback: function(r) {
if(!r.exc) { if(!r.exc) {
me.frm.set_value(me.other_fname, r.message); me.frm.set_value("taxes", r.message);
me.calculate_taxes_and_totals(); me.calculate_taxes_and_totals();
} }
} }

View File

@ -1,9 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
cur_frm.cscript.tname = "Installation Note Item";
cur_frm.cscript.fname = "items";
frappe.require("assets/erpnext/js/utils.js"); frappe.require("assets/erpnext/js/utils.js");
frappe.ui.form.on_change("Installation Note", "customer", frappe.ui.form.on_change("Installation Note", "customer",

View File

@ -12,9 +12,6 @@ from erpnext.stock.utils import get_valid_serial_nos
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
class InstallationNote(TransactionBase): class InstallationNote(TransactionBase):
tname = 'Installation Note Item'
fname = 'items'
def __init__(self, arg1, arg2=None): def __init__(self, arg1, arg2=None):
super(InstallationNote, self).__init__(arg1, arg2) super(InstallationNote, self).__init__(arg1, arg2)
self.status_updater = [{ self.status_updater = [{

View File

@ -10,9 +10,6 @@ from frappe.model.mapper import get_mapped_doc
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
class Opportunity(TransactionBase): class Opportunity(TransactionBase):
fname = 'enq_details'
tname = 'Opportunity Item'
def get_item_details(self, item_code): def get_item_details(self, item_code):
item = frappe.db.sql("""select item_name, stock_uom, description_html, description, item_group, brand item = frappe.db.sql("""select item_name, stock_uom, description_html, description, item_group, brand
from `tabItem` where name = %s""", item_code, as_dict=1) from `tabItem` where name = %s""", item_code, as_dict=1)

View File

@ -1,12 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// Module CRM
// =====================================================================================
cur_frm.cscript.tname = "Quotation Item";
cur_frm.cscript.fname = "items";
cur_frm.cscript.other_fname = "taxes";
cur_frm.cscript.sales_team_fname = "sales_team";
{% include 'selling/sales_common.js' %} {% include 'selling/sales_common.js' %}
{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %} {% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}

View File

@ -14,9 +14,6 @@ form_grid_templates = {
} }
class Quotation(SellingController): class Quotation(SellingController):
tname = 'Quotation Item'
fname = 'items'
def validate(self): def validate(self):
super(Quotation, self).validate() super(Quotation, self).validate()
self.set_status() self.set_status()

View File

@ -1,13 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// Module CRM
cur_frm.cscript.tname = "Sales Order Item";
cur_frm.cscript.fname = "items";
cur_frm.cscript.other_fname = "taxes";
cur_frm.cscript.sales_team_fname = "sales_team";
{% include 'selling/sales_common.js' %} {% include 'selling/sales_common.js' %}
{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %} {% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
{% include 'accounts/doctype/sales_invoice/pos.js' %} {% include 'accounts/doctype/sales_invoice/pos.js' %}

View File

@ -15,12 +15,6 @@ form_grid_templates = {
} }
class SalesOrder(SellingController): class SalesOrder(SellingController):
tname = 'Sales Order Item'
fname = 'items'
person_tname = 'Target Detail'
partner_tname = 'Partner Target Detail'
territory_tname = 'Territory Target Detail'
def validate_mandatory(self): def validate_mandatory(self):
# validate transaction date v/s delivery date # validate transaction date v/s delivery date
if self.delivery_date: if self.delivery_date:
@ -122,13 +116,13 @@ class SalesOrder(SellingController):
from erpnext.stock.utils import validate_warehouse_company from erpnext.stock.utils import validate_warehouse_company
warehouses = list(set([d.warehouse for d in warehouses = list(set([d.warehouse for d in
self.get(self.fname) if d.warehouse])) self.get("items") if d.warehouse]))
for w in warehouses: for w in warehouses:
validate_warehouse_company(w, self.company) validate_warehouse_company(w, self.company)
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(SalesOrder, self).validate_with_previous_doc(self.tname, { super(SalesOrder, self).validate_with_previous_doc({
"Quotation": { "Quotation": {
"ref_dn_field": "prevdoc_docname", "ref_dn_field": "prevdoc_docname",
"compare_fields": [["company", "="], ["currency", "="]] "compare_fields": [["company", "="], ["currency", "="]]
@ -142,7 +136,7 @@ class SalesOrder(SellingController):
frappe.db.sql("update `tabOpportunity` set status = %s where name=%s",(flag,enq[0][0])) frappe.db.sql("update `tabOpportunity` set status = %s where name=%s",(flag,enq[0][0]))
def update_prevdoc_status(self, flag): def update_prevdoc_status(self, flag):
for quotation in list(set([d.prevdoc_docname for d in self.get(self.fname)])): for quotation in list(set([d.prevdoc_docname for d in self.get("items")])):
if quotation: if quotation:
doc = frappe.get_doc("Quotation", quotation) doc = frappe.get_doc("Quotation", quotation)
if doc.docstatus==2: if doc.docstatus==2:

View File

@ -1,12 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// Preset
// ------
// cur_frm.cscript.tname - Details table name
// cur_frm.cscript.fname - Details fieldname
// cur_frm.cscript.other_fname - fieldname
// cur_frm.cscript.sales_team_fname - Sales Team fieldname
frappe.provide("erpnext.selling"); frappe.provide("erpnext.selling");
frappe.require("assets/erpnext/js/transaction.js"); frappe.require("assets/erpnext/js/transaction.js");
@ -23,7 +17,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}, },
onload_post_render: function() { onload_post_render: function() {
cur_frm.get_field(this.fname).grid.set_multiple_add("item_code", "qty"); cur_frm.get_field("items").grid.set_multiple_add("item_code", "qty");
}, },
setup_queries: function() { setup_queries: function() {
@ -58,12 +52,12 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}); });
} }
if(!this.fname) { if(!this.frm.fields_dict["items"]) {
return; return;
} }
if(this.frm.fields_dict[this.fname].grid.get_field('item_code')) { if(this.frm.fields_dict["items"].grid.get_field('item_code')) {
this.frm.set_query("item_code", this.fname, function() { this.frm.set_query("item_code", "items", function() {
return { return {
query: "erpnext.controllers.queries.item_query", query: "erpnext.controllers.queries.item_query",
filters: (me.frm.doc.order_type === "Maintenance" ? filters: (me.frm.doc.order_type === "Maintenance" ?
@ -73,8 +67,8 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}); });
} }
if(this.frm.fields_dict[this.fname].grid.get_field('batch_no')) { if(this.frm.fields_dict["items"].grid.get_field('batch_no')) {
this.frm.set_query("batch_no", this.fname, function(doc, cdt, cdn) { this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn); var item = frappe.get_doc(cdt, cdn);
if(!item.item_code) { if(!item.item_code) {
frappe.throw(__("Please enter Item Code to get batch no")); frappe.throw(__("Please enter Item Code to get batch no"));
@ -231,7 +225,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}, },
toggle_editable_price_list_rate: function() { toggle_editable_price_list_rate: function() {
var df = frappe.meta.get_docfield(this.tname, "price_list_rate", this.frm.doc.name); var df = frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "price_list_rate", this.frm.doc.name);
var editable_price_list_rate = cint(frappe.defaults.get_default("editable_price_list_rate")); var editable_price_list_rate = cint(frappe.defaults.get_default("editable_price_list_rate"));
if(df && editable_price_list_rate) { if(df && editable_price_list_rate) {
@ -555,10 +549,10 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
} }
setup_field_label_map(["base_rate", "base_price_list_rate", "base_amount"], setup_field_label_map(["base_rate", "base_price_list_rate", "base_amount"],
company_currency, this.fname); company_currency, "items");
setup_field_label_map(["rate", "price_list_rate", "amount"], setup_field_label_map(["rate", "price_list_rate", "amount"],
this.frm.doc.currency, this.fname); this.frm.doc.currency, "items");
setup_field_label_map(["tax_amount", "total"], company_currency, "taxes"); setup_field_label_map(["tax_amount", "total"], company_currency, "taxes");
@ -568,7 +562,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
} }
// toggle columns // toggle columns
var item_grid = this.frm.fields_dict[this.fname].grid; var item_grid = this.frm.fields_dict["items"].grid;
var show = (this.frm.doc.currency != company_currency) || var show = (this.frm.doc.currency != company_currency) ||
((cur_frm.doc.taxes || []).filter( ((cur_frm.doc.taxes || []).filter(
function(d) { return d.included_in_print_rate===1}).length); function(d) { return d.included_in_print_rate===1}).length);
@ -595,7 +589,7 @@ frappe.ui.form.on(cur_frm.doctype,"project_name", function(frm) {
args: { project_name: frm.doc.project_name }, args: { project_name: frm.doc.project_name },
callback: function(r, rt) { callback: function(r, rt) {
if(!r.exc) { if(!r.exc) {
$.each(frm.doc[cur_frm.cscript.fname] || [], function(i, row) { $.each(frm.doc["items"] || [], function(i, row) {
frappe.model.set_value(row.doctype, row.name, "cost_center", r.message); frappe.model.set_value(row.doctype, row.name, "cost_center", r.message);
msgprint(__("Cost Center For Item with Item Code '"+row.item_name+"' has been Changed to "+ r.message)); msgprint(__("Cost Center For Item with Item Code '"+row.item_name+"' has been Changed to "+ r.message));
}) })

View File

@ -88,7 +88,7 @@ class AuthorizationControl(TransactionBase):
add_cond = " and master_name = '"+cstr(customer).replace("'", "\\'")+"'" add_cond = " and master_name = '"+cstr(customer).replace("'", "\\'")+"'"
if based_on == 'Itemwise Discount': if based_on == 'Itemwise Discount':
if doc_obj: if doc_obj:
for t in doc_obj.get(doc_obj.fname): for t in doc_obj.get("items"):
self.validate_auth_rule(doctype_name, t.discount_percentage, based_on, add_cond, company,t.item_code ) self.validate_auth_rule(doctype_name, t.discount_percentage, based_on, add_cond, company,t.item_code )
else: else:
self.validate_auth_rule(doctype_name, auth_value, based_on, add_cond, company) self.validate_auth_rule(doctype_name, auth_value, based_on, add_cond, company)
@ -97,7 +97,7 @@ class AuthorizationControl(TransactionBase):
av_dis = 0 av_dis = 0
if doc_obj: if doc_obj:
price_list_rate, base_rate = 0, 0 price_list_rate, base_rate = 0, 0
for d in doc_obj.get(doc_obj.fname): for d in doc_obj.get("items"):
if d.base_price_list_rate and d.base_rate: if d.base_price_list_rate and d.base_rate:
price_list_rate += flt(d.base_price_list_rate) price_list_rate += flt(d.base_price_list_rate)
base_rate += flt(d.base_rate) base_rate += flt(d.base_rate)

View File

@ -1,12 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
// Module Material Management
cur_frm.cscript.tname = "Delivery Note Item";
cur_frm.cscript.fname = "items";
cur_frm.cscript.other_fname = "taxes";
cur_frm.cscript.sales_team_fname = "sales_team";
{% include 'selling/sales_common.js' %}; {% include 'selling/sales_common.js' %};
{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %} {% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
{% include 'accounts/doctype/sales_invoice/pos.js' %} {% include 'accounts/doctype/sales_invoice/pos.js' %}
@ -46,7 +40,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
// unhide expense_account and cost_center is auto_accounting_for_stock enabled // unhide expense_account and cost_center is auto_accounting_for_stock enabled
var aii_enabled = cint(sys_defaults.auto_accounting_for_stock) var aii_enabled = cint(sys_defaults.auto_accounting_for_stock)
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp(["expense_account", "cost_center"], aii_enabled); cur_frm.fields_dict["items"].grid.set_column_disp(["expense_account", "cost_center"], aii_enabled);
if (this.frm.doc.docstatus===0) { if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('From Sales Order'), cur_frm.add_custom_button(__('From Sales Order'),
@ -205,12 +199,12 @@ if (sys_defaults.auto_accounting_for_stock) {
cur_frm.cscript.expense_account = function(doc, cdt, cdn){ cur_frm.cscript.expense_account = function(doc, cdt, cdn){
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if(d.expense_account) { if(d.expense_account) {
var cl = doc[cur_frm.cscript.fname] || []; var cl = doc["items"] || [];
for(var i = 0; i < cl.length; i++){ for(var i = 0; i < cl.length; i++){
if(!cl[i].expense_account) cl[i].expense_account = d.expense_account; if(!cl[i].expense_account) cl[i].expense_account = d.expense_account;
} }
} }
refresh_field(cur_frm.cscript.fname); refresh_field("items");
} }
// expense account // expense account
@ -228,12 +222,12 @@ if (sys_defaults.auto_accounting_for_stock) {
cur_frm.cscript.cost_center = function(doc, cdt, cdn){ cur_frm.cscript.cost_center = function(doc, cdt, cdn){
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if(d.cost_center) { if(d.cost_center) {
var cl = doc[cur_frm.cscript.fname] || []; var cl = doc["items"] || [];
for(var i = 0; i < cl.length; i++){ for(var i = 0; i < cl.length; i++){
if(!cl[i].cost_center) cl[i].cost_center = d.cost_center; if(!cl[i].cost_center) cl[i].cost_center = d.cost_center;
} }
} }
refresh_field(cur_frm.cscript.fname); refresh_field("items");
} }
cur_frm.fields_dict.items.grid.get_field("cost_center").get_query = function(doc) { cur_frm.fields_dict.items.grid.get_field("cost_center").get_query = function(doc) {

View File

@ -17,9 +17,6 @@ form_grid_templates = {
} }
class DeliveryNote(SellingController): class DeliveryNote(SellingController):
tname = 'Delivery Note Item'
fname = 'items'
def __init__(self, arg1, arg2=None): def __init__(self, arg1, arg2=None):
super(DeliveryNote, self).__init__(arg1, arg2) super(DeliveryNote, self).__init__(arg1, arg2)
self.status_updater = [{ self.status_updater = [{
@ -122,7 +119,7 @@ class DeliveryNote(SellingController):
for fn in (("Sales Order", "against_sales_order"), ("Sales Invoice", "against_sales_invoice")): for fn in (("Sales Order", "against_sales_order"), ("Sales Invoice", "against_sales_invoice")):
if filter(None, [getattr(d, fn[1], None) for d in items]): if filter(None, [getattr(d, fn[1], None) for d in items]):
super(DeliveryNote, self).validate_with_previous_doc(self.tname, { super(DeliveryNote, self).validate_with_previous_doc({
fn[0]: { fn[0]: {
"ref_dn_field": fn[1], "ref_dn_field": fn[1],
"compare_fields": [["customer", "="], ["company", "="], ["project_name", "="], "compare_fields": [["customer", "="], ["company", "="], ["project_name", "="],
@ -131,7 +128,7 @@ class DeliveryNote(SellingController):
}) })
if cint(frappe.defaults.get_global_default('maintain_same_sales_rate')): if cint(frappe.defaults.get_global_default('maintain_same_sales_rate')):
super(DeliveryNote, self).validate_with_previous_doc(self.tname, { super(DeliveryNote, self).validate_with_previous_doc({
fn[0] + " Item": { fn[0] + " Item": {
"ref_dn_field": "so_detail", "ref_dn_field": "so_detail",
"compare_fields": [["rate", "="]], "compare_fields": [["rate", "="]],
@ -222,10 +219,10 @@ class DeliveryNote(SellingController):
""" """
Validate that if packed qty exists, it should be equal to qty Validate that if packed qty exists, it should be equal to qty
""" """
if not any([flt(d.get('packed_qty')) for d in self.get(self.fname)]): if not any([flt(d.get('packed_qty')) for d in self.get("items")]):
return return
has_error = False has_error = False
for d in self.get(self.fname): for d in self.get("items"):
if flt(d.get('qty')) != flt(d.get('packed_qty')): if flt(d.get('qty')) != flt(d.get('packed_qty')):
frappe.msgprint(_("Packed quantity must equal quantity for Item {0} in row {1}").format(d.item_code, d.idx)) frappe.msgprint(_("Packed quantity must equal quantity for Item {0} in row {1}").format(d.item_code, d.idx))
has_error = True has_error = True

View File

@ -1,9 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
cur_frm.cscript.tname = "Material Request Item";
cur_frm.cscript.fname = "items";
{% include 'buying/doctype/purchase_common/purchase_common.js' %}; {% include 'buying/doctype/purchase_common/purchase_common.js' %};
frappe.require("assets/erpnext/js/utils.js"); frappe.require("assets/erpnext/js/utils.js");
@ -11,7 +8,7 @@ frappe.require("assets/erpnext/js/utils.js");
erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.extend({ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.extend({
onload: function(doc) { onload: function(doc) {
this._super(); this._super();
this.frm.set_query("item_code", this.frm.cscript.fname, function() { this.frm.set_query("item_code", "items", function() {
return { return {
query: "erpnext.controllers.queries.item_query" query: "erpnext.controllers.queries.item_query"
} }

View File

@ -18,9 +18,6 @@ form_grid_templates = {
} }
class MaterialRequest(BuyingController): class MaterialRequest(BuyingController):
tname = 'Material Request Item'
fname = 'items'
def get_feed(self): def get_feed(self):
return _("{0}: {1}").format(self.status, self.material_request_type) return _("{0}: {1}").format(self.status, self.material_request_type)
@ -115,13 +112,13 @@ class MaterialRequest(BuyingController):
if self.material_request_type == "Purchase": if self.material_request_type == "Purchase":
return return
item_doclist = self.get("items") self.get("items") = self.get("items")
if not mr_items: if not mr_items:
mr_items = [d.name for d in item_doclist] mr_items = [d.name for d in self.get("items")]
per_ordered = 0.0 per_ordered = 0.0
for d in item_doclist: for d in self.get("items"):
if d.name in mr_items: if d.name in mr_items:
d.ordered_qty = flt(frappe.db.sql("""select sum(transfer_qty) d.ordered_qty = flt(frappe.db.sql("""select sum(transfer_qty)
from `tabStock Entry Detail` where material_request = %s from `tabStock Entry Detail` where material_request = %s
@ -129,14 +126,14 @@ class MaterialRequest(BuyingController):
(self.name, d.name))[0][0]) (self.name, d.name))[0][0])
frappe.db.set_value(d.doctype, d.name, "ordered_qty", d.ordered_qty) frappe.db.set_value(d.doctype, d.name, "ordered_qty", d.ordered_qty)
# note: if qty is 0, its row is still counted in len(item_doclist) # note: if qty is 0, its row is still counted in len(self.get("items"))
# hence adding 1 to per_ordered # hence adding 1 to per_ordered
if (d.ordered_qty > d.qty) or not d.qty: if (d.ordered_qty > d.qty) or not d.qty:
per_ordered += 1.0 per_ordered += 1.0
elif d.qty > 0: elif d.qty > 0:
per_ordered += flt(d.ordered_qty / flt(d.qty)) per_ordered += flt(d.ordered_qty / flt(d.qty))
self.per_ordered = flt((per_ordered / flt(len(item_doclist))) * 100.0, 2) self.per_ordered = flt((per_ordered / flt(len(self.get("items")))) * 100.0, 2)
frappe.db.set_value(self.doctype, self.name, "per_ordered", self.per_ordered) frappe.db.set_value(self.doctype, self.name, "per_ordered", self.per_ordered)
def update_requested_qty(self, mr_item_rows=None): def update_requested_qty(self, mr_item_rows=None):

View File

@ -1,10 +1,6 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
cur_frm.cscript.tname = "Purchase Receipt Item";
cur_frm.cscript.fname = "items";
cur_frm.cscript.other_fname = "taxes";
{% include 'buying/doctype/purchase_common/purchase_common.js' %}; {% include 'buying/doctype/purchase_common/purchase_common.js' %};
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %} {% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
{% include 'accounts/doctype/sales_invoice/pos.js' %} {% include 'accounts/doctype/sales_invoice/pos.js' %}

View File

@ -16,9 +16,6 @@ form_grid_templates = {
} }
class PurchaseReceipt(BuyingController): class PurchaseReceipt(BuyingController):
tname = 'Purchase Receipt Item'
fname = 'items'
def __init__(self, arg1, arg2=None): def __init__(self, arg1, arg2=None):
super(PurchaseReceipt, self).__init__(arg1, arg2) super(PurchaseReceipt, self).__init__(arg1, arg2)
self.status_updater = [{ self.status_updater = [{
@ -101,7 +98,7 @@ class PurchaseReceipt(BuyingController):
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(PurchaseReceipt, self).validate_with_previous_doc(self.tname, { super(PurchaseReceipt, self).validate_with_previous_doc({
"Purchase Order": { "Purchase Order": {
"ref_dn_field": "prevdoc_docname", "ref_dn_field": "prevdoc_docname",
"compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]], "compare_fields": [["supplier", "="], ["company", "="], ["currency", "="]],
@ -114,7 +111,7 @@ class PurchaseReceipt(BuyingController):
}) })
if cint(frappe.defaults.get_global_default('maintain_same_rate')): if cint(frappe.defaults.get_global_default('maintain_same_rate')):
super(PurchaseReceipt, self).validate_with_previous_doc(self.tname, { super(PurchaseReceipt, self).validate_with_previous_doc({
"Purchase Order Item": { "Purchase Order Item": {
"ref_dn_field": "prevdoc_detail_docname", "ref_dn_field": "prevdoc_detail_docname",
"compare_fields": [["rate", "="]], "compare_fields": [["rate", "="]],

View File

@ -1,8 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt
cur_frm.cscript.tname = "Stock Entry Detail";
cur_frm.cscript.fname = "items";
frappe.require("assets/erpnext/js/controllers/stock_controller.js"); frappe.require("assets/erpnext/js/controllers/stock_controller.js");
frappe.require("assets/erpnext/js/utils.js"); frappe.require("assets/erpnext/js/utils.js");
frappe.provide("erpnext.stock"); frappe.provide("erpnext.stock");
@ -56,7 +53,7 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
}, },
onload_post_render: function() { onload_post_render: function() {
cur_frm.get_field(this.fname).grid.set_multiple_add("item_code", "qty"); cur_frm.get_field("items").grid.set_multiple_add("item_code", "qty");
this.set_default_account(); this.set_default_account();
}, },

View File

@ -26,14 +26,12 @@ form_grid_templates = {
} }
class StockEntry(StockController): class StockEntry(StockController):
fname = 'items'
def get_feed(self): def get_feed(self):
return _("From {0} to {1}").format(self.from_warehouse, self.to_warehouse) return _("From {0} to {1}").format(self.from_warehouse, self.to_warehouse)
def onload(self): def onload(self):
if self.docstatus==1: if self.docstatus==1:
for item in self.get(self.fname): for item in self.get("items"):
item.update(get_available_qty(item.item_code, item.update(get_available_qty(item.item_code,
item.s_warehouse)) item.s_warehouse))
@ -869,7 +867,7 @@ def get_sales_account_from_item(doc, ref_item):
account = None account = None
if not getattr(ref_item, "income_account", None): if not getattr(ref_item, "income_account", None):
if ref_item.parent_item: if ref_item.parent_item:
parent_item = doc.get(doc.fname, {"item_code": ref_item.parent_item})[0] parent_item = doc.get("items", {"item_code": ref_item.parent_item})[0]
account = parent_item.income_account account = parent_item.income_account
else: else:
account = ref_item.income_account account = ref_item.income_account
@ -944,7 +942,7 @@ def make_return_jv_from_purchase_receipt(se, ref):
if not invoice_against_receipt: if not invoice_against_receipt:
purchase_orders_against_receipt = [d.prevdoc_docname for d in purchase_orders_against_receipt = [d.prevdoc_docname for d in
ref.doc.get(ref.doc.fname, {"prevdoc_doctype": "Purchase Order"}) ref.doc.get("items", {"prevdoc_doctype": "Purchase Order"})
if getattr(d, "prevdoc_docname", None)] if getattr(d, "prevdoc_docname", None)]
if purchase_orders_against_receipt: if purchase_orders_against_receipt:

View File

@ -107,7 +107,6 @@ cur_frm.fields_dict['items'].grid.get_field('item_code').get_query = function(do
} }
cur_frm.cscript.item_code = function(doc, cdt, cdn) { cur_frm.cscript.item_code = function(doc, cdt, cdn) {
var fname = cur_frm.cscript.fname;
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if (d.item_code) { if (d.item_code) {
return get_server_fields('get_item_details', d.item_code, 'items', return get_server_fields('get_item_details', d.item_code, 'items',

View File

@ -82,7 +82,6 @@ cur_frm.fields_dict['purposes'].grid.get_field('item_code').get_query = function
} }
cur_frm.cscript.item_code = function(doc, cdt, cdn) { cur_frm.cscript.item_code = function(doc, cdt, cdn) {
var fname = cur_frm.cscript.fname;
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if (d.item_code) { if (d.item_code) {
return get_server_fields('get_item_details',d.item_code, 'purposes',doc,cdt,cdn,1); return get_server_fields('get_item_details',d.item_code, 'purposes',doc,cdt,cdn,1);

View File

@ -58,12 +58,12 @@ class TransactionBase(StatusUpdater):
def validate_uom_is_integer(self, uom_field, qty_fields): def validate_uom_is_integer(self, uom_field, qty_fields):
validate_uom_is_integer(self, uom_field, qty_fields) validate_uom_is_integer(self, uom_field, qty_fields)
def validate_with_previous_doc(self, source_dt, ref): def validate_with_previous_doc(self, ref):
for key, val in ref.items(): for key, val in ref.items():
is_child = val.get("is_child_table") is_child = val.get("is_child_table")
ref_doc = {} ref_doc = {}
item_ref_dn = [] item_ref_dn = []
for d in self.get_all_children(source_dt): for d in self.get_all_children(self.doctype + " Item"):
ref_dn = d.get(val["ref_dn_field"]) ref_dn = d.get(val["ref_dn_field"])
if ref_dn: if ref_dn:
if is_child: if is_child: