From 7a23057eabc8b552c1e666ca4314e6fb086bde0f Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Fri, 8 Nov 2019 12:52:54 +0530 Subject: [PATCH] feat: Enhancement in landed cost voucher (#19252) * feat: Enhancement in landed cost voucher * fix: Make GL entries based on ledgers in Landed cost voucher * fix: Patch to update expense account in Landed Cost Voucher and Stock Entry * fix: Ability to select expense account in Stock Entry * fix: Renaming and test case fixes * fix: Test Cases * fix: Additional cost in Stock Entry * fix: Changed filters and test case fixes * fix: Upadte filters in stokc entry expense account filter * fix: company filter --- .../purchase_invoice/purchase_invoice.py | 22 ++- erpnext/manufacturing/doctype/bom/bom.py | 3 + .../doctype/work_order/work_order.py | 3 +- erpnext/patches.txt | 1 + ...se_account_in_landed_cost_voucher_taxes.py | 33 ++++ .../landed_cost_taxes_and_charges.json | 164 +++++------------- .../landed_cost_voucher.js | 16 +- .../test_landed_cost_voucher.py | 2 +- .../purchase_receipt/purchase_receipt.py | 47 ++++- .../stock/doctype/stock_entry/stock_entry.js | 15 +- .../stock/doctype/stock_entry/stock_entry.py | 57 +++--- .../doctype/stock_entry/test_stock_entry.py | 8 +- 12 files changed, 202 insertions(+), 169 deletions(-) create mode 100644 erpnext/patches/v12_0/set_expense_account_in_landed_cost_voucher_taxes.py diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 4ea9b1c6c97..9c1a9ece779 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -25,6 +25,7 @@ from erpnext.accounts.doctype.sales_invoice.sales_invoice import validate_inter_ unlink_inter_company_doc from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import get_party_tax_withholding_details from erpnext.accounts.deferred_revenue import validate_service_stop_date +from erpnext.stock.doctype.purchase_receipt.purchase_receipt import get_item_account_wise_additional_cost form_grid_templates = { "items": "templates/form_grid/item_grid.html" @@ -436,6 +437,8 @@ class PurchaseInvoice(BuyingController): if self.update_stock and self.auto_accounting_for_stock: warehouse_account = get_warehouse_account_map(self.company) + landed_cost_entries = get_item_account_wise_additional_cost(self.name) + voucher_wise_stock_value = {} if self.update_stock: for d in frappe.get_all('Stock Ledger Entry', @@ -463,15 +466,16 @@ class PurchaseInvoice(BuyingController): ) # Amount added through landed-cost-voucher - if flt(item.landed_cost_voucher_amount): - gl_entries.append(self.get_gl_dict({ - "account": expenses_included_in_valuation, - "against": item.expense_account, - "cost_center": item.cost_center, - "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "credit": flt(item.landed_cost_voucher_amount), - "project": item.project - }, item=item)) + if landed_cost_entries: + for account, amount in iteritems(landed_cost_entries[(item.item_code, item.name)]): + gl_entries.append(self.get_gl_dict({ + "account": account, + "against": item.expense_account, + "cost_center": item.cost_center, + "remarks": self.get("remarks") or _("Accounting Entry for Stock"), + "credit": flt(amount), + "project": item.project + }, item=item)) # sub-contracting warehouse if flt(item.rm_supp_cost): diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index a1bf35fd087..db79d7feda4 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -776,6 +776,8 @@ def add_additional_cost(stock_entry, work_order): # Add non stock items cost in the additional cost bom = frappe.get_doc('BOM', work_order.bom_no) table = 'exploded_items' if work_order.get('use_multi_level_bom') else 'items' + expenses_included_in_valuation = frappe.get_cached_value("Company", work_order.company, + "expenses_included_in_valuation") items = {} for d in bom.get(table): @@ -786,6 +788,7 @@ def add_additional_cost(stock_entry, work_order): for name in non_stock_items: stock_entry.append('additional_costs', { + 'expense_account': expenses_included_in_valuation, 'description': name[0], 'amount': items.get(name[0]) }) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index b57548e960e..ae4d9be2826 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -645,7 +645,8 @@ def make_stock_entry(work_order_id, purpose, qty=None): stock_entry.to_warehouse = work_order.fg_warehouse stock_entry.project = work_order.project if purpose=="Manufacture": - additional_costs = get_additional_costs(work_order, fg_qty=stock_entry.fg_completed_qty) + additional_costs = get_additional_costs(work_order, fg_qty=stock_entry.fg_completed_qty, + company=work_order.company) stock_entry.set("additional_costs", additional_costs) stock_entry.set_stock_entry_type() diff --git a/erpnext/patches.txt b/erpnext/patches.txt index f594f96aea5..047fc85f0a4 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -640,6 +640,7 @@ erpnext.patches.v12_0.create_default_energy_point_rules erpnext.patches.v12_0.set_produced_qty_field_in_sales_order_for_work_order erpnext.patches.v12_0.generate_leave_ledger_entries erpnext.patches.v12_0.set_default_shopify_app_type +erpnext.patches.v12_0.set_expense_account_in_landed_cost_voucher_taxes erpnext.patches.v12_0.replace_accounting_with_accounts_in_home_settings erpnext.patches.v12_0.set_payment_entry_status erpnext.patches.v12_0.update_owner_fields_in_acc_dimension_custom_fields diff --git a/erpnext/patches/v12_0/set_expense_account_in_landed_cost_voucher_taxes.py b/erpnext/patches/v12_0/set_expense_account_in_landed_cost_voucher_taxes.py new file mode 100644 index 00000000000..a996a69b3d9 --- /dev/null +++ b/erpnext/patches/v12_0/set_expense_account_in_landed_cost_voucher_taxes.py @@ -0,0 +1,33 @@ +from __future__ import unicode_literals +import frappe +from six import iteritems + +def execute(): + frappe.reload_doctype('Landed Cost Taxes and Charges') + + company_account_map = frappe._dict(frappe.db.sql(""" + SELECT name, expenses_included_in_valuation from `tabCompany` + """)) + + for company, account in iteritems(company_account_map): + frappe.db.sql(""" + UPDATE + `tabLanded Cost Taxes and Charges` t, `tabLanded Cost Voucher` l + SET + t.expense_account = %s + WHERE + l.docstatus = 1 + AND l.company = %s + AND t.parent = l.name + """, (account, company)) + + frappe.db.sql(""" + UPDATE + `tabLanded Cost Taxes and Charges` t, `tabStock Entry` s + SET + t.expense_account = %s + WHERE + s.docstatus = 1 + AND s.company = %s + AND t.parent = s.name + """, (account, company)) \ No newline at end of file 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 1aaf73f3ad1..0cc243d4cb5 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 @@ -1,129 +1,51 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, - "creation": "2014-07-11 11:51:00.453717", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "creation": "2014-07-11 11:51:00.453717", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "expense_account", + "description", + "col_break3", + "amount" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "description", - "fieldtype": "Small Text", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Description", - "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": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, + "fieldname": "description", + "fieldtype": "Small Text", + "in_list_view": 1, + "label": "Description", + "reqd": 1 + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "col_break3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 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, - "set_only_once": 0, - "unique": 0, + "fieldname": "col_break3", + "fieldtype": "Column Break", "width": "50%" - }, + }, { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "amount", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Amount", - "length": 0, - "no_copy": 0, - "options": "Company:company:default_currency", - "permlevel": 0, - "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, - "set_only_once": 0, - "unique": 0 + "fieldname": "amount", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Amount", + "options": "Company:company:default_currency", + "reqd": 1 + }, + { + "fieldname": "expense_account", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Expense Account", + "options": "Account", + "reqd": 1 } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "max_attachments": 0, - "modified": "2017-11-15 19:27:59.542487", - "modified_by": "Administrator", - "module": "Stock", - "name": "Landed Cost Taxes and Charges", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 0, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 0, - "track_seen": 0 + ], + "istable": 1, + "modified": "2019-09-30 18:28:32.070655", + "modified_by": "Administrator", + "module": "Stock", + "name": "Landed Cost Taxes and Charges", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC" } \ No newline at end of file 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 edc34442208..c9a3fd976f3 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js @@ -30,6 +30,16 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({ this.frm.add_fetch("receipt_document", "posting_date", "posting_date"); this.frm.add_fetch("receipt_document", "base_grand_total", "grand_total"); + this.frm.set_query("expense_account", "taxes", function() { + return { + query: "erpnext.controllers.queries.tax_account_query", + filters: { + "account_type": ["Tax", "Chargeable", "Income Account", "Expenses Included In Valuation", "Expenses Included In Asset Valuation"], + "company": me.frm.doc.company + } + }; + }); + }, refresh: function(frm) { @@ -38,7 +48,7 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
- + ${__("Notes")}:
|