[fix] default account for manufacturing stock entry should be cogs

This commit is contained in:
Rushabh Mehta 2015-02-25 17:15:45 +05:30
parent 8f62e2448c
commit 66a92792b4
6 changed files with 60 additions and 19 deletions

View File

@ -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

View 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()

View File

@ -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",

View File

@ -106,7 +106,21 @@ class Company(Document):
account.insert()
def set_default_accounts(self):
def _set_default_account(fieldname, account_type):
self._set_default_account("default_cash_account", "Cash")
self._set_default_account("default_bank_account", "Bank")
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
@ -116,18 +130,6 @@ class Company(Document):
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 not self.default_income_account:
self.db_set("default_income_account", frappe.db.get_value("Account",
{"account_name": _("Sales"), "company": self.name}))
def create_default_cost_center(self):
cc_list = [
{

View File

@ -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",

View File

@ -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