diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index b1fe0bec84..295f649d60 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -341,13 +341,23 @@ class SalesInvoice(SellingController): super(SalesInvoice, self).validate_with_previous_doc({ "Sales Order": { "ref_dn_field": "sales_order", - "compare_fields": [["customer", "="], ["company", "="], ["project", "="], - ["currency", "="]], + "compare_fields": [["customer", "="], ["company", "="], ["project", "="], ["currency", "="]] + }, + "Sales Order Item": { + "ref_dn_field": "so_detail", + "compare_fields": [["item_code", "="], ["uom", "="], ["conversion_factor", "="]], + "is_child_table": True, + "allow_duplicate_prev_row_id": True }, "Delivery Note": { "ref_dn_field": "delivery_note", - "compare_fields": [["customer", "="], ["company", "="], ["project", "="], - ["currency", "="]], + "compare_fields": [["customer", "="], ["company", "="], ["project", "="], ["currency", "="]] + }, + "Delivery Note Item": { + "ref_dn_field": "dn_detail", + "compare_fields": [["item_code", "="], ["uom", "="], ["conversion_factor", "="]], + "is_child_table": True, + "allow_duplicate_prev_row_id": True }, }) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index 88e7d20e08..e7b0d1ac8d 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -59,7 +59,8 @@ class PurchaseOrder(BuyingController): }, "Supplier Quotation Item": { "ref_dn_field": "supplier_quotation_item", - "compare_fields": [["rate", "="], ["project", "="], ["item_code", "="]], + "compare_fields": [["rate", "="], ["project", "="], ["item_code", "="], + ["uom", "="], ["conversion_factor", "="]], "is_child_table": True } }) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 7f0e917823..03c713eef2 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -564,14 +564,14 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } }, - conversion_factor: function(doc, cdt, cdn) { + conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) { if(frappe.meta.get_docfield(cdt, "stock_qty", cdn)) { var item = frappe.get_doc(cdt, cdn); frappe.model.round_floats_in(item, ["qty", "conversion_factor"]); item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item)); refresh_field("stock_qty", item.name, item.parentfield); this.toggle_conversion_factor(item); - this.apply_price_list(item, true); + if(!dont_fetch_price_list_rate) this.apply_price_list(item, true); } }, @@ -582,7 +582,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }, qty: function(doc, cdt, cdn) { - this.conversion_factor(doc, cdt, cdn); + this.conversion_factor(doc, cdt, cdn, true); + this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true); }, set_dynamic_labels: function() { diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index a2a0115c1b..1c730ffd08 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -117,18 +117,31 @@ class DeliveryNote(SellingController): if not self.installation_status: self.installation_status = 'Not Installed' def validate_with_previous_doc(self): - 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 self.get("items")]): - super(DeliveryNote, self).validate_with_previous_doc({ - fn[0]: { - "ref_dn_field": fn[1], - "compare_fields": [["customer", "="], ["company", "="], ["project", "="], - ["currency", "="]], - }, - }) + super(DeliveryNote, self).validate_with_previous_doc({ + "Sales Order": { + "ref_dn_field": "against_sales_order", + "compare_fields": [["customer", "="], ["company", "="], ["project", "="], ["currency", "="]] + }, + "Sales Order Item": { + "ref_dn_field": "so_detail", + "compare_fields": [["item_code", "="], ["uom", "="], ["conversion_factor", "="]], + "is_child_table": True, + "allow_duplicate_prev_row_id": True + }, + "Sales Invoice": { + "ref_dn_field": "against_sales_invoice", + "compare_fields": [["customer", "="], ["company", "="], ["project", "="], ["currency", "="]] + }, + "Sales Invoice Item": { + "ref_dn_field": "si_detail", + "compare_fields": [["item_code", "="], ["uom", "="], ["conversion_factor", "="]], + "is_child_table": True, + "allow_duplicate_prev_row_id": True + }, + }) - if cint(frappe.db.get_single_value('Selling Settings', 'maintain_same_sales_rate')) and not self.is_return: + if cint(frappe.db.get_single_value('Selling Settings', 'maintain_same_sales_rate')) \ + and not self.is_return: self.validate_rate_with_reference_doc([["Sales Order", "against_sales_order", "so_detail"], ["Sales Invoice", "against_sales_invoice", "si_detail"]])