Browse Source

[mapper]

develop
Nabin Hait 12 years ago
parent
commit
a5be5c41cc
  1. 2
      accounts/doctype/sales_invoice/sales_invoice.js
  2. 2
      buying/doctype/purchase_order/purchase_order.py
  3. 2
      selling/doctype/quotation/quotation.py
  4. 85
      selling/doctype/sales_order/sales_order.js
  5. 16
      selling/doctype/sales_order/sales_order.py
  6. 74
      selling/doctype/sales_order/sales_order.txt
  7. 26
      stock/doctype/delivery_note/delivery_note.js
  8. 45
      stock/doctype/delivery_note/delivery_note.py
  9. 48
      stock/doctype/delivery_note/delivery_note.txt
  10. 2
      stock/doctype/purchase_receipt/purchase_receipt.py

2
accounts/doctype/sales_invoice/sales_invoice.js

@ -194,7 +194,7 @@ cur_frm.cscript.is_opening = function(doc, dt, dn) {
cur_frm.cscript.get_items = function(doc, dt, dn) {
if(doc.delivery_note_main) {
wn.model.map_current_doc({
method: "selling.doctype.delivery_note.delivery_note.make_sales_invoice",
method: "stock.doctype.delivery_note.delivery_note.make_sales_invoice",
source_name: cur_frm.doc.delivery_note_main,
})
}

2
buying/doctype/purchase_order/purchase_order.py

@ -271,7 +271,7 @@ def make_purchase_invoice(source_name, target_doclist=None):
"purchase_rate": "rate"
},
"postprocess": update_item,
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.amount
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.import_amount
},
"Purchase Taxes and Charges": {
"doctype": "Purchase Taxes and Charges",

2
selling/doctype/quotation/quotation.py

@ -280,4 +280,6 @@ def make_sales_order(source_name, target_doclist=None):
}
}, target_doclist)
# postprocess: fetch shipping address, set missing values
return [d.fields for d in doclist]

85
selling/doctype/sales_order/sales_order.js

@ -42,21 +42,23 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
// delivery note
if(flt(doc.per_delivered, 2) < 100 && doc.order_type=='Sales')
cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
cur_frm.add_custom_button('Make Delivery', this.make_delivery_note);
// maintenance
if(flt(doc.per_delivered, 2) < 100 && (doc.order_type !='Sales')) {
cur_frm.add_custom_button('Make Maint. Visit', cur_frm.cscript.make_maintenance_visit);
cur_frm.add_custom_button('Make Maint. Schedule', cur_frm.cscript['Make Maintenance Schedule']);
cur_frm.add_custom_button('Make Maint. Visit', this.make_maintenance_visit);
cur_frm.add_custom_button('Make Maint. Schedule',
this.make_maintainance_schedule);
}
// indent
if(!doc.order_type || (doc.order_type == 'Sales'))
cur_frm.add_custom_button('Make ' + wn._('Material Request'), cur_frm.cscript['Make Material Request']);
cur_frm.add_custom_button('Make ' + wn._('Material Request'),
this.make_material_request);
// sales invoice
if(flt(doc.per_billed, 2) < 100)
cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Sales Invoice']);
cur_frm.add_custom_button('Make Invoice', this.make_sales_invoice);
// stop
if(flt(doc.per_delivered, 2) < 100 || doc.per_billed < 100)
@ -78,6 +80,39 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
reserved_warehouse: function(doc, cdt, cdn) {
this.warehouse(doc, cdt, cdn);
},
make_material_request: function() {
wn.model.open_mapped_doc({
method: "selling.doctype.sales_order.sales_order.make_material_request",
source_name: cur_frm.doc.name
})
},
make_delivery_note: function() {
console.log(cur_frm.doc.name);
wn.model.open_mapped_doc({
method: "selling.doctype.sales_order.sales_order.make_delivery_note",
source_name: cur_frm.doc.name
})
},
make_sales_invoice: function() {
wn.model.open_mapped_doc({
method: "selling.doctype.quotation.quotation.make_quotation",
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,
});
unhide_field(['quotation_date', 'customer_address',
'contact_person', 'territory', 'customer_group']);
}
});
// for backward compatibility: combine new and previous states
@ -87,23 +122,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
}
cur_frm.cscript.pull_quotation_details = function(doc,dt,dn) {
var callback = function(r,rt){
var doc = locals[cur_frm.doctype][cur_frm.docname];
if(!r.exc){
doc.quotation_no = r.message;
if(doc.quotation_no) {
unhide_field(['quotation_date', 'customer_address',
'contact_person', 'territory', 'customer_group']);
if(doc.customer) get_server_fields('get_shipping_address', doc.customer, '', doc, dt, dn, 0);
}
cur_frm.refresh_fields();
}
}
$c_obj(make_doclist(doc.doctype, doc.name),'pull_quotation_details','',callback);
}
cur_frm.cscript.new_contact = function(){
tn = wn.model.make_new_doc_and_get_name('Contact');
@ -194,29 +212,6 @@ cur_frm.cscript.make_maintenance_visit = function() {
}
}
cur_frm.cscript['Make Material Request'] = function() {
wn.model.open_mapped_doc({
method: "selling.doctype.sales_order.sales_order.make_material_request",
source_name: cur_frm.doc.name
})
}
cur_frm.cscript['Make Delivery Note'] = function() {
wn.model.open_mapped_doc({
method: "selling.doctype.sales_order.sales_order.make_delivery_note",
source_name: cur_frm.doc.name
})
}
cur_frm.cscript['Make Sales Invoice'] = function() {
wn.model.open_mapped_doc({
method: "selling.doctype.sales_order.sales_order.make_sales_invoice",
source_name: cur_frm.doc.name
})
}
cur_frm.cscript['Stop Sales Order'] = function() {
var doc = cur_frm.doc;

16
selling/doctype/sales_order/sales_order.py

@ -39,18 +39,6 @@ class DocType(SellingController):
self.person_tname = 'Target Detail'
self.partner_tname = 'Partner Target Detail'
self.territory_tname = 'Territory Target Detail'
def pull_quotation_details(self):
self.doclist = self.doc.clear_table(self.doclist, 'other_charges')
self.doclist = self.doc.clear_table(self.doclist, 'sales_order_details')
self.doclist = self.doc.clear_table(self.doclist, 'sales_team')
self.doclist = self.doc.clear_table(self.doclist, 'tc_details')
if self.doc.quotation_no:
get_obj('DocType Mapper', 'Quotation-Sales Order').dt_map('Quotation', 'Sales Order', self.doc.quotation_no, self.doc, self.doclist, "[['Quotation', 'Sales Order'],['Quotation Item', 'Sales Order Item'],['Sales Taxes and Charges','Sales Taxes and Charges'],['Sales Team','Sales Team'],['TC Detail','TC Detail']]")
else:
msgprint("Please select Quotation whose details need to pull")
return cstr(self.doc.quotation_no)
def get_contact_details(self):
get_obj('Sales Common').get_contact_details(self,0)
@ -406,7 +394,7 @@ def make_material_request(source_name, target_doclist=None):
def make_delivery_note(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
def update_item(obj, target):
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)
target.qty = flt(obj.qty) - flt(obj.delivered_qty)
@ -472,7 +460,7 @@ def make_sales_invoice(source_name, target_doclist=None):
"reserved_warehouse": "warehouse"
},
"postprocess": update_item,
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.amount
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.export_amount
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",

74
selling/doctype/sales_order/sales_order.txt

@ -2,7 +2,7 @@
{
"creation": "2013-06-18 12:39:59",
"docstatus": 0,
"modified": "2013-07-05 14:54:26",
"modified": "2013-07-06 18:38:37",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -33,8 +33,8 @@
"parent": "Sales Order",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1
"read": 1,
"report": 1
},
{
"doctype": "DocType",
@ -405,7 +405,6 @@
"fieldtype": "Button",
"label": "Pull Quotation Items",
"oldfieldtype": "Button",
"options": "pull_quotation_details",
"print_hide": 1
},
{
@ -975,13 +974,23 @@
"options": "Sales Team",
"print_hide": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Sales Manager",
"submit": 0,
"write": 0
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"report": 1,
"role": "Sales User",
"permlevel": 0,
"role": "Sales Manager",
"submit": 1,
"write": 1
},
@ -990,18 +999,63 @@
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"report": 1,
"role": "Maintenance User",
"permlevel": 0,
"role": "Sales User",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"role": "Accounts User"
"permlevel": 1,
"role": "Sales User",
"submit": 0,
"write": 0
},
{
"doctype": "DocPerm",
"match": "customer",
"match": "customer_name",
"permlevel": 0,
"role": "Customer"
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Maintenance Manager",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Maintenance Manager",
"submit": 0
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Maintenance User",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Maintenance User",
"submit": 0
}
]

26
stock/doctype/delivery_note/delivery_note.js

@ -29,7 +29,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
refresh: function(doc, dt, dn) {
this._super();
if(flt(doc.per_billed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', cur_frm.cscript['Make Sales Invoice']);
if(flt(doc.per_billed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', this.make_sales_invoice);
if(flt(doc.per_installed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Installation Note', cur_frm.cscript['Make Installation Note']);
@ -45,6 +45,20 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
var aii_enabled = cint(sys_defaults.auto_inventory_accounting)
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("expense_account", aii_enabled);
cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("cost_center", aii_enabled);
},
get_items: function() {
wn.model.map_current_doc({
method: "selling.doctype.sales_order.sales_order.make_delivery_note",
source_name: cur_frm.doc.sales_order_no,
})
},
make_sales_invoice: function() {
wn.model.open_mapped_doc({
method: "stock.doctype.delivery_note.delivery_note.make_sales_invoice",
source_name: cur_frm.doc.name
})
}
});
@ -55,16 +69,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
}
cur_frm.cscript.get_items = function(doc,dt,dn) {
wn.model.map_current_doc({
method: "selling.doctype.sales_order.sales_order.make_delivery_note",
source_name: cur_frm.doc.sales_order_no,
})
}
//================ create new contact ============================================================================
cur_frm.cscript.new_contact = function(){
tn = wn.model.make_new_doc_and_get_name('Contact');
locals['Contact'][tn].is_customer = 1;

45
stock/doctype/delivery_note/delivery_note.py

@ -363,3 +363,48 @@ class DocType(SellingController):
if gl_entries:
from accounts.general_ledger import make_gl_entries
make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
@webnotes.whitelist()
def make_sales_invoice(source_name, target_doclist=None):
from webnotes.model.mapper import get_mapped_doclist
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)
target.qty = obj.basic_rate and target.amount / flt(obj.basic_rate) or obj.qty
def update_accounts(source, target):
si = webnotes.bean(target)
si.run_method("update_accounts")
doclist = get_mapped_doclist("Delivery Note", source_name, {
"Delivery Note": {
"doctype": "Sales Invoice",
"validation": {
"docstatus": ["=", 1]
}
},
"Delivery Note Item": {
"doctype": "Sales Invoice Item",
"field_map": {
"name": "dn_detail",
"parent": "delivery_note",
"prevdoc_detail_docname": "so_detail",
"prevdoc_docname": "sales_order",
"serial_no": "serial_no"
},
"postprocess": update_item,
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.export_amount
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",
},
"Sales Team": {
"doctype": "Sales Team",
"field_map": {
"incentives": "incentives"
}
}
}, target_doclist, update_accounts)
return [d.fields for d in doclist]

48
stock/doctype/delivery_note/delivery_note.txt

@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:09",
"docstatus": 0,
"modified": "2013-07-05 14:34:50",
"modified": "2013-07-06 19:04:46",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -34,7 +34,6 @@
"parent": "Delivery Note",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"report": 1
},
@ -401,7 +400,6 @@
"hidden": 0,
"label": "Get Items",
"oldfieldtype": "Button",
"options": "pull_sales_order_details",
"print_hide": 1,
"read_only": 0
},
@ -1127,39 +1125,83 @@
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Material User",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Material User",
"submit": 0,
"write": 0
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Material Manager",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Material Manager",
"submit": 0,
"write": 0
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Sales User",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Sales User",
"submit": 0,
"write": 0
},
{
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Accounts User",
"submit": 0,
"write": 0
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Accounts User",
"submit": 0
},
{
"doctype": "DocPerm",
"match": "customer_name",
"permlevel": 0,
"role": "Customer"
}
]

2
stock/doctype/purchase_receipt/purchase_receipt.py

@ -360,7 +360,7 @@ def make_purchase_invoice(source_name, target_doclist=None):
"purchase_rate": "rate"
},
"postprocess": update_item,
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.amount
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.import_amount
},
"Purchase Taxes and Charges": {
"doctype": "Purchase Taxes and Charges",

Loading…
Cancel
Save