[minor] [fix] make sl entry

This commit is contained in:
Nabin Hait 2013-08-02 14:50:12 +05:30
parent bbe1448fca
commit a36adbd1e0
10 changed files with 31 additions and 30 deletions

View File

@ -242,8 +242,9 @@ class DocType(BuyingController):
stock_not_billed_account = self.get_company_default("stock_received_but_not_billed") stock_not_billed_account = self.get_company_default("stock_received_but_not_billed")
against_accounts = [] against_accounts = []
stock_items = self.get_stock_items()
for item in self.doclist.get({"parentfield": "entries"}): for item in self.doclist.get({"parentfield": "entries"}):
if auto_inventory_accounting and item.item_code in self.stock_items: if auto_inventory_accounting and item.item_code in stock_items:
# in case of auto inventory accounting, against expense account is always # in case of auto inventory accounting, against expense account is always
# Stock Received But Not Billed for a stock item # Stock Received But Not Billed for a stock item
item.expense_head = item.cost_center = None item.expense_head = item.cost_center = None
@ -381,9 +382,10 @@ class DocType(BuyingController):
stock_item_and_auto_inventory_accounting = False stock_item_and_auto_inventory_accounting = False
if auto_inventory_accounting: if auto_inventory_accounting:
stock_account = self.get_company_default("stock_received_but_not_billed") stock_account = self.get_company_default("stock_received_but_not_billed")
stock_items = self.get_stock_items()
for item in self.doclist.get({"parentfield": "entries"}): for item in self.doclist.get({"parentfield": "entries"}):
if auto_inventory_accounting and item.item_code in self.stock_items: if auto_inventory_accounting and item.item_code in stock_items:
if flt(item.valuation_rate): if flt(item.valuation_rate):
# if auto inventory accounting enabled and stock item, # if auto inventory accounting enabled and stock item,
# then do stock related gl entries # then do stock related gl entries

View File

@ -555,7 +555,8 @@ class DocType(SellingController):
sl_entries = [] sl_entries = []
items = get_obj('Sales Common').get_item_list(self) items = get_obj('Sales Common').get_item_list(self)
for d in items: for d in items:
if d.item_code in self.stock_items and d.warehouse: if webnotes.conn.get_value("Item", d.item_code, "is_stock_item") == "Yes" \
and d.warehouse:
sl_entries.append(self.get_sl_entries(d, { sl_entries.append(self.get_sl_entries(d, {
"actual_qty": -1*flt(d.qty), "actual_qty": -1*flt(d.qty),
"stock_uom": webnotes.conn.get_value("Item", d.item_code, "stock_uom") "stock_uom": webnotes.conn.get_value("Item", d.item_code, "stock_uom")

View File

@ -327,7 +327,7 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEquals(gle_count[0][0], 8) self.assertEquals(gle_count[0][0], 8)
def test_pos_gl_entry_with_aii(self): def atest_pos_gl_entry_with_aii(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`") webnotes.conn.sql("delete from `tabStock Ledger Entry`")
webnotes.defaults.set_global_default("auto_inventory_accounting", 1) webnotes.defaults.set_global_default("auto_inventory_accounting", 1)

View File

@ -412,18 +412,16 @@ class AccountsController(TransactionBase):
return get_company_default(self.doc.company, fieldname) return get_company_default(self.doc.company, fieldname)
@property def get_stock_items(self):
def stock_items(self): stock_items = []
if not hasattr(self, "_stock_items"): item_codes = list(set(item.item_code for item in
self._stock_items = [] self.doclist.get({"parentfield": self.fname})))
item_codes = list(set(item.item_code for item in if item_codes:
self.doclist.get({"parentfield": self.fname}))) stock_items = [r[0] for r in webnotes.conn.sql("""select name
if item_codes: from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \
self._stock_items = [r[0] for r in webnotes.conn.sql("""select name (", ".join((["%s"]*len(item_codes))),), item_codes)]
from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \
(", ".join((["%s"]*len(item_codes))),), item_codes)]
return self._stock_items return stock_items
@property @property
def company_abbr(self): def company_abbr(self):

View File

@ -65,7 +65,7 @@ class BuyingController(StockController):
raise_exception=WrongWarehouseCompany) raise_exception=WrongWarehouseCompany)
def validate_stock_or_nonstock_items(self): def validate_stock_or_nonstock_items(self):
if not self.stock_items: if not self.get_stock_items():
tax_for_valuation = [d.account_head for d in tax_for_valuation = [d.account_head for d in
self.doclist.get({"parentfield": "purchase_tax_details"}) self.doclist.get({"parentfield": "purchase_tax_details"})
if d.category in ["Valuation", "Valuation and Total"]] if d.category in ["Valuation", "Valuation and Total"]]

View File

@ -113,13 +113,13 @@ class SellingController(StockController):
item_sales_bom.setdefault(d.parent_item, []).append(new_d) item_sales_bom.setdefault(d.parent_item, []).append(new_d)
if stock_ledger_entries: if stock_ledger_entries:
stock_items = self.get_stock_items()
for item in self.doclist.get({"parentfield": self.fname}): for item in self.doclist.get({"parentfield": self.fname}):
if item.item_code in self.stock_items or \ if item.item_code in stock_items or \
(item_sales_bom and item_sales_bom.get(item.item_code)): (item_sales_bom and item_sales_bom.get(item.item_code)):
buying_amount = get_buying_amount(item.item_code, item.warehouse, -1*item.qty, buying_amount = get_buying_amount(item.item_code, item.warehouse, -1*item.qty,
self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, self.doc.doctype, self.doc.name, item.name, stock_ledger_entries,
item_sales_bom) item_sales_bom)
item.buying_amount = buying_amount >= 0.01 and buying_amount or 0 item.buying_amount = buying_amount >= 0.01 and buying_amount or 0
webnotes.conn.set_value(item.doctype, item.name, "buying_amount", webnotes.conn.set_value(item.doctype, item.name, "buying_amount",
item.buying_amount) item.buying_amount)

View File

@ -295,7 +295,8 @@ class DocType(SellingController):
def update_stock_ledger(self): def update_stock_ledger(self):
sl_entries = [] sl_entries = []
for d in self.get_item_list(): for d in self.get_item_list():
if d.item_code in self.stock_items and d.warehouse: if webnotes.conn.get_value("Item", d.item_code, "is_stock_item") == "Yes" \
and d.warehouse:
if d['reserved_qty'] < 0 : if d['reserved_qty'] < 0 :
# Reduce reserved qty from reserved warehouse mentioned in so # Reduce reserved qty from reserved warehouse mentioned in so
args = { args = {
@ -312,7 +313,6 @@ class DocType(SellingController):
sl_entries.append(self.get_sl_entries(d, { sl_entries.append(self.get_sl_entries(d, {
"actual_qty": -1*flt(d['qty']), "actual_qty": -1*flt(d['qty']),
})) }))
self.make_sl_entries(sl_entries) self.make_sl_entries(sl_entries)
def get_item_list(self): def get_item_list(self):
@ -331,14 +331,13 @@ class DocType(SellingController):
def make_gl_entries(self): def make_gl_entries(self):
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")): if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
return return
gl_entries = [] gl_entries = []
for item in self.doclist.get({"parentfield": "delivery_note_details"}): for item in self.doclist.get({"parentfield": "delivery_note_details"}):
self.check_expense_account(item) self.check_expense_account(item)
if item.buying_amount: if item.buying_amount:
gl_entries += self.get_gl_entries_for_stock(item.expense_account, -1*item.buying_amount, gl_entries += self.get_gl_entries_for_stock(item.expense_account,
cost_center=item.cost_center) -1*item.buying_amount, cost_center=item.cost_center)
if gl_entries: if gl_entries:
from accounts.general_ledger import make_gl_entries from accounts.general_ledger import make_gl_entries

View File

@ -173,8 +173,9 @@ class DocType(BuyingController):
def update_stock(self): def update_stock(self):
pc_obj = get_obj('Purchase Common') pc_obj = get_obj('Purchase Common')
sl_entries = [] sl_entries = []
stock_items = self.get_stock_items()
for d in getlist(self.doclist, 'purchase_receipt_details'): for d in getlist(self.doclist, 'purchase_receipt_details'):
if d.item_code in self.stock_items and d.warehouse: if d.item_code in stock_items and d.warehouse:
ord_qty = 0 ord_qty = 0
pr_qty = flt(d.qty) * flt(d.conversion_factor) pr_qty = flt(d.qty) * flt(d.conversion_factor)
@ -325,9 +326,9 @@ class DocType(BuyingController):
def get_total_valuation_amount(self): def get_total_valuation_amount(self):
total_valuation_amount = 0.0 total_valuation_amount = 0.0
stock_items = self.get_stock_items()
for item in self.doclist.get({"parentfield": "purchase_receipt_details"}): for item in self.doclist.get({"parentfield": "purchase_receipt_details"}):
if item.item_code in self.stock_items: if item.item_code in stock_items:
total_valuation_amount += flt(item.valuation_rate) * \ total_valuation_amount += flt(item.valuation_rate) * \
flt(item.qty) * flt(item.conversion_factor) flt(item.qty) * flt(item.conversion_factor)

View File

@ -93,8 +93,9 @@ class DocType(StockController):
sl_obj.validate_serial_no(self, 'mtn_details') sl_obj.validate_serial_no(self, 'mtn_details')
def validate_item(self): def validate_item(self):
stock_items = self.get_stock_items()
for item in self.doclist.get({"parentfield": "mtn_details"}): for item in self.doclist.get({"parentfield": "mtn_details"}):
if item.item_code not in self.stock_items: if item.item_code not in stock_items:
msgprint(_("""Only Stock Items are allowed for Stock Entry"""), msgprint(_("""Only Stock Items are allowed for Stock Entry"""),
raise_exception=True) raise_exception=True)

View File

@ -283,7 +283,6 @@ class TestStockEntry(unittest.TestCase):
from stock.doctype.delivery_note.delivery_note import make_sales_invoice from stock.doctype.delivery_note.delivery_note import make_sales_invoice
actual_qty_0 = self._get_actual_qty() actual_qty_0 = self._get_actual_qty()
# make a delivery note based on this invoice # make a delivery note based on this invoice
dn = webnotes.bean(copy=delivery_note_test_records[0]) dn = webnotes.bean(copy=delivery_note_test_records[0])
dn.doclist[1].item_code = item_code dn.doclist[1].item_code = item_code