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

This commit is contained in:
Anand Doshi 2013-07-15 18:30:02 +05:30
commit 05859ad42e
21 changed files with 175 additions and 182 deletions

View File

@ -114,16 +114,6 @@ class DocType(BuyingController):
ret={'add_tax_rate' :rate and flt(rate[0][0]) or 0 }
return ret
def validate_duplicate_docname(self,doctype):
for d in getlist(self.doclist, 'entries'):
if doctype == 'purchase_receipt' and cstr(self.doc.purchase_receipt_main) == cstr(d.purchase_receipt):
msgprint(cstr(self.doc.purchase_receipt_main) + " purchase receipt details have already been pulled.")
raise Exception , " Validation Error. "
if doctype == 'purchase_order' and cstr(self.doc.purchase_order_main) == cstr(d.purchase_order) and not d.purchase_receipt:
msgprint(cstr(self.doc.purchase_order_main) + " purchase order details have already been pulled.")
raise Exception , " Validation Error. "
def check_active_purchase_items(self):
for d in getlist(self.doclist, 'entries'):
if d.item_code: # extra condn coz item_code is not mandatory in PV
@ -145,13 +135,19 @@ class DocType(BuyingController):
raise Exception
def validate_bill_no(self):
if self.doc.bill_no and self.doc.bill_no.lower().strip() not in ['na', 'not applicable', 'none']:
b_no = sql("select bill_no, name, ifnull(is_opening,'') from `tabPurchase Invoice` where bill_no = '%s' and credit_to = '%s' and docstatus = 1 and name != '%s' " % (self.doc.bill_no, self.doc.credit_to, self.doc.name))
if self.doc.bill_no and self.doc.bill_no.lower().strip() \
not in ['na', 'not applicable', 'none']:
b_no = sql("""select bill_no, name, ifnull(is_opening,'') from `tabPurchase Invoice`
where bill_no = %s and credit_to = %s and docstatus = 1 and name != %s""",
(self.doc.bill_no, self.doc.credit_to, self.doc.name))
if b_no and cstr(b_no[0][2]) == cstr(self.doc.is_opening):
msgprint("Please check you have already booked expense against Bill No. %s in Purchase Invoice %s" % (cstr(b_no[0][0]), cstr(b_no[0][1])))
raise Exception , "Validation Error"
if not self.doc.remarks:
self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Against Bill %s dated %s" % (self.doc.bill_no, formatdate(self.doc.bill_date)))
msgprint("Please check you have already booked expense against Bill No. %s \
in Purchase Invoice %s" % (cstr(b_no[0][0]), cstr(b_no[0][1])),
raise_exception=1)
if not self.doc.remarks and self.doc.bill_date:
self.doc.remarks = (self.doc.remarks or '') + "\n" + ("Against Bill %s dated %s"
% (self.doc.bill_no, formatdate(self.doc.bill_date)))
else:
if not self.doc.remarks:
self.doc.remarks = "No Remarks"

View File

@ -127,7 +127,7 @@ cur_frm.cscript.row_id = function(doc, cdt, cdn) {
refresh_field('row_id',d.name,'purchase_tax_details');
}
cur_frm.set_query("account_head", "purchase_tax_details", function() {
cur_frm.set_query("account_head", "purchase_tax_details", function(doc) {
return {
filters: [
["Account", "group_or_ledger", "=", "Ledger"],

View File

@ -276,25 +276,6 @@ class DocType(SellingController):
if self.doc.debit_to:
self.doc.customer = webnotes.conn.get_value('Account',self.doc.debit_to,'master_name')
def update_accounts(self):
if not self.doc.debit_to:
self.doc.debit_to = self.get_debit_to().get("debit_to")
self.get_income_expense_account('entries')
def get_income_expense_account(self,doctype):
auto_inventory_accounting = cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))
default_cost_center = webnotes.conn.get_value("Company", self.doc.company, "cost_center")
for d in getlist(self.doclist, doctype):
if d.item_code:
item = webnotes.conn.get_value("Item", d.item_code, ["default_income_account",
"default_sales_cost_center", "purchase_account"], as_dict=True)
d.income_account = item['default_income_account'] or ""
d.cost_center = item['default_sales_cost_center'] or default_cost_center
if auto_inventory_accounting and cint(self.doc.update_stock):
d.expense_account = item['purchase_account'] or ""
def get_barcode_details(self, barcode):
return get_obj('Sales Common').get_barcode_details(barcode)

View File

@ -25,6 +25,7 @@ wn.require("app/js/transaction.js");
erpnext.buying.BuyingController = erpnext.TransactionController.extend({
onload: function() {
this.setup_queries();
this._super();
},
setup_queries: function() {
@ -39,6 +40,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
this.frm.set_query("price_list_currency", function() {
return{
query: "controllers.queries.get_price_list_currency",
filters: {
'price_list_name': me.frm.doc.price_list_name,
'buying_or_selling': "Buying"

View File

@ -221,4 +221,4 @@ class DocType(BuyingController):
if d.prevdoc_doctype and d.prevdoc_docname:
dt = sql("select transaction_date from `tab%s` where name = %s"
% (d.prevdoc_doctype, '%s'), (d.prevdoc_docname))
d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or ''
d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or ''

View File

@ -231,6 +231,7 @@ def make_purchase_receipt(source_name, target_doclist=None):
},
"Purchase Taxes and Charges": {
"doctype": "Purchase Taxes and Charges",
"add_if_empty": True
}
}, target_doclist, set_missing_values)
@ -271,6 +272,7 @@ def make_purchase_invoice(source_name, target_doclist=None):
},
"Purchase Taxes and Charges": {
"doctype": "Purchase Taxes and Charges",
"add_if_empty": True
}
}, target_doclist, set_missing_values)

View File

@ -102,6 +102,7 @@ def make_purchase_order(source_name, target_doclist=None):
},
"Purchase Taxes and Charges": {
"doctype": "Purchase Taxes and Charges",
"add_if_empty": True
},
}, target_doclist, set_missing_values)

View File

@ -217,4 +217,12 @@ def get_project_name(doctype, txt, searchfield, start, page_len, filters):
and %(cond)s `tabProject`.name like "%(txt)s" %(mcond)s
order by `tabProject`.name asc
limit %(start)s, %(page_len)s """ % {'cond': cond,'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield),'start': start, 'page_len': page_len})
'mcond':get_match_cond(doctype, searchfield),'start': start, 'page_len': page_len})
def get_price_list_currency(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select ref_currency from `tabItem Price`
where price_list_name = %s and buying_or_selling = %s
and `%s` like %s order by ref_currency asc limit %s, %s""" %
("%s", "%s", searchfield, "%s", "%s", "%s"),
(filters["price_list_name"], filters['buying_or_selling'], "%%%s%%" % txt,
start, page_len))

View File

@ -29,6 +29,9 @@ class SellingController(StockController):
self.set_missing_values()
self.set_taxes("other_charges", "charge")
if self.meta.get_field("debit_to") and not self.doc.debit_to:
self.doc.debit_to = self.get_debit_to().get("debit_to")
def set_missing_values(self, for_validate=False):
super(SellingController, self).set_missing_values(for_validate)

View File

@ -117,7 +117,8 @@ def make_salary_slip(source_name, target_doclist=None):
["depend_on_lwp", "d_depends_on_lwp"],
["d_modified_amt", "d_amount"],
["d_modified_amt", "d_modified_amount"]
]
],
"add_if_empty": True
},
"Salary Structure Earning": {
"doctype": "Salary Slip Earning",
@ -125,7 +126,8 @@ def make_salary_slip(source_name, target_doclist=None):
["depend_on_lwp", "e_depends_on_lwp"],
["modified_value", "e_modified_amount"],
["modified_value", "e_amount"]
]
],
"add_if_empty": True
}
}, target_doclist, postprocess)

View File

@ -20,6 +20,67 @@ cur_frm.cscript.fname = "installed_item_details";
wn.provide("erpnext.selling");
// TODO commonify this code
erpnext.selling.InstallationNote = wn.ui.form.Controller.extend({
onload: function() {
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,
{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();
},
setup_queries: function() {
var me = this;
this.frm.set_query("customer_address", function() {
return {
filters: {'customer': me.frm.doc.customer }
}
});
this.frm.set_query("contact_person", function() {
return {
filters: {'customer': me.frm.doc.customer }
}
});
this.frm.set_query("territory", function() {
return {
filters: {'is_group': "No" }
}
});
this.frm.set_query("customer", function() {
return {
query: "controllers.queries.customer_query"
}
});
},
refresh: function() {
if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(wn._('From Delivery Note'),
function() {
wn.model.map_current_doc({
method: "stock.doctype.delivery_note.delivery_note.make_installation_note",
source_doctype: "Delivery Note",
get_query_filters: {
docstatus: 1,
status: ["!=", "Stopped"],
per_installed: ["<", 99.99],
customer: cur_frm.doc.customer || undefined,
company: cur_frm.doc.company
}
})
}
);
}
},
customer: function() {
var me = this;
if(this.frm.doc.customer) {
@ -37,65 +98,29 @@ erpnext.selling.InstallationNote = wn.ui.form.Controller.extend({
'territory', 'customer_group']);
}
},
get_items: function() {
wn.model.map_current_doc({
method: "stock.doctype.delivery_note.delivery_note.make_installation_note",
source_name: cur_frm.doc.delivery_note_no,
})
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) {
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,
callback: function(r) {
me.frm.refresh_fields();
}
});
}
},
contact_person: function() {
this.customer_address();
},
});
$.extend(cur_frm.cscript, new erpnext.selling.InstallationNote({frm: cur_frm}));
cur_frm.cscript.onload = function(doc, dt, dn) {
if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
if(doc.__islocal){
set_multiple(dt,dn,{inst_date:get_today()});
hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
}
if (doc.customer) {
unhide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
}
}
cur_frm.fields_dict['delivery_note_no'].get_query = function(doc) {
doc = locals[this.doctype][this.docname];
var filter = {
'company': doc.company,
'docstatus': 1,
'per_installed': 99.99
};
if(doc.customer) filter['customer'] = doc.customer;
return { filters: filter }
}
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
return{
filters: { 'is_group': "No" }
}
}
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
}
cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
return{
filters: { 'customer': doc.customer }
}
}
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
return{
filters: { 'customer': doc.customer }
}
}
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return{
query:"controllers.queries.customer_query"
}
}
$.extend(cur_frm.cscript, new erpnext.selling.InstallationNote({frm: cur_frm}));

View File

@ -52,12 +52,6 @@ class DocType(TransactionBase):
sales_com_obj = get_obj(dt = 'Sales Common')
sales_com_obj.check_active_sales_items(self)
sales_com_obj.get_prevdoc_date(self)
def validate_prev_docname(self):
for d in getlist(self.doclist, 'installed_item_details'):
if self.doc.delivery_note_no == d.prevdoc_docname:
msgprint(cstr(self.doc.delivery_note_no) +
" delivery note details have already been pulled", raise_exception=1)
def validate_fiscal_year(self):
from accounts.utils import validate_fiscal_year

View File

@ -2,7 +2,7 @@
{
"creation": "2013-04-30 13:13:06",
"docstatus": 0,
"modified": "2013-07-07 18:10:24",
"modified": "2013-07-15 17:09:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -240,28 +240,6 @@
"oldfieldtype": "Section Break",
"options": "Simple"
},
{
"doctype": "DocField",
"fieldname": "delivery_note_no",
"fieldtype": "Link",
"label": "Delivery Note No",
"no_copy": 1,
"oldfieldname": "delivery_note_no",
"oldfieldtype": "Link",
"options": "Delivery Note",
"print_hide": 0,
"reqd": 1,
"search_index": 1
},
{
"doctype": "DocField",
"fieldname": "get_items",
"fieldtype": "Button",
"hidden": 0,
"label": "Get Items",
"oldfieldtype": "Button",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "installed_item_details",

View File

@ -192,7 +192,8 @@ def make_quotation(source_name, target_doclist=None):
"parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype",
"uom": "stock_uom"
}
},
"add_if_empty": True
}
}, target_doclist)

View File

@ -235,7 +235,10 @@ def _make_sales_order(source_name, target_doclist=None, ignore_permissions=False
if customer:
target[0].customer = customer.doc.name
target[0].customer_name = customer.doc.customer_name
si = webnotes.bean(target)
si.run_method("onload_post_render")
doclist = get_mapped_doclist("Quotation", source_name, {
"Quotation": {
"doctype": "Sales Order",
@ -247,13 +250,16 @@ def _make_sales_order(source_name, target_doclist=None, ignore_permissions=False
"doctype": "Sales Order Item",
"field_map": {
"parent": "prevdoc_docname"
}
},
"add_if_empty": True
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",
"add_if_empty": True
},
"Sales Team": {
"doctype": "Sales Team",
"add_if_empty": True
}
}, target_doclist, set_missing_values, ignore_permissions=ignore_permissions)

View File

@ -330,11 +330,13 @@ class DocType(TransactionBase):
def get_prevdoc_date(self, obj):
for d in getlist(obj.doclist, obj.fname):
if d.prevdoc_doctype and d.prevdoc_docname:
if d.prevdoc_doctype == 'Sales Invoice':
dt = webnotes.conn.sql("select posting_date from `tab%s` where name = '%s'" % (d.prevdoc_doctype, d.prevdoc_docname))
if d.prevdoc_doctype in ["Sales Invoice", "Delivery Note"]:
date_field = "posting_date"
else:
dt = webnotes.conn.sql("select transaction_date from `tab%s` where name = '%s'" % (d.prevdoc_doctype, d.prevdoc_docname))
d.prevdoc_date = (dt and dt[0][0]) and dt[0][0].strftime('%Y-%m-%d') or ''
date_field = "transaction_date"
d.prevdoc_date = webnotes.conn.get_value(d.prevdoc_doctype,
d.prevdoc_docname, date_field)
def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond

View File

@ -340,6 +340,10 @@ def get_currency_and_number_format():
from tabCurrency where ifnull(enabled,0)=1""")))
}
def set_missing_values(source, target):
bean = webnotes.bean(target)
bean.run_method("onload_post_render")
@webnotes.whitelist()
def make_material_request(source_name, target_doclist=None):
def postprocess(source, doclist):
@ -395,11 +399,13 @@ def make_delivery_note(source_name, target_doclist=None):
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",
"add_if_empty": True
},
"Sales Team": {
"doctype": "Sales Team",
"doctype": "Sales Team",
"add_if_empty": True
}
}, target_doclist)
}, target_doclist, set_missing_values)
return [d.fields for d in doclist]
@ -409,10 +415,6 @@ def make_sales_invoice(source_name, target_doclist=None):
target.export_amount = flt(obj.amount) - flt(obj.billed_amt)
target.amount = target.export_amount / flt(source_parent.conversion_rate)
target.qty = obj.basic_rate and target.amount / flt(obj.basic_rate) or obj.qty
def update_accounts(source, target):
si = webnotes.bean(target)
si.run_method("update_accounts")
doclist = get_mapped_doclist("Sales Order", source_name, {
"Sales Order": {
@ -433,11 +435,13 @@ def make_sales_invoice(source_name, target_doclist=None):
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",
"add_if_empty": True
},
"Sales Team": {
"doctype": "Sales Team",
"add_if_empty": True
}
}, target_doclist, update_accounts)
}, target_doclist, set_missing_values)
return [d.fields for d in doclist]
@ -462,7 +466,8 @@ def make_maintenance_schedule(source_name, target_doclist=None):
"doctype": "Maintenance Schedule Item",
"field_map": {
"parent": "prevdoc_docname"
}
},
"add_if_empty": True
}
}, target_doclist)
@ -491,7 +496,8 @@ def make_maintenance_visit(source_name, target_doclist=None):
"field_map": {
"parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype"
}
},
"add_if_empty": True
}
}, target_doclist)

View File

@ -136,22 +136,19 @@ class DocType(SellingController):
def validate_for_items(self):
check_list, chk_dupl_itm = [], []
for d in getlist(self.doclist,'delivery_note_details'):
ch = sql("select is_stock_item from `tabItem` where name = '%s'"%d.item_code)
if d.prevdoc_doctype and d.prevdoc_detail_docname and ch and ch[0][0]=='Yes':
self.validate_items_with_prevdoc(d)
# validates whether item is not entered twice
e = [d.item_code, d.description, d.warehouse, d.prevdoc_docname or '', d.batch_no or '']
f = [d.item_code, d.description, d.prevdoc_docname or '']
if ch and ch[0][0] == 'Yes':
if webnotes.conn.get_value("Item", d.item_code, "is_stock_item") == 'Yes':
if e in check_list:
msgprint("Please check whether item %s has been entered twice wrongly." % d.item_code)
msgprint("Please check whether item %s has been entered twice wrongly."
% d.item_code)
else:
check_list.append(e)
elif ch and ch[0][0] == 'No':
else:
if f in chk_dupl_itm:
msgprint("Please check whether item %s has been entered twice wrongly." % d.item_code)
msgprint("Please check whether item %s has been entered twice wrongly."
% d.item_code)
else:
chk_dupl_itm.append(f)
@ -162,16 +159,6 @@ class DocType(SellingController):
msgprint("Please enter Warehouse for item %s as it is stock item"
% d['item_code'], raise_exception=1)
def validate_items_with_prevdoc(self, d):
"""check if same item, warehouse present in prevdoc"""
prev_item_dt = (d.prevdoc_doctype == 'Sales Order') and 'Sales Order Item' or 'Purchase Receipt Item'
data = sql("select item_code from `tab%s` where parent = '%s' and name = '%s'"\
% (prev_item_dt, d.prevdoc_docname, d.prevdoc_detail_docname))
if not data or data[0][0] != d.item_code:
msgprint("Item: %s is not matching with Sales Order: %s. Sales Order might be modified after \
fetching data from it. Please delete items and fetch again." \
% (d.item_code, d.prevdoc_docname), raise_exception=1)
def update_current_stock(self):
for d in getlist(self.doclist, 'delivery_note_details'):
@ -375,7 +362,7 @@ def make_sales_invoice(source_name, target_doclist=None):
def update_accounts(source, target):
si = webnotes.bean(target)
si.run_method("update_accounts")
si.run_method("onload_post_render")
doclist = get_mapped_doclist("Delivery Note", source_name, {
"Delivery Note": {
@ -397,12 +384,14 @@ def make_sales_invoice(source_name, target_doclist=None):
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",
"add_if_empty": True
},
"Sales Team": {
"doctype": "Sales Team",
"field_map": {
"incentives": "incentives"
}
},
"add_if_empty": True
}
}, target_doclist, update_accounts)
@ -412,14 +401,11 @@ def make_sales_invoice(source_name, target_doclist=None):
def make_installation_note(source_name, target_doclist=None):
def update_item(obj, target, source_parent):
target.qty = flt(obj.qty) - flt(obj.installed_qty)
target.prevdoc_date = source_parent.posting_date
doclist = get_mapped_doclist("Delivery Note", source_name, {
"Delivery Note": {
"doctype": "Installation Note Item",
"field_map": {
"name": "delivery_note_no",
"posting_date": "prevdoc_date"
},
"doctype": "Installation Note",
"validation": {
"docstatus": ["=", 1]
}
@ -430,11 +416,10 @@ def make_installation_note(source_name, target_doclist=None):
"name": "prevdoc_detail_docname",
"parent": "prevdoc_docname",
"parenttype": "prevdoc_doctype",
"serial_no": "serial_no"
},
"postprocess": update_item,
"condition": lambda doc: doc.installed_qty < doc.qty
}
}, target_doclist)
return [d.fields for d in doclist]

View File

@ -2,7 +2,7 @@
{
"creation": "2013-03-07 14:48:38",
"docstatus": 0,
"modified": "2013-07-09 11:39:32",
"modified": "2013-07-15 17:50:38",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -16,7 +16,7 @@
"module": "Stock",
"name": "__common__",
"read_only_onload": 1,
"search_fields": "status,transaction_date,sales_order_no"
"search_fields": "status,transaction_date"
},
{
"doctype": "DocField",

View File

@ -49,12 +49,6 @@ class DocType(BuyingController):
def get_bin_details(self, arg = ''):
return get_obj(dt='Purchase Common').get_bin_details(arg)
# validate if PO has been pulled twice
def validate_prev_docname(self):
for d in getlist(self.doclist, 'purchase_receipt_details'):
if self.doc.purchase_order_no and d.prevdoc_docname and self.doc.purchase_order_no == d.prevdoc_docname:
msgprint(cstr(self.doc.purchase_order_no) + " Purchase Order details have already been pulled. ")
raise Exception
# validate accepted and rejected qty
def validate_accepted_rejected_qty(self):
@ -383,6 +377,7 @@ def make_purchase_invoice(source_name, target_doclist=None):
},
"Purchase Taxes and Charges": {
"doctype": "Purchase Taxes and Charges",
"add_if_empty": True
}
}, target_doclist, set_missing_values)

View File

@ -277,12 +277,18 @@ class TransactionBase(StatusUpdater):
for key, val in ref.items():
is_child = val.get("is_child_table")
ref_doc = {}
item_ref_dn = []
for d in self.doclist.get({"doctype": source_dt}):
ref_dn = d.fields.get(val["ref_dn_field"])
if ref_dn:
if is_child:
self.compare_values({key: [ref_dn]}, val["compare_fields"], d)
elif ref_dn:
if ref_dn not in item_ref_dn:
item_ref_dn.append(ref_dn)
else:
webnotes.msgprint(_("Row ") + cstr(d.idx + 1) +
_(": Duplicate row from same ") + key, raise_exception=1)
elif ref_dn:
ref_doc.setdefault(key, [])
if ref_dn not in ref_doc[key]:
ref_doc[key].append(ref_dn)