From 3b3c48c8774dd0865962bb49e9dd0790421f81a9 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 8 Jul 2015 13:06:45 +0530 Subject: [PATCH 1/6] [fix] Set Customer name in opportunity as per company name in lead --- erpnext/crm/doctype/opportunity/opportunity.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 022539817e..78729a3bcb 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -79,7 +79,8 @@ class Opportunity(TransactionBase): if self.customer: self.customer_name = frappe.db.get_value("Customer", self.customer, "customer_name") elif self.lead: - self.customer_name = frappe.db.get_value("Lead", self.lead, "lead_name") + lead_name, company_name = frappe.db.get_value("Lead", self.lead, ["lead_name", "company_name"]) + self.customer_name = company_name or lead_name def get_cust_address(self,name): details = frappe.db.sql("""select customer_name, address, territory, customer_group From c450536a2cb7f9d8ff486b315d41304a2d60946d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 8 Jul 2015 13:08:02 +0530 Subject: [PATCH 2/6] [fix] Map values in Debit / Credit Note from Stock Entry --- erpnext/stock/doctype/stock_entry/stock_entry.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 813a61b7d3..d896b25d25 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -870,8 +870,6 @@ def make_return_jv(stock_entry): "account": r.get("account"), "party_type": r.get("party_type"), "party": r.get("party"), - "against_invoice": r.get("against_invoice"), - "against_voucher": r.get("against_voucher"), "balance": get_balance_on(r.get("account"), se.posting_date) if r.get("account") else 0 }) @@ -882,8 +880,7 @@ def make_return_jv_from_sales_invoice(se, ref): parent = { "account": ref.doc.debit_to, "party_type": "Customer", - "party": ref.doc.customer, - "against_invoice": ref.doc.name, + "party": ref.doc.customer } # income account entries @@ -957,9 +954,6 @@ def make_return_jv_from_delivery_note(se, ref): break - if len(invoices_against_delivery) == 1: - parent["against_invoice"] = invoices_against_delivery[0] - result = [parent] + [{"account": account} for account in children] return result @@ -1015,9 +1009,6 @@ def make_return_jv_from_purchase_receipt(se, ref): break - if len(invoice_against_receipt) == 1: - parent["against_voucher"] = invoice_against_receipt[0] - result = [parent] + [{"account": account} for account in children] return result From 28a9e35de9a93d924512d33e4c1c1395ee0fc560 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 8 Jul 2015 13:10:52 +0530 Subject: [PATCH 3/6] Validate item rate with reference document with tolerance 0.009 --- .../purchase_invoice/purchase_invoice.py | 19 +++++-------------- .../doctype/sales_invoice/sales_invoice.py | 19 +++++-------------- .../doctype/delivery_note/delivery_note.py | 17 +++++------------ .../purchase_receipt/purchase_receipt.py | 11 ++--------- erpnext/utilities/transaction_base.py | 13 ++++++++++++- 5 files changed, 29 insertions(+), 50 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 50a79ec01b..af144cbf40 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -124,20 +124,11 @@ class PurchaseInvoice(BuyingController): } }) - if cint(frappe.defaults.get_global_default('maintain_same_rate')): - super(PurchaseInvoice, self).validate_with_previous_doc({ - "Purchase Order Item": { - "ref_dn_field": "po_detail", - "compare_fields": [["rate", "="]], - "is_child_table": True, - "allow_duplicate_prev_row_id": True - }, - "Purchase Receipt Item": { - "ref_dn_field": "pr_detail", - "compare_fields": [["rate", "="]], - "is_child_table": True - } - }) + if cint(frappe.db.get_single_value('Buying Settings', 'maintain_same_rate')): + self.validate_rate_with_reference_doc([ + ["Purchase Order", "purchase_order", "po_detail"], + ["Purchase Receipt", "purchase_receipt", "pr_detail"] + ]) def set_against_expense_account(self): auto_accounting_for_stock = cint(frappe.defaults.get_global_default("auto_accounting_for_stock")) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 604370b326..75d4e2db32 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -263,20 +263,11 @@ class SalesInvoice(SellingController): }, }) - if cint(frappe.defaults.get_global_default('maintain_same_sales_rate')): - super(SalesInvoice, self).validate_with_previous_doc({ - "Sales Order Item": { - "ref_dn_field": "so_detail", - "compare_fields": [["rate", "="]], - "is_child_table": True, - "allow_duplicate_prev_row_id": True - }, - "Delivery Note Item": { - "ref_dn_field": "dn_detail", - "compare_fields": [["rate", "="]], - "is_child_table": True - } - }) + if cint(frappe.db.get_single_value('Selling Settings', 'maintain_same_sales_rate')): + self.validate_rate_with_reference_doc([ + ["Sales Order", "sales_order", "so_detail"], + ["Delivery Note", "delivery_note", "dn_detail"] + ]) def set_against_income_account(self): """Set against account for debit to account""" diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index f52f7e51ca..90a8a6c720 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -108,11 +108,9 @@ class DeliveryNote(SellingController): if not self.installation_status: self.installation_status = 'Not Installed' def validate_with_previous_doc(self): - items = self.get("items") - for fn in (("Sales Order", "against_sales_order", "so_detail"), ("Sales Invoice", "against_sales_invoice", "si_detail")): - if filter(None, [getattr(d, fn[1], None) for d in items]): + if filter(None, [getattr(d, fn[1], None) for d in self.get("items")]): super(DeliveryNote, self).validate_with_previous_doc({ fn[0]: { "ref_dn_field": fn[1], @@ -120,15 +118,10 @@ class DeliveryNote(SellingController): ["currency", "="]], }, }) - - if cint(frappe.defaults.get_global_default('maintain_same_sales_rate')): - super(DeliveryNote, self).validate_with_previous_doc({ - fn[0] + " Item": { - "ref_dn_field": fn[2], - "compare_fields": [["rate", "="]], - "is_child_table": True - } - }) + + if cint(frappe.db.get_single_value('Selling Settings', 'maintain_same_sales_rate')): + self.validate_rate_with_reference_doc([["Sales Order", "sales_order", "so_detail"], + ["Sales Invoice", "sales_invoice", "si_detail"]]) def validate_proj_cust(self): """check for does customer belong to same project as entered..""" diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index e56cd1e907..e78288908d 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -104,15 +104,8 @@ class PurchaseReceipt(BuyingController): } }) - if cint(frappe.defaults.get_global_default('maintain_same_rate')): - super(PurchaseReceipt, self).validate_with_previous_doc({ - "Purchase Order Item": { - "ref_dn_field": "prevdoc_detail_docname", - "compare_fields": [["rate", "="]], - "is_child_table": True - } - }) - + if cint(frappe.db.get_single_value('Buying Settings', 'maintain_same_rate')): + self.validate_rate_with_reference_doc([["Purchase Order", "prevdoc_docname", "prevdoc_detail_docname"]]) def po_required(self): if frappe.db.get_value("Buying Settings", None, "po_required") == 'Yes': diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index be74aeb920..63e8f6761e 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import cstr, now_datetime, cint +from frappe.utils import cstr, now_datetime, cint, flt import frappe.share from erpnext.controllers.status_updater import StatusUpdater @@ -92,6 +92,17 @@ class TransactionBase(StatusUpdater): for field, condition in fields: if prevdoc_values[field] is not None: self.validate_value(field, condition, prevdoc_values[field], doc) + + + def validate_rate_with_reference_doc(self, ref_details): + for ref_dt, ref_dn_field, ref_link_field in ref_details: + for d in self.get("items"): + if d.get(ref_link_field): + ref_rate = frappe.db.get_value(ref_dt + " Item", d.get(ref_link_field), "rate") + + if abs(flt(d.rate - ref_rate, d.precision("rate"))) >= .01: + frappe.throw(_("Row #{0}: Rate must be same with {1}: {2} ({3} / {4}) ") + .format(d.idx, ref_dt, d.get(ref_dn_field), d.rate, ref_rate)) def delete_events(ref_type, ref_name): From 00d79eb68d5aae658f79713ce971311026649b75 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 8 Jul 2015 14:32:27 +0530 Subject: [PATCH 4/6] minor fix --- erpnext/stock/doctype/manage_variants/manage_variants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/manage_variants/manage_variants.py b/erpnext/stock/doctype/manage_variants/manage_variants.py index b6784d3a2e..9bee7fae2d 100644 --- a/erpnext/stock/doctype/manage_variants/manage_variants.py +++ b/erpnext/stock/doctype/manage_variants/manage_variants.py @@ -36,8 +36,8 @@ class ManageVariants(Document): def get_attributes(self): attributes = {} self.set('attributes', []) - for d in frappe.db.sql("""select attribute, attribute_value from `tabVariant Attribute` as attribute, - `tabItem` as item where attribute.parent= item.name and item.variant_of = %s""", self.item_code, as_dict=1): + for d in frappe.db.sql("""select attribute, attribute_value from `tabVariant Attribute` as attr, + `tabItem` as item where attr.parent= item.name and item.variant_of = %s""", self.item_code, as_dict=1): attributes.setdefault(d.attribute, []).append(d.attribute_value) for d in attributes: attribute_values = set(attributes[d]) From 4439d8264ffc808bc9b10305253cb857915aa706 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 8 Jul 2015 14:32:56 +0530 Subject: [PATCH 5/6] minor fix --- erpnext/stock/doctype/manage_variants/manage_variants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/manage_variants/manage_variants.py b/erpnext/stock/doctype/manage_variants/manage_variants.py index 9bee7fae2d..4dcfb22dac 100644 --- a/erpnext/stock/doctype/manage_variants/manage_variants.py +++ b/erpnext/stock/doctype/manage_variants/manage_variants.py @@ -36,8 +36,8 @@ class ManageVariants(Document): def get_attributes(self): attributes = {} self.set('attributes', []) - for d in frappe.db.sql("""select attribute, attribute_value from `tabVariant Attribute` as attr, - `tabItem` as item where attr.parent= item.name and item.variant_of = %s""", self.item_code, as_dict=1): + for d in frappe.db.sql("""select attr.attribute, attr.attribute_value from `tabVariant Attribute` as attr, + `tabItem` as item where attr.parent = item.name and item.variant_of = %s""", self.item_code, as_dict=1): attributes.setdefault(d.attribute, []).append(d.attribute_value) for d in attributes: attribute_values = set(attributes[d]) From 5e3646ad6eb5005794b4ca0202e2c1df9c2a3f98 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 8 Jul 2015 14:39:03 +0530 Subject: [PATCH 6/6] validation message fix --- erpnext/utilities/transaction_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index 63e8f6761e..50b0319d3f 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -101,7 +101,7 @@ class TransactionBase(StatusUpdater): ref_rate = frappe.db.get_value(ref_dt + " Item", d.get(ref_link_field), "rate") if abs(flt(d.rate - ref_rate, d.precision("rate"))) >= .01: - frappe.throw(_("Row #{0}: Rate must be same with {1}: {2} ({3} / {4}) ") + frappe.throw(_("Row #{0}: Rate must be same as {1}: {2} ({3} / {4}) ") .format(d.idx, ref_dt, d.get(ref_dn_field), d.rate, ref_rate))