[merge] merge with master

This commit is contained in:
Rushabh Mehta
2013-05-24 16:09:13 +05:30
120 changed files with 1431 additions and 712 deletions

View File

@@ -77,10 +77,6 @@ class DocType:
self.doc.save()
if (flt(args.get("actual_qty")) < 0 or flt(args.get("reserved_qty")) > 0) \
and args.get("is_cancelled") == 'No' and args.get("is_amended")=='No':
self.reorder_item(args.get("voucher_type"), args.get("voucher_no"), args.get("company"))
def get_first_sle(self):
sle = sql("""
select * from `tabStock Ledger Entry`
@@ -90,82 +86,4 @@ class DocType:
order by timestamp(posting_date, posting_time) asc, name asc
limit 1
""", (self.doc.item_code, self.doc.warehouse), as_dict=1)
return sle and sle[0] or None
def reorder_item(self,doc_type,doc_name, company):
""" Reorder item if stock reaches reorder level"""
if not hasattr(webnotes, "auto_indent"):
webnotes.auto_indent = webnotes.conn.get_value('Global Defaults', None, 'auto_indent')
if webnotes.auto_indent:
#check if re-order is required
item_reorder = webnotes.conn.get("Item Reorder",
{"parent": self.doc.item_code, "warehouse": self.doc.warehouse})
if item_reorder:
reorder_level = item_reorder.warehouse_reorder_level
reorder_qty = item_reorder.warehouse_reorder_qty
material_request_type = item_reorder.material_request_type or "Purchase"
else:
reorder_level, reorder_qty = webnotes.conn.get_value("Item", self.doc.item_code,
["re_order_level", "re_order_qty"])
material_request_type = "Purchase"
if flt(reorder_qty) and flt(self.doc.projected_qty) < flt(reorder_level):
self.create_material_request(doc_type, doc_name, reorder_level, reorder_qty,
company, material_request_type)
def create_material_request(self, doc_type, doc_name, reorder_level, reorder_qty, company,
material_request_type="Purchase"):
""" Create indent on reaching reorder level """
defaults = webnotes.defaults.get_defaults()
item = webnotes.doc("Item", self.doc.item_code)
mr = webnotes.bean([{
"doctype": "Material Request",
"company": company or defaults.company,
"fiscal_year": defaults.fiscal_year,
"transaction_date": nowdate(),
"material_request_type": material_request_type,
"remark": _("This is an auto generated Material Request.") + \
_("It was raised because the (actual + ordered + indented - reserved) quantity reaches re-order level when the following record was created") + \
": " + _(doc_type) + " " + doc_name
}, {
"doctype": "Material Request Item",
"parenttype": "Material Request",
"parentfield": "indent_details",
"item_code": self.doc.item_code,
"schedule_date": add_days(nowdate(),cint(item.lead_time_days)),
"uom": self.doc.stock_uom,
"warehouse": self.doc.warehouse,
"item_name": item.item_name,
"description": item.description,
"item_group": item.item_group,
"qty": reorder_qty,
"brand": item.brand,
}])
mr.insert()
mr.submit()
msgprint("""Item: %s is to be re-ordered. Material Request %s raised.
It was generated from %s: %s""" %
(self.doc.item_code, mr.doc.name, doc_type, doc_name))
if(item.email_notify):
self.send_email_notification(doc_type, doc_name, mr)
def send_email_notification(self, doc_type, doc_name, bean):
""" Notify user about auto creation of indent"""
from webnotes.utils.email_lib import sendmail
email_list=[d[0] for d in sql("""select distinct r.parent from tabUserRole r, tabProfile p
where p.name = r.parent and p.enabled = 1 and p.docstatus < 2
and r.role in ('Purchase Manager','Material Manager')
and p.name not in ('Administrator', 'All', 'Guest')""")]
msg="""A new Material Request has been raised for Item: %s and Warehouse: %s \
on %s due to %s: %s. See %s: %s """ % (self.doc.item_code, self.doc.warehouse,
formatdate(), doc_type, doc_name, bean.doc.doctype,
get_url_to_form(bean.doc.doctype, bean.doc.name))
sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg)
return sle and sle[0] or None

View File

@@ -419,4 +419,4 @@ class DocType(SellingController):
if gl_entries:
from accounts.general_ledger import make_gl_entries
make_gl_entries(gl_entries)
make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-04-01 10:49:21",
"creation": "2013-04-22 13:15:44",
"docstatus": 0,
"modified": "2013-04-17 17:20:58",
"modified": "2013-05-22 12:05:32",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -340,6 +340,7 @@
"hidden": 1,
"in_filter": 1,
"label": "Document Type",
"no_copy": 1,
"oldfieldname": "prevdoc_doctype",
"oldfieldtype": "Data",
"print_hide": 1,
@@ -371,6 +372,7 @@
"hidden": 1,
"in_filter": 1,
"label": "Against Document Date",
"no_copy": 1,
"oldfieldname": "prevdoc_date",
"oldfieldtype": "Date",
"print_hide": 1,
@@ -383,6 +385,7 @@
"hidden": 1,
"in_filter": 1,
"label": "Against Document Detail No",
"no_copy": 1,
"oldfieldname": "prevdoc_detail_docname",
"oldfieldtype": "Data",
"print_hide": 1,

View File

@@ -51,6 +51,7 @@ class DocType(DocListController):
self.validate_barcode()
self.check_non_asset_warehouse()
self.cant_change()
self.validate_item_type_for_reorder()
if self.doc.name:
self.old_page_name = webnotes.conn.get_value('Item', self.doc.name, 'page_name')
@@ -201,6 +202,13 @@ class DocType(DocListController):
webnotes.msgprint(_("As there are existing stock transactions for this \
item, you can not change the values of 'Has Serial No', \
'Is Stock Item' and 'Valuation Method'"), raise_exception=1)
def validate_item_type_for_reorder(self):
if self.doc.re_order_level or len(self.doclist.get({"parentfield": "item_reorder",
"material_request_type": "Purchase"})):
if not self.doc.is_purchase_item:
webnotes.msgprint(_("""To set reorder level, item must be Purchase Item"""),
raise_exception=1)
def check_if_sle_exists(self):
sle = webnotes.conn.sql("""select name from `tabStock Ledger Entry`
@@ -272,7 +280,7 @@ class DocType(DocListController):
from webnotes.webutils import clear_cache
clear_cache(self.doc.page_name)
def on_rename(self,newdn,olddn):
def on_rename(self,newdn,olddn, merge=False):
webnotes.conn.sql("update tabItem set item_code = %s where name = %s", (newdn, olddn))
if self.doc.page_name:
from webnotes.webutils import clear_cache

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-05-03 10:45:46",
"docstatus": 0,
"modified": "2013-05-07 15:58:58",
"modified": "2013-05-22 15:48:27",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -363,21 +363,6 @@
"label": "Re-Order Qty",
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "column_break_31",
"fieldtype": "Column Break",
"read_only": 0
},
{
"depends_on": "eval:doc.is_stock_item==\"Yes\"",
"description": "Send an email to users of role \"Material Manager\" and \"Purchase Manager\" when re-order level is crossed.",
"doctype": "DocField",
"fieldname": "email_notify",
"fieldtype": "Check",
"label": "Notify by Email on Re-order",
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "section_break_31",

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-02-22 01:28:03",
"creation": "2013-03-07 11:42:59",
"docstatus": 0,
"modified": "2013-03-07 07:03:28",
"modified": "2013-05-22 12:01:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -35,6 +35,7 @@
"oldfieldtype": "Link",
"options": "Item",
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"search_index": 1,
"width": "100px"
@@ -48,6 +49,7 @@
"oldfieldname": "item_name",
"oldfieldtype": "Data",
"print_hide": 1,
"read_only": 0,
"reqd": 1,
"search_index": 0
},
@@ -59,6 +61,7 @@
"oldfieldname": "description",
"oldfieldtype": "Text",
"print_width": "300px",
"read_only": 0,
"reqd": 1,
"width": "300px"
},
@@ -72,6 +75,7 @@
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
@@ -84,6 +88,7 @@
"oldfieldname": "qty",
"oldfieldtype": "Currency",
"print_width": "100px",
"read_only": 0,
"width": "100px"
},
{
@@ -97,6 +102,7 @@
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"search_index": 0,
"width": "100px"
},
@@ -110,6 +116,7 @@
"options": "UOM",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
@@ -119,14 +126,16 @@
"fieldtype": "Currency",
"label": "Ref Rate ",
"options": "currency",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "discount_rate",
"fieldtype": "Float",
"label": "Discount %",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"default": "0.00",
@@ -139,6 +148,7 @@
"options": "currency",
"print_hide": 0,
"print_width": "100px",
"read_only": 0,
"width": "100px"
},
{
@@ -157,7 +167,8 @@
"fieldtype": "Currency",
"label": "Ref Rate*",
"options": "Company:company:default_currency",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"default": "0.00",
@@ -170,6 +181,7 @@
"options": "Company:company:default_currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
@@ -184,6 +196,7 @@
"options": "Company:company:default_currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 0,
"width": "100px"
},
@@ -198,6 +211,7 @@
"options": "Warehouse",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"width": "100px"
},
{
@@ -209,6 +223,7 @@
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
@@ -235,6 +250,7 @@
"oldfieldname": "serial_no",
"oldfieldtype": "Text",
"print_hide": 0,
"read_only": 0,
"report_hide": 0
},
{
@@ -242,7 +258,8 @@
"fieldname": "rejected_serial_no",
"fieldtype": "Text",
"label": "Rejected Serial No",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -252,7 +269,8 @@
"oldfieldname": "batch_no",
"oldfieldtype": "Link",
"options": "Batch",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -278,6 +296,7 @@
"oldfieldname": "schedule_date",
"oldfieldtype": "Date",
"print_hide": 1,
"read_only": 0,
"report_hide": 0,
"reqd": 0
},
@@ -288,7 +307,8 @@
"in_filter": 1,
"label": "Project Name",
"options": "Project",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -299,7 +319,8 @@
"oldfieldname": "qa_no",
"oldfieldtype": "Link",
"options": "Quality Inspection",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -336,6 +357,7 @@
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"width": "100px"
},
{
@@ -344,9 +366,11 @@
"fieldtype": "Data",
"hidden": 1,
"label": "Prevdoc Doctype",
"no_copy": 1,
"oldfieldname": "prevdoc_doctype",
"oldfieldtype": "Data",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -355,7 +379,7 @@
"hidden": 0,
"in_filter": 1,
"label": "PO No",
"no_copy": 0,
"no_copy": 1,
"oldfieldname": "prevdoc_docname",
"oldfieldtype": "Link",
"options": "Purchase Order",
@@ -373,6 +397,7 @@
"hidden": 1,
"in_filter": 1,
"label": "PO Date",
"no_copy": 1,
"oldfieldname": "prevdoc_date",
"oldfieldtype": "Date",
"print_hide": 1,
@@ -418,7 +443,7 @@
"hidden": 1,
"in_filter": 1,
"label": "Purchase Order Item No",
"no_copy": 0,
"no_copy": 1,
"oldfieldname": "prevdoc_detail_docname",
"oldfieldtype": "Data",
"print_hide": 1,
@@ -479,6 +504,7 @@
"label": "Page Break",
"oldfieldname": "page_break",
"oldfieldtype": "Check",
"print_hide": 1
"print_hide": 1,
"read_only": 0
}
]

View File

@@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import cint, getdate, nowdate
import datetime
from webnotes import msgprint
from webnotes import msgprint, _
from controllers.stock_controller import StockController
@@ -117,8 +117,11 @@ class DocType(StockController):
self.make_stock_ledger_entry(1)
self.make_gl_entries()
def on_rename(self, new, old):
def on_rename(self, new, old, merge=False):
"""rename serial_no text fields"""
if merge:
msgprint(_("Sorry. Serial Nos. cannot be merged"), raise_exception=True)
for dt in webnotes.conn.sql("""select parent from tabDocField
where fieldname='serial_no' and fieldtype='Text'"""):
@@ -139,7 +142,8 @@ class DocType(StockController):
gl_entries = self.get_gl_entries_for_stock(against_stock_account, self.doc.purchase_rate)
for entry in gl_entries:
entry["posting_date"] = self.doc.purchase_date
entry["posting_date"] = self.doc.purchase_date or (self.doc.creation and
self.doc.creation.split(' ')[0]) or nowdate()
if gl_entries:
make_gl_entries(gl_entries, cancel)

View File

@@ -57,6 +57,7 @@ class DocType(StockController):
self.validate_return_reference_doc()
self.validate_with_material_request()
self.validate_fiscal_year()
self.set_total_amount()
def on_submit(self):
self.update_serial_no(1)
@@ -174,6 +175,9 @@ class DocType(StockController):
elif self.doc.purpose != "Material Transfer":
self.doc.production_order = None
def set_total_amount(self):
self.doc.total_amount = sum([flt(item.amount) for item in self.doclist.get({"parentfield": "mtn_details"})])
def make_gl_entries(self):
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
return
@@ -220,7 +224,7 @@ class DocType(StockController):
if not flt(d.incoming_rate):
d.incoming_rate = self.get_incoming_rate(args)
d.amount = flt(d.qty) * flt(d.incoming_rate)
d.amount = flt(d.transfer_qty) * flt(d.incoming_rate)
def get_incoming_rate(self, args):
incoming_rate = 0

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-03-28 15:56:40",
"creation": "2013-04-09 11:43:55",
"docstatus": 0,
"modified": "2013-03-29 15:31:42",
"modified": "2013-05-09 13:31:00",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -518,6 +518,14 @@
"read_only": 0,
"width": "50%"
},
{
"doctype": "DocField",
"fieldname": "total_amount",
"fieldtype": "Currency",
"label": "Total Amount",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "project_name",
@@ -558,6 +566,14 @@
"read_only": 0,
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "col5",
"fieldtype": "Column Break",
"print_width": "50%",
"read_only": 0,
"width": "50%"
},
{
"allow_on_submit": 0,
"doctype": "DocField",
@@ -576,14 +592,6 @@
"reqd": 1,
"search_index": 0
},
{
"doctype": "DocField",
"fieldname": "col5",
"fieldtype": "Column Break",
"print_width": "50%",
"read_only": 0,
"width": "50%"
},
{
"allow_on_submit": 0,
"doctype": "DocField",