[fix] default account for manufacturing stock entry should be cogs
This commit is contained in:
parent
8f62e2448c
commit
66a92792b4
@ -127,3 +127,4 @@ erpnext.patches.v5_0.update_journal_entry_title
|
||||
erpnext.patches.v5_0.taxes_and_totals_in_party_currency
|
||||
erpnext.patches.v5_0.replace_renamed_fields_in_custom_scripts_and_print_formats
|
||||
erpnext.patches.v5_0.update_from_bom
|
||||
erpnext.patches.v5_0.update_account_types
|
||||
|
20
erpnext/patches/v5_0/update_account_types.py
Normal file
20
erpnext/patches/v5_0/update_account_types.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
def execute():
|
||||
for company in frappe.db.get_all("Company"):
|
||||
company = frappe.get_doc("Company", company.name)
|
||||
|
||||
match_types = ("Stock Received But Not Billed", "Stock Adjustment", "Expenses Included In Valuation",
|
||||
"Cost of Goods Sold")
|
||||
|
||||
for account_type in match_types:
|
||||
account_name = "{0} - {1}".format(account_type, company.abbr)
|
||||
current_account_type = frappe.db.get_value("Account", account_name, "account_type")
|
||||
if current_account_type != account_type:
|
||||
frappe.db.set_value("Account", account_name, "account_type", account_type)
|
||||
|
||||
company.set_default_accounts()
|
@ -188,7 +188,7 @@
|
||||
"fieldname": "default_expense_account",
|
||||
"fieldtype": "Link",
|
||||
"ignore_user_permissions": 1,
|
||||
"label": "Default Expense Account",
|
||||
"label": "Default Cost of Goods Sold Account",
|
||||
"no_copy": 1,
|
||||
"options": "Account",
|
||||
"permlevel": 0
|
||||
@ -399,7 +399,7 @@
|
||||
],
|
||||
"icon": "icon-building",
|
||||
"idx": 1,
|
||||
"modified": "2015-02-21 10:32:38.523900",
|
||||
"modified": "2015-02-25 06:28:13.565128",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Company",
|
||||
|
@ -106,28 +106,30 @@ class Company(Document):
|
||||
account.insert()
|
||||
|
||||
def set_default_accounts(self):
|
||||
def _set_default_account(fieldname, account_type):
|
||||
if self.get(fieldname):
|
||||
return
|
||||
self._set_default_account("default_cash_account", "Cash")
|
||||
self._set_default_account("default_bank_account", "Bank")
|
||||
|
||||
account = frappe.db.get_value("Account", {"account_type": account_type,
|
||||
"group_or_ledger": "Ledger", "company": self.name})
|
||||
|
||||
if account:
|
||||
self.db_set(fieldname, account)
|
||||
|
||||
_set_default_account("default_cash_account", "Cash")
|
||||
_set_default_account("default_bank_account", "Bank")
|
||||
|
||||
if cint(frappe.db.get_value("Accounts Settings", None, "auto_accounting_for_stock")):
|
||||
_set_default_account("stock_received_but_not_billed", "Stock Received But Not Billed")
|
||||
_set_default_account("stock_adjustment_account", "Stock Adjustment")
|
||||
_set_default_account("expenses_included_in_valuation", "Expenses Included In Valuation")
|
||||
if cint(frappe.db.get_single_value("Accounts Settings", "auto_accounting_for_stock")):
|
||||
self._set_default_account("stock_received_but_not_billed", "Stock Received But Not Billed")
|
||||
self._set_default_account("stock_adjustment_account", "Stock Adjustment")
|
||||
self._set_default_account("expenses_included_in_valuation", "Expenses Included In Valuation")
|
||||
self._set_default_account("default_expense_account", "Cost of Goods Sold")
|
||||
|
||||
if not self.default_income_account:
|
||||
self.db_set("default_income_account", frappe.db.get_value("Account",
|
||||
{"account_name": _("Sales"), "company": self.name}))
|
||||
|
||||
|
||||
def _set_default_account(self, fieldname, account_type):
|
||||
if self.get(fieldname):
|
||||
return
|
||||
|
||||
account = frappe.db.get_value("Account", {"account_type": account_type,
|
||||
"group_or_ledger": "Ledger", "company": self.name})
|
||||
|
||||
if account:
|
||||
self.db_set(fieldname, account)
|
||||
|
||||
def create_default_cost_center(self):
|
||||
cc_list = [
|
||||
{
|
||||
|
@ -385,6 +385,15 @@
|
||||
"precision": "",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"description": "This will override Difference Account in Item",
|
||||
"fieldname": "difference_account",
|
||||
"fieldtype": "Link",
|
||||
"label": "Difference Account",
|
||||
"options": "Account",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"fieldname": "fold",
|
||||
"fieldtype": "Fold",
|
||||
@ -645,7 +654,7 @@
|
||||
"is_submittable": 1,
|
||||
"issingle": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-02-25 01:59:14.371042",
|
||||
"modified": "2015-02-25 06:13:11.899840",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Stock Entry",
|
||||
|
@ -86,6 +86,12 @@ class StockEntry(StockController):
|
||||
if self.purpose not in valid_purposes:
|
||||
frappe.throw(_("Purpose must be one of {0}").format(comma_or(valid_purposes)))
|
||||
|
||||
if self.purpose in ("Manufacture", "Repack", "Sales Return") and not self.difference_account:
|
||||
self.difference_account = frappe.db.get_value("Company", self.company, "default_expense_account")
|
||||
|
||||
if self.purpose in ("Purchase Return") and not self.difference_account:
|
||||
frappe.throw(_("Difference Account mandatory for purpose '{0}'").format(self.purpose))
|
||||
|
||||
def set_transfer_qty(self):
|
||||
for item in self.get("items"):
|
||||
if not flt(item.qty):
|
||||
@ -108,6 +114,9 @@ class StockEntry(StockController):
|
||||
if f not in ["expense_account", "cost_center"] or not item.get(f):
|
||||
item.set(f, item_details.get(f))
|
||||
|
||||
if self.difference_account:
|
||||
item.expense_account = self.difference_account
|
||||
|
||||
if not item.transfer_qty:
|
||||
item.transfer_qty = item.qty * item.conversion_factor
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user