def repost_gle_for_stock_vouchers( stock_vouchers, posting_date, company=None, warehouse_account=None ): if not stock_vouchers: return def _delete_gl_entries(voucher_type, voucher_no): frappe.db.sql( """delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), ) stock_vouchers = sort_stock_vouchers_by_posting_date(stock_vouchers) if not warehouse_account: warehouse_account = get_warehouse_account_map(company) precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit")) or 2 gle = get_voucherwise_gl_entries(stock_vouchers, posting_date) for voucher_type, voucher_no in stock_vouchers: existing_gle = gle.get((voucher_type, voucher_no), []) voucher_obj = frappe.get_cached_doc(voucher_type, voucher_no) expected_gle = voucher_obj.get_gl_entries(warehouse_account) if expected_gle: if not existing_gle or not compare_existing_and_expected_gle( existing_gle, expected_gle, precision ): _delete_gl_entries(voucher_type, voucher_no) voucher_obj.make_gl_entries(gl_entries=expected_gle, from_repost=True) else: _delete_gl_entries(voucher_type, voucher_no)
def set_expense_account(self, for_validate=False): auto_accounting_for_stock = cint( frappe.defaults.get_global_default("auto_accounting_for_stock")) if auto_accounting_for_stock: stock_not_billed_account = self.get_company_default( "stock_received_but_not_billed") stock_items = self.get_stock_items() if self.update_stock: self.validate_item_code() self.validate_warehouse() warehouse_account = get_warehouse_account_map() for item in self.get("items"): # in case of auto inventory accounting, # expense account is always "Stock Received But Not Billed" for a stock item # except epening entry, drop-ship entry and fixed asset items if auto_accounting_for_stock and item.item_code in stock_items \ and self.is_opening == 'No' and not item.is_fixed_asset: if self.update_stock: item.expense_account = warehouse_account[ item.warehouse]["name"] else: item.expense_account = stock_not_billed_account elif not item.expense_account and for_validate: throw( _("Expense account is mandatory for item {0}").format( item.item_code or item.item_name))
def set_expense_account(self, for_validate=False): auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company) if auto_accounting_for_stock: stock_not_billed_account = self.get_company_default("stock_received_but_not_billed") stock_items = self.get_stock_items() if self.update_stock: self.validate_item_code() self.validate_warehouse() warehouse_account = get_warehouse_account_map() for item in self.get("items"): # in case of auto inventory accounting, # expense account is always "Stock Received But Not Billed" for a stock item # except epening entry, drop-ship entry and fixed asset items if auto_accounting_for_stock and item.item_code in stock_items \ and self.is_opening == 'No' and not item.is_fixed_asset \ and (not item.po_detail or not frappe.db.get_value("Purchase Order Item", item.po_detail, "delivered_by_supplier")): if self.update_stock: item.expense_account = warehouse_account[item.warehouse]["account"] else: item.expense_account = stock_not_billed_account elif not item.expense_account and for_validate: throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name))
def set_expense_account(self, for_validate=False): auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled( self.company) if auto_accounting_for_stock: stock_not_billed_account = self.get_company_default( "stock_received_but_not_billed") stock_items = self.get_stock_items() if self.update_stock: self.validate_item_code() self.validate_warehouse() warehouse_account = get_warehouse_account_map() for item in self.get("items"): # in case of auto inventory accounting, # expense account is always "Stock Received But Not Billed" for a stock item # except epening entry, drop-ship entry and fixed asset items if auto_accounting_for_stock and item.item_code in stock_items \ and self.is_opening == 'No' and not item.is_fixed_asset \ and (not item.po_detail or not frappe.db.get_value("Purchase Order Item", item.po_detail, "delivered_by_supplier")): if self.update_stock: item.expense_account = warehouse_account[ item.warehouse]["account"] else: item.expense_account = stock_not_billed_account elif not item.expense_account and for_validate: throw( _("Expense account is mandatory for item {0}").format( item.item_code or item.item_name))
def get_stock_and_account_balance(account=None, posting_date=None, company=None): if not posting_date: posting_date = nowdate() warehouse_account = get_warehouse_account_map(company) account_balance = get_balance_on(account, posting_date, in_account_currency=False) related_warehouses = [ wh for wh, wh_details in warehouse_account.items() if wh_details.account == account and not wh_details.is_group ] total_stock_value = 0.0 for warehouse in related_warehouses: value = get_stock_value_on(warehouse, posting_date) total_stock_value += value precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency") return flt(account_balance, precision), flt(total_stock_value, precision), related_warehouses
def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False): if self.docstatus == 2: delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name) if cint(erpnext.is_perpetual_inventory_enabled(self.company)): warehouse_account = get_warehouse_account_map(self.company) if self.docstatus == 1: if not gl_entries: gl_entries = self.get_gl_entries(warehouse_account) make_gl_entries(gl_entries, from_repost=from_repost) if repost_future_gle: items, warehouses = self.get_items_and_warehouses() update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items, warehouse_account, company=self.company) elif self.doctype in ['Purchase Receipt', 'Purchase Invoice' ] and self.docstatus == 1: gl_entries = [] gl_entries = self.get_asset_gl_entry(gl_entries) make_gl_entries(gl_entries, from_repost=from_repost)
def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None, warehouse_account=None, company=None): def _delete_gl_entries(voucher_type, voucher_no): frappe.db.sql( """delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no)) if not warehouse_account: warehouse_account = get_warehouse_account_map(company) future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, for_warehouses, for_items) gle = get_voucherwise_gl_entries(future_stock_vouchers, posting_date) for voucher_type, voucher_no in future_stock_vouchers: existing_gle = gle.get((voucher_type, voucher_no), []) voucher_obj = frappe.get_doc(voucher_type, voucher_no) expected_gle = voucher_obj.get_gl_entries(warehouse_account) if expected_gle: if not existing_gle or not compare_existing_and_expected_gle( existing_gle, expected_gle): _delete_gl_entries(voucher_type, voucher_no) voucher_obj.make_gl_entries(gl_entries=expected_gle, repost_future_gle=False, from_repost=True) else: _delete_gl_entries(voucher_type, voucher_no)
def get_gl_entries(self, warehouse_account=None, default_expense_account=None, default_cost_center=None): if not warehouse_account: warehouse_account = get_warehouse_account_map(self.company) sle_map = self.get_stock_ledger_details() voucher_details = self.get_voucher_details(default_expense_account, default_cost_center, sle_map) gl_list = [] warehouse_with_no_account = [] for item_row in voucher_details: sle_list = sle_map.get(item_row.name) if sle_list: for sle in sle_list: if warehouse_account.get(sle.warehouse): # from warehouse account self.check_expense_account(item_row) # If the item does not have the allow zero valuation rate flag set # and ( valuation rate not mentioned in an incoming entry # or incoming entry not found while delivering the item), # try to pick valuation rate from previous sle or Item master and update in SLE # Otherwise, throw an exception if not sle.stock_value_difference and self.doctype != "Stock Reconciliation" \ and not item_row.get("allow_zero_valuation_rate"): sle = self.update_stock_ledger_entries(sle) gl_list.append(self.get_gl_dict({ "account": warehouse_account[sle.warehouse]["account"], "against": item_row.expense_account, "cost_center": item_row.cost_center, "remarks": self.get("remarks") or "Accounting Entry for Stock", "debit": flt(sle.stock_value_difference, 2), "is_opening": item_row.get("is_opening") or self.get("is_opening") or "No", }, warehouse_account[sle.warehouse]["account_currency"], item=item_row)) # to target warehouse / expense account gl_list.append(self.get_gl_dict({ "account": item_row.expense_account, "against": warehouse_account[sle.warehouse]["account"], "cost_center": item_row.cost_center, "remarks": self.get("remarks") or "Accounting Entry for Stock", "credit": flt(sle.stock_value_difference, 2), "project": item_row.get("project") or self.get("project"), "is_opening": item_row.get("is_opening") or self.get("is_opening") or "No" }, item=item_row)) elif sle.warehouse not in warehouse_with_no_account: warehouse_with_no_account.append(sle.warehouse) if warehouse_with_no_account: for wh in warehouse_with_no_account: if frappe.db.get_value("Warehouse", wh, "company"): frappe.throw(_("Warehouse {0} is not linked to any account, please mention the account in the warehouse record or set default inventory account in company {1}.").format(wh, self.company)) return process_gl_map(gl_list)
def get_draft_gl_entries(filters,from_date,to_date): from frappe.utils import cint, getdate, formatdate target_docs_list = ["Payment Entry","Purchase Invoice","Expense Claim","Journal Entry", "Sales Invoice","Purchase Receipt","Delivery Note"] gl_entries = [] for target_doc in target_docs_list : get_all_docs = frappe.get_list(target_doc,fields=['name'], filters=[ ['docstatus',"=", 0], ['company',"=", filters.get('company')], ["posting_date",">=",getdate(from_date)], ["posting_date","<=",getdate(to_date)] ]) for doc_name in get_all_docs : doc = frappe.get_doc(target_doc,doc_name["name"]) if target_doc == "Payment Entry": if doc.payment_type in ("Receive", "Pay") and not doc.get("party_account_field"): doc.setup_party_account_field() doc.add_party_gl_entries(gl_entries) doc.add_bank_gl_entries(gl_entries) doc.add_deductions_gl_entries(gl_entries) if target_doc == "Journal Entry": gl_map = [] for d in doc.get("accounts"): if d.debit or d.credit: gl_map.append( doc.get_gl_dict({ "account": d.account, "party_type": d.party_type, "party": d.party, "against": d.against_account, "debit": flt(d.debit, d.precision("debit")), "credit": flt(d.credit, d.precision("credit")), "account_currency": d.account_currency, "debit_in_account_currency": flt(d.debit_in_account_currency, d.precision("debit_in_account_currency")), "credit_in_account_currency": flt(d.credit_in_account_currency, d.precision("credit_in_account_currency")), "against_voucher_type": d.reference_type, "against_voucher": d.reference_name, "remarks": doc.remark, "cost_center": d.cost_center, "project": d.project }) ) gl_entries.extend(gl_map) if target_doc in ["Purchase Receipt"]: from erpnext.stock import get_warehouse_account_map warehouse_account = get_warehouse_account_map() gl_entries.extend(doc.get_gl_entries(warehouse_account)) if target_doc in ["Purchase Invoice","Expense Claim","Sales Invoice","Delivery Note"]: gl_entries.extend(doc.get_gl_entries()) return gl_entries
def get_gl_entries(self, warehouse_account=None, default_expense_account=None, default_cost_center=None): if not warehouse_account: warehouse_account = get_warehouse_account_map() sle_map = self.get_stock_ledger_details() voucher_details = self.get_voucher_details(default_expense_account, default_cost_center, sle_map) gl_list = [] warehouse_with_no_account = [] for item_row in voucher_details: sle_list = sle_map.get(item_row.name) if sle_list: for sle in sle_list: if warehouse_account.get(sle.warehouse): # from warehouse account self.check_expense_account(item_row) # If the item does not have the allow zero valuation rate flag set # and ( valuation rate not mentioned in an incoming entry # or incoming entry not found while delivering the item), # try to pick valuation rate from previous sle or Item master and update in SLE # Otherwise, throw an exception if not sle.stock_value_difference and self.doctype != "Stock Reconciliation" \ and not item_row.get("allow_zero_valuation_rate"): sle = self.update_stock_ledger_entries(sle) gl_list.append(self.get_gl_dict({ "account": warehouse_account[sle.warehouse]["account"], "against": item_row.expense_account, "cost_center": item_row.cost_center, "remarks": self.get("remarks") or "Accounting Entry for Stock", "debit": flt(sle.stock_value_difference, 2), }, warehouse_account[sle.warehouse]["account_currency"])) # to target warehouse / expense account gl_list.append(self.get_gl_dict({ "account": item_row.expense_account, "against": warehouse_account[sle.warehouse]["account"], "cost_center": item_row.cost_center, "remarks": self.get("remarks") or "Accounting Entry for Stock", "credit": flt(sle.stock_value_difference, 2), "project": item_row.get("project") or self.get("project") })) elif sle.warehouse not in warehouse_with_no_account: warehouse_with_no_account.append(sle.warehouse) if warehouse_with_no_account: for wh in warehouse_with_no_account: if frappe.db.get_value("Warehouse", wh, "company"): frappe.throw(_("Warehouse {0} is not linked to any account, please mention the account in the warehouse record or set default inventory account in company {1}.").format(wh, self.company)) return process_gl_map(gl_list)
def set_expense_account(self, for_validate=False): auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company) if auto_accounting_for_stock: stock_not_billed_account = self.get_company_default("stock_received_but_not_billed") stock_items = self.get_stock_items() asset_items = [d.is_fixed_asset for d in self.items if d.is_fixed_asset] if len(asset_items) > 0: asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed") if self.update_stock: self.validate_item_code() self.validate_warehouse() if auto_accounting_for_stock: warehouse_account = get_warehouse_account_map(self.company) for item in self.get("items"): # in case of auto inventory accounting, # expense account is always "Stock Received But Not Billed" for a stock item # except opening entry, drop-ship entry and fixed asset items if item.item_code: asset_category = frappe.get_cached_value("Item", item.item_code, "asset_category") if auto_accounting_for_stock and item.item_code in stock_items \ and self.is_opening == 'No' and not item.is_fixed_asset \ and (not item.po_detail or not frappe.db.get_value("Purchase Order Item", item.po_detail, "delivered_by_supplier")): if self.update_stock and (not item.from_warehouse): item.expense_account = warehouse_account[item.warehouse]["account"] else: # check if 'Stock Received But Not Billed' account is credited in Purchase receipt or not if item.purchase_receipt: negative_expense_booked_in_pr = frappe.db.sql("""select name from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s and account = %s""", (item.purchase_receipt, stock_not_billed_account)) if negative_expense_booked_in_pr: item.expense_account = stock_not_billed_account else: # If no purchase receipt present then book expense in 'Stock Received But Not Billed' # This is done in cases when Purchase Invoice is created before Purchase Receipt item.expense_account = stock_not_billed_account elif item.is_fixed_asset and not is_cwip_accounting_enabled(asset_category): item.expense_account = get_asset_category_account('fixed_asset_account', item=item.item_code, company = self.company) elif item.is_fixed_asset and item.pr_detail: item.expense_account = asset_received_but_not_billed elif not item.expense_account and for_validate: throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name))
def execute(): company_list = frappe.db.sql_list("""Select name from tabCompany where enable_perpetual_inventory = 1""") frappe.reload_doc('accounts', 'doctype', 'sales_invoice') frappe.reload_doctype("Purchase Invoice") wh_account = get_warehouse_account_map() for pi in frappe.get_all("Purchase Invoice", fields=["name", "company"], filters={"docstatus": 1, "update_stock": 1}): if pi.company in company_list: pi_doc = frappe.get_doc("Purchase Invoice", pi.name) items, warehouses = pi_doc.get_items_and_warehouses() update_gl_entries_after(pi_doc.posting_date, pi_doc.posting_time, warehouses, items, wh_account) frappe.db.commit()
def execute(): company_list = frappe.db.sql_list("""Select name from tabCompany where enable_perpetual_inventory = 1""") frappe.reload_doc('accounts', 'doctype', 'sales_invoice') frappe.reload_doctype("Purchase Invoice") wh_account = get_warehouse_account_map() for pi in frappe.get_all("Purchase Invoice", fields=["name", "company"], filters={"docstatus": 1, "update_stock": 1}): if pi.company in company_list: pi_doc = frappe.get_doc("Purchase Invoice", pi.name) items, warehouses = pi_doc.get_items_and_warehouses() update_gl_entries_after(pi_doc.posting_date, pi_doc.posting_time, warehouses, items, wh_account, company = pi.company) frappe.db.commit()
def make_gl_entries(self, gl_entries=None): if self.docstatus == 2: make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) if cint(erpnext.is_perpetual_inventory_enabled(self.company)): warehouse_account = get_warehouse_account_map(self.company) if self.docstatus==1: if not gl_entries: gl_entries = self.get_gl_entries(warehouse_account) make_gl_entries(gl_entries) elif self.doctype in ['Purchase Receipt', 'Purchase Invoice'] and self.docstatus == 1: gl_entries = [] gl_entries = self.get_asset_gl_entry(gl_entries) make_gl_entries(gl_entries)
def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False): if self.docstatus == 2: delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name) if cint(erpnext.is_perpetual_inventory_enabled(self.company)): warehouse_account = get_warehouse_account_map() if self.docstatus==1: if not gl_entries: gl_entries = self.get_gl_entries(warehouse_account) make_gl_entries(gl_entries, from_repost=from_repost) if repost_future_gle: items, warehouses = self.get_items_and_warehouses() update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items, warehouse_account)
def get_stock_and_account_difference(account_list=None, posting_date=None): from erpnext.stock.utils import get_stock_value_on from erpnext.stock import get_warehouse_account_map if not posting_date: posting_date = nowdate() difference = {} warehouse_account = get_warehouse_account_map() for warehouse, account_data in warehouse_account.items(): if account_data.get('account') in account_list: account_balance = get_balance_on(account_data.get('account'), posting_date, in_account_currency=False) stock_value = get_stock_value_on(warehouse, posting_date) if abs(flt(stock_value) - flt(account_balance)) > 0.005: difference.setdefault(account_data.get('account'), flt(stock_value) - flt(account_balance)) return difference
def make_production_item_gl_entry(self, gl_entries): # production_item gl_entry # have to specify manually since get_voucher_details iterates through child table only prod_sle = self.get_stock_ledger_details().get(self.name)[0] if not prod_sle.stock_value_difference and not item_row.get( "allow_zero_valuation_rate"): # updates valuation_Rate, stock_value_difference etc prod_sle = self.update_stock_ledger_entries(prod_sle) warehouse_account = get_warehouse_account_map() if not warehouse_account.get(prod_sle.warehouse): frappe.throw("No warehouse account specified for {}".format( prod_sle.warehouse)) # to warehouse account gl_entries.append( self.get_gl_dict( { "account": warehouse_account[prod_sle.warehouse]["account"], "against": self.expense_account, "cost_center": self.cost_center, "remarks": self.get("remarks") or "Accounting Entry for Stock", "debit": flt(prod_sle.stock_value_difference, 2), }, warehouse_account[prod_sle.warehouse]["account_currency"])) # to expense account (Cost of Goods Sold) gl_entries.append( self.get_gl_dict({ "account": self.expense_account, "against": warehouse_account[prod_sle.warehouse]["account"], "cost_center": self.cost_center, "remarks": self.get("remarks") or "Accounting Entry for Stock", "credit": flt(prod_sle.stock_value_difference, 2), "project": self.get("project") or self.get("project") }))
def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False): if self.docstatus == 2: delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name) if cint(frappe.defaults.get_global_default( "auto_accounting_for_stock")): warehouse_account = get_warehouse_account_map() if self.docstatus == 1: if not gl_entries: gl_entries = self.get_gl_entries(warehouse_account) make_gl_entries(gl_entries, from_repost=from_repost) if repost_future_gle: items, warehouses = self.get_items_and_warehouses() update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items, warehouse_account)
def execute(): if not cint( frappe.defaults.get_global_default("auto_accounting_for_stock")): return frappe.reload_doc('accounts', 'doctype', 'sales_invoice') frappe.reload_doctype("Purchase Invoice") wh_account = get_warehouse_account_map() for pi in frappe.get_all("Purchase Invoice", filters={ "docstatus": 1, "update_stock": 1 }): pi_doc = frappe.get_doc("Purchase Invoice", pi.name) items, warehouses = pi_doc.get_items_and_warehouses() update_gl_entries_after(pi_doc.posting_date, pi_doc.posting_time, warehouses, items, wh_account) frappe.db.commit()
def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None, warehouse_account=None): def _delete_gl_entries(voucher_type, voucher_no): frappe.db.sql("""delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no)) if not warehouse_account: warehouse_account = get_warehouse_account_map() future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, for_warehouses, for_items) gle = get_voucherwise_gl_entries(future_stock_vouchers, posting_date) for voucher_type, voucher_no in future_stock_vouchers: existing_gle = gle.get((voucher_type, voucher_no), []) voucher_obj = frappe.get_doc(voucher_type, voucher_no) expected_gle = voucher_obj.get_gl_entries(warehouse_account) if expected_gle: if not existing_gle or not compare_existing_and_expected_gle(existing_gle, expected_gle): _delete_gl_entries(voucher_type, voucher_no) voucher_obj.make_gl_entries(gl_entries=expected_gle, repost_future_gle=False, from_repost=True) else: _delete_gl_entries(voucher_type, voucher_no)
def make_gl_entries(self, gl_entries=None, from_repost=False): if self.docstatus == 2: make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) provisional_accounting_for_non_stock_items = cint( frappe.db.get_value( "Company", self.company, "enable_provisional_accounting_for_non_stock_items")) if (cint(erpnext.is_perpetual_inventory_enabled(self.company)) or provisional_accounting_for_non_stock_items): warehouse_account = get_warehouse_account_map(self.company) if self.docstatus == 1: if not gl_entries: gl_entries = self.get_gl_entries(warehouse_account) make_gl_entries(gl_entries, from_repost=from_repost) elif self.doctype in ["Purchase Receipt", "Purchase Invoice" ] and self.docstatus == 1: gl_entries = [] gl_entries = self.get_asset_gl_entry(gl_entries) make_gl_entries(gl_entries, from_repost=from_repost)
def make_item_gl_entries(self, gl_entries): # item gl entries stock_items = self.get_stock_items() expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") if self.update_stock and self.auto_accounting_for_stock: warehouse_account = get_warehouse_account_map(self.company) landed_cost_entries = get_item_account_wise_additional_cost(self.name) voucher_wise_stock_value = {} if self.update_stock: for d in frappe.get_all('Stock Ledger Entry', fields = ["voucher_detail_no", "stock_value_difference"], filters={'voucher_no': self.name}): voucher_wise_stock_value.setdefault(d.voucher_detail_no, d.stock_value_difference) valuation_tax_accounts = [d.account_head for d in self.get("taxes") if d.category in ('Valuation', 'Total and Valuation') and flt(d.base_tax_amount_after_discount_amount)] for item in self.get("items"): if flt(item.base_net_amount): account_currency = get_account_currency(item.expense_account) if item.item_code: asset_category = frappe.get_cached_value("Item", item.item_code, "asset_category") if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items: # warehouse account warehouse_debit_amount = self.make_stock_adjustment_entry(gl_entries, item, voucher_wise_stock_value, account_currency) gl_entries.append( self.get_gl_dict({ "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, "project": item.project or self.project }, account_currency, item=item) ) # Amount added through landed-cost-voucher if landed_cost_entries: for account, amount in iteritems(landed_cost_entries[(item.item_code, item.name)]): gl_entries.append(self.get_gl_dict({ "account": account, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(amount), "project": item.project or self.project }, item=item)) # sub-contracting warehouse if flt(item.rm_supp_cost): supplier_warehouse_account = warehouse_account[self.supplier_warehouse]["account"] if not supplier_warehouse_account: frappe.throw(_("Please set account in Warehouse {0}") .format(self.supplier_warehouse)) gl_entries.append(self.get_gl_dict({ "account": supplier_warehouse_account, "against": item.expense_account, "cost_center": item.cost_center, "project": item.project or self.project, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.rm_supp_cost) }, warehouse_account[self.supplier_warehouse]["account_currency"], item=item)) elif not item.is_fixed_asset or (item.is_fixed_asset and not is_cwip_accounting_enabled(asset_category)): expense_account = (item.expense_account if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account) if not item.is_fixed_asset: amount = flt(item.base_net_amount, item.precision("base_net_amount")) else: amount = flt(item.base_net_amount + item.item_tax_amount, item.precision("base_net_amount")) gl_entries.append(self.get_gl_dict({ "account": expense_account, "against": self.supplier, "debit": amount, "cost_center": item.cost_center, "project": item.project or self.project }, account_currency, item=item)) # If asset is bought through this document and not linked to PR if self.update_stock and item.landed_cost_voucher_amount: expenses_included_in_asset_valuation = self.get_company_default("expenses_included_in_asset_valuation") # Amount added through landed-cost-voucher gl_entries.append(self.get_gl_dict({ "account": expenses_included_in_asset_valuation, "against": expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.landed_cost_voucher_amount), "project": item.project or self.project }, item=item)) gl_entries.append(self.get_gl_dict({ "account": expense_account, "against": expenses_included_in_asset_valuation, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "debit": flt(item.landed_cost_voucher_amount), "project": item.project or self.project }, item=item)) # update gross amount of asset bought through this document assets = frappe.db.get_all('Asset', filters={ 'purchase_invoice': self.name, 'item_code': item.item_code } ) for asset in assets: frappe.db.set_value("Asset", asset.name, "gross_purchase_amount", flt(item.valuation_rate)) frappe.db.set_value("Asset", asset.name, "purchase_receipt_amount", flt(item.valuation_rate)) if self.auto_accounting_for_stock and self.is_opening == "No" and \ item.item_code in stock_items and item.item_tax_amount: # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt if item.purchase_receipt and valuation_tax_accounts: negative_expense_booked_in_pr = frappe.db.sql("""select name from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s and account in %s""", (item.purchase_receipt, valuation_tax_accounts)) if not negative_expense_booked_in_pr: gl_entries.append( self.get_gl_dict({ "account": self.stock_received_but_not_billed, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), "remarks": self.remarks or "Accounting Entry for Stock", "cost_center": self.cost_center, "project": item.project or self.project }, item=item) ) self.negative_expense_to_be_booked += flt(item.item_tax_amount, \ item.precision("item_tax_amount"))
def validate_with_delivery_note(self): # We are only doing this: # Make SLEs for changed qtys # Make the GL wrt abv # make_sl_entries & make_gl_entries handles cancellation # not stable return if self.update_stock == 1: # do nothing if updating stock return sl_entries = [] changed_rows = [] # everything wrt stock_qty for d in [ x for x in self.items if x.validate_with_delivery_note and x.warehouse ]: if frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 and flt(d.stock_qty): delivered_qty = 0 if d.dn_detail: delivered_qty = frappe.get_value("Delivery Note Item", d.dn_detail, "stock_qty") qty_change = d.stock_qty - delivered_qty # qty_change # -ve : got return # +ve : gave more # 0 : continue if qty_change == 0: continue # return rate- code copied from selling_controller.py return_rate = 0 if cint(self.is_return ) and self.return_against and self.docstatus == 1: return_rate = self.get_incoming_rate_for_sales_return( d.item_code, self.return_against) sl_entries.append( self.get_sl_entries( d, { "actual_qty": -1 * flt(qty_change), "incoming_rate": return_rate, "parent": "consoleerp-{}".format(self.name) })) changed_rows.append(d) self.make_sl_entries(sl_entries) # above method inserts the SLEs # stock_value_difference is made only after the above method # STOCK GL ENTRIES # Proceed if perpetual inventory is enabled import erpnext if not erpnext.is_perpetual_inventory_enabled(self.company): return #--- get stock ledger entries just made from erpnext.stock import get_warehouse_account_map warehouse_account = get_warehouse_account_map() sle_map = {} stock_ledger_entries = frappe.db.sql(""" select name, warehouse, stock_value_difference, valuation_rate, voucher_detail_no, item_code, posting_date, posting_time, actual_qty, qty_after_transaction from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s and parent=%s """, (self.doctype, self.name, "consoleerp-{}".format(self.name)), as_dict=True) for sle in stock_ledger_entries: sle_map.setdefault(sle.voucher_detail_no, []).append(sle) warehouse_with_no_account = [] gl_list = [] # loop it again # stock_controller.get_gl_entries() for item_row in changed_rows: sle_list = sle_map.get(item_row.name) if sle_list: for sle in sle_list: if warehouse_account.get(sle.warehouse): # from warehouse account self.check_expense_account(item_row) # If the item does not have the allow zero valuation rate flag set # and ( valuation rate not mentioned in an incoming entry # or incoming entry not found while delivering the item), # try to pick valuation rate from previous sle or Item master and update in SLE # Otherwise, throw an exception if not sle.stock_value_difference and self.doctype != "Stock Reconciliation" \ and not item_row.get("allow_zero_valuation_rate"): sle = self.update_stock_ledger_entries(sle) gl_list.append( self.get_gl_dict( { "account": warehouse_account[sle.warehouse]["account"], "against": item_row.expense_account, "cost_center": item_row.cost_center, "remarks": "Delivery Note Validation Entry", "debit": flt(sle.stock_value_difference, 2), }, warehouse_account[sle.warehouse] ["account_currency"])) # to target warehouse / expense account gl_list.append( self.get_gl_dict({ "account": item_row.expense_account, "against": warehouse_account[sle.warehouse]["account"], "cost_center": item_row.cost_center, "remarks": "Delivery Note Validation Entry", "credit": flt(sle.stock_value_difference, 2), "project": item_row.get("project") or self.get("project") })) elif sle.warehouse not in warehouse_with_no_account: warehouse_with_no_account.append(sle.warehouse) if warehouse_with_no_account: for wh in warehouse_with_no_account: if frappe.db.get_value("Warehouse", wh, "company"): frappe.throw( _("Warehouse {0} is not linked to any account, please mention the account in the warehouse record or set default inventory account in company {1}." ).format(wh, self.company)) from erpnext.accounts.general_ledger import process_gl_map gl_list = process_gl_map(gl_list) from erpnext.accounts.general_ledger import merge_similar_entries gl_list = merge_similar_entries(gl_list) self.make_gl_entries(gl_list)
def get_gl_entries(self, warehouse_account=None, default_expense_account=None, default_cost_center=None): if not warehouse_account: warehouse_account = get_warehouse_account_map(self.company) sle_map = self.get_stock_ledger_details() voucher_details = self.get_voucher_details(default_expense_account, default_cost_center, sle_map) gl_list = [] warehouse_with_no_account = [] precision = self.get_debit_field_precision() for item_row in voucher_details: sle_list = sle_map.get(item_row.name) if sle_list: for sle in sle_list: if warehouse_account.get(sle.warehouse): # from warehouse account self.check_expense_account(item_row) # expense account/ target_warehouse / source_warehouse if item_row.get("target_warehouse"): warehouse = item_row.get("target_warehouse") expense_account = warehouse_account[warehouse][ "account"] else: expense_account = item_row.expense_account gl_list.append( self.get_gl_dict( { "account": warehouse_account[ sle.warehouse]["account"], "against": expense_account, "cost_center": item_row.cost_center, "project": item_row.project or self.get("project"), "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "debit": flt(sle.stock_value_difference, precision), "is_opening": item_row.get("is_opening") or self.get("is_opening") or "No", }, warehouse_account[sle.warehouse] ["account_currency"], item=item_row, )) gl_list.append( self.get_gl_dict( { "account": expense_account, "against": warehouse_account[ sle.warehouse]["account"], "cost_center": item_row.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(sle.stock_value_difference, precision), "project": item_row.get("project") or self.get("project"), "is_opening": item_row.get("is_opening") or self.get("is_opening") or "No", }, item=item_row, )) elif sle.warehouse not in warehouse_with_no_account: warehouse_with_no_account.append(sle.warehouse) if warehouse_with_no_account: for wh in warehouse_with_no_account: if frappe.db.get_value("Warehouse", wh, "company"): frappe.throw( _("Warehouse {0} is not linked to any account, please mention the account in the warehouse record or set default inventory account in company {1}." ).format(wh, self.company)) return process_gl_map(gl_list, precision=precision)
def make_item_gl_entries(self, gl_entries): # item gl entries stock_items = self.get_stock_items() expenses_included_in_valuation = self.get_company_default( "expenses_included_in_valuation") warehouse_account = get_warehouse_account_map() for item in self.get("items"): if flt(item.base_net_amount): account_currency = get_account_currency(item.expense_account) if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items: val_rate_db_precision = 6 if cint( item.precision("valuation_rate")) <= 6 else 9 # warehouse account warehouse_debit_amount = flt( flt(item.valuation_rate, val_rate_db_precision) * flt(item.qty) * flt(item.conversion_factor), item.precision("base_net_amount")) gl_entries.append( self.get_gl_dict( { "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, "project": item.project }, account_currency)) # Amount added through landed-cost-voucher if flt(item.landed_cost_voucher_amount): gl_entries.append( self.get_gl_dict({ "account": expenses_included_in_valuation, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.landed_cost_voucher_amount), "project": item.project })) # sub-contracting warehouse if flt(item.rm_supp_cost): supplier_warehouse_account = warehouse_account[ self.supplier_warehouse]["account"] if not supplier_warehouse_account: frappe.throw( _("Please set account in Warehouse {0}"). format(self.supplier_warehouse)) gl_entries.append( self.get_gl_dict( { "account": supplier_warehouse_account, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.rm_supp_cost) }, warehouse_account[self.supplier_warehouse] ["account_currency"])) else: gl_entries.append( self.get_gl_dict( { "account": item.expense_account, "against": self.supplier, "debit": flt(item.base_net_amount, item.precision("base_net_amount")), "debit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount")) if account_currency == self.company_currency else flt(item.net_amount, item.precision("net_amount"))), "cost_center": item.cost_center, "project": item.project }, account_currency)) if self.auto_accounting_for_stock and self.is_opening == "No" and \ item.item_code in stock_items and item.item_tax_amount: # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt if item.purchase_receipt: negative_expense_booked_in_pr = frappe.db.sql( """select name from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""", (item.purchase_receipt, self.expenses_included_in_valuation)) if not negative_expense_booked_in_pr: gl_entries.append( self.get_gl_dict({ "account": self.stock_received_but_not_billed, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), "remarks": self.remarks or "Accounting Entry for Stock" })) self.negative_expense_to_be_booked += flt(item.item_tax_amount, \ item.precision("item_tax_amount"))
def make_item_gl_entries(self, gl_entries): # item gl entries stock_items = self.get_stock_items() expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") warehouse_account = get_warehouse_account_map() for item in self.get("items"): if flt(item.base_net_amount): account_currency = get_account_currency(item.expense_account) if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items: val_rate_db_precision = 6 if cint(item.precision("valuation_rate")) <= 6 else 9 # warehouse account warehouse_debit_amount = flt(flt(item.valuation_rate, val_rate_db_precision) * flt(item.qty) * flt(item.conversion_factor), item.precision("base_net_amount")) gl_entries.append( self.get_gl_dict({ "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, "project": item.project }, account_currency) ) # Amount added through landed-cost-voucher if flt(item.landed_cost_voucher_amount): gl_entries.append(self.get_gl_dict({ "account": expenses_included_in_valuation, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.landed_cost_voucher_amount), "project": item.project })) # sub-contracting warehouse if flt(item.rm_supp_cost): supplier_warehouse_account = warehouse_account[self.supplier_warehouse]["name"] gl_entries.append(self.get_gl_dict({ "account": supplier_warehouse_account, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.rm_supp_cost) }, warehouse_account[self.supplier_warehouse]["account_currency"])) else: gl_entries.append( self.get_gl_dict({ "account": item.expense_account, "against": self.supplier, "debit": flt(item.base_net_amount, item.precision("base_net_amount")), "debit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount")) if account_currency==self.company_currency else flt(item.net_amount, item.precision("net_amount"))), "cost_center": item.cost_center, "project": item.project }, account_currency) ) if self.auto_accounting_for_stock and self.is_opening == "No" and \ item.item_code in stock_items and item.item_tax_amount: # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt if item.purchase_receipt: negative_expense_booked_in_pr = frappe.db.sql("""select name from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""", (item.purchase_receipt, self.expenses_included_in_valuation)) if not negative_expense_booked_in_pr: gl_entries.append( self.get_gl_dict({ "account": self.stock_received_but_not_billed, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), "remarks": self.remarks or "Accounting Entry for Stock" }) ) self.negative_expense_to_be_booked += flt(item.item_tax_amount, \ item.precision("item_tax_amount"))
def make_item_gl_entries(self, gl_entries): # item gl entries stock_items = self.get_stock_items() expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") if self.update_stock and self.auto_accounting_for_stock: warehouse_account = get_warehouse_account_map() voucher_wise_stock_value = {} if self.update_stock: for d in frappe.get_all('Stock Ledger Entry', fields = ["voucher_detail_no", "stock_value_difference"], filters={'voucher_no': self.name}): voucher_wise_stock_value.setdefault(d.voucher_detail_no, d.stock_value_difference) for item in self.get("items"): if flt(item.base_net_amount): account_currency = get_account_currency(item.expense_account) if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items: # warehouse account warehouse_debit_amount = self.make_stock_adjustment_entry(gl_entries, item, voucher_wise_stock_value, account_currency) gl_entries.append( self.get_gl_dict({ "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, "project": item.project }, account_currency) ) # Amount added through landed-cost-voucher if flt(item.landed_cost_voucher_amount): gl_entries.append(self.get_gl_dict({ "account": expenses_included_in_valuation, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.landed_cost_voucher_amount), "project": item.project })) # sub-contracting warehouse if flt(item.rm_supp_cost): supplier_warehouse_account = warehouse_account[self.supplier_warehouse]["account"] if not supplier_warehouse_account: frappe.throw(_("Please set account in Warehouse {0}") .format(self.supplier_warehouse)) gl_entries.append(self.get_gl_dict({ "account": supplier_warehouse_account, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.rm_supp_cost) }, warehouse_account[self.supplier_warehouse]["account_currency"])) elif not item.is_fixed_asset: gl_entries.append( self.get_gl_dict({ "account": item.expense_account if not item.enable_deferred_expense else item.deferred_expense_account, "against": self.supplier, "debit": flt(item.base_net_amount, item.precision("base_net_amount")), "debit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount")) if account_currency==self.company_currency else flt(item.net_amount, item.precision("net_amount"))), "cost_center": item.cost_center, "project": item.project }, account_currency) ) if self.auto_accounting_for_stock and self.is_opening == "No" and \ item.item_code in stock_items and item.item_tax_amount: # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt if item.purchase_receipt: negative_expense_booked_in_pr = frappe.db.sql("""select name from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""", (item.purchase_receipt, self.expenses_included_in_valuation)) if not negative_expense_booked_in_pr: gl_entries.append( self.get_gl_dict({ "account": self.stock_received_but_not_billed, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), "remarks": self.remarks or "Accounting Entry for Stock", "cost_center": self.cost_center }) ) self.negative_expense_to_be_booked += flt(item.item_tax_amount, \ item.precision("item_tax_amount"))
def make_item_gl_entries(self, gl_entries): # item gl entries stock_items = self.get_stock_items() expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") if self.update_stock and self.auto_accounting_for_stock: warehouse_account = get_warehouse_account_map(self.company) voucher_wise_stock_value = {} if self.update_stock: for d in frappe.get_all('Stock Ledger Entry', fields = ["voucher_detail_no", "stock_value_difference"], filters={'voucher_no': self.name}): voucher_wise_stock_value.setdefault(d.voucher_detail_no, d.stock_value_difference) for item in self.get("items"): if flt(item.base_net_amount): account_currency = get_account_currency(item.expense_account) if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items: # warehouse account warehouse_debit_amount = self.make_stock_adjustment_entry(gl_entries, item, voucher_wise_stock_value, account_currency) gl_entries.append( self.get_gl_dict({ "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, "project": item.project }, account_currency) ) # Amount added through landed-cost-voucher if flt(item.landed_cost_voucher_amount): gl_entries.append(self.get_gl_dict({ "account": expenses_included_in_valuation, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.landed_cost_voucher_amount), "project": item.project })) # sub-contracting warehouse if flt(item.rm_supp_cost): supplier_warehouse_account = warehouse_account[self.supplier_warehouse]["account"] if not supplier_warehouse_account: frappe.throw(_("Please set account in Warehouse {0}") .format(self.supplier_warehouse)) gl_entries.append(self.get_gl_dict({ "account": supplier_warehouse_account, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.rm_supp_cost) }, warehouse_account[self.supplier_warehouse]["account_currency"])) elif not item.is_fixed_asset or (item.is_fixed_asset and is_cwip_accounting_disabled()): expense_account = (item.expense_account if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account) gl_entries.append( self.get_gl_dict({ "account": expense_account, "against": self.supplier, "debit": flt(item.base_net_amount, item.precision("base_net_amount")), "debit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount")) if account_currency==self.company_currency else flt(item.net_amount, item.precision("net_amount"))), "cost_center": item.cost_center, "project": item.project }, account_currency) ) if self.auto_accounting_for_stock and self.is_opening == "No" and \ item.item_code in stock_items and item.item_tax_amount: # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt if item.purchase_receipt: negative_expense_booked_in_pr = frappe.db.sql("""select name from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""", (item.purchase_receipt, self.expenses_included_in_valuation)) if not negative_expense_booked_in_pr: gl_entries.append( self.get_gl_dict({ "account": self.stock_received_but_not_billed, "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), "remarks": self.remarks or "Accounting Entry for Stock", "cost_center": self.cost_center }) ) self.negative_expense_to_be_booked += flt(item.item_tax_amount, \ item.precision("item_tax_amount"))
def make_item_gl_entries(self, gl_entries): # item gl entries stock_items = self.get_stock_items() expenses_included_in_valuation = self.get_company_default( "expenses_included_in_valuation") warehouse_account = get_warehouse_account_map() for item in self.get("items"): if flt(item.base_net_amount): account_currency = get_account_currency(item.expense_account) if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items: val_rate_db_precision = 6 if cint( item.precision("valuation_rate")) <= 6 else 9 # warehouse account warehouse_debit_amount = flt( flt(item.valuation_rate, val_rate_db_precision) * flt(item.qty) * flt(item.conversion_factor), item.precision("base_net_amount")) gl_entries.append( self.get_gl_dict( { "account": item.expense_account, "against": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, "project": item.project }, account_currency)) # Amount added through landed-cost-voucher if flt(item.landed_cost_voucher_amount): gl_entries.append( self.get_gl_dict({ "account": expenses_included_in_valuation, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.landed_cost_voucher_amount), "project": item.project })) # sub-contracting warehouse if flt(item.rm_supp_cost): supplier_warehouse_account = warehouse_account[ self.supplier_warehouse]["name"] gl_entries.append( self.get_gl_dict( { "account": supplier_warehouse_account, "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.rm_supp_cost) }, warehouse_account[self.supplier_warehouse] ["account_currency"])) else: gl_entries.append( self.get_gl_dict( { "account": item.expense_account, "against": self.supplier, "debit": flt(item.base_net_amount, item.precision("base_net_amount")), "debit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount")) if account_currency == self.company_currency else flt(item.net_amount, item.precision("net_amount"))), "cost_center": item.cost_center, "project": item.project }, account_currency)) """