[fix] update future gl entries for stock

This commit is contained in:
Nabin Hait
2013-11-14 18:40:08 +05:30
parent 155232e04e
commit e83069cb32
9 changed files with 112 additions and 39 deletions

View File

@@ -5,6 +5,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes import _, msgprint
from webnotes.utils import flt, cint, today, cstr
from webnotes.model.code import get_obj
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
@@ -422,3 +423,12 @@ class AccountsController(TransactionBase):
self._abbr = webnotes.conn.get_value("Company", self.doc.company, "abbr")
return self._abbr
def check_credit_limit(self, account):
total_outstanding = webnotes.conn.sql("""
select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
from `tabGL Entry` where account = %s""", account)
total_outstanding = flt(total_outstanding[0][0]) if total_outstanding else 0
if total_outstanding:
get_obj('Account', account).check_credit_limit(total_outstanding)

View File

@@ -11,7 +11,7 @@ from controllers.accounts_controller import AccountsController
from accounts.general_ledger import make_gl_entries, delete_gl_entries
class StockController(AccountsController):
def make_gl_entries(self):
def make_gl_entries(self, update_gl_entries_after=True):
if self.doc.docstatus == 2:
delete_gl_entries(voucher_type=self.doc.doctype, voucher_no=self.doc.name)
@@ -19,12 +19,13 @@ class StockController(AccountsController):
warehouse_account = self.get_warehouse_account()
if self.doc.docstatus==1:
gl_entries = self.get_gl_entries_for_stock(warehouse_account)
gl_entries = self.get_gl_entries(warehouse_account)
make_gl_entries(gl_entries)
self.update_gl_entries_after(warehouse_account)
if update_gl_entries_after:
self.update_gl_entries_after(warehouse_account)
def get_gl_entries_for_stock(self, warehouse_account=None, default_expense_account=None,
def get_gl_entries(self, warehouse_account=None, default_expense_account=None,
default_cost_center=None):
from accounts.general_ledger import process_gl_map
if not warehouse_account:
@@ -99,12 +100,10 @@ class StockController(AccountsController):
gle = self.get_voucherwise_gl_entries(future_stock_vouchers)
if not warehouse_account:
warehouse_account = self.get_warehouse_account()
for voucher_type, voucher_no in future_stock_vouchers:
existing_gle = gle.get((voucher_type, voucher_no), [])
voucher_obj = webnotes.get_obj(voucher_type, voucher_no)
expected_gle = voucher_obj.get_gl_entries_for_stock(warehouse_account)
expected_gle = voucher_obj.get_gl_entries(warehouse_account)
if expected_gle:
matched = True
if existing_gle:
@@ -121,7 +120,7 @@ class StockController(AccountsController):
if not matched:
self.delete_gl_entries(voucher_type, voucher_no)
make_gl_entries(expected_gle)
voucher_obj.make_gl_entries(update_gl_entries_after=False)
else:
self.delete_gl_entries(voucher_type, voucher_no)