From a9ec49e0bf8b666ecd2aecd5994e36efe332b56b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 15 Jul 2013 16:33:24 +0530 Subject: [PATCH 1/4] [fix] [mapper] add rows only table is blank, allow multiple time pull and validation if same item pulled twice --- .../purchase_invoice/purchase_invoice.py | 10 ------ .../doctype/sales_invoice/sales_invoice.py | 19 ------------ .../doctype/purchase_order/purchase_order.py | 2 ++ .../supplier_quotation/supplier_quotation.py | 1 + controllers/selling_controller.py | 3 ++ .../salary_structure/salary_structure.py | 6 ++-- .../installation_note/installation_note.py | 6 ---- selling/doctype/opportunity/opportunity.py | 3 +- selling/doctype/quotation/quotation.py | 10 ++++-- selling/doctype/sales_order/sales_order.py | 24 ++++++++------ stock/doctype/delivery_note/delivery_note.py | 31 ++++++------------- .../purchase_receipt/purchase_receipt.py | 7 +---- utilities/transaction_base.py | 8 ++++- 13 files changed, 53 insertions(+), 77 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index f1c9c42644..235f34fce5 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -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 diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 79f757f423..93fb47f9db 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -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) diff --git a/buying/doctype/purchase_order/purchase_order.py b/buying/doctype/purchase_order/purchase_order.py index 0ba00a6de1..406f3a990b 100644 --- a/buying/doctype/purchase_order/purchase_order.py +++ b/buying/doctype/purchase_order/purchase_order.py @@ -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) diff --git a/buying/doctype/supplier_quotation/supplier_quotation.py b/buying/doctype/supplier_quotation/supplier_quotation.py index 128cee2d65..ae3fbd3dd9 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.py +++ b/buying/doctype/supplier_quotation/supplier_quotation.py @@ -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) diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py index 80bb9143a1..2cd1be2067 100644 --- a/controllers/selling_controller.py +++ b/controllers/selling_controller.py @@ -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) diff --git a/hr/doctype/salary_structure/salary_structure.py b/hr/doctype/salary_structure/salary_structure.py index 37b0b4720c..c7b33e4ae2 100644 --- a/hr/doctype/salary_structure/salary_structure.py +++ b/hr/doctype/salary_structure/salary_structure.py @@ -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) diff --git a/selling/doctype/installation_note/installation_note.py b/selling/doctype/installation_note/installation_note.py index a91db0ed5c..fd85443db6 100644 --- a/selling/doctype/installation_note/installation_note.py +++ b/selling/doctype/installation_note/installation_note.py @@ -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 diff --git a/selling/doctype/opportunity/opportunity.py b/selling/doctype/opportunity/opportunity.py index fe4042b6c8..d4a97b6c8b 100644 --- a/selling/doctype/opportunity/opportunity.py +++ b/selling/doctype/opportunity/opportunity.py @@ -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) diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index f1e11a0ee8..1b286d111b 100644 --- a/selling/doctype/quotation/quotation.py +++ b/selling/doctype/quotation/quotation.py @@ -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) diff --git a/selling/doctype/sales_order/sales_order.py b/selling/doctype/sales_order/sales_order.py index be57853b4a..13f0e9f043 100644 --- a/selling/doctype/sales_order/sales_order.py +++ b/selling/doctype/sales_order/sales_order.py @@ -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) diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index 77038bb603..77c70ee004 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -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) diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py index 0ec73361c6..14d0c031a1 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/stock/doctype/purchase_receipt/purchase_receipt.py @@ -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) diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index ed404dd220..8f168f6479 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -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) From 40cb8fb1933ea60c686c5478c9293efbd1a967cc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 15 Jul 2013 17:23:49 +0530 Subject: [PATCH 2/4] [fix] [minor] Installation Note: pulling from DN and code cleanup --- .../installation_note/installation_note.js | 145 ++++++++++-------- .../installation_note/installation_note.txt | 24 +-- selling/doctype/sales_common/sales_common.py | 10 +- stock/doctype/delivery_note/delivery_note.py | 10 +- 4 files changed, 95 insertions(+), 94 deletions(-) diff --git a/selling/doctype/installation_note/installation_note.js b/selling/doctype/installation_note/installation_note.js index 4cbd67d729..3f02c834f3 100644 --- a/selling/doctype/installation_note/installation_note.js +++ b/selling/doctype/installation_note/installation_note.js @@ -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" - } -} \ No newline at end of file +$.extend(cur_frm.cscript, new erpnext.selling.InstallationNote({frm: cur_frm})); \ No newline at end of file diff --git a/selling/doctype/installation_note/installation_note.txt b/selling/doctype/installation_note/installation_note.txt index d148f3125b..7486586c3f 100644 --- a/selling/doctype/installation_note/installation_note.txt +++ b/selling/doctype/installation_note/installation_note.txt @@ -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", diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index ab5cd0a274..c174b13a69 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -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 diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index 77c70ee004..24df878919 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -401,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] } @@ -419,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] \ No newline at end of file From da46a3782fdfabc1f3f410dad1f7c6aa37002d40 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 15 Jul 2013 17:52:10 +0530 Subject: [PATCH 3/4] [fix] [minor] get query --- buying/doctype/purchase_common/purchase_common.js | 2 ++ buying/doctype/purchase_common/purchase_common.py | 2 +- controllers/queries.py | 10 +++++++++- stock/doctype/material_request/material_request.txt | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index bf2cbce91f..e93d34ed73 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -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" diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py index 1eb2809e36..e14b1caaae 100644 --- a/buying/doctype/purchase_common/purchase_common.py +++ b/buying/doctype/purchase_common/purchase_common.py @@ -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 '' \ No newline at end of file diff --git a/controllers/queries.py b/controllers/queries.py index ab2e234f18..d5f8dcb94f 100644 --- a/controllers/queries.py +++ b/controllers/queries.py @@ -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}) \ No newline at end of file + '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)) \ No newline at end of file diff --git a/stock/doctype/material_request/material_request.txt b/stock/doctype/material_request/material_request.txt index 92bca0ada9..f6dd6e64f0 100644 --- a/stock/doctype/material_request/material_request.txt +++ b/stock/doctype/material_request/material_request.txt @@ -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", From 00dadc8bd5734652e2f41f725c6a0d827c895e4d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 15 Jul 2013 18:16:37 +0530 Subject: [PATCH 4/4] [fix] [minor] get query --- .../purchase_invoice/purchase_invoice.py | 18 ++++++++++++------ .../purchase_taxes_and_charges_master.js | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 235f34fce5..aa82492baa 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -135,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" diff --git a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js index 5717bbfb25..e414c82d44 100644 --- a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js +++ b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js @@ -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"],