sales bom cleanup

This commit is contained in:
Rushabh Mehta 2012-07-11 19:18:50 +05:30
parent cda9732f51
commit b9fabf8e16
9 changed files with 106 additions and 403 deletions

View File

@ -340,7 +340,12 @@ cur_frm.cscript.export_rate = function(doc,cdt,cdn) {
// ************* GET OTHER CHARGES BASED ON COMPANY *************
cur_frm.fields_dict.charge.get_query = function(doc) {
return 'SELECT DISTINCT `tabSales Taxes and Charges Master`.name FROM `tabSales Taxes and Charges Master` WHERE `tabSales Taxes and Charges Master`.company = "'+doc.company+'" AND `tabSales Taxes and Charges Master`.company is not NULL AND `tabSales Taxes and Charges Master`.docstatus != 2 AND `tabSales Taxes and Charges Master`.%(key)s LIKE "%s" ORDER BY `tabSales Taxes and Charges Master`.name LIMIT 50';
return 'SELECT DISTINCT `tabSales Taxes and Charges Master`.name FROM \
`tabSales Taxes and Charges Master` WHERE `tabSales Taxes and Charges Master`.company = "'
+doc.company+'" AND `tabSales Taxes and Charges Master`.company is not NULL \
AND `tabSales Taxes and Charges Master`.docstatus != 2 \
AND `tabSales Taxes and Charges Master`.%(key)s LIKE "%s" \
ORDER BY `tabSales Taxes and Charges Master`.name LIMIT 50';
}
// ********************* Get Charges ****************************

View File

@ -40,8 +40,7 @@ class DocType:
"""download 3 column template with all Items"""
default_currency = webnotes.conn.get_default('currency')
item_list = webnotes.conn.sql("""select name from tabItem where
ifnull(is_stock_item,'')='Yes' and (ifnull(is_sales_item,'')='Yes'
or ifnull(is_service_item,'')='Yes')""")
(ifnull(is_sales_item,'')='Yes' or ifnull(is_service_item,'')='Yes')""")
data = [self.get_price(i[0], default_currency) for i in item_list]
return [['Item', 'Rate', 'Currency']] + data

View File

@ -5,7 +5,7 @@
{
'creation': '2012-07-03 13:30:55',
'docstatus': 0,
'modified': '2012-07-11 17:06:32',
'modified': '2012-07-11 17:35:10',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -20,6 +20,7 @@
'allow_trash': 1,
'autoname': u'field:price_list_name',
'colour': u'White:FFF',
'description': u'Maintain multiple selling rates for the same **Item** using **Price Lists**. You can upload / edit multiple prices by downloading and uploading the template.',
'doctype': 'DocType',
'document_type': u'Master',
'max_attachments': 1,

View File

@ -14,35 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.cscript.onload = function(doc, cdt, cdn) {
if(!doc.price_list) set_multiple(cdt,cdn,{price_list:sys_defaults.price_list_name});
}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.enable_fields('new_item_code', doc.__islocal);
if(!doc.__islocal) {
get_field(doc.doctype, 'new_item_code', doc.name).permlevel = 1;
cur_frm.add_custom_button("Check for Duplicates", function() {
cur_frm.call_server('check_duplicate', 1)
}, 'icon-search')
}
}
/* Get Item Code */
cur_frm.cscript.item_code = function(doc, dt, dn) {
var d = locals[dt][dn];
if (d.item_code){
get_server_fields('get_item_details', d.item_code, 'sales_bom_items', doc ,dt, dn, 1);
}
cur_frm.fields_dict.new_item_code.get_query = function() {
return 'select name, description from tabItem where is_stock_item="No" and is_sales_item="Yes"\
and name not in (select name from `tabSales BOM`)\
and `%(key)s` like "%s"'
}
cur_frm.fields_dict.new_item_code.query_description = 'Select Item where "Is Stock Item" is "No" \
and "Is Sales Item" is "Yes" and there is no other Sales BOM';
cur_frm.cscript.price_list = function(doc, cdt, cdn) {
$c_obj(make_doclist(cdt,cdn), 'get_rates', '', function(r,rt){refresh_field('sales_bom_items');});
}
cur_frm.cscript.currency = function(doc, cdt, cdn) {
$c_obj(make_doclist(cdt,cdn), 'get_rates', '', function(r,rt){refresh_field('sales_bom_items');});
}
cur_frm.cscript.find_sales_bom = function(doc, dt, dn) {
$c_obj(make_doclist(dt,dn), 'check_duplicate', 1, '');
}

View File

@ -14,24 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Please edit this list and import only required elements
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, getchildren, make_autoname
from webnotes.model.doclist import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
from webnotes.utils import flt
from webnotes.model.utils import getlist
class DocType:
def __init__(self,d,dl):
@ -40,138 +25,41 @@ class DocType:
def autoname(self):
self.doc.name = self.doc.new_item_code
# Get Ref Rates
# --------------
def get_rates(self):
for d in getlist(self.doclist, "sales_bom_items"):
r = sql("select ref_rate from `tabItem Price` where price_list_name=%s and parent=%s and ref_currency = %s", (self.doc.price_list, d.item_code, self.doc.currency))
d.rate = r and flt(r[0][0]) or 0.00
# Get Item Details
# -----------------
def get_item_details(self, name):
det = sql("select description, stock_uom from `tabItem` where name = '%s' " % cstr(name))
rate = sql("select ref_rate from `tabItem Price` where price_list_name = %s and parent = %s and ref_currency = %s", (self.doc.price_list, name, self.doc.currency))
return {'description' : det and det[0][0] or '', 'uom': det and det[0][1] or '', 'rate': rate and flt(rate[0][0]) or 0.00}
def get_main_item(self):
is_main_item = []
for d in getlist(self.doclist,'sales_bom_items'):
if d.is_main_item == 'Yes':
is_main_item.append(d.item_code)
# Check that Sales Bom Item cannot be child of Sales Bom.
if d.item_code == self.doc.new_item_code:
msgprint("Sales Bom Item " + d.new_item_code +" cannot be child item.")
raise Exception
if len(is_main_item) > 1:
msgprint('Main item cannot be more than one.')
raise Exception , " Validation Error."
if len(is_main_item) == 0:
msgprint("At least one item should be main item.")
raise Exception , " Validation Error."
return is_main_item[0]
# Make Item
# ---------
def create_new_item(self):
i = Document("Item")
i.item_code = self.doc.new_item_code
i.item_name = self.doc.new_item_name
i.name = i.item_code
i.is_sales_item = 'Yes'
i.is_stock_item = 'No'
i.save(1)
# Update Rate
def update_ref_rate(self, i):
ref_rate = 0
if self.doc.price_list:
if not cstr(self.doc.currency):
msgprint("Please enter Currency.")
raise Exception
for d in getlist(self.doclist, "sales_bom_items"):
item_rate = sql("select ref_rate,ref_currency from `tabItem Price` where price_list_name=%s and parent=%s", (self.doc.price_list, d.item_code))
ref_rate += flt(d.qty) * (item_rate and flt(item_rate[0][0]) or 0)
if ref_rate:
# clear old rates
sql("delete from `tabItem Price` where parent=%s and price_list_name = %s", (i.name, self.doc.price_list))
pld = addchild(i,"ref_rate_details", "Item Price")
pld.price_list_name = self.doc.price_list
pld.ref_rate = flt(ref_rate)
pld.ref_currency = self.doc.currency
pld.save()
# Update Items
# ------------
def update_item(self):
i = Document("Item", self.doc.new_item_code)
# update fields
i.brand = self.doc.new_item_brand
i.stock_uom = self.doc.stock_uom
i.item_group = self.doc.item_group
i.item_name = self.doc.new_item_name
i.description = self.doc.description
# set default as 'No' or 0
i.is_sample_item = 'No'
i.is_asset_item = 'No'
i.is_purchase_item = 'No'
i.is_manufactured_item = 'No'
i.is_sub_contracted_item = 'No'
i.is_service_item = 'No'
i.inspection_required = 'No'
i.has_serial_no = 'No'
i.lead_time_days = flt(0)
# update rates
self.update_ref_rate(i)
i.save()
msgprint("Items: %s updated successfully. To update more details open and edit item master" % self.doc.new_item_code)
def validate(self):
# check for duplicate
self.check_duplicate()
item_code = self.get_main_item()
if not self.doc.new_item_code:
self.doc.new_item_code = make_autoname(item_code +'.###')
def on_update(self):
# if no item code, create new item code
if not sql("select name from tabItem where name=%s", self.doc.new_item_code):
self.create_new_item()
self.update_item()
self.validate_main_item()
def validate_main_item(self):
"""main item must have Is Stock Item as No and Is Sales Item as Yes"""
if not webnotes.conn.sql("""select name from tabItem where name=%s and
ifnull(is_stock_item,'')='No' and ifnull(is_sales_item,'')='Yes'"""):
webnotes.msgprint("""Parent Item %s is either a Stock Item or a not a Sales Item""",
raise_exception=1)
def check_duplicate(self, finder=0):
il = getlist(self.doclist, "sales_bom_items")
if not il:
msgprint("Add atleast one item")
webnotes.msgprint("Add atleast one item")
return
# get all Sales BOM that have the first item
sbl = sql("select distinct parent from `tabSales BOM Item` where item_code=%s and parent != %s and docstatus != 2", (il[0].item_code, self.doc.name))
sbl = webnotes.conn.sql("""select distinct parent from `tabSales BOM Item` where item_code=%s
and parent != %s and docstatus != 2""", (il[0].item_code, self.doc.name))
# check all siblings
sub_items = [[d.item_code, flt(d.qty)] for d in il]
for s in sbl:
t = sql("select item_code, qty from `tabSales BOM Item` where parent=%s and docstatus != 2", s[0])
t = webnotes.conn.sql("""select item_code, qty from `tabSales BOM Item` where parent=%s and
docstatus != 2""", s[0])
t = [[d[0], flt(d[1])] for d in t]
if self.has_same_items(sub_items, t):
msgprint("%s has the same Sales BOM details" % s[0])
webnotes.msgprint("%s has the same Sales BOM details" % s[0])
raise Exception
if finder:
msgprint("There is no Sales BOM present with the following Combination.")
webnotes.msgprint("There is no Sales BOM present with the following Combination.")
def has_same_items(self, l1, l2):

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-04-30 12:08:49',
'creation': '2012-07-03 13:30:44',
'docstatus': 0,
'modified': '2012-05-04 09:53:08',
'modified': '2012-07-11 19:17:51',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -15,10 +15,10 @@
'_last_update': u'1322549701',
'allow_trash': 1,
'colour': u'White:FFF',
'description': u'Aggregate item and accessories to form a Sales Item. There is no inventory of the new item but of the sub-components.',
'description': u'Aggregate group of **Items** into another **Item**. This is useful if you are bundling a certain **Items** into a package and you maintain stock of the packed **Items** and not the packed **Item**. \n\nThe package **Item** will have "Is Stock Item" as "No" and "Is Sales Item" as "Yes".\n\nFor Example: If you are selling Laptops and Backpacks separately and have a special price if the customer buys both, then the Laptop + Backpack will be a new Sales BOM Item.\n\nNote: BOM = Bill of Materials',
'doctype': 'DocType',
'document_type': u'Master',
'is_submittable': 1,
'is_submittable': 0,
'module': u'Stock',
'name': '__common__',
'section_style': u'Simple',
@ -33,17 +33,20 @@
'name': '__common__',
'parent': u'Sales BOM',
'parentfield': u'fields',
'parenttype': u'DocType'
'parenttype': u'DocType',
'permlevel': 0
},
# These values are common for all DocPerm
{
'amend': 0,
'doctype': u'DocPerm',
'name': '__common__',
'parent': u'Sales BOM',
'parentfield': u'permissions',
'parenttype': u'DocType',
'read': 1
'read': 1,
'submit': 0
},
# DocType, Sales BOM
@ -54,73 +57,61 @@
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Material Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 1,
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Material Manager',
'submit': 1,
'write': 1
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Material User',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Material User',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Sales User',
'submit': 0,
'role': u'Material Manager',
'write': 1
},
# DocPerm
{
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Material User',
'write': 0
},
# DocPerm
{
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Material User',
'write': 0
},
# DocPerm
{
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Sales User',
'write': 1
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Sales User',
'submit': 0,
'write': 0
},
@ -129,167 +120,32 @@
'doctype': u'DocField',
'fieldname': u'basic_section',
'fieldtype': u'Section Break',
'label': u'Basic Section',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'col1',
'fieldtype': u'Column Break',
'permlevel': 0,
'width': u'50%'
'label': u'Sales BOM Item'
},
# DocField
{
'colour': u'White:FFF',
'description': u'Item code of the new aggregate item.',
'description': u'The Item that represents the Package. This Item must have "Is Stock Item" as "No" and "Is Sales Item" as "Yes"',
'doctype': u'DocField',
'fieldname': u'new_item_code',
'fieldtype': u'Data',
'label': u'New Item Code',
'fieldtype': u'Link',
'label': u'Parent Item',
'no_copy': 1,
'oldfieldname': u'new_item_code',
'oldfieldtype': u'Data',
'options': u'Item',
'reqd': 1
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'new_item_name',
'fieldtype': u'Data',
'label': u'New Item Name',
'oldfieldname': u'new_item_name',
'oldfieldtype': u'Data',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'new_item_brand',
'fieldtype': u'Data',
'label': u'New Item Brand',
'oldfieldname': u'new_item_brand',
'oldfieldtype': u'Data',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'description',
'fieldtype': u'Text',
'label': u'New Description',
'oldfieldname': u'description',
'oldfieldtype': u'Text',
'permlevel': 0,
'reqd': 1,
'width': u'300px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'col2',
'fieldtype': u'Column Break',
'permlevel': 0,
'width': u'50%'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'item_group',
'fieldtype': u'Link',
'label': u'Item Group',
'oldfieldname': u'item_group',
'oldfieldtype': u'Link',
'options': u'Item Group',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'stock_uom',
'fieldtype': u'Link',
'label': u'Stock UOM',
'oldfieldname': u'stock_uom',
'oldfieldtype': u'Link',
'options': u'UOM',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'price_list',
'fieldtype': u'Select',
'label': u'Price List',
'oldfieldname': u'price_list',
'oldfieldtype': u'Select',
'options': u'link:Price List',
'permlevel': 0,
'trigger': u'Client'
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'currency',
'fieldtype': u'Select',
'label': u'Currency',
'oldfieldname': u'currency',
'oldfieldtype': u'Select',
'options': u'link:Currency',
'permlevel': 0,
'trigger': u'Client'
},
# DocField
{
'depends_on': u'eval:doc.amended_from',
'description': u'The date at which current entry is corrected in the system.',
'doctype': u'DocField',
'fieldname': u'amendment_date',
'fieldtype': u'Date',
'label': u'Amendment Date',
'no_copy': 1,
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'amended_from',
'fieldtype': u'Link',
'label': u'Amended From',
'no_copy': 1,
'options': u'Sales BOM',
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'colour': u'White:FFF',
'description': u'List items that form a package. One of the items has to be a "main item".',
'description': u'List items that form the package.',
'doctype': u'DocField',
'fieldname': u'item_section',
'fieldtype': u'Section Break',
'label': u'Items',
'permlevel': 0
'label': u'Package Items'
},
# DocField
@ -301,30 +157,6 @@
'oldfieldname': u'sales_bom_items',
'oldfieldtype': u'Table',
'options': u'Sales BOM Item',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Add a few items and find if there are any Sales BOM created with the same combination to help you identify duplication.',
'doctype': u'DocField',
'fieldname': u'find_sales_bom',
'fieldtype': u'Button',
'label': u'Find Sales BOM',
'oldfieldtype': u'Button',
'permlevel': 0,
'trigger': u'Client'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'trash_reason',
'fieldtype': u'Small Text',
'label': u'Trash Reason',
'oldfieldname': u'trash_reason',
'oldfieldtype': u'Small Text',
'permlevel': 1
'reqd': 1
}
]

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-03-27 14:36:37',
'creation': '2012-07-03 13:30:46',
'docstatus': 0,
'modified': '2012-03-27 14:36:37',
'modified': '2012-07-11 18:56:27',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -20,7 +20,7 @@
'section_style': u'Tray',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 3
'version': 1
},
# These values are common for all DocField
@ -38,18 +38,6 @@
'name': u'Sales BOM Item'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'is_main_item',
'fieldtype': u'Select',
'label': u'Is Main Item',
'oldfieldname': u'is_main_item',
'oldfieldtype': u'Select',
'options': u'\nYes\nNo',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
@ -64,6 +52,18 @@
'trigger': u'Client'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'qty',
'fieldtype': u'Currency',
'label': u'Qty',
'oldfieldname': u'qty',
'oldfieldtype': u'Currency',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
@ -87,18 +87,6 @@
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'qty',
'fieldtype': u'Currency',
'label': u'Qty',
'oldfieldname': u'qty',
'oldfieldtype': u'Currency',
'permlevel': 0,
'reqd': 1
},
# DocField
{
'doctype': u'DocField',

View File

@ -49,6 +49,11 @@
title = "Details packages against a delivery"
href="#!List/Packing Slip">Packing Slip</a>
</div>
<div class="section-item">
<a class="section-link"
title = "Multiple prices lists for items"
href="#!List/Price List">Price List</a>
</div>
<div class="section-item">
<a class="section-link"
title = "Readings of incoming quality inspections"

View File

@ -1229,7 +1229,7 @@ d.set_search=function(dt){if(d.style!='Search'){d.rows['Result'].innerHTML='';d.
d.style='Search';if(d.input){d.input=null;sel_type=null;}
d.sel_type=get_label_doctype(dt);d.set_title('Quick Search for '+dt);}
$(inp).keydown(function(e){if(e.which==13){if(!btn.disabled)btn.onclick();}})
d.set_query_description=function(txt){if(!txt)txt=d.input&&d.input.query_description||null;if(txt){d.rows['Help'].innerHTML='<div class="help-box" style="margin-top:0px">'+txt+'</div>';}else{d.rows['Help'].innerHTML=''}}
d.set_query_description=function(txt){txt=d.input&&d.input.query_description||txt;if(txt){d.rows['Help'].innerHTML='<div class="help-box" style="margin-top:0px">'+txt+'</div>';}else{d.rows['Help'].innerHTML=''}}
d.onshow=function(){if(d.set_doctype!=d.sel_type){d.rows['Result'].innerHTML='';d.values_len=0;}
inp.value='';if(d.input&&d.input.txt.value){inp.value=d.input.txt.value;}
try{inp.focus();}catch(e){}