[mapper] support

This commit is contained in:
Nabin Hait
2013-07-07 12:32:01 +05:30
parent 650501526f
commit 2b3ca41450
10 changed files with 256 additions and 231 deletions

View File

@@ -48,7 +48,7 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
if(flt(doc.per_delivered, 2) < 100 && (doc.order_type !='Sales')) {
cur_frm.add_custom_button('Make Maint. Visit', this.make_maintenance_visit);
cur_frm.add_custom_button('Make Maint. Schedule',
this.make_maintainance_schedule);
this.make_maintenance_schedule);
}
// indent
@@ -98,13 +98,26 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
make_sales_invoice: function() {
wn.model.open_mapped_doc({
method: "selling.doctype.quotation.quotation.make_quotation",
method: "selling.doctype.sales_order.sales_order.make_sales_invoice",
source_name: cur_frm.doc.name
})
},
make_maintenance_schedule: function() {
wn.model.open_mapped_doc({
method: "selling.doctype.sales_order.sales_order.make_maintenance_schedule",
source_name: cur_frm.doc.name
})
},
make_maintenance_visit: function() {
wn.model.open_mapped_doc({
method: "selling.doctype.sales_order.sales_order.make_maintenance_visit",
source_name: cur_frm.doc.name
})
},
pull_quotation_details: function() {
wn.model.map_current_doc({
method: "selling.doctype.quotation.quotation.make_sales_order",
source_name: cur_frm.doc.quotation_no,
@@ -155,64 +168,6 @@ cur_frm.fields_dict['quotation_no'].get_query = function(doc) {
ORDER BY `tabQuotation`.`name` DESC LIMIT 50', {cond:cond});
}
//----------- make maintenance schedule----------
cur_frm.cscript['Make Maintenance Schedule'] = function() {
var doc = cur_frm.doc;
if (doc.docstatus == 1) {
$c_obj(make_doclist(doc.doctype, doc.name),'check_maintenance_schedule','',
function(r,rt){
if(r.message == 'No'){
n = wn.model.make_new_doc_and_get_name("Maintenance Schedule");
$c('dt_map', args={
'docs':wn.model.compress([locals["Maintenance Schedule"][n]]),
'from_doctype':'Sales Order',
'to_doctype':'Maintenance Schedule',
'from_docname':doc.name,
'from_to_list':"[['Sales Order', 'Maintenance Schedule'], ['Sales Order Item', 'Maintenance Schedule Item']]"
}
, function(r,rt) {
loaddoc("Maintenance Schedule", n);
}
);
}
else{
msgprint("You have already created Maintenance Schedule against this Sales Order");
}
}
);
}
}
cur_frm.cscript.make_maintenance_visit = function() {
var doc = cur_frm.doc;
if (doc.docstatus == 1) {
$c_obj(make_doclist(doc.doctype, doc.name),'check_maintenance_visit','',
function(r,rt){
if(r.message == 'No'){
n = wn.model.make_new_doc_and_get_name("Maintenance Visit");
$c('dt_map', args={
'docs':wn.model.compress([locals["Maintenance Visit"][n]]),
'from_doctype':'Sales Order',
'to_doctype':'Maintenance Visit',
'from_docname':doc.name,
'from_to_list':"[['Sales Order', 'Maintenance Visit'], ['Sales Order Item', 'Maintenance Visit Purpose']]"
}
, function(r,rt) {
loaddoc("Maintenance Visit", n);
}
);
}
else{
msgprint("You have already completed maintenance against this Sales Order");
}
}
);
}
}
cur_frm.cscript['Stop Sales Order'] = function() {
var doc = cur_frm.doc;

View File

@@ -23,6 +23,7 @@ from webnotes.utils import cstr, flt, getdate
from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import msgprint
from webnotes.model.mapper import get_mapped_doclist
sql = webnotes.conn.sql
@@ -55,20 +56,6 @@ class DocType(SellingController):
def get_rate(self,arg):
return get_obj('Sales Common').get_rate(arg)
def check_maintenance_schedule(self):
nm = sql("select t1.name from `tabMaintenance Schedule` t1, `tabMaintenance Schedule Item` t2 where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1", self.doc.name)
nm = nm and nm[0][0] or ''
if not nm:
return 'No'
def check_maintenance_visit(self):
nm = sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1 and t1.completion_status='Fully Completed'", self.doc.name)
nm = nm and nm[0][0] or ''
if not nm:
return 'No'
def validate_fiscal_year(self):
get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.transaction_date,'Sales Order Date')
@@ -365,9 +352,7 @@ def get_currency_and_number_format():
}
@webnotes.whitelist()
def make_material_request(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def make_material_request(source_name, target_doclist=None):
def postprocess(source, doclist):
doclist[0].material_request_type = "Purchase"
@@ -391,9 +376,7 @@ def make_material_request(source_name, target_doclist=None):
return [d.fields for d in doclist]
@webnotes.whitelist()
def make_delivery_note(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def make_delivery_note(source_name, target_doclist=None):
def update_item(obj, target, source_parent):
target.amount = (flt(obj.qty) - flt(obj.delivered_qty)) * flt(obj.basic_rate)
target.export_amount = (flt(obj.qty) - flt(obj.delivered_qty)) * flt(obj.export_rate)
@@ -433,9 +416,7 @@ def make_delivery_note(source_name, target_doclist=None):
return [d.fields for d in doclist]
@webnotes.whitelist()
def make_sales_invoice(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def make_sales_invoice(source_name, target_doclist=None):
def update_item(obj, target, source_parent):
target.export_amount = flt(obj.amount) - flt(obj.billed_amt)
target.amount = target.export_amount / flt(source_parent.conversion_rate)
@@ -470,4 +451,60 @@ def make_sales_invoice(source_name, target_doclist=None):
}
}, target_doclist, update_accounts)
return [d.fields for d in doclist]
return [d.fields for d in doclist]
@webnotes.whitelist()
def make_maintenance_schedule(source_name, target_doclist=None):
maint_schedule = webnotes.conn.sql("""select t1.name
from `tabMaintenance Schedule` t1, `tabMaintenance Schedule Item` t2
where t2.parent=t1.name and t2.prevdoc_docname=%s and t1.docstatus=1""", source_name)
if not maint_schedule:
doclist = get_mapped_doclist("Sales Order", source_name, {
"Sales Order": {
"doctype": "Maintenance Schedule",
"field_map": {
"name": "sales_order_no"
},
"validation": {
"docstatus": ["=", 1]
}
},
"Sales Order Item": {
"doctype": "Maintenance Schedule Item",
"field_map": {
"parent": "prevdoc_docname"
}
}
}, target_doclist)
return [d.fields for d in doclist]
@webnotes.whitelist()
def make_maintenance_visit(source_name, target_doclist=None):
visit = webnotes.conn.sql("""select t1.name
from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2
where t2.parent=t1.name and t2.prevdoc_docname=%s
and t1.docstatus=1 and t1.completion_status='Fully Completed'""", source_name)
if not visit:
doclist = get_mapped_doclist("Sales Order", source_name, {
"Sales Order": {
"doctype": "Maintenance Visit",
"field_map": {
"name": "sales_order_no"
},
"validation": {
"docstatus": ["=", 1]
}
},
"Sales Order Item": {
"doctype": "Maintenance Visit Purpose",
"field_map": {
"parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype"
}
}
}, target_doclist)
return [d.fields for d in doclist]