Merge branch 'responsive' of github.com:webnotes/erpnext into responsive

This commit is contained in:
Rushabh Mehta 2013-07-05 10:51:51 +05:30
commit 8005362c6c
20 changed files with 277 additions and 344 deletions

View File

@ -1,123 +0,0 @@
[
{
"creation": "2010-08-08 17:09:35",
"docstatus": 0,
"modified": "2013-07-03 18:00:40",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Table Mapper Detail",
"name": "__common__",
"parent": "Purchase Order-Purchase Invoice",
"parentfield": "table_mapper_details",
"parenttype": "DocType Mapper"
},
{
"doctype": "Field Mapper Detail",
"name": "__common__",
"parent": "Purchase Order-Purchase Invoice",
"parentfield": "field_mapper_details",
"parenttype": "DocType Mapper"
},
{
"doctype": "DocType Mapper",
"from_doctype": "Purchase Order",
"module": "Accounts",
"name": "__common__",
"ref_doc_submitted": 1,
"to_doctype": "Purchase Invoice"
},
{
"doctype": "DocType Mapper",
"name": "Purchase Order-Purchase Invoice"
},
{
"doctype": "Field Mapper Detail",
"from_field": "eval: (flt(obj.amount) - flt(obj.billed_amt)) / obj.purchase_rate",
"map": "Yes",
"match_id": 1,
"to_field": "qty"
},
{
"doctype": "Field Mapper Detail",
"from_field": "purchase_rate",
"map": "Yes",
"match_id": 1,
"to_field": "rate"
},
{
"doctype": "Field Mapper Detail",
"from_field": "eval: flt(obj.amount) - flt(obj.billed_amt)",
"map": "Yes",
"match_id": 1,
"to_field": "amount"
},
{
"doctype": "Field Mapper Detail",
"from_field": "eval: (flt(obj.amount) - flt(obj.billed_amt)) / flt(obj.conversion_rate)",
"map": "Yes",
"match_id": 1,
"to_field": "import_amount"
},
{
"doctype": "Field Mapper Detail",
"from_field": "parent",
"map": "Yes",
"match_id": 1,
"to_field": "purchase_order"
},
{
"doctype": "Field Mapper Detail",
"from_field": "name",
"map": "Yes",
"match_id": 1,
"to_field": "po_detail"
},
{
"doctype": "Field Mapper Detail",
"from_field": "naming_series",
"map": "No",
"match_id": 0,
"to_field": "naming_series"
},
{
"doctype": "Field Mapper Detail",
"from_field": "total_tax",
"map": "Yes",
"match_id": 0,
"to_field": "total_tax"
},
{
"doctype": "Field Mapper Detail",
"from_field": "conversion_rate",
"map": "Yes",
"match_id": 0,
"to_field": "conversion_rate"
},
{
"doctype": "Table Mapper Detail",
"from_table": "Purchase Order",
"match_id": 0,
"to_table": "Purchase Invoice",
"validation_logic": "docstatus =1"
},
{
"doctype": "Table Mapper Detail",
"from_field": "po_details",
"from_table": "Purchase Order Item",
"match_id": 1,
"to_field": "entries",
"to_table": "Purchase Invoice Item",
"validation_logic": "ifnull(billed_amt,0) < amount and docstatus = 1"
},
{
"doctype": "Table Mapper Detail",
"from_field": "purchase_tax_details",
"from_table": "Purchase Taxes and Charges",
"match_id": 2,
"to_field": "purchase_tax_details",
"to_table": "Purchase Taxes and Charges",
"validation_logic": "docstatus =1"
}
]

View File

@ -1,144 +0,0 @@
[
{
"creation": "2010-08-08 17:09:35",
"docstatus": 0,
"modified": "2013-07-03 17:56:30",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Table Mapper Detail",
"name": "__common__",
"parent": "Purchase Receipt-Purchase Invoice",
"parentfield": "table_mapper_details",
"parenttype": "DocType Mapper"
},
{
"doctype": "Field Mapper Detail",
"name": "__common__",
"parent": "Purchase Receipt-Purchase Invoice",
"parentfield": "field_mapper_details",
"parenttype": "DocType Mapper"
},
{
"doctype": "DocType Mapper",
"from_doctype": "Purchase Receipt",
"module": "Accounts",
"name": "__common__",
"ref_doc_submitted": 1,
"to_doctype": "Purchase Invoice"
},
{
"doctype": "DocType Mapper",
"name": "Purchase Receipt-Purchase Invoice"
},
{
"doctype": "Field Mapper Detail",
"from_field": "eval: (flt(obj.amount) - flt(obj.billed_amt)) / obj.purchase_rate",
"map": "Yes",
"match_id": 1,
"to_field": "qty"
},
{
"doctype": "Field Mapper Detail",
"from_field": "purchase_rate",
"map": "Yes",
"match_id": 1,
"to_field": "rate"
},
{
"doctype": "Field Mapper Detail",
"from_field": "eval: flt(obj.amount) - flt(obj.billed_amt)",
"map": "Yes",
"match_id": 1,
"to_field": "amount"
},
{
"doctype": "Field Mapper Detail",
"from_field": "eval: (flt(obj.amount) - flt(obj.billed_amt)) / flt(obj.conversion_rate)",
"map": "Yes",
"match_id": 1,
"to_field": "import_amount"
},
{
"doctype": "Field Mapper Detail",
"from_field": "parent",
"map": "Yes",
"match_id": 1,
"to_field": "purchase_receipt"
},
{
"doctype": "Field Mapper Detail",
"from_field": "prevdoc_docname",
"map": "Yes",
"match_id": 1,
"to_field": "purchase_order"
},
{
"doctype": "Field Mapper Detail",
"from_field": "name",
"map": "Yes",
"match_id": 1,
"to_field": "pr_detail"
},
{
"doctype": "Field Mapper Detail",
"from_field": "prevdoc_detail_docname",
"map": "Yes",
"match_id": 1,
"to_field": "po_detail"
},
{
"doctype": "Field Mapper Detail",
"from_field": "naming_series",
"map": "No",
"match_id": 0,
"to_field": "naming_series"
},
{
"doctype": "Field Mapper Detail",
"from_field": "net_total",
"map": "Yes",
"match_id": 0,
"to_field": "net_total"
},
{
"doctype": "Field Mapper Detail",
"from_field": "grand_total",
"map": "Yes",
"match_id": 0,
"to_field": "grand_total"
},
{
"doctype": "Field Mapper Detail",
"from_field": "total_tax",
"map": "Yes",
"match_id": 0,
"to_field": "total_tax"
},
{
"doctype": "Table Mapper Detail",
"from_field": "purchase_receipt_details",
"from_table": "Purchase Receipt Item",
"match_id": 1,
"to_field": "entries",
"to_table": "Purchase Invoice Item",
"validation_logic": "ifnull(billed_amt,0) < amount"
},
{
"doctype": "Table Mapper Detail",
"from_table": "Purchase Receipt",
"match_id": 0,
"to_table": "Purchase Invoice",
"validation_logic": "docstatus=1"
},
{
"doctype": "Table Mapper Detail",
"from_field": "purchase_tax_details",
"from_table": "Purchase Taxes and Charges",
"match_id": 2,
"to_field": "purchase_tax_details",
"to_table": "Purchase Taxes and Charges",
"validation_logic": "docstatus=1"
}
]

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt, fmt_money
from webnotes import msgprint
from webnotes import msgprint, _
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
@ -196,10 +196,23 @@ class DocType:
if parts[-1].lower() != company_abbr.lower():
parts.append(company_abbr)
# rename account name
account_name = " - ".join(parts[:-1])
sql("update `tabAccount` set account_name = %s where name = %s", (account_name, old))
new_account_name = " - ".join(parts[:-1])
sql("update `tabAccount` set account_name = %s where name = %s", (new_account_name, old))
if merge:
new_name = " - ".join(parts)
val = list(webnotes.conn.get_value("Account", new_name,
["group_or_ledger", "debit_or_credit", "is_pl_account"]))
if val != [self.doc.group_or_ledger, self.doc.debit_or_credit, self.doc.is_pl_account]:
msgprint(_("""Merging is only possible if following \
properties are same in both records.
Group or Ledger, Debit or Credit, Is PL Account"""), raise_exception=1)
from webnotes.utils.nestedset import rebuild_tree
rebuild_tree("Account", "parent_account")
return " - ".join(parts)

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import cint
class DocType:
def __init__(self, d, dl):

View File

@ -98,5 +98,7 @@ class DocType(DocTypeNestedSet):
cost_center_name = " - ".join(parts[:-1])
webnotes.conn.sql("update `tabCost Center` set cost_center_name = %s where name = %s", \
(cost_center_name, old))
super(DocType, self).on_rename(new, old, merge, "group_or_ledger")
return " - ".join(parts)

View File

@ -58,7 +58,7 @@ def execute(filters=None):
row.append(invoice_tax_map.get(inv.name, {}).get(tax_acc))
# total tax, grand total, outstanding amount & rounded total
row += [inv.other_charges_total, inv.grand_total, flt(inv.grand_total, 2), \
row += [inv.total_tax, inv.grand_total, flt(inv.grand_total, 2), \
inv.outstanding_amount]
data.append(row)
@ -164,4 +164,4 @@ def get_account_details(invoice_list):
where name in (%s)""" % ", ".join(["%s"]*len(accounts)), tuple(accounts), as_dict=1):
account_map[acc.name] = acc.parent_account
return account_map
return account_map

View File

@ -83,7 +83,13 @@ cur_frm.cscript.get_last_purchase_rate = function(doc, cdt, cdn){
}
//========================= Make Purchase Receipt =======================================================
cur_frm.cscript.get_items = function(doc, dt, dn) {
wn.model.map_current_doc({
method: "stock.doctype.material_request.material_request.make_purchase_order",
source_name: cur_frm.doc.indent_no,
})
}
cur_frm.cscript['Make Purchase Receipt'] = function() {
n = wn.model.make_new_doc_and_get_name('Purchase Receipt');
$c('dt_map', args={

View File

@ -21,7 +21,6 @@ from webnotes.utils import cstr, flt
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
from buying.utils import get_last_purchase_details
sql = webnotes.conn.sql
@ -72,24 +71,6 @@ class DocType(BuyingController):
def get_bin_details(self, arg = ''):
return get_obj(dt='Purchase Common').get_bin_details(arg)
# Pull Material Request
def get_indent_details(self):
if self.doc.indent_no:
get_obj('DocType Mapper','Material Request-Purchase Order').dt_map('Material Request','Purchase Order',self.doc.indent_no, self.doc, self.doclist, "[['Material Request','Purchase Order'],['Material Request Item', 'Purchase Order Item']]")
for d in getlist(self.doclist, 'po_details'):
if d.item_code and not d.purchase_rate:
last_purchase_details = get_last_purchase_details(d.item_code, self.doc.name)
if last_purchase_details:
conversion_factor = d.conversion_factor or 1.0
conversion_rate = self.doc.fields.get('conversion_rate') or 1.0
d.purchase_ref_rate = last_purchase_details['purchase_ref_rate'] * conversion_factor
d.discount_rate = last_purchase_details['discount_rate']
d.purchase_rate = last_purchase_details['purchase_rate'] * conversion_factor
d.import_ref_rate = d.purchase_ref_rate / conversion_rate
d.import_rate = d.purchase_rate / conversion_rate
else:
d.purchase_ref_rate = d.discount_rate = d.purchase_rate = d.import_ref_rate = d.import_rate = 0.0
def get_supplier_quotation_items(self):
if self.doc.supplier_quotation:
get_obj("DocType Mapper", "Supplier Quotation-Purchase Order").dt_map("Supplier Quotation",

View File

@ -2,7 +2,7 @@
{
"creation": "2013-05-21 16:16:39",
"docstatus": 0,
"modified": "2013-07-04 10:48:54",
"modified": "2013-07-04 18:10:21",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -31,7 +31,6 @@
"parent": "Purchase Order",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"report": 1
},
@ -208,7 +207,6 @@
"label": "Get Items",
"no_copy": 0,
"oldfieldtype": "Button",
"options": "get_indent_details",
"print_hide": 1
},
{
@ -789,15 +787,37 @@
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Material User",
"submit": 0,
"write": 0
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Material User",
"submit": 0,
"write": 0
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Purchase Manager",
"submit": 0,
"write": 0
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Purchase Manager",
"submit": 1,
"write": 1
@ -807,13 +827,24 @@
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Purchase User",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "All",
"submit": 0
},
{
"doctype": "DocPerm",
"match": "supplier",
"permlevel": 0,
"role": "Supplier"
}
]

View File

@ -31,6 +31,12 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
cur_frm.add_custom_button("Make Purchase Order", cur_frm.cscript.make_purchase_order);
}
},
get_items: function() {
wn.model.map_current_doc({
method: "stock.doctype.material_request.material_request.make_supplier_quotation",
source_name: cur_frm.doc.indent_no,
})
}
});
// for backward compatibility: combine new and previous states

View File

@ -17,7 +17,6 @@
from __future__ import unicode_literals
import webnotes
from webnotes.model.code import get_obj
from setup.utils import get_company_currency
from controllers.buying_controller import BuyingController
class DocType(BuyingController):
@ -49,19 +48,6 @@ class DocType(BuyingController):
def on_trash(self):
pass
def get_indent_details(self):
if self.doc.indent_no:
mapper = get_obj("DocType Mapper", "Material Request-Supplier Quotation")
mapper.dt_map("Material Request", "Supplier Quotation", self.doc.indent_no,
self.doc, self.doclist, """[['Material Request', 'Supplier Quotation'],
['Material Request Item', 'Supplier Quotation Item']]""")
from webnotes.model.bean import getlist
for d in getlist(self.doclist, self.fname):
if d.item_code and not d.purchase_rate:
d.purchase_ref_rate = d.discount_rate = d.purchase_rate = 0.0
d.import_ref_rate = d.import_rate = 0.0
def validate_fiscal_year(self):
get_obj(dt = 'Purchase Common').validate_fiscal_year( \

View File

@ -2,7 +2,7 @@
{
"creation": "2013-05-21 16:16:45",
"docstatus": 0,
"modified": "2013-07-04 10:51:05",
"modified": "2013-07-04 18:47:51",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -31,7 +31,6 @@
"parent": "Supplier Quotation",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"report": 1
},
@ -191,8 +190,7 @@
"fieldtype": "Button",
"hidden": 0,
"label": "Get Items",
"oldfieldtype": "Button",
"options": "get_indent_details"
"oldfieldtype": "Button"
},
{
"doctype": "DocField",
@ -644,6 +642,7 @@
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Manufacturing Manager",
"submit": 1,
"write": 1
@ -653,6 +652,7 @@
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Purchase Manager",
"submit": 1,
"write": 1
@ -662,6 +662,7 @@
"cancel": 0,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Purchase User",
"submit": 0,
"write": 1
@ -671,6 +672,7 @@
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Material User",
"submit": 0,
"write": 0
@ -680,8 +682,19 @@
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Supplier",
"submit": 0,
"write": 0
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "All",
"submit": 0,
"write": 0
}
]

View File

@ -254,9 +254,6 @@ class DocType(SellingController):
@webnotes.whitelist()
def make_sales_order(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
if target_doclist:
target_doclist = json.loads(target_doclist)
doclist = get_mapped_doclist("Quotation", source_name, {
"Quotation": {

View File

@ -256,7 +256,7 @@ def create_territories():
country = webnotes.conn.get_value("Control Panel", None, "country")
root_territory = get_root_of("Territory")
for name in (country, "Rest Of The World"):
if not webnotes.conn.exists("Territory", name):
if name and not webnotes.conn.exists("Territory", name):
webnotes.bean({
"doctype": "Territory",
"territory_name": name,

View File

@ -32,7 +32,8 @@ def get_company_currency(company):
def get_root_of(doctype):
"""Get root element of a DocType with a tree structure"""
result = webnotes.conn.sql_list("""select name from `tab%s`
where lft=1 and rgt=(select max(rgt) from `tab%s`)""" % (doctype, doctype))
where lft=1 and rgt=(select max(rgt) from `tab%s` where docstatus < 2)""" %
(doctype, doctype))
return result[0] if result else None
def get_ancestors_of(doctype, name):

View File

@ -287,8 +287,14 @@ class DocType(DocListController):
from webnotes.webutils import clear_cache
clear_cache(self.doc.page_name)
def on_rename(self,newdn,olddn, merge=False):
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
clear_cache(self.doc.page_name)
clear_cache(self.doc.page_name)
if merge:
from stock.stock_ledger import update_entries_after
for wh in webnotes.conn.sql("""select warehouse from `tabBin`
where item_code=%s""", newdn):
update_entries_after({"item_code": newdn, "warehouse": wh})

View File

@ -36,23 +36,27 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
if(doc.docstatus == 1 && doc.status != 'Stopped'){
if(doc.material_request_type === "Purchase")
cur_frm.add_custom_button("Make Supplier Quotation", cur_frm.cscript.make_supplier_quotation);
cur_frm.add_custom_button("Make Supplier Quotation",
cur_frm.cscript.make_supplier_quotation);
if(doc.material_request_type === "Transfer" && doc.status === "Submitted")
cur_frm.add_custom_button("Transfer Material", cur_frm.cscript.make_stock_entry);
if(flt(doc.per_ordered, 2) < 100) {
if(doc.material_request_type === "Purchase")
cur_frm.add_custom_button('Make Purchase Order', cur_frm.cscript['Make Purchase Order']);
cur_frm.add_custom_button('Make Purchase Order',
cur_frm.cscript.make_purchase_order);
cur_frm.add_custom_button('Stop Material Request', cur_frm.cscript['Stop Material Request']);
cur_frm.add_custom_button('Stop Material Request',
cur_frm.cscript['Stop Material Request']);
}
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
}
if(doc.docstatus == 1 && doc.status == 'Stopped')
cur_frm.add_custom_button('Unstop Material Request', cur_frm.cscript['Unstop Material Request']);
cur_frm.add_custom_button('Unstop Material Request',
cur_frm.cscript['Unstop Material Request']);
if(doc.material_request_type === "Transfer") {
cur_frm.toggle_display("sales_order_no", false);
@ -66,6 +70,27 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
calculate_taxes_and_totals: function() {
return;
},
make_purchase_order: function() {
wn.model.open_mapped_doc({
method: "stock.doctype.material_request.material_request.make_purchase_order",
source_name: cur_frm.doc.name
})
},
make_supplier_quotation: function() {
wn.model.open_mapped_doc({
method: "stock.doctype.material_request.material_request.make_supplier_quotation",
source_name: cur_frm.doc.name
})
},
make_stock_entry: function() {
wn.model.open_mapped_doc({
method: "stock.doctype.material_request.material_request.make_stock_entry",
source_name: cur_frm.doc.name
})
}
});
@ -96,25 +121,6 @@ cur_frm.cscript['Unstop Material Request'] = function(){
if (check) {
$c('runserverobj', args={'method':'update_status', 'arg': 'Submitted','docs': wn.model.compress(make_doclist(doc.doctype, doc.name))}, function(r,rt) {
cur_frm.refresh();
});
}
};
cur_frm.cscript['Make Purchase Order'] = function() {
cur_frm.map([
["Material Request", "Purchase Order"],
["Material Request Item", "Purchase Order Item"]]);
};
cur_frm.cscript.make_supplier_quotation = function() {
cur_frm.map([
["Material Request", "Supplier Quotation"],
["Material Request Item", "Supplier Quotation Item"]]);
};
cur_frm.cscript.make_stock_entry = function() {
cur_frm.map([
["Material Request", "Stock Entry"],
["Material Request Item", "Stock Entry Detail"]]);
};

View File

@ -240,3 +240,101 @@ def _update_requested_qty(controller, mr_obj, mr_items):
"indented_qty": (se_detail.docstatus==2 and 1 or -1) * add_indented_qty,
"posting_date": controller.doc.posting_date,
})
@webnotes.whitelist()
def make_purchase_order(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def update_item(obj, target):
target.conversion_factor = 1
target.qty = flt(obj.qty) - flt(obj.ordered_qty)
def set_missing_values(source, target):
po = webnotes.bean(target)
po.run_method("set_missing_values")
doclist = get_mapped_doclist("Material Request", source_name, {
"Material Request": {
"doctype": "Purchase Order",
"validation": {
"docstatus": ["=", 1],
"material_request_type": ["=", "Purchase"]
}
},
"Material Request Item": {
"doctype": "Purchase Order Item",
"field_map": {
"name": "prevdoc_detail_docname",
"parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype",
"uom": "stock_uom"
},
"postprocess": update_item
}
}, target_doclist, set_missing_values)
return [d.fields for d in doclist]
@webnotes.whitelist()
def make_supplier_quotation(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def set_missing_values(source, target):
sq = webnotes.bean(target)
sq.run_method("set_missing_values")
doclist = get_mapped_doclist("Material Request", source_name, {
"Material Request": {
"doctype": "Supplier Quotation",
"validation": {
"docstatus": ["=", 1],
"material_request_type": ["=", "Purchase"]
}
},
"Material Request Item": {
"doctype": "Supplier Quotation Item",
"field_map": {
"name": "prevdoc_detail_docname",
"parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype"
}
}
}, target_doclist, set_missing_values)
return [d.fields for d in doclist]
@webnotes.whitelist()
def make_stock_entry(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def set_purpose(source, target):
target[0].purpose = "Material Transfer"
def update_item(source, target):
target.conversion_factor = 1
target.qty = flt(source.qty) - flt(source.ordered_qty)
doclist = get_mapped_doclist("Material Request", source_name, {
"Material Request": {
"doctype": "Stock Entry",
"validation": {
"docstatus": ["=", 1],
"material_request_type": ["=", "Transfer"]
}
},
"Material Request Item": {
"doctype": "Stock Entry Detail",
"field_map": {
"name": "material_request_item",
"parent": "material_request",
"uom": "stock_uom",
"warehouse": "t_warehouse"
},
"postprocess": update_item
}
}, target_doclist, set_purpose)
return [d.fields for d in doclist]

View File

@ -6,6 +6,53 @@ import webnotes, unittest
from webnotes.utils import flt
class TestMaterialRequest(unittest.TestCase):
def test_make_purchase_order(self):
from stock.doctype.material_request.material_request import make_purchase_order
mr = webnotes.bean(copy=test_records[0]).insert()
self.assertRaises(webnotes.ValidationError, make_purchase_order,
mr.doc.name)
mr = webnotes.bean("Material Request", mr.doc.name)
mr.submit()
po = make_purchase_order(mr.doc.name)
self.assertEquals(po[0]["doctype"], "Purchase Order")
self.assertEquals(len(po), len(mr.doclist))
def test_make_supplier_quotation(self):
from stock.doctype.material_request.material_request import make_supplier_quotation
mr = webnotes.bean(copy=test_records[0]).insert()
self.assertRaises(webnotes.ValidationError, make_supplier_quotation,
mr.doc.name)
mr = webnotes.bean("Material Request", mr.doc.name)
mr.submit()
sq = make_supplier_quotation(mr.doc.name)
self.assertEquals(sq[0]["doctype"], "Supplier Quotation")
self.assertEquals(len(sq), len(mr.doclist))
def test_make_stock_entry(self):
from stock.doctype.material_request.material_request import make_stock_entry
mr = webnotes.bean(copy=test_records[0]).insert()
self.assertRaises(webnotes.ValidationError, make_stock_entry,
mr.doc.name)
mr = webnotes.bean("Material Request", mr.doc.name)
mr.doc.material_request_type = "Transfer"
mr.submit()
se = make_stock_entry(mr.doc.name)
self.assertEquals(se[0]["doctype"], "Stock Entry")
self.assertEquals(len(se), len(mr.doclist))
def _test_expected(self, doclist, expected_values):
for i, expected in enumerate(expected_values):
for fieldname, val in expected.items():

View File

@ -204,3 +204,9 @@ class DocType:
else:
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
def on_rename(self, newdn, olddn, merge=False):
if merge:
from stock.stock_ledger import update_entries_after
for item_code in webnotes.conn.sql("""select item_code from `tabBin`
where warehouse=%s""", newdn):
update_entries_after({"item_code": item_code, "warehouse": newdn})