From 4436157da14c02596115854dbbfe0daa780c8b92 Mon Sep 17 00:00:00 2001 From: nabinhait Date: Sat, 12 Jul 2014 23:24:10 +0530 Subject: [PATCH] Landed cost redesign initial commit #1921 --- .../landed_cost_item/landed_cost_item.json | 85 ++++++++++++---- .../landed_cost_purchase_receipt.json | 40 +++++++- .../landed_cost_taxes_and_charges/__init__.py | 0 .../landed_cost_taxes_and_charges.json | 51 ++++++++++ .../landed_cost_taxes_and_charges.py | 9 ++ .../doctype/landed_cost_voucher/__init__.py | 0 .../landed_cost_voucher.js | 82 ++++++++++++++++ .../landed_cost_voucher.json | 97 +++++++++++++++++++ .../landed_cost_voucher.py | 83 ++++++++++++++++ 9 files changed, 426 insertions(+), 21 deletions(-) create mode 100644 erpnext/stock/doctype/landed_cost_taxes_and_charges/__init__.py create mode 100644 erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json create mode 100644 erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.py create mode 100644 erpnext/stock/doctype/landed_cost_voucher/__init__.py create mode 100644 erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js create mode 100644 erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.json create mode 100644 erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py 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 f761ebabb1..c5887d47f4 100644 --- a/erpnext/stock/doctype/landed_cost_item/landed_cost_item.json +++ b/erpnext/stock/doctype/landed_cost_item/landed_cost_item.json @@ -1,27 +1,18 @@ { - "creation": "2013-02-22 01:28:02.000000", + "creation": "2013-02-22 01:28:02", "docstatus": 0, "doctype": "DocType", "fields": [ { - "fieldname": "account_head", + "fieldname": "item_code", "fieldtype": "Link", "in_list_view": 1, - "label": "Account Head", - "oldfieldname": "account_head", - "oldfieldtype": "Link", - "options": "Account", + "label": "Item Code", + "options": "Item", "permlevel": 0, + "read_only": 1, "reqd": 1, - "search_index": 1 - }, - { - "fieldname": "cost_center", - "fieldtype": "Link", - "label": "Cost Center", - "options": "Cost Center", - "permlevel": 0, - "reqd": 1 + "width": "100px" }, { "fieldname": "description", @@ -32,8 +23,46 @@ "oldfieldtype": "Data", "permlevel": 0, "print_width": "300px", + "read_only": 1, "reqd": 1, - "width": "300px" + "width": "120px" + }, + { + "fieldname": "purchase_receipt", + "fieldtype": "Link", + "hidden": 0, + "label": "Purchase Receipt", + "options": "Purchase Receipt", + "permlevel": 0, + "read_only": 1 + }, + { + "fieldname": "warehouse", + "fieldtype": "Link", + "hidden": 0, + "label": "Warehouse", + "options": "Warehouse", + "permlevel": 0, + "read_only": 1 + }, + { + "fieldname": "col_break2", + "fieldtype": "Column Break", + "permlevel": 0 + }, + { + "fieldname": "qty", + "fieldtype": "Float", + "label": "Qty", + "permlevel": 0, + "read_only": 1 + }, + { + "fieldname": "rate", + "fieldtype": "Currency", + "label": "Rate", + "permlevel": 0, + "read_only": 1 }, { "fieldname": "amount", @@ -44,14 +73,34 @@ "oldfieldtype": "Currency", "options": "currency", "permlevel": 0, + "read_only": 1, "reqd": 1 + }, + { + "fieldname": "old_valuation_rate", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Old Valuation Rate", + "permlevel": 0, + "read_only": 1, + "width": "" + }, + { + "fieldname": "new_valuation_rate", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "New Valuation Rate", + "permlevel": 0, + "read_only": 1, + "width": "" } ], "idx": 1, "istable": 1, - "modified": "2013-12-20 19:23:18.000000", + "modified": "2014-07-11 15:20:53.714633", "modified_by": "Administrator", "module": "Stock", "name": "Landed Cost Item", - "owner": "wasim@webnotestech.com" + "owner": "wasim@webnotestech.com", + "permissions": [] } \ No newline at end of file diff --git a/erpnext/stock/doctype/landed_cost_purchase_receipt/landed_cost_purchase_receipt.json b/erpnext/stock/doctype/landed_cost_purchase_receipt/landed_cost_purchase_receipt.json index b50c148292..651f28834b 100644 --- a/erpnext/stock/doctype/landed_cost_purchase_receipt/landed_cost_purchase_receipt.json +++ b/erpnext/stock/doctype/landed_cost_purchase_receipt/landed_cost_purchase_receipt.json @@ -1,5 +1,5 @@ { - "creation": "2013-02-22 01:28:02.000000", + "creation": "2013-02-22 01:28:02", "docstatus": 0, "doctype": "DocType", "fields": [ @@ -13,14 +13,48 @@ "options": "Purchase Receipt", "permlevel": 0, "print_width": "220px", + "read_only": 0, + "reqd": 1, "width": "220px" + }, + { + "fieldname": "supplier", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Supplier", + "options": "Supplier", + "permlevel": 0, + "read_only": 1 + }, + { + "fieldname": "col_break1", + "fieldtype": "Column Break", + "permlevel": 0, + "width": "50%" + }, + { + "fieldname": "posting_date", + "fieldtype": "Date", + "in_list_view": 1, + "label": "Posting Date", + "permlevel": 0, + "read_only": 1 + }, + { + "fieldname": "grand_total", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Grand Total", + "permlevel": 0, + "read_only": 1 } ], "idx": 1, "istable": 1, - "modified": "2013-12-20 19:23:18.000000", + "modified": "2014-07-11 12:12:08.572263", "modified_by": "Administrator", "module": "Stock", "name": "Landed Cost Purchase Receipt", - "owner": "wasim@webnotestech.com" + "owner": "wasim@webnotestech.com", + "permissions": [] } \ No newline at end of file diff --git a/erpnext/stock/doctype/landed_cost_taxes_and_charges/__init__.py b/erpnext/stock/doctype/landed_cost_taxes_and_charges/__init__.py new file mode 100644 index 0000000000..e69de29bb2 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 new file mode 100644 index 0000000000..d077dbc31d --- /dev/null +++ b/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.json @@ -0,0 +1,51 @@ +{ + "creation": "2014-07-11 11:51:00.453717", + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "fields": [ + { + "fieldname": "description", + "fieldtype": "Small Text", + "in_list_view": 1, + "label": "Description", + "permlevel": 0, + "reqd": 1 + }, + { + "fieldname": "col_break3", + "fieldtype": "Column Break", + "permlevel": 0, + "width": "50%" + }, + { + "fieldname": "account", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Account", + "options": "Account", + "permlevel": 0, + "print_hide": 1, + "read_only": 0, + "reqd": 1 + }, + { + "fieldname": "amount", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Amount", + "permlevel": 0, + "reqd": 1 + } + ], + "istable": 1, + "modified": "2014-07-11 13:00:14.770284", + "modified_by": "Administrator", + "module": "Stock", + "name": "Landed Cost Taxes and Charges", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.py b/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.py new file mode 100644 index 0000000000..2e1f5a31f3 --- /dev/null +++ b/erpnext/stock/doctype/landed_cost_taxes_and_charges/landed_cost_taxes_and_charges.py @@ -0,0 +1,9 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class LandedCostTaxesandCharges(Document): + pass \ No newline at end of file diff --git a/erpnext/stock/doctype/landed_cost_voucher/__init__.py b/erpnext/stock/doctype/landed_cost_voucher/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js new file mode 100644 index 0000000000..47ba0e1c40 --- /dev/null +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js @@ -0,0 +1,82 @@ +// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + + +frappe.provide("erpnext.stock"); +frappe.require("assets/erpnext/js/controllers/stock_controller.js"); + +erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({ + setup: function() { + var me = this; + this.frm.fields_dict.landed_cost_purchase_receipts.grid.get_field('purchase_receipt').get_query = + function() { + if(!me.frm.doc.company) msgprint(__("Please enter company first")); + return { + filters:[ + ['Purchase Receipt', 'docstatus', '=', '1'], + ['Purchase Receipt', 'company', '=', me.frm.doc.company], + ] + } + }; + + this.frm.fields_dict.landed_cost_taxes_and_charges.grid.get_field('account').get_query = function() { + if(!me.frm.doc.company) msgprint(__("Please enter company first")); + return { + filters:[ + ['Account', 'group_or_ledger', '=', 'Ledger'], + ['Account', 'account_type', 'in', ['Tax', 'Chargeable']], + ['Account', 'company', '=', me.frm.doc.company] + ] + } + }; + + this.frm.add_fetch("purchase_receipt", "supplier", "supplier"); + this.frm.add_fetch("purchase_receipt", "posting_date", "posting_date"); + this.frm.add_fetch("purchase_receipt", "grand_total", "grand_total"); + + }, + + get_items_from_purchase_receipts: function() { + var me = this; + if(!this.frm.doc.landed_cost_purchase_receipts.length) { + msgprint(__("Please enter Purchase Receipt first")); + } else { + return this.frm.call({ + doc: me.frm.doc, + method: "get_items_from_purchase_receipts" + }); + } + }, + + amount: function() { + this.set_total_taxes_and_charges(); + this.set_new_valuation_rate(); + }, + + set_total_taxes_and_charges: function() { + total_taxes_and_charges = 0.0; + $.each(this.frm.doc.landed_cost_taxes_and_charges, function(i, d) { + total_taxes_and_charges += flt(d.amount) + }); + cur_frm.set_value("total_taxes_and_charges", total_taxes_and_charges); + }, + + set_new_valuation_rate: function() { + var me = this; + if(this.frm.doc.landed_cost_taxes_and_charges.length) { + var total_item_cost = 0.0; + $.each(this.frm.doc.landed_cost_items, function(i, d) { + total_item_cost += flt(d.amount) + }); + + $.each(this.frm.doc.landed_cost_items, function(i, item) { + var charges_for_item = flt(item.amount) * flt(me.frm.doc.total_taxes_and_charges) / flt(total_item_cost) + item.new_valuation_rate = flt(item.old_valuation_rate) + charges_for_item + }); + refresh_field("landed_cost_items"); + } + } + +}); + +cur_frm.script_manager.make(erpnext.stock.LandedCostVoucher); \ No newline at end of file diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.json b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.json new file mode 100644 index 0000000000..11425c27b7 --- /dev/null +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.json @@ -0,0 +1,97 @@ +{ + "allow_import": 0, + "autoname": "LCV.####", + "creation": "2014-07-11 11:33:42.547339", + "docstatus": 0, + "doctype": "DocType", + "document_type": "Transaction", + "fields": [ + { + "fieldname": "company", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Company", + "options": "Company", + "permlevel": 0, + "reqd": 1 + }, + { + "fieldname": "landed_cost_purchase_receipts", + "fieldtype": "Table", + "label": "Purchase Receipts", + "options": "Landed Cost Purchase Receipt", + "permlevel": 0 + }, + { + "fieldname": "get_items_from_purchase_receipts", + "fieldtype": "Button", + "label": "Get Items From Purchase Receipts", + "permlevel": 0 + }, + { + "fieldname": "landed_cost_items", + "fieldtype": "Table", + "label": "Purchase Receipt Items", + "no_copy": 1, + "options": "Landed Cost Item", + "permlevel": 0, + "read_only": 0 + }, + { + "fieldname": "landed_cost_taxes_and_charges", + "fieldtype": "Table", + "label": "Taxes and Charges", + "options": "Landed Cost Taxes and Charges", + "permlevel": 0 + }, + { + "fieldname": "total_taxes_and_charges", + "fieldtype": "Currency", + "label": "Total Taxes and Charges", + "permlevel": 0, + "read_only": 1, + "reqd": 1 + }, + { + "fieldname": "landed_cost_help", + "fieldtype": "HTML", + "label": "Landed Cost Help", + "options": "", + "permlevel": 0 + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "Landed Cost Voucher", + "permlevel": 0, + "print_hide": 1, + "read_only": 1 + } + ], + "is_submittable": 1, + "modified": "2014-07-11 15:34:51.306164", + "modified_by": "Administrator", + "module": "Stock", + "name": "Landed Cost Voucher", + "name_case": "", + "owner": "Administrator", + "permissions": [ + { + "amend": 1, + "cancel": 1, + "create": 1, + "delete": 1, + "export": 1, + "permlevel": 0, + "read": 1, + "report": 1, + "role": "Material Manager", + "submit": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py new file mode 100644 index 0000000000..7ebdb0be24 --- /dev/null +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py @@ -0,0 +1,83 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe import _ +from frappe.utils import flt +from frappe.model.document import Document + +class LandedCostVoucher(Document): + def get_items_from_purchase_receipts(self): + self.set("landed_cost_items", []) + for pr in self.get("landed_cost_purchase_receipts"): + pr_items = frappe.db.sql("""select item_code, description, qty, rate, amount, valuation_rate, warehouse + from `tabPurchase Receipt Item` where parent = %s""", pr.purchase_receipt, as_dict=True) + for d in pr_items: + item = self.append("landed_cost_items") + item.item_code = d.item_code + item.description = d.description + item.qty = d.qty + item.rate = d.rate + item.amount = d.amount + item.old_valuation_rate = d.valuation_rate + item.purchase_receipt = pr.purchase_receipt + item.warehouse = d.warehouse + + if self.total_taxes_and_charges: + self.set_new_valuation_rate() + + def validate(self): + self.check_mandatory() + self.validate_purchase_receipts() + self.set_total_taxes_and_charges() + if not self.get("landed_cost_items"): + self.get_items_from_purchase_receipts() + else: + self.set_new_valuation_rate() + + def check_mandatory(self): + if not self.get("landed_cost_purchase_receipts"): + frappe.throw(_("Please enter Purchase Receipts")) + + if not self.get("landed_cost_taxes_and_charges"): + frappe.throw(_("Please enter Taxes and Charges")) + + def validate_purchase_receipts(self): + purchase_receipts = [] + for d in self.get("landed_cost_purchase_receipts"): + if frappe.db.get_value("Purchase Receipt", d.purchase_receipt, "docstatus") != 1: + frappe.throw(_("Purchase Receipt must be submitted")) + else: + purchase_receipts.append(d.purchase_receipt) + + for item in self.get("landed_cost_items"): + if not item.purchase_receipt: + frappe.throw(_("Item must be added using 'Get Items from Purchase Receipts' button")) + elif item.purchase_receipt not in purchase_receipts: + frappe.throw(_("Item Row {0}: Purchase Reciept {1} does not exist in above 'Purchase Receipts' table") + .format(item.idx, item.purchase_receipt)) + + def set_total_taxes_and_charges(self): + total_taxes_and_charges = 0.0 + for d in self.get("landed_cost_taxes_and_charges"): + total_taxes_and_charges += flt(d.amount) + + self.total_taxes_and_charges = total_taxes_and_charges + + def set_new_valuation_rate(self): + total_item_cost = sum([flt(d.amount) for d in self.get("landed_cost_items")]) + + for item in self.get("landed_cost_items"): + charges_for_item = flt(item.amount) * flt(self.total_taxes_and_charges) / flt(total_item_cost) + item.new_valuation_rate = flt(item.old_valuation_rate) + charges_for_item + + def on_submit(self): + self.make_stock_ledger_entries() + self.make_gl_entries() + + def make_stock_ledger_entries(self): + pass + + def make_gl_entries(self): + pass \ No newline at end of file