[mapper] material request to purchase order

This commit is contained in:
Nabin Hait 2013-07-04 17:50:06 +05:30
parent 3ccfb028fe
commit df1fca9f65
5 changed files with 53 additions and 7 deletions

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

@ -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

@ -102,10 +102,11 @@ cur_frm.cscript['Unstop Material Request'] = function(){
};
cur_frm.cscript['Make Purchase Order'] = function() {
cur_frm.map([
["Material Request", "Purchase Order"],
["Material Request Item", "Purchase Order Item"]]);
};
wn.model.open_mapped_doc({
method: "stock.doctype.material_request.material_request.make_purchase_order",
source_name: cur_frm.doc.name
})
}
cur_frm.cscript.make_supplier_quotation = function() {
cur_frm.map([

View File

@ -240,3 +240,35 @@ 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)
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)
return [d.fields for d in doclist]

View File

@ -6,6 +6,21 @@ 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_expected(self, doclist, expected_values):
for i, expected in enumerate(expected_values):
for fieldname, val in expected.items():