[minor] repost future gl entries only for current voucher items

This commit is contained in:
Nabin Hait
2013-09-04 17:55:45 +05:30
32 changed files with 293 additions and 78 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes.widgets.reportview import get_match_cond
def get_filters_cond(doctype, filters, conditions):
if filters:
@@ -22,34 +23,6 @@ def get_filters_cond(doctype, filters, conditions):
cond = ''
return cond
def get_match_cond(doctype, searchfield = 'name'):
from webnotes.widgets.reportview import build_match_conditions
cond = build_match_conditions(doctype)
if cond:
cond = ' and ' + cond
else:
cond = ''
return cond
# searches for enabled profiles
def profile_query(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name, concat_ws(' ', first_name, middle_name, last_name)
from `tabProfile`
where ifnull(enabled, 0)=1
and docstatus < 2
and name not in ('Administrator', 'Guest')
and (%(key)s like "%(txt)s"
or concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s")
%(mcond)s
order by
case when name like "%(txt)s" then 0 else 1 end,
case when concat_ws(' ', first_name, middle_name, last_name) like "%(txt)s"
then 0 else 1 end,
name asc
limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len})
# searches for active employees
def employee_query(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name, employee_name from `tabEmployee`
@@ -196,10 +169,12 @@ def get_price_list_currency(doctype, txt, searchfield, start, page_len, filters)
def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select `tabDelivery Note`.name, `tabDelivery Note`.customer_name
from `tabDelivery Note`
where `tabDelivery Note`.`%(key)s` like %(txt)s %(fcond)s and
where `tabDelivery Note`.`%(key)s` like %(txt)s and
`tabDelivery Note`.docstatus = 1 %(fcond)s and
(ifnull((select sum(qty) from `tabDelivery Note Item` where
`tabDelivery Note Item`.parent=`tabDelivery Note`.name), 0) >
ifnull((select sum(qty) from `tabSales Invoice Item` where
`tabSales Invoice Item`.docstatus = 1 and
`tabSales Invoice Item`.delivery_note=`tabDelivery Note`.name), 0))
%(mcond)s order by `tabDelivery Note`.`%(key)s` asc
limit %(start)s, %(page_len)s""" % {

View File

@@ -14,11 +14,11 @@ class StockController(AccountsController):
def make_gl_entries(self):
if not cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
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:
else:
delete_gl_entries(voucher_type=self.doc.doctype, voucher_no=self.doc.name)
self.update_gl_entries_after()
@@ -117,15 +117,19 @@ class StockController(AccountsController):
def get_future_stock_vouchers(self):
future_stock_vouchers = []
item_codes = webnotes.conn.sql_list("""select distinct item_code
from `tabStock Ledger Entry`
where voucher_type=%s and voucher_no=%s""", (self.doc.doctype, self.doc.name))
if hasattr(self, "fname"):
item_list = [d.item_code for d in self.doclist.get({"parentfield": self.fname})]
condition = ''.join(['and item_code in (\'', '\', \''.join(item_list) ,'\')'])
else:
condition = ""
for d in webnotes.conn.sql("""select distinct sle.voucher_type, sle.voucher_no
from `tabStock Ledger Entry` sle
where timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s)
order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""",
(self.doc.posting_date, self.doc.posting_time), as_dict=True):
where timestamp(sle.posting_date, sle.posting_time) >= timestamp(%s, %s) %s
order by timestamp(sle.posting_date, sle.posting_time) asc, name asc""" %
('%s', '%s', condition), (self.doc.posting_date, self.doc.posting_time),
as_dict=True):
future_stock_vouchers.append([d.voucher_type, d.voucher_no])
return future_stock_vouchers