Merge branch '4.0.0-wip' of github.com:webnotes/erpnext into 4.0-hotfix

This commit is contained in:
Akhilesh Darjee 2014-02-03 16:44:14 +05:30
commit abb3af7b30
49 changed files with 1520 additions and 1599 deletions

View File

@ -3,7 +3,7 @@
{%- endif -%} {%- endif -%}
<!-- Page Layout Settings --> <!-- Page Layout Settings -->
<div class='common page-header'> <div class='common page-header'>
<table class='header-table' cellspacing=0> <table class='header-table' cellspacing=0 style="width: 100%">
<thead> <thead>
<tr><td colspan="2"><h1>{{ doc.select_print_heading or 'Invoice' }}</h1></td></tr> <tr><td colspan="2"><h1>{{ doc.select_print_heading or 'Invoice' }}</h1></td></tr>
<tr><td colspan="2"><h3>{{ doc.name }}</h3></td></tr> <tr><td colspan="2"><h3>{{ doc.name }}</h3></td></tr>
@ -28,18 +28,18 @@
<tr> <tr>
<td width=40%><b>Invoice Date</b></td> <td width=40%><b>Invoice Date</b></td>
<td>{{ utils.formatdate(doc.posting_date) }}</td> <td>{{ utils.formatdate(doc.posting_date) }}</td>
<tr> </tr>
{%- if doc.convert_into_recurring_invoice and doc.recurring_id -%} {%- if doc.convert_into_recurring_invoice and doc.recurring_id -%}
<tr> <tr>
<td width=40%><b>Invoice Period</b></td> <td width=40%><b>Invoice Period</b></td>
<td>{{ (utils.formatdate(doc.invoice_period_from_date)) + <td>{{ (utils.formatdate(doc.invoice_period_from_date)) +
' to ' + utils.formatdate(doc.invoice_period_to_date) }}</td> ' to ' + utils.formatdate(doc.invoice_period_to_date) }}</td>
<tr> </tr>
{%- endif -%} {%- endif -%}
<tr> <tr>
<td><b>Due Date</b></td> <td><b>Due Date</b></td>
<td>{{ utils.formatdate(doc.due_date) }}</td> <td>{{ utils.formatdate(doc.due_date) }}</td>
<tr> </tr>
</tbody></table></td> </tbody></table></td>
</tr> </tr>
</tbody> </tbody>

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:27:39", "creation": "2013-02-22 01:27:39",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:18", "modified": "2014-02-03 12:44:31",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -58,23 +58,8 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "debit", "fieldname": "col_break1",
"fieldtype": "Currency", "fieldtype": "Column Break"
"in_list_view": 1,
"label": "Debit",
"oldfieldname": "debit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency"
},
{
"doctype": "DocField",
"fieldname": "credit",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Credit",
"oldfieldname": "credit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency"
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -88,12 +73,55 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1 "read_only": 1
}, },
{
"doctype": "DocField",
"fieldname": "sec_break1",
"fieldtype": "Section Break"
},
{
"doctype": "DocField",
"fieldname": "debit",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Debit",
"oldfieldname": "debit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency"
},
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "credit",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Credit",
"oldfieldname": "credit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "reference", "fieldname": "reference",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Reference" "label": "Reference"
}, },
{
"doctype": "DocField",
"fieldname": "against_invoice",
"fieldtype": "Link",
"in_filter": 1,
"label": "Against Sales Invoice",
"no_copy": 1,
"oldfieldname": "against_invoice",
"oldfieldtype": "Link",
"options": "Sales Invoice",
"print_hide": 0,
"search_index": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "against_voucher", "fieldname": "against_voucher",
@ -110,16 +138,8 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "against_invoice", "fieldname": "col_break3",
"fieldtype": "Link", "fieldtype": "Column Break"
"in_filter": 1,
"label": "Against Sales Invoice",
"no_copy": 1,
"oldfieldname": "against_invoice",
"oldfieldtype": "Link",
"options": "Sales Invoice",
"print_hide": 0,
"search_index": 1
}, },
{ {
"doctype": "DocField", "doctype": "DocField",

View File

@ -75,6 +75,19 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
this.is_opening(doc); this.is_opening(doc);
}, },
supplier: function() {
if(this.frm.updating_party_details)
return;
erpnext.selling.get_party_details(this.frm,
"erpnext.accounts.party.get_party_details", {
posting_date: this.frm.doc.posting_date,
company: this.frm.doc.company,
party: this.frm.doc.supplier,
party_type: "Supplier",
account: this.frm.doc.debit_to
})
},
credit_to: function() { credit_to: function() {
this.supplier(); this.supplier();

View File

@ -12,8 +12,9 @@ from erpnext.setup.utils import get_company_currency
import webnotes.defaults import webnotes.defaults
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
from erpnext.accounts.party import get_party_account, get_due_date
class DocType(BuyingController): class DocType(BuyingController):
def __init__(self,d,dl): def __init__(self,d,dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
@ -55,31 +56,16 @@ class DocType(BuyingController):
self.update_valuation_rate("entries") self.update_valuation_rate("entries")
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "import_amount", self.validate_multiple_billing("Purchase Receipt", "pr_detail", "import_amount",
"purchase_receipt_details") "purchase_receipt_details")
def get_credit_to(self): def set_missing_values(self, for_validate=False):
ret = {} if not self.doc.credit_to:
if self.doc.supplier: self.doc.credit_to = get_party_account(self.doc.company, self.doc.supplier, "Supplier")
acc_head = webnotes.conn.sql("""select name, credit_days from `tabAccount` if not self.doc.due_date:
where (name = %s or (master_name = %s and master_type = 'supplier')) self.doc.due_date = get_due_date(self.doc.posting_date, self.doc.supplier, "Supplier",
and docstatus != 2 and company = %s""", self.doc.credit_to, self.doc.company)
(cstr(self.doc.supplier) + " - " + self.company_abbr,
self.doc.supplier, self.doc.company))
if acc_head and acc_head[0][0]:
ret['credit_to'] = acc_head[0][0]
if not self.doc.due_date:
ret['due_date'] = add_days(cstr(self.doc.posting_date),
acc_head and cint(acc_head[0][1]) or 0)
elif not acc_head:
msgprint("%s does not have an Account Head in %s. \
You must first create it from the Supplier Master" % \
(self.doc.supplier, self.doc.company))
return ret
def set_supplier_defaults(self):
self.doc.fields.update(self.get_credit_to())
super(DocType, self).set_supplier_defaults()
super(DocType, self).set_missing_values(for_validate)
def get_advances(self): def get_advances(self):
super(DocType, self).get_advances(self.doc.credit_to, super(DocType, self).get_advances(self.doc.credit_to,
"Purchase Invoice Advance", "advance_allocation_details", "debit") "Purchase Invoice Advance", "advance_allocation_details", "debit")

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-03-08 15:36:46", "creation": "2013-03-08 15:36:46",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:29", "modified": "2014-02-03 12:38:24",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -15,7 +15,6 @@
{ {
"doctype": "DocField", "doctype": "DocField",
"name": "__common__", "name": "__common__",
"no_copy": 1,
"parent": "Purchase Invoice Advance", "parent": "Purchase Invoice Advance",
"parentfield": "fields", "parentfield": "fields",
"parenttype": "DocType", "parenttype": "DocType",
@ -31,6 +30,7 @@
"fieldtype": "Link", "fieldtype": "Link",
"in_list_view": 1, "in_list_view": 1,
"label": "Journal Voucher", "label": "Journal Voucher",
"no_copy": 1,
"oldfieldname": "journal_voucher", "oldfieldname": "journal_voucher",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Journal Voucher", "options": "Journal Voucher",
@ -45,6 +45,7 @@
"hidden": 1, "hidden": 1,
"in_list_view": 0, "in_list_view": 0,
"label": "Journal Voucher Detail No", "label": "Journal Voucher Detail No",
"no_copy": 1,
"oldfieldname": "jv_detail_no", "oldfieldname": "jv_detail_no",
"oldfieldtype": "Date", "oldfieldtype": "Date",
"print_hide": 1, "print_hide": 1,
@ -52,12 +53,31 @@
"read_only": 1, "read_only": 1,
"width": "80px" "width": "80px"
}, },
{
"doctype": "DocField",
"fieldname": "remarks",
"fieldtype": "Small Text",
"in_list_view": 1,
"label": "Remarks",
"no_copy": 1,
"oldfieldname": "remarks",
"oldfieldtype": "Small Text",
"print_width": "150px",
"read_only": 1,
"width": "150px"
},
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "advance_amount", "fieldname": "advance_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1, "in_list_view": 1,
"label": "Advance Amount", "label": "Advance Amount",
"no_copy": 1,
"oldfieldname": "advance_amount", "oldfieldname": "advance_amount",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
@ -71,22 +91,11 @@
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1, "in_list_view": 1,
"label": "Allocated Amount", "label": "Allocated Amount",
"no_copy": 1,
"oldfieldname": "allocated_amount", "oldfieldname": "allocated_amount",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_width": "100px", "print_width": "100px",
"width": "100px" "width": "100px"
},
{
"doctype": "DocField",
"fieldname": "remarks",
"fieldtype": "Small Text",
"in_list_view": 1,
"label": "Remarks",
"oldfieldname": "remarks",
"oldfieldtype": "Small Text",
"print_width": "150px",
"read_only": 1,
"width": "150px"
} }
] ]

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-05-22 12:43:10", "creation": "2013-05-22 12:43:10",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:29", "modified": "2014-02-03 12:30:39",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -53,6 +53,11 @@
"reqd": 1, "reqd": 1,
"search_index": 0 "search_index": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "description", "fieldname": "description",
@ -84,6 +89,11 @@
"read_only": 0, "read_only": 0,
"reqd": 1 "reqd": 1
}, },
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "uom", "fieldname": "uom",
@ -94,6 +104,20 @@
"print_hide": 1, "print_hide": 1,
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"in_list_view": 0,
"label": "Conversion Factor",
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "sec_break1",
"fieldtype": "Section Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "import_ref_rate", "fieldname": "import_ref_rate",
@ -113,6 +137,26 @@
"print_hide": 0, "print_hide": 0,
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break3",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "purchase_ref_rate",
"fieldtype": "Currency",
"in_list_view": 0,
"label": "Price List Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "sec_break2",
"fieldtype": "Section Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "import_rate", "fieldname": "import_rate",
@ -140,13 +184,8 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "purchase_ref_rate", "fieldname": "col_break4",
"fieldtype": "Currency", "fieldtype": "Column Break"
"in_list_view": 0,
"label": "Price List Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -158,7 +197,7 @@
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1, "print_hide": 1,
"read_only": 0, "read_only": 1,
"reqd": 1 "reqd": 1
}, },
{ {
@ -196,6 +235,11 @@
"reqd": 0, "reqd": 0,
"width": "120px" "width": "120px"
}, },
{
"doctype": "DocField",
"fieldname": "col_break5",
"fieldtype": "Column Break"
},
{ {
"default": ":Company", "default": ":Company",
"doctype": "DocField", "doctype": "DocField",
@ -257,6 +301,52 @@
"read_only": 1, "read_only": 1,
"search_index": 1 "search_index": 1
}, },
{
"description": "Tax detail table fetched from item master as a string and stored in this field.\nUsed for Taxes and Charges",
"doctype": "DocField",
"fieldname": "item_tax_rate",
"fieldtype": "Small Text",
"hidden": 1,
"in_list_view": 0,
"label": "Item Tax Rate",
"oldfieldname": "item_tax_rate",
"oldfieldtype": "Small Text",
"print_hide": 1,
"read_only": 1,
"report_hide": 1
},
{
"doctype": "DocField",
"fieldname": "item_tax_amount",
"fieldtype": "Currency",
"hidden": 1,
"in_list_view": 0,
"label": "Item Tax Amount",
"no_copy": 1,
"options": "Company:company:default_currency",
"print_hide": 1,
"print_width": "150px",
"read_only": 1,
"search_index": 0,
"width": "150px"
},
{
"allow_on_submit": 1,
"doctype": "DocField",
"fieldname": "page_break",
"fieldtype": "Check",
"in_list_view": 0,
"label": "Page Break",
"no_copy": 1,
"print_hide": 1,
"read_only": 0,
"report_hide": 1
},
{
"doctype": "DocField",
"fieldname": "col_break6",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "purchase_order", "fieldname": "purchase_order",
@ -317,35 +407,6 @@
"read_only": 1, "read_only": 1,
"search_index": 1 "search_index": 1
}, },
{
"description": "Tax detail table fetched from item master as a string and stored in this field.\nUsed for Taxes and Charges",
"doctype": "DocField",
"fieldname": "item_tax_rate",
"fieldtype": "Small Text",
"hidden": 1,
"in_list_view": 0,
"label": "Item Tax Rate",
"oldfieldname": "item_tax_rate",
"oldfieldtype": "Small Text",
"print_hide": 1,
"read_only": 1,
"report_hide": 1
},
{
"doctype": "DocField",
"fieldname": "item_tax_amount",
"fieldtype": "Currency",
"hidden": 1,
"in_list_view": 0,
"label": "Item Tax Amount",
"no_copy": 1,
"options": "Company:company:default_currency",
"print_hide": 1,
"print_width": "150px",
"read_only": 1,
"search_index": 0,
"width": "150px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "valuation_rate", "fieldname": "valuation_rate",
@ -358,15 +419,6 @@
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1
}, },
{
"doctype": "DocField",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"in_list_view": 0,
"label": "Conversion Factor",
"print_hide": 1,
"read_only": 0
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "rm_supp_cost", "fieldname": "rm_supp_cost",
@ -378,17 +430,5 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1
},
{
"allow_on_submit": 1,
"doctype": "DocField",
"fieldname": "page_break",
"fieldtype": "Check",
"in_list_view": 0,
"label": "Page Break",
"no_copy": 1,
"print_hide": 1,
"read_only": 0,
"report_hide": 1
} }
] ]

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-05-21 16:16:04", "creation": "2013-05-21 16:16:04",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:38", "modified": "2014-02-03 12:36:04",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -31,7 +31,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "category", "fieldname": "category",
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1, "in_list_view": 0,
"label": "Consider Tax or Charge for", "label": "Consider Tax or Charge for",
"oldfieldname": "category", "oldfieldname": "category",
"oldfieldtype": "Select", "oldfieldtype": "Select",
@ -39,6 +39,18 @@
"read_only": 0, "read_only": 0,
"reqd": 1 "reqd": 1
}, },
{
"default": "Add",
"doctype": "DocField",
"fieldname": "add_deduct_tax",
"fieldtype": "Select",
"label": "Add or Deduct",
"oldfieldname": "add_deduct_tax",
"oldfieldtype": "Select",
"options": "Add\nDeduct",
"read_only": 0,
"reqd": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "charge_type", "fieldname": "charge_type",
@ -53,26 +65,12 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "account_head", "fieldname": "row_id",
"fieldtype": "Link", "fieldtype": "Data",
"in_list_view": 1, "hidden": 0,
"label": "Account Head", "label": "Enter Row",
"oldfieldname": "account_head", "oldfieldname": "row_id",
"oldfieldtype": "Link", "oldfieldtype": "Data",
"options": "Account",
"read_only": 0,
"reqd": 1
},
{
"default": ":Company",
"doctype": "DocField",
"fieldname": "cost_center",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Cost Center",
"oldfieldname": "cost_center",
"oldfieldtype": "Link",
"options": "Cost Center",
"read_only": 0 "read_only": 0
}, },
{ {
@ -88,6 +86,35 @@
"reqd": 1, "reqd": 1,
"width": "300px" "width": "300px"
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "account_head",
"fieldtype": "Link",
"in_list_view": 0,
"label": "Account Head",
"oldfieldname": "account_head",
"oldfieldtype": "Link",
"options": "Account",
"read_only": 0,
"reqd": 1
},
{
"default": ":Company",
"doctype": "DocField",
"fieldname": "cost_center",
"fieldtype": "Link",
"in_list_view": 0,
"label": "Cost Center",
"oldfieldname": "cost_center",
"oldfieldtype": "Link",
"options": "Cost Center",
"read_only": 0
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "rate", "fieldname": "rate",
@ -103,6 +130,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "tax_amount", "fieldname": "tax_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1,
"label": "Amount", "label": "Amount",
"oldfieldname": "tax_amount", "oldfieldname": "tax_amount",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
@ -120,28 +148,6 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1 "read_only": 1
}, },
{
"doctype": "DocField",
"fieldname": "row_id",
"fieldtype": "Data",
"hidden": 0,
"label": "Enter Row",
"oldfieldname": "row_id",
"oldfieldtype": "Data",
"read_only": 0
},
{
"default": "Add",
"doctype": "DocField",
"fieldname": "add_deduct_tax",
"fieldtype": "Select",
"label": "Add or Deduct",
"oldfieldname": "add_deduct_tax",
"oldfieldtype": "Select",
"options": "Add\nDeduct",
"read_only": 0,
"reqd": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "item_wise_tax_detail", "fieldname": "item_wise_tax_detail",

View File

@ -155,6 +155,19 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
} }
}, },
customer: function() {
if(this.frm.updating_party_details)
return;
erpnext.selling.get_party_details(this.frm,
"erpnext.accounts.party.get_party_details", {
posting_date: this.frm.doc.posting_date,
company: this.frm.doc.company,
party: this.frm.doc.customer,
party_type: "Customer",
account: this.frm.doc.debit_to
})
},
debit_to: function() { debit_to: function() {
this.customer(); this.customer();
}, },

View File

@ -8,13 +8,14 @@ import webnotes.defaults
from webnotes.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, \ from webnotes.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, \
get_first_day, get_last_day get_first_day, get_last_day
from webnotes.utils.email_lib import sendmail
from webnotes.utils import comma_and, get_url from webnotes.utils import comma_and, get_url
from webnotes.model.doc import make_autoname from webnotes.model.doc import make_autoname
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
from webnotes import _, msgprint from webnotes import _, msgprint
from erpnext.accounts.party import get_party_account, get_due_date
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
from erpnext.controllers.selling_controller import SellingController from erpnext.controllers.selling_controller import SellingController
@ -149,23 +150,13 @@ class DocType(SellingController):
self.set_pos_fields(for_validate) self.set_pos_fields(for_validate)
if not self.doc.debit_to: if not self.doc.debit_to:
self.doc.debit_to = self.get_customer_account() self.doc.debit_to = get_party_account(self.doc.company, self.doc.customer, "Customer")
if not self.doc.due_date: if not self.doc.due_date:
self.doc.due_date = self.get_due_date() self.doc.due_date = get_due_date(self.doc.posting_date, self.doc.customer, "Customer",
self.doc.debit_to, self.doc.company)
super(DocType, self).set_missing_values(for_validate) super(DocType, self).set_missing_values(for_validate)
def set_customer_defaults(self):
# TODO cleanup these methods
if self.doc.customer:
self.doc.debit_to = self.get_customer_account()
elif self.doc.debit_to:
self.doc.customer = webnotes.conn.get_value('Account', self.doc.debit_to, 'master_name')
self.doc.due_date = self.get_due_date()
super(DocType, self).set_customer_defaults()
def update_time_log_batch(self, sales_invoice): def update_time_log_batch(self, sales_invoice):
for d in self.doclist.get({"doctype":"Sales Invoice Item"}): for d in self.doclist.get({"doctype":"Sales Invoice Item"}):
if d.time_log_batch: if d.time_log_batch:
@ -192,7 +183,7 @@ class DocType(SellingController):
if pos: if pos:
if not for_validate and not self.doc.customer: if not for_validate and not self.doc.customer:
self.doc.customer = pos.customer self.doc.customer = pos.customer
self.set_customer_defaults() # self.set_customer_defaults()
for fieldname in ('territory', 'naming_series', 'currency', 'taxes_and_charges', 'letter_head', 'tc_name', for fieldname in ('territory', 'naming_series', 'currency', 'taxes_and_charges', 'letter_head', 'tc_name',
'selling_price_list', 'company', 'select_print_heading', 'cash_bank_account'): 'selling_price_list', 'company', 'select_print_heading', 'cash_bank_account'):
@ -214,46 +205,8 @@ class DocType(SellingController):
self.doc.terms = webnotes.conn.get_value("Terms and Conditions", self.doc.tc_name, "terms") self.doc.terms = webnotes.conn.get_value("Terms and Conditions", self.doc.tc_name, "terms")
# fetch charges # fetch charges
if self.doc.taxes_and_charges and not len(self.doclist.get({"parentfield": "other_charges"})): if self.doc.charge and not len(self.doclist.get({"parentfield": "other_charges"})):
self.set_taxes("other_charges", "taxes_and_charges") self.set_taxes("other_charges", "taxes_and_charges")
def get_customer_account(self):
"""Get Account Head to which amount needs to be Debited based on Customer"""
if not self.doc.company:
msgprint("Please select company first and re-select the customer after doing so",
raise_exception=1)
if self.doc.customer:
acc_head = webnotes.conn.sql("""select name from `tabAccount`
where (name = %s or (master_name = %s and master_type = 'customer'))
and docstatus != 2 and company = %s""",
(cstr(self.doc.customer) + " - " + self.get_company_abbr(),
self.doc.customer, self.doc.company))
if acc_head and acc_head[0][0]:
return acc_head[0][0]
else:
msgprint("%s does not have an Account Head in %s. \
You must first create it from the Customer Master" %
(self.doc.customer, self.doc.company))
def get_due_date(self):
"""Set Due Date = Posting Date + Credit Days"""
due_date = None
if self.doc.posting_date:
credit_days = 0
if self.doc.debit_to:
credit_days = webnotes.conn.get_value("Account", self.doc.debit_to, "credit_days")
if self.doc.customer and not credit_days:
credit_days = webnotes.conn.get_value("Customer", self.doc.customer, "credit_days")
if self.doc.company and not credit_days:
credit_days = webnotes.conn.get_value("Company", self.doc.company, "credit_days")
if credit_days:
due_date = add_days(self.doc.posting_date, credit_days)
else:
due_date = self.doc.posting_date
return due_date
def get_advances(self): def get_advances(self):
super(DocType, self).get_advances(self.doc.debit_to, super(DocType, self).get_advances(self.doc.debit_to,
@ -735,7 +688,7 @@ def manage_recurring_invoices(next_date=None, commit=True):
webnotes.conn.begin() webnotes.conn.begin()
webnotes.conn.sql("update `tabSales Invoice` set \ webnotes.conn.sql("update `tabSales Invoice` set \
convert_into_recurring_invoice = 0 where name = %s", ref_invoice) convert_into_recurring_invoice = 0 where name = %s", ref_invoice)
notify_errors(ref_invoice, ref_wrapper.doc.owner) notify_errors(ref_invoice, ref_wrapper.doc.customer, ref_wrapper.doc.owner)
webnotes.conn.commit() webnotes.conn.commit()
exception_list.append(webnotes.get_traceback()) exception_list.append(webnotes.get_traceback())
@ -784,101 +737,23 @@ def make_new_invoice(ref_wrapper, posting_date):
def send_notification(new_rv): def send_notification(new_rv):
"""Notify concerned persons about recurring invoice generation""" """Notify concerned persons about recurring invoice generation"""
subject = "Invoice : " + new_rv.doc.name
com = new_rv.doc.company
hd = '''<div><h2>%s</h2></div>
<div><h3>Invoice: %s</h3></div>
<table cellspacing= "5" cellpadding="5" width = "100%%">
<tr>
<td width = "50%%"><b>Customer</b><br>%s<br>%s</td>
<td width = "50%%">Invoice Date : %s<br>Invoice Period : %s to %s <br>Due Date : %s</td>
</tr>
</table>
''' % (com, new_rv.doc.name, new_rv.doc.customer_name, new_rv.doc.address_display, getdate(new_rv.doc.posting_date).strftime("%d-%m-%Y"), \
getdate(new_rv.doc.invoice_period_from_date).strftime("%d-%m-%Y"), getdate(new_rv.doc.invoice_period_to_date).strftime("%d-%m-%Y"),\
getdate(new_rv.doc.due_date).strftime("%d-%m-%Y"))
from webnotes.core.doctype.print_format.print_format import get_html
tbl = '''<table border="1px solid #CCC" width="100%%" cellpadding="0px" cellspacing="0px"> webnotes.sendmail(new_rv.doc.notification_email_address,
<tr> subject="New Invoice : " + new_rv.doc.name,
<td width = "15%%" bgcolor="#CCC" align="left"><b>Item</b></td> message = get_html(new_rv.doc, new_rv.doclist, "SalesInvoice"))
<td width = "40%%" bgcolor="#CCC" align="left"><b>Description</b></td>
<td width = "15%%" bgcolor="#CCC" align="center"><b>Qty</b></td>
<td width = "15%%" bgcolor="#CCC" align="center"><b>Rate</b></td>
<td width = "15%%" bgcolor="#CCC" align="center"><b>Amount</b></td>
</tr>
'''
for d in getlist(new_rv.doclist, 'entries'):
tbl += '<tr><td>' + cstr(d.item_code) +'</td><td>' + cstr(d.description) + \
'</td><td>' + cstr(d.qty) +'</td><td>' + cstr(d.basic_rate) + \
'</td><td>' + cstr(d.amount) +'</td></tr>'
tbl += '</table>'
totals ='''<table cellspacing= "5" cellpadding="5" width = "100%%">
<tr>
<td width = "50%%"></td>
<td width = "50%%">
<table width = "100%%">
<tr>
<td width = "50%%">Net Total: </td><td>%s </td>
</tr><tr>
<td width = "50%%">Total Tax: </td><td>%s </td>
</tr><tr>
<td width = "50%%">Grand Total: </td><td>%s</td>
</tr><tr>
<td width = "50%%">In Words: </td><td>%s</td>
</tr>
</table>
</td>
</tr>
<tr><td>Terms and Conditions:</td></tr>
<tr><td>%s</td></tr>
</table>
''' % (new_rv.doc.net_total,
new_rv.doc.other_charges_total,new_rv.doc.grand_total,
new_rv.doc.in_words,new_rv.doc.terms)
msg = hd + tbl + totals
sendmail(new_rv.doc.notification_email_address, subject=subject, msg = msg)
def notify_errors(inv, owner): def notify_errors(inv, customer, owner):
import webnotes
exception_msg = """
Dear User,
An error occured while creating recurring invoice from %s (at %s).
May be there are some invalid email ids mentioned in the invoice.
To stop sending repetitive error notifications from the system, we have unchecked
"Convert into Recurring" field in the invoice %s.
Please correct the invoice and make the invoice recurring again.
<b>It is necessary to take this action today itself for the above mentioned recurring invoice \
to be generated. If delayed, you will have to manually change the "Repeat on Day of Month" field \
of this invoice for generating the recurring invoice.</b>
Regards,
Administrator
""" % (inv, get_url(), inv)
subj = "[Urgent] Error while creating recurring invoice from %s" % inv
from webnotes.profile import get_system_managers from webnotes.profile import get_system_managers
recipients = get_system_managers()
owner_email = webnotes.conn.get_value("Profile", owner, "email") webnotes.sendmail(recipients=get_system_managers() + [webnotes.conn.get_value("Profile", owner, "email")],
if not owner_email in recipients: subject="[Urgent] Error while creating recurring invoice for %s" % inv,
recipients.append(owner_email) message = webnotes.get_template("template/emails/recurring_invoice_failed.html").render({
"name": inv,
assign_task_to_owner(inv, exception_msg, recipients) "customer": customer
sendmail(recipients, subject=subj, msg = exception_msg) })
assign_task_to_owner(inv, "Recurring Invoice Failed", recipients)
def assign_task_to_owner(inv, msg, users): def assign_task_to_owner(inv, msg, users):
for d in users: for d in users:

View File

@ -756,7 +756,7 @@ class TestSalesInvoice(unittest.TestCase):
def _test_recurring_invoice(self, base_si, first_and_last_day): def _test_recurring_invoice(self, base_si, first_and_last_day):
from webnotes.utils import add_months, get_last_day from webnotes.utils import add_months, get_last_day
from accounts.doctype.sales_invoice.sales_invoice \ from erpnext.accounts.doctype.sales_invoice.sales_invoice \
import manage_recurring_invoices, get_next_date import manage_recurring_invoices, get_next_date
no_of_months = ({"Monthly": 1, "Quarterly": 3, "Yearly": 12})[base_si.doc.recurring_type] no_of_months = ({"Monthly": 1, "Quarterly": 3, "Yearly": 12})[base_si.doc.recurring_type]
@ -764,10 +764,10 @@ class TestSalesInvoice(unittest.TestCase):
def _test(i): def _test(i):
self.assertEquals(i+1, webnotes.conn.sql("""select count(*) from `tabSales Invoice` self.assertEquals(i+1, webnotes.conn.sql("""select count(*) from `tabSales Invoice`
where recurring_id=%s and docstatus=1""", base_si.doc.recurring_id)[0][0]) where recurring_id=%s and docstatus=1""", base_si.doc.recurring_id)[0][0])
next_date = get_next_date(base_si.doc.posting_date, no_of_months, next_date = get_next_date(base_si.doc.posting_date, no_of_months,
base_si.doc.repeat_on_day_of_month) base_si.doc.repeat_on_day_of_month)
manage_recurring_invoices(next_date=next_date, commit=False) manage_recurring_invoices(next_date=next_date, commit=False)
recurred_invoices = webnotes.conn.sql("""select name from `tabSales Invoice` recurred_invoices = webnotes.conn.sql("""select name from `tabSales Invoice`

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:27:41", "creation": "2013-02-22 01:27:41",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-31 18:29:19", "modified": "2014-02-03 12:38:53",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -38,38 +38,6 @@
"read_only": 1, "read_only": 1,
"width": "250px" "width": "250px"
}, },
{
"doctype": "DocField",
"fieldname": "advance_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Advance amount",
"no_copy": 1,
"oldfieldname": "advance_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"print_width": "120px",
"read_only": 1,
"width": "120px"
},
{
"doctype": "DocField",
"fieldname": "allocated_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Allocated amount",
"no_copy": 1,
"oldfieldname": "allocated_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"print_width": "120px",
"width": "120px"
},
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "remarks", "fieldname": "remarks",
@ -97,5 +65,37 @@
"print_width": "120px", "print_width": "120px",
"read_only": 1, "read_only": 1,
"width": "120px" "width": "120px"
},
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "advance_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Advance amount",
"no_copy": 1,
"oldfieldname": "advance_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"print_width": "120px",
"read_only": 1,
"width": "120px"
},
{
"doctype": "DocField",
"fieldname": "allocated_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Allocated amount",
"no_copy": 1,
"oldfieldname": "allocated_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"print_width": "120px",
"width": "120px"
} }
] ]

85
erpnext/accounts/party.py Normal file
View File

@ -0,0 +1,85 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
from webnotes import _
@webnotes.whitelist()
def get_party_details(party=None, account=None, party_type="Customer", company=None, posting_date=None):
if not webnotes.has_permission(party_type, "read", party):
webnotes.throw("No Permission")
if party_type=="Customer":
get_party_details = webnotes.get_attr("erpnext.selling.doctype.customer.customer.get_customer_details")
else:
get_party_details = webnotes.get_attr("erpnext.buying.doctype.supplier.supplier.get_supplier_details")
if party:
account = get_party_account(company, party, party_type)
elif account:
party = webnotes.conn.get_value('Account', account, 'master_name')
account_fieldname = "debit_to" if party_type=="Customer" else "credit_to"
out = {
party_type.lower(): party,
account_fieldname : account,
"due_date": get_due_date(posting_date, party, party_type, account, company)
}
out.update(get_party_details(party))
return out
def get_party_account(company, party, party_type):
if not company:
webnotes.throw(_("Please select company first."))
if party:
acc_head = webnotes.conn.get_value("Account", {"master_name":party,
"master_type": party_type, "company": company})
if not acc_head:
create_party_account(party, party_type, company)
return acc_head
def get_due_date(posting_date, party, party_type, account, company):
"""Set Due Date = Posting Date + Credit Days"""
due_date = None
if posting_date:
credit_days = 0
if account:
credit_days = webnotes.conn.get_value("Account", account, "credit_days")
if party and not credit_days:
credit_days = webnotes.conn.get_value(party_type, party, "credit_days")
if company and not credit_days:
credit_days = webnotes.conn.get_value("Company", company, "credit_days")
due_date = add_days(posting_date, credit_days) if credit_days else posting_date
return due_date
def create_party_account(party, party_type, company):
if not company:
webnotes.throw(_("Company is required"))
company_details = webnotes.conn.get_value("Company", company,
["abbr", "receivables_group", "payables_group"], as_dict=True)
if not webnotes.conn.exists("Account", (party + " - " + company_details.abbr)):
parent_account = company_details.receivables_group \
if party_type=="Customer" else company_details.payables_group
# create
account = webnotes.bean({
"doctype": "Account",
'account_name': party,
'parent_account': parent_account,
'group_or_ledger':'Ledger',
'company': company,
'master_type': party_type,
'master_name': party,
"freeze_account": "No"
}).insert(ignore_permissions=True)
webnotes.msgprint(_("Account Created") + ": " + account.doc.name)

View File

@ -62,43 +62,11 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}, },
supplier: function() { supplier: function() {
var me = this; erpnext.utils.get_party_details(this.frm);
if(this.frm.doc.supplier || this.frm.doc.credit_to) {
if(!this.frm.doc.company) {
this.frm.set_value("supplier", null);
msgprint(wn._("Please specify Company"));
} else {
var buying_price_list = this.frm.doc.buying_price_list;
return this.frm.call({
doc: this.frm.doc,
method: "set_supplier_defaults",
freeze: true,
callback: function(r) {
if(!r.exc) {
if(me.frm.doc.buying_price_list !== buying_price_list) me.buying_price_list();
if (me.frm.doc.taxes_and_charges)
me.frm.script_manager.trigger("taxes_and_charges")
}
}
});
}
}
}, },
supplier_address: function() { supplier_address: function() {
var me = this; erpnext.utils.get_address_display(this.frm);
if (this.frm.doc.supplier) {
return wn.call({
doc: this.frm.doc,
method: "set_supplier_address",
freeze: true,
args: {
supplier: this.frm.doc.supplier,
address: this.frm.doc.supplier_address,
contact: this.frm.doc.contact_person
},
});
}
}, },
contact_person: function() { contact_person: function() {
@ -478,4 +446,4 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}); });
var tname = cur_frm.cscript.tname; var tname = cur_frm.cscript.tname;
var fname = cur_frm.cscript.fname; var fname = cur_frm.cscript.fname;

View File

@ -225,7 +225,6 @@ def make_purchase_invoice(source_name, target_doclist=None):
def set_missing_values(source, target): def set_missing_values(source, target):
bean = webnotes.bean(target) bean = webnotes.bean(target)
bean.run_method("set_missing_values") bean.run_method("set_missing_values")
bean.run_method("set_supplier_defaults")
def update_item(obj, target, source_parent): def update_item(obj, target, source_parent):
target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt) target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt)

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-05-24 19:29:06", "creation": "2013-05-24 19:29:06",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:32", "modified": "2014-02-03 12:08:21",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -40,22 +40,6 @@
"reqd": 1, "reqd": 1,
"search_index": 1 "search_index": 1
}, },
{
"doctype": "DocField",
"fieldname": "schedule_date",
"fieldtype": "Date",
"hidden": 0,
"in_filter": 1,
"in_list_view": 0,
"label": "Reqd By Date",
"no_copy": 0,
"oldfieldname": "schedule_date",
"oldfieldtype": "Date",
"print_hide": 1,
"read_only": 0,
"reqd": 1,
"search_index": 1
},
{ {
"description": "If Supplier Part Number exists for given Item, it gets stored here", "description": "If Supplier Part Number exists for given Item, it gets stored here",
"doctype": "DocField", "doctype": "DocField",
@ -84,10 +68,24 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "quantity_and_rate", "fieldname": "schedule_date",
"fieldtype": "Section Break", "fieldtype": "Date",
"hidden": 0,
"in_filter": 1,
"in_list_view": 0, "in_list_view": 0,
"label": "Quantity and Rate" "label": "Reqd By Date",
"no_copy": 0,
"oldfieldname": "schedule_date",
"oldfieldtype": "Date",
"print_hide": 1,
"read_only": 0,
"reqd": 1,
"search_index": 1
},
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -102,6 +100,13 @@
"reqd": 1, "reqd": 1,
"width": "300px" "width": "300px"
}, },
{
"doctype": "DocField",
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"in_list_view": 0,
"label": "Quantity and Rate"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "qty", "fieldname": "qty",
@ -130,6 +135,47 @@
"reqd": 1, "reqd": 1,
"width": "100px" "width": "100px"
}, },
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "stock_uom",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 0,
"label": "Stock UOM",
"oldfieldname": "stock_uom",
"oldfieldtype": "Data",
"options": "UOM",
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 1,
"width": "100px"
},
{
"doctype": "DocField",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"hidden": 0,
"in_list_view": 0,
"label": "UOM Conversion Factor",
"oldfieldname": "conversion_factor",
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
{
"doctype": "DocField",
"fieldname": "sec_break1",
"fieldtype": "Section Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "import_ref_rate", "fieldname": "import_ref_rate",
@ -149,6 +195,26 @@
"print_hide": 0, "print_hide": 0,
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break3",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "purchase_ref_rate",
"fieldtype": "Currency",
"in_list_view": 0,
"label": "Price List Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "sec_break2",
"fieldtype": "Section Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "import_rate", "fieldname": "import_rate",
@ -175,13 +241,8 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "purchase_ref_rate", "fieldname": "col_break4",
"fieldtype": "Currency", "fieldtype": "Column Break"
"in_list_view": 0,
"label": "Price List Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -194,7 +255,7 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1, "print_hide": 1,
"print_width": "100px", "print_width": "100px",
"read_only": 0, "read_only": 1,
"reqd": 1, "reqd": 1,
"width": "100px" "width": "100px"
}, },
@ -244,37 +305,6 @@
"read_only": 0, "read_only": 0,
"report_hide": 0 "report_hide": 0
}, },
{
"doctype": "DocField",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"hidden": 0,
"in_list_view": 0,
"label": "UOM Conversion Factor",
"oldfieldname": "conversion_factor",
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
{
"doctype": "DocField",
"fieldname": "stock_uom",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 0,
"label": "Stock UOM",
"oldfieldname": "stock_uom",
"oldfieldtype": "Data",
"options": "UOM",
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 1,
"width": "100px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "prevdoc_doctype", "fieldname": "prevdoc_doctype",
@ -325,9 +355,9 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "supplier_quotation", "fieldname": "supplier_quotation",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 1, "hidden": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 0,
"label": "Supplier Quotation", "label": "Supplier Quotation",
"no_copy": 1, "no_copy": 1,
"options": "Supplier Quotation", "options": "Supplier Quotation",
@ -347,16 +377,8 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "brand", "fieldname": "col_break5",
"fieldtype": "Link", "fieldtype": "Column Break"
"hidden": 1,
"in_list_view": 1,
"label": "Brand",
"oldfieldname": "brand",
"oldfieldtype": "Link",
"options": "Brand",
"print_hide": 1,
"read_only": 1
}, },
{ {
"description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>",
@ -374,13 +396,26 @@
"read_only": 1, "read_only": 1,
"search_index": 0 "search_index": 0
}, },
{
"doctype": "DocField",
"fieldname": "brand",
"fieldtype": "Link",
"hidden": 1,
"in_list_view": 1,
"label": "Brand",
"oldfieldname": "brand",
"oldfieldtype": "Link",
"options": "Brand",
"print_hide": 1,
"read_only": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "stock_qty", "fieldname": "stock_qty",
"fieldtype": "Float", "fieldtype": "Float",
"hidden": 0, "hidden": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Stock Qty", "label": "Qty as per Stock UOM",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "stock_qty", "oldfieldname": "stock_qty",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",

View File

@ -8,7 +8,7 @@ import webnotes.defaults
from webnotes.utils import cint from webnotes.utils import cint
from webnotes import msgprint, _ from webnotes import msgprint, _
from webnotes.model.doc import make_autoname from webnotes.model.doc import make_autoname
from erpnext.accounts.party import create_party_account
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
@ -47,88 +47,20 @@ class DocType(TransactionBase):
self.update_contact() self.update_contact()
# create account head # create account head
self.create_account_head() create_party_account(self.doc.name, "Supplier", self.doc.company)
# update credit days and limit in account # update credit days and limit in account
self.update_credit_days_limit() self.update_credit_days_limit()
def get_payables_group(self):
g = webnotes.conn.sql("select payables_group from tabCompany where name=%s", self.doc.company)
g = g and g[0][0] or ''
if not g:
msgprint("Update Company master, assign a default group for Payables")
raise Exception
return g
def add_account(self, ac, par, abbr):
ac_bean = webnotes.bean({
"doctype": "Account",
'account_name':ac,
'parent_account':par,
'group_or_ledger':'Group',
'company':self.doc.company,
"freeze_account": "No",
})
ac_bean.ignore_permissions = True
ac_bean.insert()
msgprint(_("Created Group ") + ac)
def get_company_abbr(self): def get_company_abbr(self):
return webnotes.conn.sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0] return webnotes.conn.sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
def get_parent_account(self, abbr):
if (not self.doc.supplier_type):
msgprint("Supplier Type is mandatory")
raise Exception
if not webnotes.conn.sql("select name from tabAccount where name=%s and debit_or_credit = 'Credit' and ifnull(is_pl_account, 'No') = 'No'", (self.doc.supplier_type + " - " + abbr)):
# if not group created , create it
self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr)
return self.doc.supplier_type + " - " + abbr
def validate(self): def validate(self):
#validation for Naming Series mandatory field... #validation for Naming Series mandatory field...
if webnotes.defaults.get_global_default('supp_master_name') == 'Naming Series': if webnotes.defaults.get_global_default('supp_master_name') == 'Naming Series':
if not self.doc.naming_series: if not self.doc.naming_series:
msgprint("Series is Mandatory.", raise_exception=1) msgprint("Series is Mandatory.", raise_exception=1)
def create_account_head(self):
if self.doc.company :
abbr = self.get_company_abbr()
parent_account = self.get_parent_account(abbr)
if not webnotes.conn.sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
ac_bean = webnotes.bean({
"doctype": "Account",
'account_name': self.doc.name,
'parent_account': parent_account,
'group_or_ledger':'Ledger',
'company': self.doc.company,
'account_type': '',
'tax_rate': '0',
'master_type': 'Supplier',
'master_name': self.doc.name,
"freeze_account": "No"
})
ac_bean.ignore_permissions = True
ac_bean.insert()
msgprint(_("Created Account Head: ") + ac_bean.doc.name)
else:
self.check_parent_account(parent_account, abbr)
else :
msgprint("Please select Company under which you want to create account head")
def check_parent_account(self, parent_account, abbr):
if webnotes.conn.get_value("Account", self.doc.name + " - " + abbr,
"parent_account") != parent_account:
ac = webnotes.bean("Account", self.doc.name + " - " + abbr)
ac.doc.parent_account = parent_account
ac.save()
def get_contacts(self,nm): def get_contacts(self,nm):
if nm: if nm:
contact_details =webnotes.conn.convert_to_lists(webnotes.conn.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm)) contact_details =webnotes.conn.convert_to_lists(webnotes.conn.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
@ -194,4 +126,28 @@ def get_dashboard_info(supplier):
out["total_billing"] = billing[0][0] out["total_billing"] = billing[0][0]
out["total_unpaid"] = billing[0][1] out["total_unpaid"] = billing[0][1]
return out
@webnotes.whitelist()
def get_supplier_details(supplier, price_list=None, currency=None):
if not webnotes.has_permission("Supplier", "read", supplier):
webnotes.msgprint("No Permission", raise_exception=webnotes.PermissionError)
supplier = webnotes.doc("Supplier", supplier)
out = webnotes._dict({
"supplier_address": webnotes.conn.get_value("Address",
{"supplier": supplier.name, "is_primary_address":1}, "name"),
"contact_person": webnotes.conn.get_value("Contact",
{"supplier":supplier.name, "is_primary_contact":1}, "name")
})
for f in ['currency', 'taxes_and_charges']:
if supplier.fields.get("default_" + f):
out[f] = supplier.fields.get("default_" + f)
out.supplier_name = supplier.supplier_name
out.currency = supplier.default_currency or currency
out.buying_price_list = supplier.default_price_list or price_list
return out return out

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-05-22 12:43:10", "creation": "2013-05-22 12:43:10",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:21:50", "modified": "2014-02-03 11:47:21",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -66,6 +66,11 @@
"reqd": 1, "reqd": 1,
"search_index": 1 "search_index": 1
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "description", "fieldname": "description",
@ -99,21 +104,6 @@
"reqd": 1, "reqd": 1,
"width": "60px" "width": "60px"
}, },
{
"doctype": "DocField",
"fieldname": "uom",
"fieldtype": "Link",
"in_list_view": 0,
"label": "UOM",
"oldfieldname": "uom",
"oldfieldtype": "Link",
"options": "UOM",
"print_hide": 0,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "import_ref_rate", "fieldname": "import_ref_rate",
@ -133,6 +123,41 @@
"print_hide": 0, "print_hide": 0,
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "uom",
"fieldtype": "Link",
"in_list_view": 0,
"label": "UOM",
"oldfieldname": "uom",
"oldfieldtype": "Link",
"options": "UOM",
"print_hide": 0,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
{
"doctype": "DocField",
"fieldname": "purchase_ref_rate",
"fieldtype": "Currency",
"in_list_view": 0,
"label": "Price List Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "sec_break1",
"fieldtype": "Section Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "import_rate", "fieldname": "import_rate",
@ -159,13 +184,8 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "purchase_ref_rate", "fieldname": "col_break3",
"fieldtype": "Currency", "fieldtype": "Column Break"
"in_list_view": 0,
"label": "Price List Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -178,7 +198,7 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1, "print_hide": 1,
"print_width": "100px", "print_width": "100px",
"read_only": 0, "read_only": 1,
"reqd": 1, "reqd": 1,
"width": "100px" "width": "100px"
}, },
@ -259,6 +279,11 @@
"search_index": 1, "search_index": 1,
"width": "120px" "width": "120px"
}, },
{
"doctype": "DocField",
"fieldname": "col_break4",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "prevdoc_detail_docname", "fieldname": "prevdoc_detail_docname",
@ -278,7 +303,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "brand", "fieldname": "brand",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 1, "hidden": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Brand", "label": "Brand",
"oldfieldname": "brand", "oldfieldname": "brand",
@ -292,7 +317,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "item_group", "fieldname": "item_group",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 1, "hidden": 0,
"in_filter": 1, "in_filter": 1,
"in_list_view": 0, "in_list_view": 0,
"label": "Item Group", "label": "Item Group",

View File

@ -7,6 +7,7 @@ from webnotes import _, msgprint
from webnotes.utils import flt, _round from webnotes.utils import flt, _round
from erpnext.buying.utils import get_item_details from erpnext.buying.utils import get_item_details
from erpnext.setup.utils import get_company_currency from erpnext.setup.utils import get_company_currency
from erpnext.buying.doctype.supplier.supplier import get_supplier_details
from erpnext.controllers.stock_controller import StockController from erpnext.controllers.stock_controller import StockController
@ -31,10 +32,8 @@ class BuyingController(StockController):
self.set_price_list_currency("Buying") self.set_price_list_currency("Buying")
# set contact and address details for supplier, if they are not mentioned # set contact and address details for supplier, if they are not mentioned
if self.doc.supplier and not (self.doc.contact_person and self.doc.supplier_address): if self.doc.supplier:
for fieldname, val in self.get_supplier_defaults().items(): self.doc.update_if_missing(get_supplier_details(self.doc.supplier))
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
self.doc.fields[fieldname] = val
self.set_missing_item_details(get_item_details) self.set_missing_item_details(get_item_details)
if self.doc.fields.get("__islocal"): if self.doc.fields.get("__islocal"):

View File

@ -33,18 +33,12 @@ class SellingController(StockController):
self.set_taxes("other_charges", "taxes_and_charges") self.set_taxes("other_charges", "taxes_and_charges")
def set_missing_lead_customer_details(self): def set_missing_lead_customer_details(self):
from erpnext.selling.doctype.customer.customer import get_customer_details
if self.doc.customer: if self.doc.customer:
if not (self.doc.contact_person and self.doc.customer_address and self.doc.customer_name): self.doc.update_if_missing(get_customer_details(self.doc.customer))
for fieldname, val in self.get_customer_defaults().items():
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
self.doc.fields[fieldname] = val
elif self.doc.lead: elif self.doc.lead:
if not (self.doc.customer_address and self.doc.customer_name and \ self.doc.update_if_missing(self.get_lead_defaults())
self.doc.contact_display):
for fieldname, val in self.get_lead_defaults().items():
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
self.doc.fields[fieldname] = val
def set_price_list_and_item_details(self): def set_price_list_and_item_details(self):
self.set_price_list_currency("Selling") self.set_price_list_currency("Selling")

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:27:49", "creation": "2013-02-22 01:27:49",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:22:58", "modified": "2014-02-03 12:47:39",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -62,6 +62,28 @@
"search_index": 1, "search_index": 1,
"width": "150px" "width": "150px"
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "description",
"fieldtype": "Text",
"label": "Item Description",
"oldfieldname": "description",
"oldfieldtype": "Text",
"print_width": "250px",
"reqd": 0,
"width": "250px"
},
{
"doctype": "DocField",
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"label": "Quantity and Rate"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "qty", "fieldname": "qty",
@ -72,6 +94,19 @@
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"reqd": 1 "reqd": 1
}, },
{
"description": "See \"Rate Of Materials Based On\" in Costing Section",
"doctype": "DocField",
"fieldname": "rate",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Rate"
},
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "stock_uom", "fieldname": "stock_uom",
@ -84,14 +119,6 @@
"read_only": 1, "read_only": 1,
"reqd": 1 "reqd": 1
}, },
{
"description": "See \"Rate Of Materials Based On\" in Costing Section",
"doctype": "DocField",
"fieldname": "rate",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Rate"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "amount", "fieldname": "amount",
@ -113,17 +140,6 @@
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"print_hide": 1 "print_hide": 1
}, },
{
"doctype": "DocField",
"fieldname": "description",
"fieldtype": "Text",
"label": "Item Description",
"oldfieldname": "description",
"oldfieldtype": "Text",
"print_width": "250px",
"reqd": 0,
"width": "250px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "qty_consumed_per_unit", "fieldname": "qty_consumed_per_unit",

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:27:49", "creation": "2013-02-22 01:27:49",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:22:58", "modified": "2014-02-03 12:53:03",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -14,7 +14,6 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"in_list_view": 1,
"name": "__common__", "name": "__common__",
"parent": "BOM Operation", "parent": "BOM Operation",
"parentfield": "fields", "parentfield": "fields",
@ -29,6 +28,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "operation_no", "fieldname": "operation_no",
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1,
"label": "Operation No", "label": "Operation No",
"oldfieldname": "operation_no", "oldfieldname": "operation_no",
"oldfieldtype": "Data", "oldfieldtype": "Data",
@ -38,15 +38,22 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "opn_description", "fieldname": "opn_description",
"fieldtype": "Text", "fieldtype": "Text",
"in_list_view": 1,
"label": "Operation Description", "label": "Operation Description",
"oldfieldname": "opn_description", "oldfieldname": "opn_description",
"oldfieldtype": "Text", "oldfieldtype": "Text",
"reqd": 1 "reqd": 1
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "workstation", "fieldname": "workstation",
"fieldtype": "Link", "fieldtype": "Link",
"in_list_view": 1,
"label": "Workstation", "label": "Workstation",
"oldfieldname": "workstation", "oldfieldname": "workstation",
"oldfieldtype": "Link", "oldfieldtype": "Link",
@ -57,6 +64,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "hour_rate", "fieldname": "hour_rate",
"fieldtype": "Float", "fieldtype": "Float",
"in_list_view": 0,
"label": "Hour Rate", "label": "Hour Rate",
"oldfieldname": "hour_rate", "oldfieldname": "hour_rate",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
@ -66,6 +74,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "time_in_mins", "fieldname": "time_in_mins",
"fieldtype": "Float", "fieldtype": "Float",
"in_list_view": 0,
"label": "Operation Time (mins)", "label": "Operation Time (mins)",
"oldfieldname": "time_in_mins", "oldfieldname": "time_in_mins",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
@ -76,6 +85,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "operating_cost", "fieldname": "operating_cost",
"fieldtype": "Float", "fieldtype": "Float",
"in_list_view": 1,
"label": "Operating Cost", "label": "Operating Cost",
"oldfieldname": "operating_cost", "oldfieldname": "operating_cost",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",

View File

@ -11,6 +11,7 @@
"public/js/toolbar.js", "public/js/toolbar.js",
"public/js/feature_setup.js", "public/js/feature_setup.js",
"public/js/utils.js", "public/js/utils.js",
"public/js/queries.js" "public/js/queries.js",
"public/js/utils/party.js"
] ]
} }

View File

@ -0,0 +1,76 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
wn.provide("erpnext.utils");
erpnext.utils.get_party_details = function(frm, method, args) {
if(!method) {
if(frm.doc.customer) {
method = "erpnext.selling.doctype.customer.customer.get_customer_details";
var price_list_field = "selling_price_list";
} else {
method = "erpnext.buying.doctype.supplier.supplier.get_supplier_details";
var price_list_field = "buying_price_list";
}
}
if(!args) {
if(frm.doc.customer) {
args = {
customer: frm.doc.customer,
price_list: frm.doc.selling_price_list
};
} else {
args = {
supplier: frm.doc.supplier,
price_list: frm.doc.buying_price_list
};
}
args.currency = frm.doc.currency;
}
wn.call({
method: method,
args: args,
callback: function(r) {
if(r.message) {
frm.updating_party_details = true;
frm.set_value(r.message);
frm.updating_party_details = false;
}
}
});
}
erpnext.utils.get_address_display = function(frm, address_field) {
if(frm.updating_party_details) return;
if(!address_field) {
if(frm.doc.customer) {
address_field = "customer_address";
} else {
address_field = "supplier_address";
}
}
if(frm.doc[address_field]) {
wn.call({
method: "erpnext.utilities.doctype.address.address.get_address_display",
args: {address: frm.doc[address_field] },
callback: function(r) {
if(r.message)
frm.set_value("address_display", r.message)
}
})
}
}
erpnext.utils.get_contact_details = function(frm) {
if(frm.updating_party_details) return;
if(frm.doc[address_field]) {
wn.call({
method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
args: {contact: frm.doc.contact_person },
callback: function(r) {
if(r.message)
frm.set_value(r.message);
}
})
}
}

View File

@ -3,13 +3,16 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr
from webnotes.model.doc import Document, make_autoname from webnotes.model.doc import Document, make_autoname
from webnotes import msgprint, _ from webnotes import msgprint, _
import webnotes.defaults import webnotes.defaults
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
from erpnext.utilities.doctype.address.address import get_address_display
from erpnext.utilities.doctype.contact.contact import get_contact_details
from erpnext.accounts.party import create_party_account
class DocType(TransactionBase): class DocType(TransactionBase):
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
@ -27,14 +30,6 @@ class DocType(TransactionBase):
def get_company_abbr(self): def get_company_abbr(self):
return webnotes.conn.get_value('Company', self.doc.company, 'abbr') return webnotes.conn.get_value('Company', self.doc.company, 'abbr')
def get_receivables_group(self):
g = webnotes.conn.sql("select receivables_group from tabCompany where name=%s", self.doc.company)
g = g and g[0][0] or ''
if not g:
msgprint("Update Company master, assign a default group for Receivables")
raise Exception
return g
def validate_values(self): def validate_values(self):
if webnotes.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.doc.naming_series: if webnotes.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.doc.naming_series:
@ -55,29 +50,6 @@ class DocType(TransactionBase):
webnotes.conn.sql("""update `tabContact` set customer_name=%s, modified=NOW() webnotes.conn.sql("""update `tabContact` set customer_name=%s, modified=NOW()
where customer=%s""", (self.doc.customer_name, self.doc.name)) where customer=%s""", (self.doc.customer_name, self.doc.name))
def create_account_head(self):
if self.doc.company :
abbr = self.get_company_abbr()
if not webnotes.conn.exists("Account", (self.doc.name + " - " + abbr)):
parent_account = self.get_receivables_group()
# create
ac_bean = webnotes.bean({
"doctype": "Account",
'account_name': self.doc.name,
'parent_account': parent_account,
'group_or_ledger':'Ledger',
'company':self.doc.company,
'master_type':'Customer',
'master_name':self.doc.name,
"freeze_account": "No"
})
ac_bean.ignore_permissions = True
ac_bean.insert()
msgprint(_("Account Head") + ": " + ac_bean.doc.name + _(" created"))
else :
msgprint(_("Please Select Company under which you want to create account head"))
def update_credit_days_limit(self): def update_credit_days_limit(self):
webnotes.conn.sql("""update tabAccount set credit_days = %s, credit_limit = %s webnotes.conn.sql("""update tabAccount set credit_days = %s, credit_limit = %s
where master_type='Customer' and master_name = %s""", where master_type='Customer' and master_name = %s""",
@ -111,7 +83,8 @@ class DocType(TransactionBase):
self.update_contact() self.update_contact()
# create account head # create account head
self.create_account_head() create_party_account(self.doc.name, "Customer", self.doc.company)
# update credit days and limit in account # update credit days and limit in account
self.update_credit_days_limit() self.update_credit_days_limit()
#create address and contact from lead #create address and contact from lead
@ -189,4 +162,59 @@ def get_dashboard_info(customer):
out["total_billing"] = billing[0][0] out["total_billing"] = billing[0][0]
out["total_unpaid"] = billing[0][1] out["total_unpaid"] = billing[0][1]
return out
@webnotes.whitelist()
def get_customer_details(customer, price_list=None, currency=None):
if not webnotes.has_permission("Customer", "read", customer):
webnotes.throw("Not Permitted", webnotes.PermissionError)
out = {}
customer_bean = webnotes.bean("Customer", customer)
customer = customer_bean.doc
out = webnotes._dict({
"customer_address": webnotes.conn.get_value("Address",
{"customer": customer.name, "is_primary_address":1}, "name"),
"contact_person": webnotes.conn.get_value("Contact",
{"customer":customer.name, "is_primary_contact":1}, "name")
})
# address display
out.address_display = get_address_display(out.customer_address)
# primary contact details
out.update(get_contact_details(out.contact_person))
# copy
for f in ['customer_name', 'customer_group', 'territory']:
out[f] = customer.get(f)
# fields prepended with default in Customer doctype
for f in ['sales_partner', 'commission_rate', 'currency', 'price_list', 'taxes_and_charges']:
if customer.get("default_" + f):
out[f] = customer.get("default_" + f)
# price list
from webnotes.defaults import get_defaults_for
out.selling_price_list = get_defaults_for(webnotes.session.user).get(price_list)
if isinstance(out.selling_price_list, list):
out.selling_price_list = None
out.selling_price_list = out.selling_price_list or customer.price_list \
or webnotes.conn.get_value("Customer Group",
customer.customer_group, "default_price_list") or price_list
if out.selling_price_list:
out.price_list_currency = webnotes.conn.get_value("Price List", out.selling_price_list, "currency")
if not out.currency:
out.currency = currency
# sales team
out.sales_team = [{
"sales_person": d.sales_person,
"sales_designation": d.sales_designation
} for d in customer_bean.doclist.get({"doctype":"Sales Team"})]
return out return out

View File

@ -6,7 +6,38 @@ from __future__ import unicode_literals
import webnotes import webnotes
import unittest import unittest
from webnotes.test_runner import make_test_records
class TestCustomer(unittest.TestCase): class TestCustomer(unittest.TestCase):
def test_get_customer_details(self):
from erpnext.selling.doctype.customer.customer import get_customer_details
to_check = {
'address_display': '_Test Address Line 1\n_Test City\nIndia\nPhone: +91 0000000000',
'selling_price_list': None,
'customer_group': '_Test Customer Group',
'contact_designation': None,
'customer_address': '_Test Address-Office',
'contact_department': None,
'contact_email': 'test_contact_customer@example.com',
'contact_mobile': None,
'_sales_team': [],
'contact_display': '_Test Contact For _Test Customer',
'contact_person': '_Test Contact For _Test Customer-_Test Customer',
'territory': u'_Test Territory',
'contact_phone': '+91 0000000000',
'customer_name': '_Test Customer'
}
make_test_records("Address")
make_test_records("Contact")
details = get_customer_details("_Test Customer")
for key, value in to_check.iteritems():
self.assertEquals(value, details.get(key))
def test_rename(self): def test_rename(self):
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1"), self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1"),
(("_Test Customer 1",),)) (("_Test Customer 1",),))
@ -20,7 +51,6 @@ class TestCustomer(unittest.TestCase):
webnotes.rename_doc("Customer", "_Test Customer 1 Renamed", "_Test Customer 1") webnotes.rename_doc("Customer", "_Test Customer 1 Renamed", "_Test Customer 1")
def test_merge(self): def test_merge(self):
from webnotes.test_runner import make_test_records
make_test_records("Sales Invoice") make_test_records("Sales Invoice")
# clear transactions for new name # clear transactions for new name

View File

@ -4,6 +4,16 @@
cur_frm.cscript.tname = "Installation Note Item"; cur_frm.cscript.tname = "Installation Note Item";
cur_frm.cscript.fname = "installed_item_details"; cur_frm.cscript.fname = "installed_item_details";
wn.ui.form.on_change("Installation Note", "customer",
function(frm) { erpnext.utils.get_party_details(frm); });
wn.ui.form.on_change("Installation Note", "customer_address",
function(frm) { erpnext.utils.get_address_display(frm); });
wn.ui.form.on_change("Installation Note", "contact_person",
function(frm) { erpnext.utils.get_contact_details(frm); });
wn.provide("erpnext.selling"); wn.provide("erpnext.selling");
// TODO commonify this code // TODO commonify this code
erpnext.selling.InstallationNote = wn.ui.form.Controller.extend({ erpnext.selling.InstallationNote = wn.ui.form.Controller.extend({
@ -11,11 +21,6 @@ erpnext.selling.InstallationNote = wn.ui.form.Controller.extend({
if(!this.frm.doc.status) set_multiple(dt,dn,{ status:'Draft'}); if(!this.frm.doc.status) set_multiple(dt,dn,{ status:'Draft'});
if(this.frm.doc.__islocal) set_multiple(this.frm.doc.doctype, this.frm.doc.name, if(this.frm.doc.__islocal) set_multiple(this.frm.doc.doctype, this.frm.doc.name,
{inst_date: get_today()}); {inst_date: get_today()});
fields = ['customer_address', 'contact_person','customer_name', 'address_display',
'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']
if(this.frm.doc.customer) unhide_field(fields);
else hide_field(fields)
this.setup_queries(); this.setup_queries();
}, },
@ -60,42 +65,7 @@ erpnext.selling.InstallationNote = wn.ui.form.Controller.extend({
} }
); );
} }
}, },
customer: function() {
var me = this;
if(this.frm.doc.customer) {
return this.frm.call({
doc: this.frm.doc,
method: "set_customer_defaults",
});
// TODO shift this to depends_on
unhide_field(['customer_address', 'contact_person', 'customer_name',
'address_display', 'contact_display', 'contact_mobile', 'contact_email',
'territory', 'customer_group']);
}
},
customer_address: function() {
var me = this;
if(this.frm.doc.customer) {
return this.frm.call({
doc: this.frm.doc,
args: {
customer: this.frm.doc.customer,
address: this.frm.doc.customer_address,
contact: this.frm.doc.contact_person
},
method: "get_customer_address",
freeze: true,
});
}
},
contact_person: function() {
this.customer_address();
},
}); });
$.extend(cur_frm.cscript, new erpnext.selling.InstallationNote({frm: cur_frm})); $.extend(cur_frm.cscript, new erpnext.selling.InstallationNote({frm: cur_frm}));

View File

@ -74,6 +74,7 @@
"search_index": 1 "search_index": 1
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer_address", "fieldname": "customer_address",
"fieldtype": "Link", "fieldtype": "Link",
@ -82,6 +83,7 @@
"print_hide": 1 "print_hide": 1
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_person", "fieldname": "contact_person",
"fieldtype": "Link", "fieldtype": "Link",
@ -104,6 +106,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "address_display", "fieldname": "address_display",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"hidden": 1,
"label": "Address", "label": "Address",
"read_only": 1 "read_only": 1
}, },
@ -111,10 +114,12 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_display", "fieldname": "contact_display",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"hidden": 1,
"label": "Contact", "label": "Contact",
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_mobile", "fieldname": "contact_mobile",
"fieldtype": "Text", "fieldtype": "Text",
@ -122,6 +127,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_email", "fieldname": "contact_email",
"fieldtype": "Text", "fieldtype": "Text",
@ -130,6 +136,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "customer",
"description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "territory", "fieldname": "territory",
@ -142,6 +149,7 @@
"search_index": 1 "search_index": 1
}, },
{ {
"depends_on": "customer",
"description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer_group", "fieldname": "customer_group",

View File

@ -3,6 +3,12 @@
{% include 'utilities/doctype/sms_control/sms_control.js' %}; {% include 'utilities/doctype/sms_control/sms_control.js' %};
wn.ui.form.on_change("Opportunity", "customer", function(frm) {
erpnext.utils.get_party_details(frm) });
wn.ui.form.on_change("Opportunity", "customer_address", erpnext.utils.get_address_display);
wn.ui.form.on_change("Opportunity", "contact_person", erpnext.utils.get_contact_details);
wn.provide("erpnext.selling"); wn.provide("erpnext.selling");
// TODO commonify this code // TODO commonify this code
erpnext.selling.Opportunity = wn.ui.form.Controller.extend({ erpnext.selling.Opportunity = wn.ui.form.Controller.extend({
@ -12,8 +18,6 @@ erpnext.selling.Opportunity = wn.ui.form.Controller.extend({
if(!this.frm.doc.enquiry_from && this.frm.doc.lead) if(!this.frm.doc.enquiry_from && this.frm.doc.lead)
this.frm.doc.enquiry_from = "Lead"; this.frm.doc.enquiry_from = "Lead";
if(!this.frm.doc.enquiry_from)
hide_field(['customer', 'customer_address', 'contact_person', 'customer_name','lead', 'address_display', 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']);
if(!this.frm.doc.status) if(!this.frm.doc.status)
set_multiple(cdt, cdn, { status:'Draft' }); set_multiple(cdt, cdn, { status:'Draft' });
if(!this.frm.doc.date) if(!this.frm.doc.date)
@ -23,14 +27,6 @@ erpnext.selling.Opportunity = wn.ui.form.Controller.extend({
if(!this.frm.doc.fiscal_year && sys_defaults.fiscal_year) if(!this.frm.doc.fiscal_year && sys_defaults.fiscal_year)
set_multiple(cdt, cdn, { fiscal_year:sys_defaults.fiscal_year }); set_multiple(cdt, cdn, { fiscal_year:sys_defaults.fiscal_year });
if(this.frm.doc.enquiry_from) {
if(this.frm.doc.enquiry_from == 'Customer') {
hide_field('lead');
}
else if (this.frm.doc.enquiry_from == 'Lead') {
hide_field(['customer', 'customer_address', 'contact_person', 'customer_group']);
}
}
if(!this.frm.doc.__islocal) { if(!this.frm.doc.__islocal) {
cur_frm.communication_view = new wn.views.CommunicationList({ cur_frm.communication_view = new wn.views.CommunicationList({
@ -73,22 +69,7 @@ erpnext.selling.Opportunity = wn.ui.form.Controller.extend({
me.frm.set_query(opts[0], erpnext.queries[opts[1]]); me.frm.set_query(opts[0], erpnext.queries[opts[1]]);
}); });
}, },
customer: function() {
var me = this;
if(this.frm.doc.customer) {
// TODO shift this to depends_on
unhide_field(['customer_address', 'contact_person', 'customer_name',
'address_display', 'contact_display', 'contact_mobile', 'contact_email',
'territory', 'customer_group']);
return this.frm.call({
doc: this.frm.doc,
method: "set_customer_defaults",
});
}
},
create_quotation: function() { create_quotation: function() {
wn.model.open_mapped_doc({ wn.model.open_mapped_doc({
method: "erpnext.selling.doctype.opportunity.opportunity.make_quotation", method: "erpnext.selling.doctype.opportunity.opportunity.make_quotation",
@ -109,10 +90,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.add_custom_button(wn._('Opportunity Lost'), cur_frm.cscript['Declare Opportunity Lost']); cur_frm.add_custom_button(wn._('Opportunity Lost'), cur_frm.cscript['Declare Opportunity Lost']);
cur_frm.add_custom_button(wn._('Send SMS'), cur_frm.cscript.send_sms, "icon-mobile-phone"); cur_frm.add_custom_button(wn._('Send SMS'), cur_frm.cscript.send_sms, "icon-mobile-phone");
} }
cur_frm.toggle_display("contact_info", doc.customer || doc.lead);
} }
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
@ -122,50 +100,18 @@ cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
cur_frm.cscript.item_code = function(doc, cdt, cdn) { cur_frm.cscript.item_code = function(doc, cdt, cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if (d.item_code) if (d.item_code) {
return get_server_fields('get_item_details', d.item_code, 'enquiry_details', doc, cdt, cdn, 1); return get_server_fields('get_item_details', d.item_code,
} 'enquiry_details', doc, cdt, cdn, 1);
// hide - unhide fields on basis of enquiry_from lead or customer
cur_frm.cscript.enquiry_from = function(doc, cdt, cdn) {
cur_frm.cscript.lead_cust_show(doc, cdt, cdn);
}
// hide - unhide fields based on lead or customer
cur_frm.cscript.lead_cust_show = function(doc, cdt, cdn) {
if(doc.enquiry_from == 'Lead') {
unhide_field(['lead']);
hide_field(['customer','customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
doc.lead = doc.customer = doc.customer_address = doc.contact_person = doc.address_display = doc.contact_display = doc.contact_mobile = doc.contact_email = doc.territory = doc.customer_group = "";
} }
else if(doc.enquiry_from == 'Customer') {
unhide_field(['customer']);
hide_field(['lead', 'address_display', 'contact_display', 'contact_mobile',
'contact_email', 'territory', 'customer_group']);
doc.lead = doc.customer = doc.customer_address = doc.contact_person = doc.address_display = doc.contact_display = doc.contact_mobile = doc.contact_email = doc.territory = doc.customer_group = "";
}
}
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc, dt, dn) {
args = {
address: doc.customer_address,
contact: doc.contact_person
}
if(doc.customer) args.update({customer: doc.customer});
return get_server_fields('get_customer_address', JSON.stringify(args),'', doc, dt, dn, 1);
} }
cur_frm.cscript.lead = function(doc, cdt, cdn) { cur_frm.cscript.lead = function(doc, cdt, cdn) {
cur_frm.toggle_display("contact_info", doc.customer || doc.lead); cur_frm.toggle_display("contact_info", doc.customer || doc.lead);
wn.model.map_current_doc({ wn.model.map_current_doc({
method: "erpnext.selling.doctype.lead.lead.make_opportunity", method: "erpnext.selling.doctype.lead.lead.make_opportunity",
source_name: cur_frm.doc.lead source_name: cur_frm.doc.lead
}); });
unhide_field(['customer_name', 'address_display','contact_mobile', 'customer_address',
'contact_email', 'territory']);
} }
cur_frm.cscript['Declare Opportunity Lost'] = function() { cur_frm.cscript['Declare Opportunity Lost'] = function() {

View File

@ -81,6 +81,7 @@
"reqd": 1 "reqd": 1
}, },
{ {
"depends_on": "eval:doc.enquiry_from===\"Customer\"",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer", "fieldname": "customer",
"fieldtype": "Link", "fieldtype": "Link",
@ -97,6 +98,7 @@
"search_index": 0 "search_index": 0
}, },
{ {
"depends_on": "eval:doc.enquiry_from===\"Lead\"",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "lead", "fieldname": "lead",
"fieldtype": "Link", "fieldtype": "Link",
@ -184,6 +186,7 @@
"read_only": 0 "read_only": 0
}, },
{ {
"depends_on": "eval:doc.lead || doc.customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_info", "fieldname": "contact_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
@ -192,6 +195,7 @@
"read_only": 0 "read_only": 0
}, },
{ {
"depends_on": "eval:doc.customer || doc.lead",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer_address", "fieldname": "customer_address",
"fieldtype": "Link", "fieldtype": "Link",
@ -205,13 +209,14 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "address_display", "fieldname": "address_display",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"hidden": 0, "hidden": 1,
"label": "Address", "label": "Address",
"oldfieldname": "address", "oldfieldname": "address",
"oldfieldtype": "Small Text", "oldfieldtype": "Small Text",
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "customer",
"description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "territory", "fieldname": "territory",
@ -225,7 +230,7 @@
"search_index": 1 "search_index": 1
}, },
{ {
"depends_on": "eval:doc.enquiry_from==\"Customer\"", "depends_on": "customer",
"description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer_group", "fieldname": "customer_group",
@ -248,6 +253,7 @@
"read_only": 0 "read_only": 0
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer_name", "fieldname": "customer_name",
"fieldtype": "Data", "fieldtype": "Data",
@ -256,6 +262,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "eval:doc.lead || doc.customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_person", "fieldname": "contact_person",
"fieldtype": "Link", "fieldtype": "Link",
@ -266,6 +273,7 @@
"read_only": 0 "read_only": 0
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_display", "fieldname": "contact_display",
"fieldtype": "Small Text", "fieldtype": "Small Text",
@ -273,6 +281,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "eval:doc.lead || doc.customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_email", "fieldname": "contact_email",
"fieldtype": "Text", "fieldtype": "Text",
@ -280,6 +289,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "eval:doc.lead || doc.customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_mobile", "fieldname": "contact_mobile",
"fieldtype": "Text", "fieldtype": "Text",

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:27:51", "creation": "2013-02-22 01:27:51",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:22", "modified": "2014-02-03 12:40:44",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -45,18 +45,6 @@
"oldfieldtype": "Data", "oldfieldtype": "Data",
"reqd": 1 "reqd": 1
}, },
{
"doctype": "DocField",
"fieldname": "description",
"fieldtype": "Text",
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Text",
"print_width": "300px",
"reqd": 1,
"width": "300px"
},
{ {
"description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>",
"doctype": "DocField", "doctype": "DocField",
@ -84,6 +72,23 @@
"print_hide": 1, "print_hide": 1,
"search_index": 0 "search_index": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "description",
"fieldtype": "Text",
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Text",
"print_width": "300px",
"reqd": 1,
"width": "300px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "quantity_and_rate", "fieldname": "quantity_and_rate",
@ -112,6 +117,11 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1 "print_hide": 1
}, },
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "uom", "fieldname": "uom",

View File

@ -10,6 +10,7 @@
wn.provide("erpnext.selling"); wn.provide("erpnext.selling");
wn.require("assets/erpnext/js/transaction.js"); wn.require("assets/erpnext/js/transaction.js");
{% include "public/js/controllers/accounts.js" %} {% include "public/js/controllers/accounts.js" %}
erpnext.selling.SellingController = erpnext.TransactionController.extend({ erpnext.selling.SellingController = erpnext.TransactionController.extend({
@ -103,49 +104,15 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}, },
customer: function() { customer: function() {
var me = this; erpnext.utils.get_party_details(this.frm);
if(this.frm.doc.customer || this.frm.doc.debit_to) {
if(!this.frm.doc.company) {
this.frm.set_value("customer", null);
msgprint(wn._("Please specify Company"));
} else {
var selling_price_list = this.frm.doc.selling_price_list;
return this.frm.call({
doc: this.frm.doc,
method: "set_customer_defaults",
freeze: true,
callback: function(r) {
if(!r.exc) {
(me.frm.doc.selling_price_list !== selling_price_list) ?
me.selling_price_list() :
me.price_list_currency();
if (me.frm.doc.taxes_and_charges)
me.frm.script_manager.trigger("taxes_and_charges")
}
}
});
}
}
}, },
customer_address: function() { customer_address: function() {
var me = this; erpnext.utils.get_address_display(this.frm, "customer_address");
if(this.frm.doc.customer) {
return this.frm.call({
doc: this.frm.doc,
args: {
customer: this.frm.doc.customer,
address: this.frm.doc.customer_address,
contact: this.frm.doc.contact_person
},
method: "set_customer_address",
freeze: true,
});
}
}, },
contact_person: function() { contact_person: function() {
this.customer_address(); erpnext.utils.get_contact_details(this.frm);
}, },
barcode: function(doc, cdt, cdn) { barcode: function(doc, cdt, cdn) {
@ -670,4 +637,4 @@ var set_sales_bom_help = function(doc) {
} }
} }
refresh_field('sales_bom_help'); refresh_field('sales_bom_help');
} }

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-04-10 08:35:39", "creation": "2013-04-10 08:35:39",
"docstatus": 0, "docstatus": 0,
"modified": "2014-01-20 17:48:28", "modified": "2014-01-30 16:32:41",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -110,6 +110,7 @@
"fieldname": "default_cash_account", "fieldname": "default_cash_account",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Default Cash Account", "label": "Default Cash Account",
"no_copy": 1,
"options": "Account", "options": "Account",
"read_only": 0 "read_only": 0
}, },
@ -142,6 +143,7 @@
"fieldname": "default_expense_account", "fieldname": "default_expense_account",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Default Expense Account", "label": "Default Expense Account",
"no_copy": 1,
"options": "Account" "options": "Account"
}, },
{ {
@ -149,6 +151,7 @@
"fieldname": "default_income_account", "fieldname": "default_income_account",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Default Income Account", "label": "Default Income Account",
"no_copy": 1,
"options": "Account" "options": "Account"
}, },
{ {

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:28:02", "creation": "2013-02-22 01:28:02",
"docstatus": 0, "docstatus": 0,
"modified": "2013-12-20 19:23:21", "modified": "2014-02-03 11:35:26",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -41,20 +41,24 @@
"width": "100px" "width": "100px"
}, },
{ {
"allow_on_submit": 0,
"doctype": "DocField", "doctype": "DocField",
"fieldname": "schedule_date", "fieldname": "item_name",
"fieldtype": "Date", "fieldtype": "Data",
"in_list_view": 1, "in_filter": 1,
"label": "Required Date", "in_list_view": 0,
"no_copy": 0, "label": "Item Name",
"oldfieldname": "schedule_date", "oldfieldname": "item_name",
"oldfieldtype": "Date", "oldfieldtype": "Data",
"print_hide": 0,
"print_width": "100px", "print_width": "100px",
"reqd": 1, "reqd": 0,
"search_index": 1,
"width": "100px" "width": "100px"
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "description", "fieldname": "description",
@ -87,21 +91,6 @@
"reqd": 1, "reqd": 1,
"width": "80px" "width": "80px"
}, },
{
"doctype": "DocField",
"fieldname": "uom",
"fieldtype": "Link",
"in_list_view": 0,
"label": "Stock UOM",
"no_copy": 0,
"oldfieldname": "uom",
"oldfieldtype": "Link",
"options": "UOM",
"print_width": "70px",
"read_only": 1,
"reqd": 1,
"width": "70px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "warehouse", "fieldname": "warehouse",
@ -116,38 +105,47 @@
"reqd": 0, "reqd": 0,
"width": "100px" "width": "100px"
}, },
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "uom",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Stock UOM",
"no_copy": 0,
"oldfieldname": "uom",
"oldfieldtype": "Link",
"options": "UOM",
"print_width": "70px",
"read_only": 1,
"reqd": 1,
"width": "70px"
},
{
"allow_on_submit": 0,
"doctype": "DocField",
"fieldname": "schedule_date",
"fieldtype": "Date",
"in_list_view": 1,
"label": "Required Date",
"no_copy": 0,
"oldfieldname": "schedule_date",
"oldfieldtype": "Date",
"print_hide": 0,
"print_width": "100px",
"reqd": 1,
"width": "100px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "more_info", "fieldname": "more_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "More Info" "label": "More Info"
}, },
{
"doctype": "DocField",
"fieldname": "lead_time_date",
"fieldtype": "Date",
"in_list_view": 0,
"label": "Lead Time Date",
"no_copy": 1,
"oldfieldname": "lead_time_date",
"oldfieldtype": "Date",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "item_name",
"fieldtype": "Data",
"in_filter": 1,
"in_list_view": 1,
"label": "Item Name",
"oldfieldname": "item_name",
"oldfieldtype": "Data",
"print_width": "100px",
"reqd": 0,
"search_index": 1,
"width": "100px"
},
{ {
"description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>",
"doctype": "DocField", "doctype": "DocField",
@ -177,6 +175,33 @@
"read_only": 1, "read_only": 1,
"width": "100px" "width": "100px"
}, },
{
"doctype": "DocField",
"fieldname": "lead_time_date",
"fieldtype": "Date",
"in_list_view": 0,
"label": "Lead Time Date",
"no_copy": 1,
"oldfieldname": "lead_time_date",
"oldfieldtype": "Date",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "sales_order_no",
"fieldtype": "Link",
"label": "Sales Order No",
"no_copy": 0,
"options": "Sales Order",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "col_break3",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "min_order_qty", "fieldname": "min_order_qty",
@ -214,16 +239,6 @@
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"read_only": 1 "read_only": 1
}, },
{
"doctype": "DocField",
"fieldname": "sales_order_no",
"fieldtype": "Link",
"label": "Sales Order No",
"no_copy": 0,
"options": "Sales Order",
"print_hide": 1,
"read_only": 1
},
{ {
"allow_on_submit": 1, "allow_on_submit": 1,
"doctype": "DocField", "doctype": "DocField",

View File

@ -301,7 +301,6 @@ def make_purchase_invoice(source_name, target_doclist=None):
def set_missing_values(source, target): def set_missing_values(source, target):
bean = webnotes.bean(target) bean = webnotes.bean(target)
bean.run_method("set_missing_values") bean.run_method("set_missing_values")
bean.run_method("set_supplier_defaults")
doclist = get_mapped_doclist("Purchase Receipt", source_name, { doclist = get_mapped_doclist("Purchase Receipt", source_name, {
"Purchase Receipt": { "Purchase Receipt": {

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-05-24 19:29:10", "creation": "2013-05-24 19:29:10",
"docstatus": 0, "docstatus": 0,
"modified": "2014-01-15 16:00:44", "modified": "2014-02-03 12:18:24",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -55,6 +55,11 @@
"reqd": 1, "reqd": 1,
"search_index": 0 "search_index": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "description", "fieldname": "description",
@ -116,6 +121,11 @@
"search_index": 0, "search_index": 0,
"width": "100px" "width": "100px"
}, },
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "uom", "fieldname": "uom",
@ -131,6 +141,35 @@
"reqd": 1, "reqd": 1,
"width": "100px" "width": "100px"
}, },
{
"doctype": "DocField",
"fieldname": "stock_uom",
"fieldtype": "Link",
"in_list_view": 0,
"label": "Stock UOM",
"oldfieldname": "stock_uom",
"oldfieldtype": "Data",
"options": "UOM",
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 1,
"width": "100px"
},
{
"doctype": "DocField",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"in_list_view": 0,
"label": "Conversion Factor",
"oldfieldname": "conversion_factor",
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "rate_and_amount", "fieldname": "rate_and_amount",
@ -157,6 +196,26 @@
"print_hide": 1, "print_hide": 1,
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break3",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "purchase_ref_rate",
"fieldtype": "Currency",
"in_list_view": 0,
"label": "Price List Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "sec_break1",
"fieldtype": "Section Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "import_rate", "fieldname": "import_rate",
@ -184,13 +243,8 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "purchase_ref_rate", "fieldname": "col_break4",
"fieldtype": "Currency", "fieldtype": "Column Break"
"in_list_view": 0,
"label": "Price List Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -203,7 +257,7 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1, "print_hide": 1,
"print_width": "100px", "print_width": "100px",
"read_only": 0, "read_only": 1,
"reqd": 1, "reqd": 1,
"width": "100px" "width": "100px"
}, },
@ -218,7 +272,7 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1, "print_hide": 1,
"print_width": "100px", "print_width": "100px",
"read_only": 0, "read_only": 1,
"reqd": 0, "reqd": 0,
"width": "100px" "width": "100px"
}, },
@ -244,68 +298,6 @@
"read_only": 0, "read_only": 0,
"width": "100px" "width": "100px"
}, },
{
"doctype": "DocField",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"in_list_view": 0,
"label": "Conversion Factor",
"oldfieldname": "conversion_factor",
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
{
"doctype": "DocField",
"fieldname": "stock_uom",
"fieldtype": "Link",
"in_list_view": 0,
"label": "Stock UOM",
"oldfieldname": "stock_uom",
"oldfieldtype": "Data",
"options": "UOM",
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 1,
"width": "100px"
},
{
"doctype": "DocField",
"fieldname": "serial_no",
"fieldtype": "Text",
"in_filter": 1,
"in_list_view": 1,
"label": "Serial No",
"no_copy": 1,
"oldfieldname": "serial_no",
"oldfieldtype": "Text",
"print_hide": 0,
"read_only": 0,
"report_hide": 0
},
{
"doctype": "DocField",
"fieldname": "rejected_serial_no",
"fieldtype": "Text",
"label": "Rejected Serial No",
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "batch_no",
"fieldtype": "Link",
"label": "Batch No",
"oldfieldname": "batch_no",
"oldfieldtype": "Link",
"options": "Batch",
"print_hide": 1,
"read_only": 0
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "rejected_warehouse", "fieldname": "rejected_warehouse",
@ -321,19 +313,6 @@
"read_only": 0, "read_only": 0,
"width": "100px" "width": "100px"
}, },
{
"doctype": "DocField",
"fieldname": "schedule_date",
"fieldtype": "Date",
"label": "Required By",
"no_copy": 0,
"oldfieldname": "schedule_date",
"oldfieldtype": "Date",
"print_hide": 1,
"read_only": 0,
"report_hide": 0,
"reqd": 0
},
{ {
"default": ":Company", "default": ":Company",
"depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)", "depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)",
@ -368,36 +347,22 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "brand", "fieldname": "schedule_date",
"fieldtype": "Link", "fieldtype": "Date",
"hidden": 1, "label": "Required By",
"label": "Brand", "no_copy": 0,
"oldfieldname": "brand", "oldfieldname": "schedule_date",
"oldfieldtype": "Link", "oldfieldtype": "Date",
"options": "Brand",
"print_hide": 1,
"read_only": 1
},
{
"description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>",
"doctype": "DocField",
"fieldname": "item_group",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Item Group",
"oldfieldname": "item_group",
"oldfieldtype": "Link",
"options": "Item Group",
"print_hide": 1, "print_hide": 1,
"read_only": 1, "read_only": 1,
"search_index": 1 "report_hide": 0,
"reqd": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "stock_qty", "fieldname": "stock_qty",
"fieldtype": "Float", "fieldtype": "Float",
"label": "Stock Qty", "label": "Qty as per Stock UOM",
"oldfieldname": "stock_qty", "oldfieldname": "stock_qty",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"print_hide": 1, "print_hide": 1,
@ -435,6 +400,87 @@
"search_index": 1, "search_index": 1,
"width": "150px" "width": "150px"
}, },
{
"doctype": "DocField",
"fieldname": "prevdoc_detail_docname",
"fieldtype": "Data",
"hidden": 1,
"in_filter": 1,
"label": "Purchase Order Item No",
"no_copy": 1,
"oldfieldname": "prevdoc_detail_docname",
"oldfieldtype": "Data",
"print_hide": 1,
"print_width": "150px",
"read_only": 1,
"search_index": 1,
"width": "150px"
},
{
"doctype": "DocField",
"fieldname": "col_break5",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "serial_no",
"fieldtype": "Text",
"in_filter": 1,
"in_list_view": 1,
"label": "Serial No",
"no_copy": 1,
"oldfieldname": "serial_no",
"oldfieldtype": "Text",
"print_hide": 0,
"read_only": 0,
"report_hide": 0
},
{
"doctype": "DocField",
"fieldname": "rejected_serial_no",
"fieldtype": "Text",
"label": "Rejected Serial No",
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "batch_no",
"fieldtype": "Link",
"label": "Batch No",
"oldfieldname": "batch_no",
"oldfieldtype": "Link",
"options": "Batch",
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "brand",
"fieldtype": "Link",
"hidden": 1,
"label": "Brand",
"oldfieldname": "brand",
"oldfieldtype": "Link",
"options": "Brand",
"print_hide": 1,
"read_only": 1
},
{
"description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>",
"doctype": "DocField",
"fieldname": "item_group",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Item Group",
"oldfieldname": "item_group",
"oldfieldtype": "Link",
"options": "Item Group",
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "rm_supp_cost", "fieldname": "rm_supp_cost",
@ -468,22 +514,6 @@
"search_index": 0, "search_index": 0,
"width": "150px" "width": "150px"
}, },
{
"doctype": "DocField",
"fieldname": "prevdoc_detail_docname",
"fieldtype": "Data",
"hidden": 1,
"in_filter": 1,
"label": "Purchase Order Item No",
"no_copy": 1,
"oldfieldname": "prevdoc_detail_docname",
"oldfieldtype": "Data",
"print_hide": 1,
"print_width": "150px",
"read_only": 1,
"search_index": 1,
"width": "150px"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "valuation_rate", "fieldname": "valuation_rate",

View File

@ -93,9 +93,8 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
if(cint(wn.defaults.get_default("auto_accounting_for_stock"))) { if(cint(wn.defaults.get_default("auto_accounting_for_stock"))) {
var account_for = "stock_adjustment_account"; var account_for = "stock_adjustment_account";
if (this.frm.doc.purpose == "Sales Return")
account_for = "stock_in_hand_account"; if (this.frm.doc.purpose == "Purchase Return")
else if (this.frm.doc.purpose == "Purchase Return")
account_for = "stock_received_but_not_billed"; account_for = "stock_received_but_not_billed";
return this.frm.call({ return this.frm.call({
@ -236,7 +235,50 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
mtn_details_on_form_rendered: function(doc, grid_row) { mtn_details_on_form_rendered: function(doc, grid_row) {
erpnext.setup_serial_no(grid_row) erpnext.setup_serial_no(grid_row)
},
customer: function() {
return this.frm.call({
method: "erpnext.selling.doctype.customer.customer.get_customer_details",
args: { customer: this.frm.doc.customer }
});
},
supplier: function() {
return this.frm.call({
method: "erpnext.buying.doctype.supplier.supplier.get_supplier_details",
args: { supplier: this.frm.doc.supplier }
});
},
delivery_note_no: function() {
this.get_party_details({
ref_dt: "Delivery Note",
ref_dn: this.frm.doc.delivery_note_no
})
},
sales_invoice_no: function() {
this.get_party_details({
ref_dt: "Sales Invoice",
ref_dn: this.frm.doc.sales_invoice_no
})
},
purchase_receipt_no: function() {
this.get_party_details({
ref_dt: "Purchase Receipt",
ref_dn: this.frm.doc.purchase_receipt_no
})
},
get_party_details: function(args) {
return this.frm.call({
method: "erpnext.stock.doctype.stock_entry.stock_entry.get_party_details",
args: args,
})
} }
}); });
cur_frm.script_manager.make(erpnext.stock.StockEntry); cur_frm.script_manager.make(erpnext.stock.StockEntry);
@ -265,31 +307,6 @@ cur_frm.cscript.toggle_related_fields = function(doc) {
} }
} }
cur_frm.cscript.delivery_note_no = function(doc, cdt, cdn) {
if(doc.delivery_note_no)
return get_server_fields('get_cust_values', '', '', doc, cdt, cdn, 1);
}
cur_frm.cscript.sales_invoice_no = function(doc, cdt, cdn) {
if(doc.sales_invoice_no)
return get_server_fields('get_cust_values', '', '', doc, cdt, cdn, 1);
}
cur_frm.cscript.customer = function(doc, cdt, cdn) {
if(doc.customer)
return get_server_fields('get_cust_addr', '', '', doc, cdt, cdn, 1);
}
cur_frm.cscript.purchase_receipt_no = function(doc, cdt, cdn) {
if(doc.purchase_receipt_no)
return get_server_fields('get_supp_values', '', '', doc, cdt, cdn, 1);
}
cur_frm.cscript.supplier = function(doc, cdt, cdn) {
if(doc.supplier)
return get_server_fields('get_supp_addr', '', '', doc, cdt, cdn, 1);
}
cur_frm.fields_dict['production_order'].get_query = function(doc) { cur_frm.fields_dict['production_order'].get_query = function(doc) {
return { return {
filters: [ filters: [
@ -389,4 +406,4 @@ cur_frm.fields_dict.customer.get_query = function(doc, cdt, cdn) {
cur_frm.fields_dict.supplier.get_query = function(doc, cdt, cdn) { cur_frm.fields_dict.supplier.get_query = function(doc, cdt, cdn) {
return { query: "erpnext.controllers.queries.supplier_query" } return { query: "erpnext.controllers.queries.supplier_query" }
} }

View File

@ -590,56 +590,6 @@ class DocType(StockController):
# increment idx by 1 # increment idx by 1
idx += 1 idx += 1
return idx return idx
def get_cust_values(self):
"""fetches customer details"""
if self.doc.delivery_note_no:
doctype = "Delivery Note"
name = self.doc.delivery_note_no
else:
doctype = "Sales Invoice"
name = self.doc.sales_invoice_no
result = webnotes.conn.sql("""select customer, customer_name,
address_display as customer_address
from `tab%s` where name=%s""" % (doctype, "%s"), (name,), as_dict=1)
return result and result[0] or {}
def get_cust_addr(self):
from erpnext.utilities.transaction_base import get_default_address, get_address_display
res = webnotes.conn.sql("select customer_name from `tabCustomer` where name = '%s'"%self.doc.customer)
address_display = None
customer_address = get_default_address("customer", self.doc.customer)
if customer_address:
address_display = get_address_display(customer_address)
ret = {
'customer_name' : res and res[0][0] or '',
'customer_address' : address_display}
return ret
def get_supp_values(self):
result = webnotes.conn.sql("""select supplier, supplier_name,
address_display as supplier_address
from `tabPurchase Receipt` where name=%s""", (self.doc.purchase_receipt_no,),
as_dict=1)
return result and result[0] or {}
def get_supp_addr(self):
from erpnext.utilities.transaction_base import get_default_address, get_address_display
res = webnotes.conn.sql("""select supplier_name from `tabSupplier`
where name=%s""", self.doc.supplier)
address_display = None
supplier_address = get_default_address("customer", self.doc.customer)
if supplier_address:
address_display = get_address_display(supplier_address)
ret = {
'supplier_name' : res and res[0][0] or '',
'supplier_address' : address_display }
return ret
def validate_with_material_request(self): def validate_with_material_request(self):
for item in self.doclist.get({"parentfield": "mtn_details"}): for item in self.doclist.get({"parentfield": "mtn_details"}):
@ -653,6 +603,17 @@ class DocType(StockController):
+ _("Material Request") + (" - %s" % item.material_request), + _("Material Request") + (" - %s" % item.material_request),
raise_exception=webnotes.MappingMismatchError) raise_exception=webnotes.MappingMismatchError)
@webnotes.whitelist()
def get_party_details(ref_dt, ref_dn):
if ref_dt in ["Delivery Note", "Sales Invoice"]:
res = webnotes.conn.get_value(ref_dt, ref_dn,
["customer", "customer_name", "address_display as customer_address"], as_dict=1)
else:
res = webnotes.conn.get_value(ref_dt, ref_dn,
["supplier", "supplier_name", "address_display as supplier_address"], as_dict=1)
print ref_dt, ref_dn, res
return res or {}
@webnotes.whitelist() @webnotes.whitelist()
def get_production_order_details(production_order): def get_production_order_details(production_order):
result = webnotes.conn.sql("""select bom_no, result = webnotes.conn.sql("""select bom_no,
@ -965,5 +926,4 @@ def make_return_jv_from_purchase_receipt(se, ref):
result = [parent] + [{"account": account} for account in children] result = [parent] + [{"account": account} for account in children]
return result return result

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-03-29 18:22:12", "creation": "2013-03-29 18:22:12",
"docstatus": 0, "docstatus": 0,
"modified": "2014-01-15 16:08:45", "modified": "2014-02-03 12:59:27",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -38,6 +38,11 @@
"options": "Warehouse", "options": "Warehouse",
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break1",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "t_warehouse", "fieldname": "t_warehouse",
@ -51,6 +56,11 @@
"options": "Warehouse", "options": "Warehouse",
"read_only": 0 "read_only": 0
}, },
{
"doctype": "DocField",
"fieldname": "sec_break1",
"fieldtype": "Section Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "item_code", "fieldname": "item_code",
@ -73,6 +83,11 @@
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1
}, },
{
"doctype": "DocField",
"fieldname": "col_break2",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "description", "fieldname": "description",
@ -85,6 +100,12 @@
"read_only": 0, "read_only": 0,
"width": "300px" "width": "300px"
}, },
{
"doctype": "DocField",
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"label": "Quantity and Rate"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "qty", "fieldname": "qty",
@ -108,6 +129,58 @@
"read_only": 0, "read_only": 0,
"reqd": 1 "reqd": 1
}, },
{
"doctype": "DocField",
"fieldname": "incoming_rate",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Valuation Rate",
"oldfieldname": "incoming_rate",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"read_only": 0,
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "col_break3",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "stock_uom",
"fieldtype": "Link",
"in_filter": 0,
"label": "Stock UOM",
"oldfieldname": "stock_uom",
"oldfieldtype": "Link",
"options": "UOM",
"print_hide": 1,
"read_only": 1,
"reqd": 1,
"search_index": 0
},
{
"doctype": "DocField",
"fieldname": "conversion_factor",
"fieldtype": "Float",
"label": "Conversion Factor",
"oldfieldname": "conversion_factor",
"oldfieldtype": "Currency",
"print_hide": 1,
"read_only": 1,
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "amount",
"fieldtype": "Currency",
"label": "Amount",
"oldfieldname": "amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"read_only": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "serial_no_batch", "fieldname": "serial_no_batch",
@ -125,6 +198,11 @@
"read_only": 0, "read_only": 0,
"reqd": 0 "reqd": 0
}, },
{
"doctype": "DocField",
"fieldname": "col_break4",
"fieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "batch_no", "fieldname": "batch_no",
@ -142,28 +220,6 @@
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Accounting" "label": "Accounting"
}, },
{
"doctype": "DocField",
"fieldname": "incoming_rate",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Valuation Rate",
"oldfieldname": "incoming_rate",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"read_only": 0,
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "amount",
"fieldtype": "Currency",
"label": "Amount",
"oldfieldname": "amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"read_only": 1
},
{ {
"depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)", "depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)",
"doctype": "DocField", "doctype": "DocField",
@ -173,6 +229,11 @@
"options": "Account", "options": "Account",
"print_hide": 1 "print_hide": 1
}, },
{
"doctype": "DocField",
"fieldname": "col_break5",
"fieldtype": "Column Break"
},
{ {
"default": ":Company", "default": ":Company",
"depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)", "depends_on": "eval:cint(sys_defaults.auto_accounting_for_stock)",
@ -207,15 +268,21 @@
"search_index": 1 "search_index": 1
}, },
{ {
"description": "BOM No. for a Finished Good Item",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "conversion_factor", "fieldname": "bom_no",
"fieldtype": "Float", "fieldtype": "Link",
"label": "Conversion Factor", "hidden": 1,
"oldfieldname": "conversion_factor", "label": "BOM No",
"oldfieldtype": "Currency", "no_copy": 0,
"options": "BOM",
"print_hide": 1, "print_hide": 1,
"read_only": 1, "read_only": 0
"reqd": 1 },
{
"doctype": "DocField",
"fieldname": "col_break6",
"fieldtype": "Column Break"
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -228,32 +295,6 @@
"read_only": 1, "read_only": 1,
"reqd": 1 "reqd": 1
}, },
{
"doctype": "DocField",
"fieldname": "stock_uom",
"fieldtype": "Link",
"in_filter": 0,
"label": "Stock UOM",
"oldfieldname": "stock_uom",
"oldfieldtype": "Link",
"options": "UOM",
"print_hide": 1,
"read_only": 1,
"reqd": 1,
"search_index": 0
},
{
"description": "BOM No. for a Finished Good Item",
"doctype": "DocField",
"fieldname": "bom_no",
"fieldtype": "Link",
"hidden": 1,
"label": "BOM No",
"no_copy": 0,
"options": "BOM",
"print_hide": 1,
"read_only": 0
},
{ {
"description": "Material Request used to make this Stock Entry", "description": "Material Request used to make this Stock Entry",
"doctype": "DocField", "doctype": "DocField",

View File

@ -2,27 +2,21 @@
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
wn.provide("erpnext.support"); wn.provide("erpnext.support");
// TODO commonify this code
wn.ui.form.on_change("Customer Issue", "customer", function(frm) {
erpnext.utils.get_party_details(frm) });
wn.ui.form.on_change("Customer Issue", "customer_address",
erpnext.utils.get_address_display);
wn.ui.form.on_change("Customer Issue", "contact_person",
erpnext.utils.get_contact_details);
erpnext.support.CustomerIssue = wn.ui.form.Controller.extend({ erpnext.support.CustomerIssue = wn.ui.form.Controller.extend({
refresh: function() { refresh: function() {
if((cur_frm.doc.status=='Open' || cur_frm.doc.status == 'Work In Progress')) { if((cur_frm.doc.status=='Open' || cur_frm.doc.status == 'Work In Progress')) {
cur_frm.add_custom_button(wn._('Make Maintenance Visit'), this.make_maintenance_visit) cur_frm.add_custom_button(wn._('Make Maintenance Visit'), this.make_maintenance_visit)
} }
}, },
customer: function() {
var me = this;
if(this.frm.doc.customer) {
// TODO shift this to depends_on
unhide_field(['customer_address', 'contact_person']);
return this.frm.call({
doc: this.frm.doc,
method: "set_customer_defaults",
});
}
},
make_maintenance_visit: function() { make_maintenance_visit: function() {
wn.model.open_mapped_doc({ wn.model.open_mapped_doc({
method: "erpnext.support.doctype.customer_issue.customer_issue.make_maintenance_visit", method: "erpnext.support.doctype.customer_issue.customer_issue.make_maintenance_visit",
@ -35,16 +29,7 @@ $.extend(cur_frm.cscript, new erpnext.support.CustomerIssue({frm: cur_frm}));
cur_frm.cscript.onload = function(doc,cdt,cdn){ cur_frm.cscript.onload = function(doc,cdt,cdn){
if(!doc.status) if(!doc.status)
set_multiple(dt,dn,{status:'Open'}); set_multiple(dt,dn,{status:'Open'});
if(doc.__islocal){
hide_field(['customer_address','contact_person']);
}
}
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
if(doc.customer)
return 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.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
@ -82,6 +67,8 @@ cur_frm.add_fetch('serial_no', 'amc_expiry_date', 'amc_expiry_date');
cur_frm.add_fetch('serial_no', 'customer', 'customer'); cur_frm.add_fetch('serial_no', 'customer', 'customer');
cur_frm.add_fetch('serial_no', 'customer_name', 'customer_name'); cur_frm.add_fetch('serial_no', 'customer_name', 'customer_name');
cur_frm.add_fetch('serial_no', 'delivery_address', 'customer_address'); cur_frm.add_fetch('serial_no', 'delivery_address', 'customer_address');
cur_frm.add_fetch('item_code', 'item_name', 'item_name');
cur_frm.add_fetch('item_code', 'description', 'description');
cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) {
if(doc.serial_no) { if(doc.serial_no) {
@ -98,8 +85,6 @@ cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) {
} }
} }
cur_frm.add_fetch('item_code', 'item_name', 'item_name');
cur_frm.add_fetch('item_code', 'description', 'description');
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {

View File

@ -276,6 +276,7 @@
"width": "50%" "width": "50%"
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer_name", "fieldname": "customer_name",
"fieldtype": "Data", "fieldtype": "Data",
@ -283,6 +284,7 @@
"read_only": 1 "read_only": 1
}, },
{ {
"depends_on": "customer",
"description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer_group", "fieldname": "customer_group",
@ -293,6 +295,7 @@
"reqd": 0 "reqd": 0
}, },
{ {
"depends_on": "customer",
"description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>", "description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "territory", "fieldname": "territory",
@ -307,10 +310,27 @@
"search_index": 1 "search_index": 1
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "address_display", "fieldname": "contact_display",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"label": "Address", "label": "Contact",
"read_only": 1
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "contact_mobile",
"fieldtype": "Data",
"label": "Mobile No",
"read_only": 1
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "contact_email",
"fieldtype": "Data",
"label": "Contact Email",
"read_only": 1 "read_only": 1
}, },
{ {
@ -320,27 +340,8 @@
"width": "50%" "width": "50%"
}, },
{ {
"doctype": "DocField", "depends_on": "customer",
"fieldname": "contact_display", "description": "If different than customer address",
"fieldtype": "Small Text",
"label": "Contact",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "contact_mobile",
"fieldtype": "Data",
"label": "Mobile No",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "contact_email",
"fieldtype": "Data",
"label": "Contact Email",
"read_only": 1
},
{
"doctype": "DocField", "doctype": "DocField",
"fieldname": "service_address", "fieldname": "service_address",
"fieldtype": "Small Text", "fieldtype": "Small Text",
@ -348,6 +349,15 @@
"oldfieldname": "service_address", "oldfieldname": "service_address",
"oldfieldtype": "Small Text" "oldfieldtype": "Small Text"
}, },
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "address_display",
"fieldtype": "Small Text",
"hidden": 0,
"label": "Address",
"read_only": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "more_info", "fieldname": "more_info",

View File

@ -2,6 +2,14 @@
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
wn.provide("erpnext.support"); wn.provide("erpnext.support");
wn.ui.form.on_change("Maintenance Schedule", "customer", function(frm) {
erpnext.utils.get_party_details(frm) });
wn.ui.form.on_change("Maintenance Schedule", "customer_address",
erpnext.utils.get_address_display);
wn.ui.form.on_change("Maintenance Schedule", "contact_person",
erpnext.utils.get_contact_details);
// TODO commonify this code // TODO commonify this code
erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
refresh: function() { refresh: function() {
@ -30,36 +38,16 @@ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
}); });
} }
}, },
customer: function() {
var me = this;
if(this.frm.doc.customer) {
return this.frm.call({
doc: me.frm.doc,
method: "set_customer_defaults",
});
}
},
}); });
$.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm})); $.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm}));
cur_frm.cscript.onload = function(doc, dt, dn) { cur_frm.cscript.onload = function(doc, dt, dn) {
if (!doc.status) if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
set_multiple(dt, dn, { status:'Draft' });
if(doc.__islocal){
if (doc.__islocal) { set_multiple(dt,dn,{transaction_date:get_today()});
set_multiple(dt, dn, { transaction_date:get_today() }); }
hide_field(['customer_address', 'contact_person', 'customer_name', 'address_display',
'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']);
}
}
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc, dt, dn) {
if (doc.customer) {
return 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.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {

View File

@ -54,12 +54,6 @@
"oldfieldtype": "Section Break", "oldfieldtype": "Section Break",
"options": "icon-user" "options": "icon-user"
}, },
{
"doctype": "DocField",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"oldfieldtype": "Column Break"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer", "fieldname": "customer",
@ -76,83 +70,10 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "customer_address", "fieldname": "column_break0",
"fieldtype": "Link",
"label": "Customer Address",
"options": "Address",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "contact_person",
"fieldtype": "Link",
"label": "Contact Person",
"options": "Contact",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "customer_name",
"fieldtype": "Data",
"in_filter": 1,
"in_list_view": 1,
"label": "Customer Name",
"oldfieldname": "customer_name",
"oldfieldtype": "Data",
"read_only": 1,
"reqd": 0,
"search_index": 0
},
{
"doctype": "DocField",
"fieldname": "address_display",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Address",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "contact_display",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Contact",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "contact_mobile",
"fieldtype": "Data",
"hidden": 1,
"label": "Mobile No",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "contact_email",
"fieldtype": "Data",
"hidden": 1,
"label": "Contact Email",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "column_break1",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"oldfieldtype": "Column Break" "oldfieldtype": "Column Break"
}, },
{
"doctype": "DocField",
"fieldname": "transaction_date",
"fieldtype": "Date",
"in_filter": 1,
"label": "Transaction Date",
"oldfieldname": "transaction_date",
"oldfieldtype": "Date",
"reqd": 1,
"search_index": 0
},
{ {
"default": "Draft", "default": "Draft",
"doctype": "DocField", "doctype": "DocField",
@ -170,49 +91,15 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "amended_from", "fieldname": "transaction_date",
"fieldtype": "Data", "fieldtype": "Date",
"ignore_restrictions": 1,
"label": "Amended From",
"no_copy": 1,
"oldfieldname": "amended_from",
"oldfieldtype": "Data",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "company",
"fieldtype": "Link",
"in_filter": 1, "in_filter": 1,
"label": "Company", "label": "Transaction Date",
"oldfieldname": "company", "oldfieldname": "transaction_date",
"oldfieldtype": "Link", "oldfieldtype": "Date",
"options": "Company",
"reqd": 1, "reqd": 1,
"search_index": 0 "search_index": 0
}, },
{
"description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>",
"doctype": "DocField",
"fieldname": "territory",
"fieldtype": "Link",
"in_filter": 1,
"label": "Territory",
"oldfieldname": "territory",
"oldfieldtype": "Link",
"options": "Territory",
"reqd": 1,
"search_index": 0
},
{
"description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>",
"doctype": "DocField",
"fieldname": "customer_group",
"fieldtype": "Link",
"label": "Customer Group",
"options": "Customer Group",
"reqd": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "items", "fieldname": "items",
@ -255,6 +142,120 @@
"options": "Maintenance Schedule Detail", "options": "Maintenance Schedule Detail",
"read_only": 1 "read_only": 1
}, },
{
"doctype": "DocField",
"fieldname": "contact_info",
"fieldtype": "Section Break",
"label": "Contact Info"
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "customer_name",
"fieldtype": "Data",
"in_filter": 1,
"in_list_view": 1,
"label": "Customer Name",
"oldfieldname": "customer_name",
"oldfieldtype": "Data",
"read_only": 1,
"reqd": 0,
"search_index": 0
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "contact_person",
"fieldtype": "Link",
"label": "Contact Person",
"options": "Contact",
"print_hide": 1
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "contact_mobile",
"fieldtype": "Data",
"hidden": 1,
"label": "Mobile No",
"read_only": 1
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "contact_email",
"fieldtype": "Data",
"hidden": 1,
"label": "Contact Email",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "contact_display",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Contact",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "column_break_17",
"fieldtype": "Column Break"
},
{
"depends_on": "customer",
"doctype": "DocField",
"fieldname": "customer_address",
"fieldtype": "Link",
"label": "Customer Address",
"options": "Address",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "address_display",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Address",
"read_only": 1
},
{
"depends_on": "customer",
"description": "<a href=\"#Sales Browser/Territory\">Add / Edit</a>",
"doctype": "DocField",
"fieldname": "territory",
"fieldtype": "Link",
"in_filter": 1,
"label": "Territory",
"oldfieldname": "territory",
"oldfieldtype": "Link",
"options": "Territory",
"reqd": 1,
"search_index": 0
},
{
"depends_on": "customer",
"description": "<a href=\"#Sales Browser/Customer Group\">Add / Edit</a>",
"doctype": "DocField",
"fieldname": "customer_group",
"fieldtype": "Link",
"label": "Customer Group",
"options": "Customer Group",
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "company",
"fieldtype": "Link",
"in_filter": 1,
"label": "Company",
"oldfieldname": "company",
"oldfieldtype": "Link",
"options": "Company",
"reqd": 1,
"search_index": 0
},
{ {
"doctype": "DocPerm" "doctype": "DocPerm"
} }

View File

@ -2,6 +2,14 @@
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
wn.provide("erpnext.support"); wn.provide("erpnext.support");
wn.ui.form.on_change("Maintenance Visit", "customer", function(frm) {
erpnext.utils.get_party_details(frm) });
wn.ui.form.on_change("Maintenance Visit", "customer_address",
erpnext.utils.get_address_display);
wn.ui.form.on_change("Maintenance Visit", "contact_person",
erpnext.utils.get_contact_details);
// TODO commonify this code // TODO commonify this code
erpnext.support.MaintenanceVisit = wn.ui.form.Controller.extend({ erpnext.support.MaintenanceVisit = wn.ui.form.Controller.extend({
refresh: function() { refresh: function() {
@ -44,20 +52,7 @@ erpnext.support.MaintenanceVisit = wn.ui.form.Controller.extend({
}) })
}); });
} }
cur_frm.cscript.hide_contact_info();
}, },
customer: function() {
var me = this;
if(this.frm.doc.customer) {
// TODO shift this to depends_on
cur_frm.cscript.hide_contact_info();
return this.frm.call({
doc: this.frm.doc,
method: "set_customer_defaults",
});
}
},
}); });
$.extend(cur_frm.cscript, new erpnext.support.MaintenanceVisit({frm: cur_frm})); $.extend(cur_frm.cscript, new erpnext.support.MaintenanceVisit({frm: cur_frm}));
@ -65,15 +60,6 @@ $.extend(cur_frm.cscript, new erpnext.support.MaintenanceVisit({frm: cur_frm}));
cur_frm.cscript.onload = function(doc, dt, dn) { cur_frm.cscript.onload = function(doc, dt, dn) {
if(!doc.status) set_multiple(dt,dn,{status:'Draft'}); if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
if(doc.__islocal) set_multiple(dt,dn,{mntc_date:get_today()}); if(doc.__islocal) set_multiple(dt,dn,{mntc_date:get_today()});
cur_frm.cscript.hide_contact_info();
}
cur_frm.cscript.hide_contact_info = function() {
cur_frm.toggle_display("contact_info_section", cur_frm.doc.customer ? true : false);
}
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
if(doc.customer) return 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.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {

View File

@ -269,6 +269,7 @@
"search_index": 0 "search_index": 0
}, },
{ {
"depends_on": "customer",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contact_info_section", "fieldname": "contact_info_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",

View File

@ -5,20 +5,8 @@ cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return{ query: "erpnext.controllers.queries.customer_query" } } return{ query: "erpnext.controllers.queries.customer_query" } }
wn.provide("erpnext.support"); wn.provide("erpnext.support");
// TODO commonify this code
erpnext.support.SupportTicket = wn.ui.form.Controller.extend({
customer: function() {
var me = this;
if(this.frm.doc.customer) {
return this.frm.call({
doc: this.frm.doc,
method: "set_customer_defaults",
});
}
}
});
$.extend(cur_frm.cscript, new erpnext.support.SupportTicket({frm: cur_frm})); cur_frm.add_fetch("customer", "customer_name", "customer_name")
$.extend(cur_frm.cscript, { $.extend(cur_frm.cscript, {
onload: function(doc, dt, dn) { onload: function(doc, dt, dn) {

View File

@ -0,0 +1,12 @@
<h2>Recurring Invoice Failed</h2>
<p>An error occured while creating recurring invoice <b>{{ name }}</b> for <b>{{ customer }}</b>.</p>
<p>This could be because of some invalid email ids in the invoice.</p>
<p>To stop sending repetitive error notifications from the system, we have unchecked
"Convert into Recurring" field in the invoice {{ name }}.</p>
<p><b>Please correct the invoice and make the invoice recurring again.</b></p>
<hr>
<p><b>It is necessary to take this action today itself for the above mentioned recurring invoice \
to be generated. If delayed, you will have to manually change the "Repeat on Day of Month" field \
of this invoice for generating the recurring invoice.</b></p>
<p>[This email is autogenerated]</p>

View File

@ -51,3 +51,26 @@ class DocType:
webnotes.conn.sql("""update `tabAddress` set `%s`=0 where `%s`=%s and name!=%s""" % webnotes.conn.sql("""update `tabAddress` set `%s`=0 where `%s`=%s and name!=%s""" %
(is_address_type, fieldname, "%s", "%s"), (self.doc.fields[fieldname], self.doc.name)) (is_address_type, fieldname, "%s", "%s"), (self.doc.fields[fieldname], self.doc.name))
break break
@webnotes.whitelist()
def get_address_display(address_dict):
if not isinstance(address_dict, dict):
address_dict = webnotes.conn.get_value("Address", address_dict, "*", as_dict=True) or {}
meta = webnotes.get_doctype("Address")
sequence = (("", "address_line1"),
("\n", "address_line2"),
("\n", "city"),
("\n", "state"),
("\n" + meta.get_label("pincode") + ": ", "pincode"),
("\n", "country"),
("\n" + meta.get_label("phone") + ": ", "phone"),
("\n" + meta.get_label("fax") + ": ", "fax"))
display = ""
for separator, fieldname in sequence:
if address_dict.get(fieldname):
display += separator + address_dict.get(fieldname)
return display.strip()

View File

@ -5,9 +5,9 @@ from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr, extract_email_id from webnotes.utils import cstr, extract_email_id
from erpnext.utilities.transaction_base import TransactionBase from erpnext.controllers.status_updater import StatusUpdater
class DocType(TransactionBase): class DocType(StatusUpdater):
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
@ -49,3 +49,19 @@ class DocType(TransactionBase):
def on_trash(self): def on_trash(self):
webnotes.conn.sql("""update `tabSupport Ticket` set contact='' where contact=%s""", webnotes.conn.sql("""update `tabSupport Ticket` set contact='' where contact=%s""",
self.doc.name) self.doc.name)
@webnotes.whitelist()
def get_contact_details(contact):
contact = webnotes.doc("Contact", contact)
out = {
"contact_person": contact.get("name"),
"contact_display": " ".join(filter(None,
[contact.get("first_name"), contact.get("last_name")])),
"contact_email": contact.get("email_id"),
"contact_mobile": contact.get("mobile_no"),
"contact_phone": contact.get("phone"),
"contact_designation": contact.get("designation"),
"contact_department": contact.get("department")
}
return out

View File

@ -2,36 +2,14 @@
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes, json import webnotes
from webnotes import msgprint, _ from webnotes import msgprint, _
from webnotes.utils import cstr, flt, now_datetime, cint from webnotes.utils import cstr, flt, now_datetime, cint
from webnotes.model.doc import addchild
from erpnext.controllers.status_updater import StatusUpdater from erpnext.controllers.status_updater import StatusUpdater
class TransactionBase(StatusUpdater): class TransactionBase(StatusUpdater):
def get_default_address_and_contact(self, party_field, party_name=None):
"""get a dict of default field values of address and contact for a given party type
party_type can be one of: customer, supplier"""
if not party_name:
party_name = self.doc.fields.get(party_field)
return get_default_address_and_contact(party_field, party_name,
fetch_shipping_address=True if self.meta.get_field("shipping_address_name") else False)
def set_address_fields(self):
party_type, party_name = self.get_party_type_and_name()
if party_type in ("Customer", "Lead"):
if self.doc.customer_address:
self.doc.address_display = get_address_display(self.doc.customer_address)
if self.doc.shipping_address_name:
self.doc.shipping_address = get_address_display(self.doc.shipping_address_name)
elif self.doc.supplier_address:
self.doc.address_display = get_address_display(self.doc.supplier_address)
def set_contact_fields(self): def set_contact_fields(self):
party_type, party_name = self.get_party_type_and_name() party_type, party_name = self.get_party_type_and_name()
@ -53,96 +31,6 @@ class TransactionBase(StatusUpdater):
break break
return self._party_type_and_name return self._party_type_and_name
def get_customer_defaults(self):
if not self.doc.customer: return {}
out = self.get_default_address_and_contact("customer")
customer = webnotes.doc("Customer", self.doc.customer)
for f in ['customer_name', 'customer_group', 'territory']:
out[f] = customer.fields.get(f)
# fields prepended with default in Customer doctype
for f in ['sales_partner', 'commission_rate', 'currency', 'price_list', 'taxes_and_charges']:
if customer.fields.get("default_" + f):
out[f] = customer.fields.get("default_" + f)
return out
def set_customer_defaults(self):
"""
For a customer:
1. Sets default address and contact
2. Sets values like Territory, Customer Group, etc.
3. Clears existing Sales Team and fetches the one mentioned in Customer
"""
customer_defaults = self.get_customer_defaults()
customer_defaults["selling_price_list"] = \
self.get_user_default_price_list("selling_price_list") or \
customer_defaults.get("price_list") or \
webnotes.conn.get_value("Customer Group", self.doc.customer_group,
"default_price_list") or self.doc.selling_price_list
for fieldname, val in customer_defaults.items():
if self.meta.get_field(fieldname):
self.doc.fields[fieldname] = val
if self.meta.get_field("sales_team") and self.doc.customer:
self.set_sales_team_for_customer()
def get_user_default_price_list(self, price_list):
from webnotes.defaults import get_defaults_for
user_default_price_list = get_defaults_for(webnotes.session.user).get(price_list)
return cstr(user_default_price_list) \
if not isinstance(user_default_price_list, list) else ""
def set_sales_team_for_customer(self):
from webnotes.model import default_fields
# clear table
self.doclist = self.doc.clear_table(self.doclist, "sales_team")
sales_team = webnotes.conn.sql("""select * from `tabSales Team`
where parenttype="Customer" and parent=%s""", self.doc.customer, as_dict=True)
for i, sales_person in enumerate(sales_team):
# remove default fields
for fieldname in default_fields:
if fieldname in sales_person:
del sales_person[fieldname]
sales_person.update({
"doctype": "Sales Team",
"parentfield": "sales_team",
"idx": i + 1
})
# add child
self.doclist.append(sales_person)
def get_supplier_defaults(self):
out = self.get_default_address_and_contact("supplier")
supplier = webnotes.doc("Supplier", self.doc.supplier)
out["supplier_name"] = supplier.supplier_name
if supplier.default_currency:
out["currency"] = supplier.default_currency
# fields prepended with default in Customer doctype
for f in ['currency', 'taxes_and_charges']:
if supplier.fields.get("default_" + f):
out[f] = supplier.fields.get("default_" + f)
out["buying_price_list"] = self.get_user_default_price_list("buying_price_list") or \
supplier.default_price_list or self.doc.buying_price_list
return out
def set_supplier_defaults(self):
for fieldname, val in self.get_supplier_defaults().items():
if self.meta.get_field(fieldname):
self.doc.fields[fieldname] = val
def get_lead_defaults(self): def get_lead_defaults(self):
out = self.get_default_address_and_contact("lead") out = self.get_default_address_and_contact("lead")
@ -157,88 +45,6 @@ class TransactionBase(StatusUpdater):
def set_lead_defaults(self): def set_lead_defaults(self):
self.doc.fields.update(self.get_lead_defaults()) self.doc.fields.update(self.get_lead_defaults())
def get_customer_address(self, args):
args = json.loads(args)
ret = {
'customer_address' : args["address"],
'address_display' : get_address_display(args["address"]),
}
if args.get('contact'):
ret.update(map_party_contact_details(args['contact']))
return ret
def set_customer_address(self, args):
self.doc.fields.update(self.get_customer_address(args))
# TODO deprecate this - used only in sales_order.js
def get_shipping_address(self, name):
shipping_address = get_default_address("customer", name, is_shipping_address=True)
return {
'shipping_address_name' : shipping_address,
'shipping_address' : get_address_display(shipping_address) if shipping_address else None
}
# Get Supplier Default Primary Address - first load
# -----------------------
def get_default_supplier_address(self, args):
if isinstance(args, basestring):
args = json.loads(args)
address_name = get_default_address("supplier", args["supplier"])
ret = {
'supplier_address' : address_name,
'address_display' : get_address_display(address_name),
}
ret.update(map_party_contact_details(None, "supplier", args["supplier"]))
ret.update(self.get_supplier_details(args['supplier']))
return ret
# Get Supplier Address
# -----------------------
def get_supplier_address(self, args):
args = json.loads(args)
ret = {
'supplier_address' : args['address'],
'address_display' : get_address_display(args["address"]),
}
ret.update(map_party_contact_details(contact_name=args['contact']))
return ret
def set_supplier_address(self, args):
self.doc.fields.update(self.get_supplier_address(args))
# Get Supplier Details
# -----------------------
def get_supplier_details(self, name):
supplier_details = webnotes.conn.sql("""\
select supplier_name, default_currency
from `tabSupplier`
where name = %s and docstatus < 2""", name, as_dict=1)
if supplier_details:
return {
'supplier_name': (supplier_details[0]['supplier_name']
or self.doc.fields.get('supplier_name')),
'currency': (supplier_details[0]['default_currency']
or self.doc.fields.get('currency')),
}
else:
return {}
# Get Sales Person Details of Customer
# ------------------------------------
def get_sales_person(self, name):
self.doclist = self.doc.clear_table(self.doclist,'sales_team')
idx = 0
for d in webnotes.conn.sql("select sales_person, allocated_percentage, allocated_amount, incentives from `tabSales Team` where parent = '%s'" % name):
ch = addchild(self.doc, 'sales_team', 'Sales Team', self.doclist)
ch.sales_person = d and cstr(d[0]) or ''
ch.allocated_percentage = d and flt(d[1]) or 0
ch.allocated_amount = d and flt(d[2]) or 0
ch.incentives = d and flt(d[3]) or 0
ch.idx = idx
idx += 1
def load_notification_message(self): def load_notification_message(self):
dt = self.doc.doctype.lower().replace(" ", "_") dt = self.doc.doctype.lower().replace(" ", "_")
@ -321,68 +127,13 @@ class TransactionBase(StatusUpdater):
if prevdoc_values[field] is not None: if prevdoc_values[field] is not None:
self.validate_value(field, condition, prevdoc_values[field], doc) self.validate_value(field, condition, prevdoc_values[field], doc)
def get_default_address_and_contact(party_field, party_name, fetch_shipping_address=False):
out = {}
# get addresses
billing_address = get_default_address(party_field, party_name)
if billing_address:
out[party_field + "_address"] = billing_address
out["address_display"] = get_address_display(billing_address)
else:
out[party_field + "_address"] = out["address_display"] = None
if fetch_shipping_address:
shipping_address = get_default_address(party_field, party_name, is_shipping_address=True)
if shipping_address:
out["shipping_address_name"] = shipping_address
out["shipping_address"] = get_address_display(shipping_address)
else:
out["shipping_address_name"] = out["shipping_address"] = None
# get contact
if party_field == "lead":
out["customer_address"] = out.get("lead_address")
out.update(map_lead_contact_details(party_name))
else:
out.update(map_party_contact_details(None, party_field, party_name))
return out
def get_default_address(party_field, party_name, is_shipping_address=False):
if is_shipping_address:
order_by = "is_shipping_address desc, is_primary_address desc, name asc"
else:
order_by = "is_primary_address desc, name asc"
address = webnotes.conn.sql("""select name from `tabAddress` where `%s`=%s order by %s
limit 1""" % (party_field, "%s", order_by), party_name)
return address[0][0] if address else None
def get_default_contact(party_field, party_name): def get_default_contact(party_field, party_name):
contact = webnotes.conn.sql("""select name from `tabContact` where `%s`=%s contact = webnotes.conn.sql("""select name from `tabContact` where `%s`=%s
order by is_primary_contact desc, name asc limit 1""" % (party_field, "%s"), order by is_primary_contact desc, name asc limit 1""" % (party_field, "%s"),
(party_name,)) (party_name,))
return contact[0][0] if contact else None return contact[0][0] if contact else None
def get_address_display(address_dict):
if not isinstance(address_dict, dict):
address_dict = webnotes.conn.get_value("Address", address_dict, "*", as_dict=True) or {}
meta = webnotes.get_doctype("Address")
sequence = (("", "address_line1"), ("\n", "address_line2"), ("\n", "city"),
("\n", "state"), ("\n" + meta.get_label("pincode") + ": ", "pincode"), ("\n", "country"),
("\n" + meta.get_label("phone") + ": ", "phone"), ("\n" + meta.get_label("fax") + ": ", "fax"))
display = ""
for separator, fieldname in sequence:
if address_dict.get(fieldname):
display += separator + address_dict.get(fieldname)
return display.strip()
def map_lead_contact_details(party_name): def map_lead_contact_details(party_name):
out = {} out = {}
for fieldname in ["contact_display", "contact_email", "contact_mobile", "contact_phone"]: for fieldname in ["contact_display", "contact_email", "contact_mobile", "contact_phone"]: