mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 11:49:10 +00:00
Merge branch 'master' of https://github.com/webnotes/erpnext
This commit is contained in:
@@ -466,9 +466,8 @@ class DocType(BuyingController):
|
|||||||
# expense will be booked in sales invoice
|
# expense will be booked in sales invoice
|
||||||
stock_item_and_auto_inventory_accounting = True
|
stock_item_and_auto_inventory_accounting = True
|
||||||
|
|
||||||
valuation_amt = (flt(item.amount, self.precision.item.amount) +
|
valuation_amt = (flt(item.amount) + flt(item.item_tax_amount) +
|
||||||
flt(item.item_tax_amount, self.precision.item.item_tax_amount) +
|
flt(item.rm_supp_cost))
|
||||||
flt(item.rm_supp_cost, self.precision.item.rm_supp_cost))
|
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ erpnext.AccountsChart = Class.extend({
|
|||||||
if (wn.model.can_read(this.ctype) !== -1) {
|
if (wn.model.can_read(this.ctype) !== -1) {
|
||||||
node_links.push('<a onclick="erpnext.account_chart.open();">Edit</a>');
|
node_links.push('<a onclick="erpnext.account_chart.open();">Edit</a>');
|
||||||
}
|
}
|
||||||
if (data.expandable) {
|
if (data.expandable && wn.boot.profile.in_create.indexOf(this.ctype) !== -1) {
|
||||||
node_links.push('<a onclick="erpnext.account_chart.new_node();">Add Child</a>');
|
node_links.push('<a onclick="erpnext.account_chart.new_node();">Add Child</a>');
|
||||||
} else if (this.ctype === 'Account' && wn.boot.profile.can_read.indexOf("GL Entry") !== -1) {
|
} else if (this.ctype === 'Account' && wn.boot.profile.can_read.indexOf("GL Entry") !== -1) {
|
||||||
node_links.push('<a onclick="erpnext.account_chart.show_ledger();">View Ledger</a>');
|
node_links.push('<a onclick="erpnext.account_chart.show_ledger();">View Ledger</a>');
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ def add_ac(args=None):
|
|||||||
ac.doc.doctype = "Account"
|
ac.doc.doctype = "Account"
|
||||||
ac.doc.old_parent = ""
|
ac.doc.old_parent = ""
|
||||||
ac.doc.freeze_account = "No"
|
ac.doc.freeze_account = "No"
|
||||||
ac.ignore_permissions = 1
|
|
||||||
ac.insert()
|
ac.insert()
|
||||||
return ac.doc.name
|
return ac.doc.name
|
||||||
|
|
||||||
@@ -138,7 +137,6 @@ def add_cc(args=None):
|
|||||||
cc = webnotes.bean(args)
|
cc = webnotes.bean(args)
|
||||||
cc.doc.doctype = "Cost Center"
|
cc.doc.doctype = "Cost Center"
|
||||||
cc.doc.old_parent = ""
|
cc.doc.old_parent = ""
|
||||||
cc.ignore_permissions = 1
|
|
||||||
cc.insert()
|
cc.insert()
|
||||||
return cc.doc.name
|
return cc.doc.name
|
||||||
|
|
||||||
|
|||||||
@@ -185,21 +185,22 @@ class DocType(BuyingController):
|
|||||||
if d.fields.has_key(x):
|
if d.fields.has_key(x):
|
||||||
d.fields[x] = f_lst[x]
|
d.fields[x] = f_lst[x]
|
||||||
|
|
||||||
item = sql("select is_stock_item, is_purchase_item, is_sub_contracted_item from tabItem where name=%s and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())", d.item_code)
|
item = sql("select is_stock_item, is_purchase_item, is_sub_contracted_item, end_of_life from tabItem where name=%s",
|
||||||
|
d.item_code)
|
||||||
if not item:
|
if not item:
|
||||||
msgprint("Item %s does not exist in Item Master." % cstr(d.item_code))
|
msgprint("Item %s does not exist in Item Master." % cstr(d.item_code), raise_exception=True)
|
||||||
raise Exception
|
|
||||||
|
from stock.utils import validate_end_of_life
|
||||||
|
validate_end_of_life(d.item_code, item[0][3])
|
||||||
|
|
||||||
# validate stock item
|
# validate stock item
|
||||||
if item[0][0]=='Yes' and d.qty and not d.warehouse:
|
if item[0][0]=='Yes' and d.qty and not d.warehouse:
|
||||||
msgprint("Warehouse is mandatory for %s, since it is a stock item" %
|
msgprint("Warehouse is mandatory for %s, since it is a stock item" %
|
||||||
d.item_code, raise_exception=1)
|
d.item_code, raise_exception=1)
|
||||||
|
|
||||||
# validate purchase item
|
# validate purchase item
|
||||||
if item[0][1] != 'Yes' and item[0][2] != 'Yes':
|
if item[0][1] != 'Yes' and item[0][2] != 'Yes':
|
||||||
msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code))
|
msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code), raise_exception=True)
|
||||||
raise Exception
|
|
||||||
|
|
||||||
|
|
||||||
if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname:
|
if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname:
|
||||||
# check warehouse, uom in previous doc and in current doc are same.
|
# check warehouse, uom in previous doc and in current doc are same.
|
||||||
@@ -215,13 +216,13 @@ class DocType(BuyingController):
|
|||||||
|
|
||||||
# Check if Warehouse has been modified.
|
# Check if Warehouse has been modified.
|
||||||
if not cstr(data[0]['warehouse']) == cstr(d.warehouse):
|
if not cstr(data[0]['warehouse']) == cstr(d.warehouse):
|
||||||
msgprint("Please check warehouse %s of Item %s which is not present in %s %s ." % (d.warehouse, d.item_code, d.prevdoc_doctype, d.prevdoc_docname))
|
msgprint("Please check warehouse %s of Item %s which is not present in %s %s ." % \
|
||||||
raise Exception
|
(d.warehouse, d.item_code, d.prevdoc_doctype, d.prevdoc_docname), raise_exception=True)
|
||||||
|
|
||||||
# Check if UOM has been modified.
|
# Check if UOM has been modified.
|
||||||
if not cstr(data[0]['uom']) == cstr(d.uom) and not cstr(d.prevdoc_doctype) == 'Material Request':
|
if not cstr(data[0]['uom']) == cstr(d.uom) and not cstr(d.prevdoc_doctype) == 'Material Request':
|
||||||
msgprint("Please check UOM %s of Item %s which is not present in %s %s ." % (d.uom, d.item_code, d.prevdoc_doctype, d.prevdoc_docname))
|
msgprint("Please check UOM %s of Item %s which is not present in %s %s ." % \
|
||||||
raise Exception
|
(d.uom, d.item_code, d.prevdoc_doctype, d.prevdoc_docname), raise_exception=True)
|
||||||
|
|
||||||
# list criteria that should not repeat if item is stock item
|
# list criteria that should not repeat if item is stock item
|
||||||
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or '']
|
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or '']
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ from webnotes.model.doc import make_autoname
|
|||||||
|
|
||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
|
|
||||||
from accounts.utils import add_ac
|
|
||||||
from utilities.transaction_base import TransactionBase
|
from utilities.transaction_base import TransactionBase
|
||||||
|
|
||||||
class DocType(TransactionBase):
|
class DocType(TransactionBase):
|
||||||
@@ -71,14 +70,16 @@ class DocType(TransactionBase):
|
|||||||
return g
|
return g
|
||||||
|
|
||||||
def add_account(self, ac, par, abbr):
|
def add_account(self, ac, par, abbr):
|
||||||
ac = add_ac({
|
ac_bean = webnotes.bean({
|
||||||
|
"doctype": "Account",
|
||||||
'account_name':ac,
|
'account_name':ac,
|
||||||
'parent_account':par,
|
'parent_account':par,
|
||||||
'group_or_ledger':'Group',
|
'group_or_ledger':'Group',
|
||||||
'company':self.doc.company,
|
'company':self.doc.company,
|
||||||
'account_type':'',
|
"freeze_account": "No",
|
||||||
'tax_rate':'0'
|
|
||||||
})
|
})
|
||||||
|
ac_bean.ignore_permissions = True
|
||||||
|
ac_bean.insert()
|
||||||
|
|
||||||
msgprint(_("Created Group ") + ac)
|
msgprint(_("Created Group ") + ac)
|
||||||
|
|
||||||
@@ -109,8 +110,8 @@ class DocType(TransactionBase):
|
|||||||
parent_account = self.get_parent_account(abbr)
|
parent_account = self.get_parent_account(abbr)
|
||||||
|
|
||||||
if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
|
if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
|
||||||
|
ac_bean = webnotes.bean({
|
||||||
ac = add_ac({
|
"doctype": "Account",
|
||||||
'account_name': self.doc.name,
|
'account_name': self.doc.name,
|
||||||
'parent_account': parent_account,
|
'parent_account': parent_account,
|
||||||
'group_or_ledger':'Ledger',
|
'group_or_ledger':'Ledger',
|
||||||
@@ -119,8 +120,12 @@ class DocType(TransactionBase):
|
|||||||
'tax_rate': '0',
|
'tax_rate': '0',
|
||||||
'master_type': 'Supplier',
|
'master_type': 'Supplier',
|
||||||
'master_name': self.doc.name,
|
'master_name': self.doc.name,
|
||||||
|
"freeze_account": "No"
|
||||||
})
|
})
|
||||||
msgprint(_("Created Account Head: ") + ac)
|
ac_bean.ignore_permissions = True
|
||||||
|
ac_bean.insert()
|
||||||
|
|
||||||
|
msgprint(_("Created Account Head: ") + ac_bean.doc.name)
|
||||||
else:
|
else:
|
||||||
self.check_parent_account(parent_account, abbr)
|
self.check_parent_account(parent_account, abbr)
|
||||||
else :
|
else :
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
|
from utilities.transaction_base import delete_events
|
||||||
|
|
||||||
# delete orphaned Event User
|
# delete orphaned Event User
|
||||||
webnotes.conn.sql("""delete from `tabEvent User`
|
webnotes.conn.sql("""delete from `tabEvent User`
|
||||||
where not exists(select name from `tabEvent` where `tabEvent`.name = `tabEvent User`.parent)""")
|
where not exists(select name from `tabEvent` where `tabEvent`.name = `tabEvent User`.parent)""")
|
||||||
@@ -15,5 +17,4 @@ def execute():
|
|||||||
webnotes.get_obj(dt, ref_name).add_calendar_event()
|
webnotes.get_obj(dt, ref_name).add_calendar_event()
|
||||||
else:
|
else:
|
||||||
# remove events where ref doc doesn't exist
|
# remove events where ref doc doesn't exist
|
||||||
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
delete_events(dt, ref_name)
|
||||||
where ref_type=%s and ref_name=%s""", (dt, ref_name)))
|
|
||||||
@@ -19,6 +19,7 @@ import webnotes
|
|||||||
|
|
||||||
from webnotes.utils import flt, getdate
|
from webnotes.utils import flt, getdate
|
||||||
from webnotes import msgprint
|
from webnotes import msgprint
|
||||||
|
from utilities.transaction_base import delete_events
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, doc, doclist=None):
|
def __init__(self, doc, doclist=None):
|
||||||
@@ -69,7 +70,7 @@ class DocType:
|
|||||||
|
|
||||||
def add_calendar_event(self):
|
def add_calendar_event(self):
|
||||||
# delete any earlier event for this project
|
# delete any earlier event for this project
|
||||||
self.delete_events()
|
delete_events(self.doc.doctype, self.doc.name)
|
||||||
|
|
||||||
# add events
|
# add events
|
||||||
for milestone in self.doclist.get({"parentfield": "project_milestones"}):
|
for milestone in self.doclist.get({"parentfield": "project_milestones"}):
|
||||||
@@ -87,8 +88,4 @@ class DocType:
|
|||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self.delete_events()
|
delete_events(self.doc.doctype, self.doc.name)
|
||||||
|
|
||||||
def delete_events(self):
|
|
||||||
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
|
||||||
where ref_type=%s and ref_name=%s""", (self.doc.doctype, self.doc.name)))
|
|
||||||
@@ -115,18 +115,20 @@ class DocType(TransactionBase):
|
|||||||
if not webnotes.conn.exists("Account", (self.doc.name + " - " + abbr)):
|
if not webnotes.conn.exists("Account", (self.doc.name + " - " + abbr)):
|
||||||
parent_account = self.get_receivables_group()
|
parent_account = self.get_receivables_group()
|
||||||
# create
|
# create
|
||||||
from accounts.utils import add_ac
|
ac_bean = webnotes.bean({
|
||||||
ac = add_ac({
|
"doctype": "Account",
|
||||||
'account_name':self.doc.name,
|
'account_name': self.doc.name,
|
||||||
'parent_account': parent_account,
|
'parent_account': parent_account,
|
||||||
'group_or_ledger':'Ledger',
|
'group_or_ledger':'Ledger',
|
||||||
'company':self.doc.company,
|
'company':self.doc.company,
|
||||||
'account_type':'',
|
|
||||||
'tax_rate':'0',
|
|
||||||
'master_type':'Customer',
|
'master_type':'Customer',
|
||||||
'master_name':self.doc.name
|
'master_name':self.doc.name,
|
||||||
|
"freeze_account": "No"
|
||||||
})
|
})
|
||||||
msgprint("Account Head: %s created" % ac)
|
ac_bean.ignore_permissions = True
|
||||||
|
ac_bean.insert()
|
||||||
|
|
||||||
|
msgprint("Account Head: %s created" % ac_bean.doc.name)
|
||||||
else :
|
else :
|
||||||
msgprint("Please Select Company under which you want to create account head")
|
msgprint("Please Select Company under which you want to create account head")
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-01-23 19:57:18",
|
"creation": "2013-06-11 14:26:44",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-01-29 16:28:03",
|
"modified": "2013-06-11 14:27:57",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@@ -270,7 +270,7 @@
|
|||||||
"label": "Credit Days",
|
"label": "Credit Days",
|
||||||
"oldfieldname": "credit_days",
|
"oldfieldname": "credit_days",
|
||||||
"oldfieldtype": "Int",
|
"oldfieldtype": "Int",
|
||||||
"permlevel": 2
|
"permlevel": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@@ -280,7 +280,7 @@
|
|||||||
"oldfieldname": "credit_limit",
|
"oldfieldname": "credit_limit",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
"permlevel": 2
|
"permlevel": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@@ -339,7 +339,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"permlevel": 2,
|
"permlevel": 1,
|
||||||
"role": "Sales User"
|
"role": "Sales User"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -355,7 +355,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"permlevel": 2,
|
"permlevel": 1,
|
||||||
"role": "Sales Master Manager",
|
"role": "Sales Master Manager",
|
||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,7 +222,6 @@ class DocType:
|
|||||||
# Create default cost center
|
# Create default cost center
|
||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
def create_default_cost_center(self):
|
def create_default_cost_center(self):
|
||||||
from accounts.utils import add_cc
|
|
||||||
cc_list = [
|
cc_list = [
|
||||||
{
|
{
|
||||||
'cost_center_name':'Root',
|
'cost_center_name':'Root',
|
||||||
@@ -244,7 +243,10 @@ class DocType:
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
for cc in cc_list:
|
for cc in cc_list:
|
||||||
add_cc(cc)
|
cc.update({"doctype": "Cost Center"})
|
||||||
|
cc_bean = webnotes.bean(cc)
|
||||||
|
cc_bean.ignore_permissions = True
|
||||||
|
cc_bean.insert()
|
||||||
|
|
||||||
webnotes.conn.set_value("Company", self.doc.name, "cost_center",
|
webnotes.conn.set_value("Company", self.doc.name, "cost_center",
|
||||||
"Default CC Ledger - " + self.doc.abbr)
|
"Default CC Ledger - " + self.doc.abbr)
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ def execute_daily():
|
|||||||
|
|
||||||
# daily backup
|
# daily backup
|
||||||
from setup.doctype.backup_manager.backup_manager import take_backups_daily
|
from setup.doctype.backup_manager.backup_manager import take_backups_daily
|
||||||
take_backups_daily()
|
run_fn(take_backups_daily)
|
||||||
|
|
||||||
# check reorder level
|
# check reorder level
|
||||||
from stock.utils import reorder_item
|
from stock.utils import reorder_item
|
||||||
@@ -61,7 +61,7 @@ def execute_daily():
|
|||||||
|
|
||||||
def execute_weekly():
|
def execute_weekly():
|
||||||
from setup.doctype.backup_manager.backup_manager import take_backups_weekly
|
from setup.doctype.backup_manager.backup_manager import take_backups_weekly
|
||||||
take_backups_weekly()
|
run_fn(take_backups_weekly)
|
||||||
|
|
||||||
def execute_monthly():
|
def execute_monthly():
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
st2.insert()
|
st2.insert()
|
||||||
st2.submit()
|
st2.submit()
|
||||||
|
|
||||||
|
from stock.utils import reorder_item
|
||||||
|
reorder_item()
|
||||||
|
|
||||||
mr_name = webnotes.conn.sql("""select parent from `tabMaterial Request Item`
|
mr_name = webnotes.conn.sql("""select parent from `tabMaterial Request Item`
|
||||||
where item_code='_Test Item'""")
|
where item_code='_Test Item'""")
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,14 @@ from webnotes import msgprint, _
|
|||||||
import json
|
import json
|
||||||
from webnotes.utils import flt, cstr, nowdate, add_days, cint
|
from webnotes.utils import flt, cstr, nowdate, add_days, cint
|
||||||
from webnotes.defaults import get_global_default
|
from webnotes.defaults import get_global_default
|
||||||
|
from webnotes.utils.email_lib import sendmail
|
||||||
|
|
||||||
def validate_end_of_life(item_code, end_of_life=None, verbose=1):
|
def validate_end_of_life(item_code, end_of_life=None, verbose=1):
|
||||||
if not end_of_life:
|
if not end_of_life:
|
||||||
end_of_life = webnotes.conn.get_value("Item", item_code, "end_of_life")
|
end_of_life = webnotes.conn.get_value("Item", item_code, "end_of_life")
|
||||||
|
|
||||||
from webnotes.utils import getdate, now_datetime, formatdate
|
from webnotes.utils import getdate, now_datetime, formatdate
|
||||||
if end_of_life and getdate(end_of_life) > now_datetime().date():
|
if end_of_life and getdate(end_of_life) <= now_datetime().date():
|
||||||
msg = (_("Item") + " %(item_code)s: " + _("reached its end of life on") + \
|
msg = (_("Item") + " %(item_code)s: " + _("reached its end of life on") + \
|
||||||
" %(date)s. " + _("Please check") + ": %(end_of_life_label)s " + \
|
" %(date)s. " + _("Please check") + ": %(end_of_life_label)s " + \
|
||||||
"in Item master") % {
|
"in Item master") % {
|
||||||
@@ -205,7 +206,11 @@ def reorder_item():
|
|||||||
if webnotes.auto_indent:
|
if webnotes.auto_indent:
|
||||||
material_requests = {}
|
material_requests = {}
|
||||||
bin_list = webnotes.conn.sql("""select item_code, warehouse, projected_qty
|
bin_list = webnotes.conn.sql("""select item_code, warehouse, projected_qty
|
||||||
from tabBin where ifnull(item_code, '') != '' and ifnull(warehouse, '') != ''""",
|
from tabBin where ifnull(item_code, '') != '' and ifnull(warehouse, '') != ''
|
||||||
|
and exists (select name from `tabItem`
|
||||||
|
where `tabItem`.name = `tabBin`.item_code and
|
||||||
|
is_stock_item='Yes' and (is_purchase_item='Yes' or is_sub_contracted_item='Yes') and
|
||||||
|
(ifnull(end_of_life, '')='') or end_of_life > now())""",
|
||||||
as_dict=True)
|
as_dict=True)
|
||||||
for bin in bin_list:
|
for bin in bin_list:
|
||||||
#check if re-order is required
|
#check if re-order is required
|
||||||
@@ -220,7 +225,7 @@ def reorder_item():
|
|||||||
["re_order_level", "re_order_qty"])
|
["re_order_level", "re_order_qty"])
|
||||||
material_request_type = "Purchase"
|
material_request_type = "Purchase"
|
||||||
|
|
||||||
if reorder_level and flt(bin.projected_qty) < flt(reorder_level):
|
if flt(reorder_level) and flt(bin.projected_qty) < flt(reorder_level):
|
||||||
if flt(reorder_level) - flt(bin.projected_qty) > flt(reorder_qty):
|
if flt(reorder_level) - flt(bin.projected_qty) > flt(reorder_qty):
|
||||||
reorder_qty = flt(reorder_level) - flt(bin.projected_qty)
|
reorder_qty = flt(reorder_level) - flt(bin.projected_qty)
|
||||||
|
|
||||||
@@ -242,10 +247,14 @@ def create_material_request(material_requests):
|
|||||||
""" Create indent on reaching reorder level """
|
""" Create indent on reaching reorder level """
|
||||||
mr_list = []
|
mr_list = []
|
||||||
defaults = webnotes.defaults.get_defaults()
|
defaults = webnotes.defaults.get_defaults()
|
||||||
|
exceptions_list = []
|
||||||
for request_type in material_requests:
|
for request_type in material_requests:
|
||||||
for company in material_requests[request_type]:
|
for company in material_requests[request_type]:
|
||||||
items = material_requests[request_type][company]
|
try:
|
||||||
if items:
|
items = material_requests[request_type][company]
|
||||||
|
if not items:
|
||||||
|
continue
|
||||||
|
|
||||||
mr = [{
|
mr = [{
|
||||||
"doctype": "Material Request",
|
"doctype": "Material Request",
|
||||||
"company": company,
|
"company": company,
|
||||||
@@ -257,27 +266,34 @@ def create_material_request(material_requests):
|
|||||||
quantity reaches re-order level when the following record was created""")
|
quantity reaches re-order level when the following record was created""")
|
||||||
}]
|
}]
|
||||||
|
|
||||||
for d in items:
|
for d in items:
|
||||||
item = webnotes.doc("Item", d.item_code)
|
item = webnotes.doc("Item", d.item_code)
|
||||||
mr.append({
|
mr.append({
|
||||||
"doctype": "Material Request Item",
|
"doctype": "Material Request Item",
|
||||||
"parenttype": "Material Request",
|
"parenttype": "Material Request",
|
||||||
"parentfield": "indent_details",
|
"parentfield": "indent_details",
|
||||||
"item_code": d.item_code,
|
"item_code": d.item_code,
|
||||||
"schedule_date": add_days(nowdate(),cint(item.lead_time_days)),
|
"schedule_date": add_days(nowdate(),cint(item.lead_time_days)),
|
||||||
"uom": item.stock_uom,
|
"uom": item.stock_uom,
|
||||||
"warehouse": d.warehouse,
|
"warehouse": d.warehouse,
|
||||||
"item_name": item.item_name,
|
"item_name": item.item_name,
|
||||||
"description": item.description,
|
"description": item.description,
|
||||||
"item_group": item.item_group,
|
"item_group": item.item_group,
|
||||||
"qty": d.reorder_qty,
|
"qty": d.reorder_qty,
|
||||||
"brand": item.brand,
|
"brand": item.brand,
|
||||||
})
|
})
|
||||||
|
|
||||||
mr_bean = webnotes.bean(mr)
|
mr_bean = webnotes.bean(mr)
|
||||||
mr_bean.insert()
|
mr_bean.insert()
|
||||||
mr_bean.submit()
|
mr_bean.submit()
|
||||||
mr_list.append(mr_bean)
|
mr_list.append(mr_bean)
|
||||||
|
|
||||||
|
except:
|
||||||
|
if webnotes.message_log:
|
||||||
|
exceptions_list.append([] + webnotes.message_log)
|
||||||
|
webnotes.message_log = []
|
||||||
|
else:
|
||||||
|
exceptions_list.append(webnotes.getTraceback())
|
||||||
|
|
||||||
if mr_list:
|
if mr_list:
|
||||||
if not hasattr(webnotes, "reorder_email_notify"):
|
if not hasattr(webnotes, "reorder_email_notify"):
|
||||||
@@ -286,11 +302,13 @@ def create_material_request(material_requests):
|
|||||||
|
|
||||||
if(webnotes.reorder_email_notify):
|
if(webnotes.reorder_email_notify):
|
||||||
send_email_notification(mr_list)
|
send_email_notification(mr_list)
|
||||||
|
|
||||||
|
if exceptions_list:
|
||||||
|
notify_errors(exceptions_list)
|
||||||
|
|
||||||
def send_email_notification(mr_list):
|
def send_email_notification(mr_list):
|
||||||
""" Notify user about auto creation of indent"""
|
""" Notify user about auto creation of indent"""
|
||||||
|
|
||||||
from webnotes.utils.email_lib import sendmail
|
|
||||||
email_list = webnotes.conn.sql_list("""select distinct r.parent
|
email_list = webnotes.conn.sql_list("""select distinct r.parent
|
||||||
from tabUserRole r, tabProfile p
|
from tabUserRole r, tabProfile p
|
||||||
where p.name = r.parent and p.enabled = 1 and p.docstatus < 2
|
where p.name = r.parent and p.enabled = 1 and p.docstatus < 2
|
||||||
@@ -307,4 +325,22 @@ def send_email_notification(mr_list):
|
|||||||
cstr(item.qty) + "</td><td>" + cstr(item.uom) + "</td></tr>"
|
cstr(item.qty) + "</td><td>" + cstr(item.uom) + "</td></tr>"
|
||||||
msg += "</table>"
|
msg += "</table>"
|
||||||
|
|
||||||
sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg)
|
sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg)
|
||||||
|
|
||||||
|
def notify_errors(exceptions_list):
|
||||||
|
subject = "[Important] [ERPNext] Error(s) while creating Material Requests based on Re-order Levels"
|
||||||
|
msg = """Dear System Manager,
|
||||||
|
|
||||||
|
An error occured for certain Items while creating Material Requests based on Re-order level.
|
||||||
|
|
||||||
|
Please rectify these issues:
|
||||||
|
---
|
||||||
|
|
||||||
|
%s
|
||||||
|
|
||||||
|
---
|
||||||
|
Regards,
|
||||||
|
Administrator""" % ("\n\n".join(["\n".join(msg) for msg in exceptions_list]),)
|
||||||
|
|
||||||
|
from webnotes.profile import get_system_managers
|
||||||
|
sendmail(get_system_managers(), subject=subject, msg=msg)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from webnotes import msgprint
|
|||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
|
|
||||||
|
|
||||||
from utilities.transaction_base import TransactionBase
|
from utilities.transaction_base import TransactionBase, delete_events
|
||||||
|
|
||||||
class DocType(TransactionBase):
|
class DocType(TransactionBase):
|
||||||
def __init__(self, doc, doclist=[]):
|
def __init__(self, doc, doclist=[]):
|
||||||
@@ -327,13 +327,7 @@ class DocType(TransactionBase):
|
|||||||
if d.serial_no:
|
if d.serial_no:
|
||||||
self.update_amc_date(d.serial_no, '')
|
self.update_amc_date(d.serial_no, '')
|
||||||
webnotes.conn.set(self.doc, 'status', 'Cancelled')
|
webnotes.conn.set(self.doc, 'status', 'Cancelled')
|
||||||
self.delete_events()
|
delete_events(self.doc.doctype, self.doc.name)
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self.delete_events()
|
delete_events(self.doc.doctype, self.doc.name)
|
||||||
|
|
||||||
def delete_events(self):
|
|
||||||
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
|
||||||
where ref_type=%s and ref_name=%s""", (self.doc.doctype, self.doc.name)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -303,3 +303,8 @@ class TransactionBase(DocListController):
|
|||||||
})
|
})
|
||||||
|
|
||||||
webnotes.bean(event_doclist).insert()
|
webnotes.bean(event_doclist).insert()
|
||||||
|
|
||||||
|
|
||||||
|
def delete_events(ref_type, ref_name):
|
||||||
|
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
||||||
|
where ref_type=%s and ref_name=%s""", (ref_type, ref_name)), for_reload=True)
|
||||||
Reference in New Issue
Block a user