From a83de5eac1e8380ed23c65d64f6fb47076f2de94 Mon Sep 17 00:00:00 2001 From: bhupen Date: Thu, 22 Dec 2016 14:17:22 +0530 Subject: [PATCH] applicabe charges field is now editable --- .../landed_cost_item/landed_cost_item.json | 35 ++++- .../landed_cost_taxes_and_charges.json | 12 +- .../landed_cost_voucher.js | 24 +++- .../landed_cost_voucher.json | 123 +++++++++++++----- .../landed_cost_voucher.py | 22 ++-- 5 files changed, 163 insertions(+), 53 deletions(-) diff --git a/erpnext/stock/doctype/landed_cost_item/landed_cost_item.json b/erpnext/stock/doctype/landed_cost_item/landed_cost_item.json index e679054815..61c19f0583 100644 --- a/erpnext/stock/doctype/landed_cost_item/landed_cost_item.json +++ b/erpnext/stock/doctype/landed_cost_item/landed_cost_item.json @@ -9,11 +9,13 @@ "doctype": "DocType", "document_type": "Document", "editable_grid": 1, + "engine": "InnoDB", "fields": [ { "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "item_code", "fieldtype": "Link", "hidden": 0, @@ -21,6 +23,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Item Code", "length": 0, "no_copy": 0, @@ -29,6 +32,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 1, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 1, "search_index": 0, @@ -40,6 +44,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "description", "fieldtype": "Text Editor", "hidden": 0, @@ -47,6 +52,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Description", "length": 0, "no_copy": 0, @@ -57,6 +63,7 @@ "print_hide_if_no_value": 0, "print_width": "300px", "read_only": 1, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 1, "search_index": 0, @@ -68,6 +75,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "receipt_document_type", "fieldtype": "Select", "hidden": 0, @@ -75,6 +83,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, + "in_standard_filter": 0, "label": "Receipt Document Type", "length": 0, "no_copy": 1, @@ -84,6 +93,7 @@ "print_hide": 1, "print_hide_if_no_value": 0, "read_only": 1, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -94,6 +104,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "receipt_document", "fieldtype": "Dynamic Link", "hidden": 0, @@ -101,6 +112,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, + "in_standard_filter": 0, "label": "Receipt Document", "length": 0, "no_copy": 1, @@ -110,6 +122,7 @@ "print_hide": 1, "print_hide_if_no_value": 0, "read_only": 1, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -120,6 +133,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "col_break2", "fieldtype": "Column Break", "hidden": 0, @@ -127,12 +141,14 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, + "in_standard_filter": 0, "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -143,6 +159,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "qty", "fieldtype": "Float", "hidden": 0, @@ -150,6 +167,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Qty", "length": 0, "no_copy": 0, @@ -157,6 +175,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 1, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -167,6 +186,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "rate", "fieldtype": "Currency", "hidden": 0, @@ -174,6 +194,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, + "in_standard_filter": 0, "label": "Rate", "length": 0, "no_copy": 0, @@ -182,6 +203,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 1, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -192,6 +214,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "amount", "fieldtype": "Currency", "hidden": 0, @@ -199,6 +222,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Amount", "length": 0, "no_copy": 0, @@ -209,6 +233,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 1, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 1, "search_index": 0, @@ -219,6 +244,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "applicable_charges", "fieldtype": "Currency", "hidden": 0, @@ -226,6 +252,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Applicable Charges", "length": 0, "no_copy": 0, @@ -233,7 +260,8 @@ "permlevel": 0, "print_hide": 0, "print_hide_if_no_value": 0, - "read_only": 1, + "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -244,6 +272,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "purchase_receipt_item", "fieldtype": "Data", "hidden": 1, @@ -251,6 +280,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, + "in_standard_filter": 0, "label": "Purchase Receipt Item", "length": 0, "no_copy": 1, @@ -258,6 +288,7 @@ "print_hide": 1, "print_hide_if_no_value": 0, "read_only": 1, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -275,7 +306,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2016-07-11 03:28:01.757912", + "modified": "2016-12-20 04:50:19.785273", "modified_by": "Administrator", "module": "Stock", "name": "Landed Cost Item", diff --git a/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json b/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json index b1f5a8ccdb..dbc6a88ba3 100644 --- a/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json +++ b/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json @@ -9,11 +9,13 @@ "doctype": "DocType", "document_type": "", "editable_grid": 1, + "engine": "InnoDB", "fields": [ { "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "description", "fieldtype": "Text Editor", "hidden": 0, @@ -21,6 +23,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Description", "length": 0, "no_copy": 0, @@ -28,6 +31,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 1, "search_index": 0, @@ -38,6 +42,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "col_break3", "fieldtype": "Column Break", "hidden": 0, @@ -45,12 +50,14 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, + "in_standard_filter": 0, "length": 0, "no_copy": 0, "permlevel": 0, "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, @@ -62,6 +69,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "amount", "fieldtype": "Currency", "hidden": 0, @@ -69,6 +77,7 @@ "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "Amount", "length": 0, "no_copy": 0, @@ -77,6 +86,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 1, "search_index": 0, @@ -94,7 +104,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2016-07-11 03:28:01.958276", + "modified": "2016-12-20 05:44:54.700163", "modified_by": "Administrator", "module": "Stock", "name": "Landed Cost Taxes and Charges", diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js index 525853bf44..5035379e8b 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js @@ -32,7 +32,7 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({ }, - refresh: function() { + refresh: function(frm) { var help_content = [ '

', '', @@ -70,12 +70,15 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({ } else { return this.frm.call({ doc: me.frm.doc, - method: "get_items_from_purchase_receipts" + method: "get_items_from_purchase_receipts", + callback: function(r, rt) { + me.set_applicable_charges_for_item(); + } }); } }, - amount: function() { + amount: function(frm) { this.set_total_taxes_and_charges(); this.set_applicable_charges_for_item(); }, @@ -90,17 +93,28 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({ set_applicable_charges_for_item: function() { var me = this; + + + console.log(this.frm) if(this.frm.doc.taxes.length) { + var total_item_cost = 0.0; + var based_on = this.frm.doc.distribute_charges_based_on.toLowerCase(); $.each(this.frm.doc.items || [], function(i, d) { - total_item_cost += flt(d.amount) + total_item_cost += flt(d[based_on]) }); $.each(this.frm.doc.items || [], function(i, item) { - item.applicable_charges = flt(item.amount) * flt(me.frm.doc.total_taxes_and_charges) / flt(total_item_cost) + + item.applicable_charges = flt(item[based_on]) * flt(me.frm.doc.total_taxes_and_charges) / flt(total_item_cost) + + }); refresh_field("items"); } + }, + distribute_charges_based_on: function (frm) { + this.set_applicable_charges_for_item(); } }); diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.json b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.json index 227541f375..db6e40207a 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.json +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.json @@ -10,6 +10,7 @@ "doctype": "DocType", "document_type": "Document", "editable_grid": 0, + "engine": "InnoDB", "fields": [ { "allow_on_submit": 0, @@ -96,6 +97,34 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "purchase_receipt_items", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Purchase Receipt Items", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -151,6 +180,35 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "sec_break1", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Additional Charges", + "length": 0, + "no_copy": 0, + "options": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -184,7 +242,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "sec_break1", + "fieldname": "section_break_9", "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, @@ -194,7 +252,6 @@ "in_standard_filter": 0, "length": 0, "no_copy": 0, - "options": "Simple", "permlevel": 0, "precision": "", "print_hide": 0, @@ -235,34 +292,6 @@ "set_only_once": 0, "unique": 0 }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "amended_from", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Amended From", - "length": 0, - "no_copy": 1, - "options": "Landed Cost Voucher", - "permlevel": 0, - "print_hide": 1, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, { "allow_on_submit": 0, "bold": 0, @@ -295,7 +324,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "default": "Amount", + "default": "", "fieldname": "distribute_charges_based_on", "fieldtype": "Select", "hidden": 0, @@ -320,6 +349,34 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "amended_from", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Amended From", + "length": 0, + "no_copy": 1, + "options": "Landed Cost Voucher", + "permlevel": 0, + "print_hide": 1, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -378,7 +435,7 @@ ], "hide_heading": 0, "hide_toolbar": 0, - "icon": "fa fa-usd", + "icon": "icon-usd", "idx": 0, "image_view": 0, "in_create": 0, @@ -387,7 +444,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-11-07 05:09:46.981120", + "modified": "2016-12-21 01:40:13.959409", "modified_by": "Administrator", "module": "Stock", "name": "Landed Cost Voucher", diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py index cdf7263126..aacf02c4e0 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py @@ -29,9 +29,6 @@ class LandedCostVoucher(Document): item.receipt_document = pr.receipt_document item.purchase_receipt_item = d.name - if self.get("taxes"): - self.set_applicable_charges_for_item() - def validate(self): self.check_mandatory() self.validate_purchase_receipts() @@ -39,15 +36,13 @@ class LandedCostVoucher(Document): if not self.get("items"): self.get_items_from_purchase_receipts() else: - self.set_applicable_charges_for_item() + self.validate_applicable_charges_for_item() def check_mandatory(self): if not self.get("purchase_receipts"): frappe.throw(_("Please enter Receipt Document")) - if not self.get("taxes"): - frappe.throw(_("Please enter Taxes and Charges")) - + def validate_purchase_receipts(self): receipt_documents = [] @@ -67,15 +62,18 @@ class LandedCostVoucher(Document): def set_total_taxes_and_charges(self): self.total_taxes_and_charges = sum([flt(d.amount) for d in self.get("taxes")]) - def set_applicable_charges_for_item(self): + def validate_applicable_charges_for_item(self): based_on = self.distribute_charges_based_on.lower() + total = sum([flt(d.get(based_on)) for d in self.get("items")]) - + if not total: - frappe.throw(_("Total {0} for all items is zero, may you should change 'Distribute Charges Based On'").format(based_on)) + frappe.throw(_("Total {0} for all items is zero, may be you should change 'Distribute Charges Based On'").format(based_on)) + + if self.total_taxes_and_charges != sum([flt(d.applicable_charges) for d in self.get("items")]): + frappe.throw(_("Total Applicable Charges in Purchase Receipt Items table must be same as Total Taxes and Charges")) + - for item in self.get("items"): - item.applicable_charges = flt(item.get(based_on)) * flt(self.total_taxes_and_charges) / flt(total) def on_submit(self): self.update_landed_cost()