mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-03 05:28:27 +00:00
Merge branch '1310' of github.com:webnotes/erpnext
Conflicts: accounts/doctype/account/account.py controllers/accounts_controller.py patches/patch_list.py selling/doctype/sales_common/sales_common.py stock/doctype/purchase_receipt/purchase_receipt.py
This commit is contained in:
@@ -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
|
||||
@@ -423,6 +424,16 @@ class AccountsController(TransactionBase):
|
||||
|
||||
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 = total_outstanding[0][0] if total_outstanding else 0
|
||||
if total_outstanding:
|
||||
get_obj('Account', account).check_credit_limit(total_outstanding)
|
||||
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_tax_rate(account_head):
|
||||
return webnotes.conn.get_value("Account", account_head, "tax_rate")
|
||||
return webnotes.conn.get_value("Account", account_head, "tax_rate")
|
||||
@@ -247,14 +247,14 @@ class SellingController(StockController):
|
||||
customer_account = webnotes.conn.get_value("Account", {"company": self.doc.company,
|
||||
"master_name": self.doc.customer}, "name")
|
||||
if customer_account:
|
||||
total_outstanding = 0
|
||||
total_outstanding = webnotes.conn.sql("""select
|
||||
sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
|
||||
from `tabGL Entry` where account = %s""", customer_account)[0][0]
|
||||
from `tabGL Entry` where account = %s""", customer_account)
|
||||
total_outstanding = total_outstanding[0][0] if total_outstanding else 0
|
||||
|
||||
outstanding_including_current = flt(total_outstanding) + flt(grand_total)
|
||||
webnotes.bean('Account', customer_account).run_method("check_credit_limit",
|
||||
customer_account, self.doc.company, outstanding_including_current)
|
||||
outstanding_including_current)
|
||||
|
||||
def validate_max_discount(self):
|
||||
for d in self.doclist.get({"parentfield": self.fname}):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user