[fix] [minor] perpetual inventory: account for each warehouse

This commit is contained in:
Nabin Hait
2013-09-17 10:21:20 +05:30
parent 87eb4b99a8
commit 7a75e10a61
18 changed files with 241 additions and 171 deletions

View File

@@ -5,7 +5,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes import _, msgprint
from webnotes.utils import flt, cint, today, cstr
from setup.utils import get_company_currency, get_price_list_currency
from setup.utils import get_company_currency
from accounts.utils import get_fiscal_year, validate_fiscal_year
from utilities.transaction_base import TransactionBase, validate_conversion_rate
import json
@@ -13,7 +13,6 @@ import json
class AccountsController(TransactionBase):
def validate(self):
self.set_missing_values(for_validate=True)
self.validate_date_with_fiscal_year()
if self.meta.get_field("currency"):
self.calculate_taxes_and_totals()
@@ -54,35 +53,37 @@ class AccountsController(TransactionBase):
self.doc.doctype + _(" can not be made."), raise_exception=1)
def set_price_list_currency(self, buying_or_selling):
company_currency = get_company_currency(self.doc.company)
fieldname = buying_or_selling.lower() + "_price_list"
# TODO - change this, since price list now has only one currency allowed
if self.meta.get_field(fieldname) and self.doc.fields.get(fieldname) and \
not self.doc.price_list_currency:
self.doc.fields.update(get_price_list_currency(self.doc.fields.get(fieldname)))
if self.doc.price_list_currency:
if not self.doc.plc_conversion_rate:
if self.doc.price_list_currency == company_currency:
self.doc.plc_conversion_rate = 1.0
else:
exchange = self.doc.price_list_currency + "-" + company_currency
self.doc.plc_conversion_rate = flt(webnotes.conn.get_value("Currency Exchange",
exchange, "exchange_rate"))
if not self.doc.currency:
self.doc.currency = self.doc.price_list_currency
self.doc.conversion_rate = self.doc.plc_conversion_rate
if self.meta.get_field("currency"):
if self.doc.currency and self.doc.currency != company_currency:
if not self.doc.conversion_rate:
exchange = self.doc.currency + "-" + company_currency
self.doc.conversion_rate = flt(webnotes.conn.get_value("Currency Exchange",
exchange, "exchange_rate"))
else:
self.doc.conversion_rate = 1
company_currency = get_company_currency(self.doc.company)
# price list part
fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
else "buying_price_list"
if self.meta.get_field(fieldname) and self.doc.fields.get(fieldname):
if not self.doc.price_list_currency:
self.doc.price_list_currency = webnotes.conn.get_value("Price List",
self.doc.fields.get(fieldame), "currency")
if self.doc.price_list_currency == company_currency:
self.doc.plc_conversion_rate = 1.0
elif not self.doc.plc_conversion_rate:
self.doc.plc_conversion_rate = self.get_exchange_rate(
self.doc.price_list_currency, company_currency)
# currency
if not self.doc.currency:
self.doc.currency = self.doc.price_list_currency
self.doc.conversion_rate = self.doc.plc_conversion_rate
elif self.doc.currency == company_currency:
self.doc.conversion_rate = 1.0
elif not self.doc.conversion_rate:
self.doc.conversion_rate = self.get_exchange_rate(self.doc.currency,
company_currency)
def get_exchange_rate(self, from_currency, to_currency):
exchange = "%s-%s" % (from_currency, to_currency)
return flt(webnotes.conn.get_value("Currency Exchange", exchange, "exchange_rate"))
def set_missing_item_details(self, get_item_details):
"""set missing item values"""
for item in self.doclist.get({"parentfield": self.fname}):

View File

@@ -23,7 +23,7 @@ class SellingController(StockController):
self.set_price_list_and_item_details()
if self.doc.fields.get("__islocal"):
self.set_taxes("other_charges", "charge")
def set_missing_lead_customer_details(self):
if self.doc.customer:
if not (self.doc.contact_person and self.doc.customer_address and self.doc.customer_name):

View File

@@ -16,7 +16,7 @@ class StockController(AccountsController):
return
if self.doc.docstatus==1:
gl_entries = self.get_gl_entries_for_stock()
gl_entries = self.get_gl_entries_for_stock()
make_gl_entries(gl_entries)
else:
delete_gl_entries(voucher_type=self.doc.doctype, voucher_no=self.doc.name)
@@ -31,12 +31,12 @@ class StockController(AccountsController):
default_cost_center)
gl_list = []
warehouse_with_no_account = []
for detail in voucher_details:
sle_list = stock_ledger.get(detail.name)
if sle_list:
for sle in sle_list:
if warehouse_account.get(sle.warehouse):
# from warehouse account
gl_list.append(self.get_gl_dict({
"account": warehouse_account[sle.warehouse],
@@ -54,6 +54,12 @@ class StockController(AccountsController):
"remarks": self.doc.remarks or "Accounting Entry for Stock",
"credit": sle.stock_value_difference
}))
elif sle.warehouse not in warehouse_with_no_account:
warehouse_with_no_account.append(sle.warehouse)
if warehouse_with_no_account:
msgprint(_("No accounting entries for following warehouses") + ": \n" +
"\n".join(warehouse_with_no_account))
return process_gl_map(gl_list)
@@ -80,9 +86,11 @@ class StockController(AccountsController):
return stock_ledger
def get_warehouse_account(self):
warehouse_account = dict(webnotes.conn.sql("""select name, account from `tabWarehouse`
where ifnull(account, '') != ''"""))
for d in webnotes.conn.sql("select name from tabWarehouse"):
webnotes.bean("Warehouse", d[0]).save()
warehouse_account = dict(webnotes.conn.sql("""select master_name, name from tabAccount
where account_type = 'Warehouse' and ifnull(master_name, '') != ''"""))
return warehouse_account
def update_gl_entries_after(self):