mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 00:44:45 +00:00
[usability] item price moved to price list
This commit is contained in:
@@ -1,26 +1,6 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
wn.provide("erpnext.stock");
|
||||
|
||||
erpnext.stock.Item = wn.ui.form.Controller.extend({
|
||||
onload: function() {
|
||||
this.frm.add_fetch("price_list", "currency", "ref_currency");
|
||||
this.frm.add_fetch("price_list", "buying_or_selling", "buying_or_selling");
|
||||
},
|
||||
|
||||
ref_rate_details_add: function(doc, cdt, cdn) {
|
||||
var row = wn.model.get_doc(cdt, cdn);
|
||||
if(row.price_list && !row.ref_currency) {
|
||||
// execute fetch
|
||||
var df = wn.meta.get_docfield(row.doctype, "price_list", row.parent);
|
||||
this.frm.script_manager.validate_link_and_fetch(df, row.name, row.price_list);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.script_manager.make(erpnext.stock.Item);
|
||||
|
||||
cur_frm.cscript.refresh = function(doc) {
|
||||
// make sensitive fields(has_serial_no, is_stock_item, valuation_method)
|
||||
// read only if any stock ledger entry exists
|
||||
|
||||
@@ -11,7 +11,6 @@ from webnotes import msgprint, _
|
||||
|
||||
from webnotes.model.controller import DocListController
|
||||
|
||||
class PriceListCurrencyMismatch(Exception): pass
|
||||
class WarehouseNotSet(Exception): pass
|
||||
|
||||
class DocType(DocListController):
|
||||
@@ -32,9 +31,8 @@ class DocType(DocListController):
|
||||
self.check_stock_uom_with_bin()
|
||||
self.validate_conversion_factor()
|
||||
self.add_default_uom_in_conversion_factor_table()
|
||||
self.valiadte_item_type()
|
||||
self.validate_item_type()
|
||||
self.check_for_active_boms()
|
||||
self.validate_price_lists()
|
||||
self.fill_customer_code()
|
||||
self.check_item_tax()
|
||||
self.validate_barcode()
|
||||
@@ -87,7 +85,7 @@ class DocType(DocListController):
|
||||
As UOM: %s is not Stock UOM of Item: %s""" %
|
||||
(d.uom, d.uom, self.doc.name)), raise_exception=1)
|
||||
|
||||
def valiadte_item_type(self):
|
||||
def validate_item_type(self):
|
||||
if cstr(self.doc.is_manufactured_item) == "No":
|
||||
self.doc.is_pro_applicable = "No"
|
||||
|
||||
@@ -125,22 +123,7 @@ class DocType(DocListController):
|
||||
'is_pro_applicable' :'Allow Production Order'}
|
||||
for d in fl:
|
||||
if cstr(self.doc.fields.get(d)) != 'Yes':
|
||||
_check_for_active_boms(fl[d])
|
||||
|
||||
def validate_price_lists(self):
|
||||
price_lists=[]
|
||||
for d in getlist(self.doclist,'ref_rate_details'):
|
||||
if d.price_list in price_lists:
|
||||
msgprint(_("Cannot have two prices for same Price List") + ": " + d.price_list,
|
||||
raise_exception= webnotes.DuplicateEntryError)
|
||||
else:
|
||||
price_list_currency = webnotes.conn.get_value("Price List", d.price_list, "currency")
|
||||
if price_list_currency and d.ref_currency != price_list_currency:
|
||||
msgprint(_("Currency does not match Price List Currency for Price List") \
|
||||
+ ": " + d.price_list, raise_exception=PriceListCurrencyMismatch)
|
||||
|
||||
price_lists.append(d.price_list)
|
||||
|
||||
_check_for_active_boms(fl[d])
|
||||
|
||||
def fill_customer_code(self):
|
||||
""" Append all the customer codes and insert into "customer_code" field of item table """
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-05-03 10:45:46",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-08-30 16:21:38",
|
||||
"modified": "2013-09-11 11:50:10",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -625,25 +625,6 @@
|
||||
"options": "Item Tax",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "price_list_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Price Lists and Rates",
|
||||
"options": "icon-money",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"description": "Create a price list from Price List master and enter standard ref rates against each of them. On selection of a price list in Quotation, Sales Order or Delivery Note, corresponding ref rate will be fetched for this item.",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "ref_rate_details",
|
||||
"fieldtype": "Table",
|
||||
"label": "Item Prices",
|
||||
"oldfieldname": "ref_rate_details",
|
||||
"oldfieldtype": "Table",
|
||||
"options": "Item Price",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "inspection_criteria",
|
||||
|
||||
@@ -9,20 +9,6 @@ test_ignore = ["BOM"]
|
||||
test_dependencies = ["Warehouse"]
|
||||
|
||||
class TestItem(unittest.TestCase):
|
||||
def test_duplicate_price_list(self):
|
||||
item = webnotes.bean(copy=test_records[0])
|
||||
item.doc.item_code = "_Test Item 10"
|
||||
item_price = item.doclist.get({"doctype": "Item Price"})[0]
|
||||
item.doclist.append(webnotes.doc(item_price.fields.copy()))
|
||||
self.assertRaises(webnotes.DuplicateEntryError, item.insert)
|
||||
|
||||
def test_price_list_mismatch(self):
|
||||
from stock.doctype.item.item import PriceListCurrencyMismatch
|
||||
item = webnotes.bean(copy=test_records[0])
|
||||
item.doc.item_code = "_Test Item 11"
|
||||
item_price = item.doclist.get({"doctype": "Item Price"})[0].ref_currency="USD"
|
||||
self.assertRaises(PriceListCurrencyMismatch, item.insert)
|
||||
|
||||
def test_default_warehouse(self):
|
||||
from stock.doctype.item.item import WarehouseNotSet
|
||||
item = webnotes.bean(copy=test_records[0])
|
||||
@@ -57,14 +43,7 @@ test_records = [
|
||||
"warehouse_reorder_level": 20,
|
||||
"warehouse_reorder_qty": 20,
|
||||
"material_request_type": "Purchase"
|
||||
}, {
|
||||
"doctype": "Item Price",
|
||||
"parentfield": "ref_rate_details",
|
||||
"price_list": "_Test Price List",
|
||||
"ref_rate": 100,
|
||||
"ref_currency": "INR",
|
||||
"buying_or_selling": "Selling"
|
||||
}
|
||||
},
|
||||
],
|
||||
[{
|
||||
"doctype": "Item",
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Price of the Item in a particular Price List.
|
||||
@@ -1 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
@@ -1,9 +0,0 @@
|
||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
@@ -1,78 +0,0 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-05-02 16:29:48",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-08-09 14:46:58",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"autoname": "RFD/.#####",
|
||||
"doctype": "DocType",
|
||||
"in_create": 0,
|
||||
"istable": 1,
|
||||
"module": "Stock",
|
||||
"name": "__common__",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"in_list_view": 1,
|
||||
"name": "__common__",
|
||||
"parent": "Item Price",
|
||||
"parentfield": "fields",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocType",
|
||||
"name": "Item Price"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "price_list",
|
||||
"fieldtype": "Link",
|
||||
"in_filter": 1,
|
||||
"label": "Price List Name",
|
||||
"oldfieldname": "price_list_name",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "Price List",
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "ref_rate",
|
||||
"fieldtype": "Currency",
|
||||
"in_filter": 1,
|
||||
"label": "Ref Rate",
|
||||
"oldfieldname": "ref_rate",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "ref_currency",
|
||||
"reqd": 1,
|
||||
"search_index": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "ref_currency",
|
||||
"fieldtype": "Link",
|
||||
"in_filter": 1,
|
||||
"label": "Currency",
|
||||
"oldfieldname": "ref_currency",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "Currency",
|
||||
"read_only": 1,
|
||||
"reqd": 0,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"default": "Selling",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "buying_or_selling",
|
||||
"fieldtype": "Select",
|
||||
"label": "Valid for Buying or Selling?",
|
||||
"options": "Buying\nSelling",
|
||||
"read_only": 1,
|
||||
"reqd": 1
|
||||
}
|
||||
]
|
||||
@@ -23,8 +23,8 @@ def execute(filters=None):
|
||||
item_map[item]["description"], item_map[item]["stock_uom"],
|
||||
flt(last_purchase_rate.get(item, 0), precision),
|
||||
flt(val_rate_map.get(item, 0), precision),
|
||||
pl.get(item, {}).get("selling"),
|
||||
pl.get(item, {}).get("buying"),
|
||||
pl.get(item, {}).get("Selling"),
|
||||
pl.get(item, {}).get("Buying"),
|
||||
flt(bom_rate.get(item, 0), precision),
|
||||
flt(item_map[item]["standard_rate"], precision)
|
||||
])
|
||||
@@ -56,24 +56,21 @@ def get_price_list():
|
||||
"""Get selling & buying price list of every item"""
|
||||
|
||||
rate = {}
|
||||
|
||||
price_list = webnotes.conn.sql("""select parent, selling, buying,
|
||||
concat(price_list, " - ", ref_currency, " ", ref_rate) as price
|
||||
from `tabItem Price` where docstatus<2""", as_dict=1)
|
||||
|
||||
price_list = webnotes.conn.sql("""select ip.item_code, pl.buying_or_selling,
|
||||
concat(pl.name, " - ", pl.currency, " ", ip.ref_rate) as price
|
||||
from `tabItem Price` ip, `tabPrice List` pl where
|
||||
ip.parent = pl.name and pl.docstatus<2""", as_dict=1)
|
||||
|
||||
for j in price_list:
|
||||
if j.price:
|
||||
if j.selling:
|
||||
rate.setdefault(j.parent, {}).setdefault("selling", []).append(j.price)
|
||||
if j.buying:
|
||||
rate.setdefault(j.parent, {}).setdefault("buying", []).append(j.price)
|
||||
|
||||
rate.setdefault(j.item_code, {}).setdefault(j.buying_or_selling, []).append(j.price)
|
||||
item_rate_map = {}
|
||||
|
||||
for item in rate:
|
||||
item_rate_map.setdefault(item, {}).setdefault("selling",
|
||||
", ".join(rate[item].get("selling", [])))
|
||||
item_rate_map[item]["buying"] = ", ".join(rate[item].get("buying", []))
|
||||
for buying_or_selling in rate[item]:
|
||||
item_rate_map.setdefault(item, {}).setdefault(buying_or_selling,
|
||||
", ".join(rate[item].get(buying_or_selling, [])))
|
||||
|
||||
return item_rate_map
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-02-22 18:01:55",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-05-07 11:52:00",
|
||||
"modified": "2013-09-10 15:50:26",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -10,7 +10,7 @@
|
||||
"doctype": "Report",
|
||||
"is_standard": "Yes",
|
||||
"name": "__common__",
|
||||
"query": "select\n item.name as \"ID:Link/Item:120\", \n item.item_name as \"Item Name::120\", \n item_price.price_list as \"Price List::80\",\n item_price.ref_currency as \"Currency::40\", \n item_price.ref_rate as \"Rate:Float:80\",\n item.description as \"Description::160\",\n item.item_group as \"Item Group:Link/Item Group:100\",\n item.brand as \"Brand::100\"\nfrom `tabItem` item, `tabItem Price` item_price\nwhere\n item_price.parent = item.name",
|
||||
"query": "select\n item.name as \"ID:Link/Item:120\", \n item.item_name as \"Item Name::120\", \n item_price.parent as \"Price List::80\",\n price_list.currency as \"Currency::40\", \n item_price.ref_rate as \"Rate:Float:80\",\n item.description as \"Description::160\",\n item.item_group as \"Item Group:Link/Item Group:100\",\n item.brand as \"Brand::100\"\nfrom `tabItem` item, `tabItem Price` item_price, `tabPrice List` price_list\nwhere\n item_price.item_code = item.name and\n item_price.parent = price_list.name",
|
||||
"ref_doctype": "Item",
|
||||
"report_name": "Item-Wise Price List",
|
||||
"report_type": "Query Report"
|
||||
|
||||
Reference in New Issue
Block a user