Merge branch 'shf_rename' of github.com:webnotes/erpnext into shf_rename
This commit is contained in:
commit
44279f87b4
@ -8,11 +8,11 @@
|
|||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# Please edit this list and import only required elements
|
# Please edit this list and import only required elements
|
||||||
import webnotes
|
import webnotes
|
||||||
@ -34,188 +34,160 @@ convert_to_lists = webnotes.conn.convert_to_lists
|
|||||||
|
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self,d,dl):
|
def __init__(self,d,dl):
|
||||||
self.doc, self.doclist = d,dl
|
self.doc, self.doclist = d,dl
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
self.doc.name = make_autoname(self.doc.new_item_code)
|
self.doc.name = make_autoname(self.doc.new_item_code)
|
||||||
|
|
||||||
|
|
||||||
# Get Ref Rates
|
# Get Ref Rates
|
||||||
# --------------
|
# --------------
|
||||||
def get_rates(self):
|
def get_rates(self):
|
||||||
for d in getlist(self.doclist, "sales_bom_items"):
|
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))
|
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
|
d.rate = r and flt(r[0][0]) or 0.00
|
||||||
|
|
||||||
|
|
||||||
# Get Item Details
|
# Get Item Details
|
||||||
# -----------------
|
# -----------------
|
||||||
def get_item_details(self, name):
|
def get_item_details(self, name):
|
||||||
det = sql("select description, stock_uom from `tabItem` where name = '%s' " % cstr(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))
|
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}
|
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):
|
def get_main_item(self):
|
||||||
is_main_item = []
|
is_main_item = []
|
||||||
for d in getlist(self.doclist,'sales_bom_items'):
|
for d in getlist(self.doclist,'sales_bom_items'):
|
||||||
if d.is_main_item == 'Yes':
|
if d.is_main_item == 'Yes':
|
||||||
is_main_item.append(d.item_code)
|
is_main_item.append(d.item_code)
|
||||||
# Check that Sales Bom Item cannot be child of Sales Bom.
|
# Check that Sales Bom Item cannot be child of Sales Bom.
|
||||||
if sql("select name from `tabSales BOM` where name = '%s' " % d.item_code):
|
if sql("select name from `tabSales BOM` where name = '%s' " % d.item_code):
|
||||||
msgprint("Sales Bom Item " + d.item_code +" cannot be child item.")
|
msgprint("Sales Bom Item " + d.item_code +" cannot be child item.")
|
||||||
raise Exception
|
raise Exception
|
||||||
# Check if is_main_item is modified once saved
|
# Check if is_main_item is modified once saved
|
||||||
if not self.doc.fields.get('__islocal') and d.is_main_item == "Yes" and cstr(d.item_code) != cstr(self.doc.name)[:-3] :
|
if not self.doc.fields.get('__islocal') and d.is_main_item == "Yes" and cstr(d.item_code) != cstr(self.doc.name)[:-3] :
|
||||||
msgprint("Modifying the main item is not allowed.")
|
msgprint("Modifying the main item is not allowed.")
|
||||||
raise Exception
|
raise Exception
|
||||||
if len(is_main_item) > 1:
|
if len(is_main_item) > 1:
|
||||||
msgprint('Main item cannot be more than one.')
|
msgprint('Main item cannot be more than one.')
|
||||||
raise Exception , " Validation Error."
|
raise Exception , " Validation Error."
|
||||||
if len(is_main_item) == 0:
|
if len(is_main_item) == 0:
|
||||||
msgprint("At least one item should be main item.")
|
msgprint("At least one item should be main item.")
|
||||||
raise Exception , " Validation Error."
|
raise Exception , " Validation Error."
|
||||||
return is_main_item[0]
|
return is_main_item[0]
|
||||||
|
|
||||||
|
|
||||||
# Make Item
|
# Make Item
|
||||||
# ---------
|
# ---------
|
||||||
def create_new_item(self):
|
def create_new_item(self):
|
||||||
i = Document("Item")
|
i = Document("Item")
|
||||||
|
|
||||||
i.item_code = self.doc.new_item_code
|
i.item_code = self.doc.new_item_code
|
||||||
i.item_name = self.doc.new_item_name
|
i.item_name = self.doc.new_item_name
|
||||||
i.name = i.item_code
|
i.name = i.item_code
|
||||||
i.is_sales_item = 'Yes'
|
i.is_sales_item = 'Yes'
|
||||||
i.is_stock_item = 'No'
|
i.is_stock_item = 'No'
|
||||||
i.save(1)
|
i.save(1)
|
||||||
|
|
||||||
# This function is deprecated as we will see only pricelist which is selected
|
# Update Rate
|
||||||
# def get_price_lists(self):
|
def update_ref_rate(self, i):
|
||||||
# return [i[0] for i in sql("select name from `tabPrice List` where docstatus != 2")]
|
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)
|
||||||
|
|
||||||
# Update Rate
|
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))
|
||||||
|
|
||||||
def update_ref_rate(self, i):
|
pld = addchild(i,"ref_rate_details", "Item Price")
|
||||||
ref_rate,count, p, currency = 0,0, self.doc.price_list, self.doc.currency
|
pld.price_list_name = self.doc.price_List
|
||||||
if not cstr(self.doc.price_list):
|
pld.ref_rate = flt(ref_rate)
|
||||||
msgprint("Please enter Price List.")
|
pld.ref_currency = self.doc.currency
|
||||||
raise Exception
|
pld.save()
|
||||||
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", (p, d.item_code))
|
|
||||||
if not item_rate:
|
|
||||||
msgprint("Item %s does not have a rate for Price List %s. Did not update rates for this Price List" % (d.item_code, p))
|
|
||||||
raise Exception
|
|
||||||
# if count == 0 : currency = cstr(item_rate[0][1])
|
|
||||||
if not cstr(currency) == cstr(item_rate[0][1]):
|
|
||||||
msgprint("Item %s currency %s does not match with other items currency i.e. %s " %(d.item_code,item_rate[0][1],currency))
|
|
||||||
raise Exception
|
|
||||||
count += 1
|
|
||||||
ref_rate += (flt(d.qty) * flt(item_rate[0][0]))
|
|
||||||
|
|
||||||
pld = addchild(i,"ref_rate_details", "Item Price")
|
# Update Items
|
||||||
pld.price_list_name = p
|
# ------------
|
||||||
pld.ref_rate = flt(ref_rate)
|
def update_item(self):
|
||||||
pld.ref_currency = currency
|
i = Document("Item", self.doc.new_item_code)
|
||||||
pld.save()
|
|
||||||
|
# update fields
|
||||||
|
i.brand = self.doc.new_item_brand
|
||||||
|
i.stock_uom = self.doc.stock_uom
|
||||||
|
i.item_group = self.doc.item_group
|
||||||
|
|
||||||
|
# update rates
|
||||||
|
new_rates = {}
|
||||||
|
self.update_ref_rate(i)
|
||||||
|
|
||||||
|
i.item_name = self.doc.new_item_name
|
||||||
|
i.description = self.doc.description
|
||||||
|
|
||||||
|
# set default as 'No' or 0 in Item Master as per TIC/3456
|
||||||
|
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)
|
||||||
|
i.save()
|
||||||
|
msgprint("Items updated successfully.")
|
||||||
|
|
||||||
|
|
||||||
# Update Items
|
def validate(self):
|
||||||
# ------------
|
# check for duplicate
|
||||||
def update_item(self):
|
self.check_duplicate()
|
||||||
i = Document("Item", self.doc.new_item_code)
|
item_code = self.get_main_item()
|
||||||
|
if not self.doc.new_item_code:
|
||||||
# update fields
|
self.doc.new_item_code = make_autoname(item_code +'.###')
|
||||||
i.brand = self.doc.new_item_brand
|
|
||||||
i.stock_uom = self.doc.stock_uom
|
|
||||||
i.item_group = self.doc.item_group
|
|
||||||
|
|
||||||
# clear old rates
|
|
||||||
sql("delete from `tabItem Price` where parent=%s", i.name)
|
|
||||||
|
|
||||||
# update rates
|
|
||||||
new_rates = {}
|
|
||||||
# pl_list = self.get_price_lists()
|
|
||||||
#for p in self.get_price_lists():
|
|
||||||
self.update_ref_rate(i)
|
|
||||||
|
|
||||||
# update description and item name
|
|
||||||
n1, n2 = [], []
|
|
||||||
for d in getlist(self.doclist, "sales_bom_items"):
|
|
||||||
n, desc = sql("select item_name, description from tabItem where name=%s", d.item_code)[0]
|
|
||||||
n1.append(n)
|
|
||||||
n2.append(desc)
|
|
||||||
|
|
||||||
self.doc.new_item_name = (' ').join(n1)
|
|
||||||
self.doc.description = ("\n" + "\n").join(n2)
|
|
||||||
|
|
||||||
i.item_name = self.doc.new_item_name
|
|
||||||
i.description = self.doc.description
|
|
||||||
|
|
||||||
# set default as 'No' or 0 in Item Master as per TIC/3456
|
|
||||||
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)
|
|
||||||
i.save()
|
|
||||||
msgprint("Items updated successfully.")
|
|
||||||
|
|
||||||
|
|
||||||
def validate(self):
|
def on_update(self):
|
||||||
# check for duplicate
|
# if no item code, create new item code
|
||||||
self.check_duplicate()
|
if not sql("select name from tabItem where name=%s", self.doc.new_item_code):
|
||||||
item_code = self.get_main_item()
|
self.create_new_item()
|
||||||
if not self.doc.new_item_code:
|
self.update_item()
|
||||||
self.doc.new_item_code = make_autoname(item_code +'.###')
|
|
||||||
|
|
||||||
|
|
||||||
def on_update(self):
|
def check_duplicate(self, finder=0):
|
||||||
# if no item code, create new item code
|
il = getlist(self.doclist, "sales_bom_items")
|
||||||
if not sql("select name from tabItem where name=%s", self.doc.new_item_code):
|
if not il:
|
||||||
self.create_new_item()
|
msgprint("Add atleast one item")
|
||||||
self.update_item()
|
return
|
||||||
|
|
||||||
|
# get all Sales BOM that have the first item
|
||||||
|
sbl = sql("select distinct parent from `tabSales BOM Item` where item_code=%s", il[0].item_code)
|
||||||
|
|
||||||
|
# check all siblings
|
||||||
|
sub_items = [[d.item_code, flt(d.qty)] for d in il]
|
||||||
|
|
||||||
|
for s in sbl:
|
||||||
|
if not cstr(s[0]) == cstr(self.doc.name) :
|
||||||
|
t = sql("select item_code, qty from `tabSales BOM Item` where parent=%s", 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])
|
||||||
|
raise Exception
|
||||||
|
if finder:
|
||||||
|
msgprint("There is no Sales BOM present with the following Combination.")
|
||||||
|
|
||||||
|
|
||||||
def check_duplicate(self, finder=0):
|
def has_same_items(self, l1, l2):
|
||||||
il = getlist(self.doclist, "sales_bom_items")
|
if len(l1)!=len(l2): return 0
|
||||||
if not il:
|
for l in l2:
|
||||||
msgprint("Add atleast one item")
|
if l not in l1:
|
||||||
return
|
return 0
|
||||||
|
for l in l1:
|
||||||
# get all Sales BOM that have the first item
|
if l not in l2:
|
||||||
sbl = sql("select distinct parent from `tabSales BOM Item` where item_code=%s", il[0].item_code)
|
return 0
|
||||||
|
return 1
|
||||||
# check all siblings
|
|
||||||
sub_items = [[d.item_code, flt(d.qty)] for d in il]
|
|
||||||
|
|
||||||
for s in sbl:
|
|
||||||
if not cstr(s[0]) == cstr(self.doc.name) :
|
|
||||||
t = sql("select item_code, qty from `tabSales BOM Item` where parent=%s", 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])
|
|
||||||
raise Exception
|
|
||||||
if finder:
|
|
||||||
msgprint("There is no Sales BOM present with the following Combination.")
|
|
||||||
|
|
||||||
|
|
||||||
def has_same_items(self, l1, l2):
|
|
||||||
if len(l1)!=len(l2): return 0
|
|
||||||
for l in l2:
|
|
||||||
if l not in l1:
|
|
||||||
return 0
|
|
||||||
for l in l1:
|
|
||||||
if l not in l2:
|
|
||||||
return 0
|
|
||||||
return 1
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
# These values are common in all dictionaries
|
# These values are common in all dictionaries
|
||||||
{
|
{
|
||||||
'creation': '2012-03-27 14:36:36',
|
'creation': '2012-04-23 16:00:21',
|
||||||
'docstatus': 0,
|
'docstatus': 0,
|
||||||
'modified': '2012-03-27 14:45:51',
|
'modified': '2012-04-24 15:07:42',
|
||||||
'modified_by': u'Administrator',
|
'modified_by': u'Administrator',
|
||||||
'owner': u'Administrator'
|
'owner': u'Administrator'
|
||||||
},
|
},
|
||||||
@ -24,7 +24,7 @@
|
|||||||
'section_style': u'Simple',
|
'section_style': u'Simple',
|
||||||
'server_code_error': u' ',
|
'server_code_error': u' ',
|
||||||
'show_in_menu': 0,
|
'show_in_menu': 0,
|
||||||
'version': 40
|
'version': 1
|
||||||
},
|
},
|
||||||
|
|
||||||
# These values are common for all DocField
|
# These values are common for all DocField
|
||||||
@ -52,30 +52,6 @@
|
|||||||
'name': u'Sales BOM'
|
'name': u'Sales BOM'
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocPerm
|
|
||||||
{
|
|
||||||
'amend': 0,
|
|
||||||
'cancel': 1,
|
|
||||||
'create': 1,
|
|
||||||
'doctype': u'DocPerm',
|
|
||||||
'permlevel': 0,
|
|
||||||
'role': u'Sales User',
|
|
||||||
'submit': 0,
|
|
||||||
'write': 1
|
|
||||||
},
|
|
||||||
|
|
||||||
# DocPerm
|
|
||||||
{
|
|
||||||
'amend': 0,
|
|
||||||
'cancel': 0,
|
|
||||||
'create': 0,
|
|
||||||
'doctype': u'DocPerm',
|
|
||||||
'permlevel': 1,
|
|
||||||
'role': u'Sales User',
|
|
||||||
'submit': 0,
|
|
||||||
'write': 0
|
|
||||||
},
|
|
||||||
|
|
||||||
# DocPerm
|
# DocPerm
|
||||||
{
|
{
|
||||||
'amend': 0,
|
'amend': 0,
|
||||||
@ -124,15 +100,28 @@
|
|||||||
'write': 0
|
'write': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
# DocPerm
|
||||||
{
|
{
|
||||||
'doctype': u'DocField',
|
'amend': 0,
|
||||||
'fieldname': u'trash_reason',
|
'cancel': 1,
|
||||||
'fieldtype': u'Small Text',
|
'create': 1,
|
||||||
'label': u'Trash Reason',
|
'doctype': u'DocPerm',
|
||||||
'oldfieldname': u'trash_reason',
|
'permlevel': 0,
|
||||||
'oldfieldtype': u'Small Text',
|
'role': u'Sales User',
|
||||||
'permlevel': 1
|
'submit': 0,
|
||||||
|
'write': 1
|
||||||
|
},
|
||||||
|
|
||||||
|
# DocPerm
|
||||||
|
{
|
||||||
|
'amend': 0,
|
||||||
|
'cancel': 0,
|
||||||
|
'create': 0,
|
||||||
|
'doctype': u'DocPerm',
|
||||||
|
'permlevel': 1,
|
||||||
|
'role': u'Sales User',
|
||||||
|
'submit': 0,
|
||||||
|
'write': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
@ -145,7 +134,7 @@
|
|||||||
'oldfieldname': u'new_item_code',
|
'oldfieldname': u'new_item_code',
|
||||||
'oldfieldtype': u'Data',
|
'oldfieldtype': u'Data',
|
||||||
'permlevel': 1,
|
'permlevel': 1,
|
||||||
'reqd': 0
|
'reqd': 1
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
@ -156,7 +145,8 @@
|
|||||||
'label': u'New Item Name',
|
'label': u'New Item Name',
|
||||||
'oldfieldname': u'new_item_name',
|
'oldfieldname': u'new_item_name',
|
||||||
'oldfieldtype': u'Data',
|
'oldfieldtype': u'Data',
|
||||||
'permlevel': 0
|
'permlevel': 0,
|
||||||
|
'reqd': 1
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
@ -167,7 +157,7 @@
|
|||||||
'label': u'New Item Brand',
|
'label': u'New Item Brand',
|
||||||
'oldfieldname': u'new_item_brand',
|
'oldfieldname': u'new_item_brand',
|
||||||
'oldfieldtype': u'Data',
|
'oldfieldtype': u'Data',
|
||||||
'permlevel': 1
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
@ -178,7 +168,8 @@
|
|||||||
'label': u'New Description',
|
'label': u'New Description',
|
||||||
'oldfieldname': u'description',
|
'oldfieldname': u'description',
|
||||||
'oldfieldtype': u'Text',
|
'oldfieldtype': u'Text',
|
||||||
'permlevel': 1,
|
'permlevel': 0,
|
||||||
|
'reqd': 1,
|
||||||
'width': u'300px'
|
'width': u'300px'
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -191,7 +182,8 @@
|
|||||||
'oldfieldname': u'item_group',
|
'oldfieldname': u'item_group',
|
||||||
'oldfieldtype': u'Link',
|
'oldfieldtype': u'Link',
|
||||||
'options': u'Item Group',
|
'options': u'Item Group',
|
||||||
'permlevel': 0
|
'permlevel': 0,
|
||||||
|
'reqd': 1
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
@ -267,7 +259,7 @@
|
|||||||
'fieldtype': u'Date',
|
'fieldtype': u'Date',
|
||||||
'label': u'Amendment Date',
|
'label': u'Amendment Date',
|
||||||
'no_copy': 1,
|
'no_copy': 1,
|
||||||
'permlevel': 0,
|
'permlevel': 1,
|
||||||
'print_hide': 1
|
'print_hide': 1
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -281,5 +273,16 @@
|
|||||||
'options': u'Sales Invoice',
|
'options': u'Sales Invoice',
|
||||||
'permlevel': 1,
|
'permlevel': 1,
|
||||||
'print_hide': 1
|
'print_hide': 1
|
||||||
|
},
|
||||||
|
|
||||||
|
# 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
|
||||||
}
|
}
|
||||||
]
|
]
|
Loading…
x
Reference in New Issue
Block a user