def make_gl_entries(self):
		gl_entries = []
		net_pl_balance = 0
		pl_accounts = self.get_pl_balances()

		for acc in pl_accounts:
			if flt(acc.balance_in_company_currency):
				gl_entries.append(self.get_gl_dict({
					"account": acc.account,
					"cost_center": acc.cost_center,
					"account_currency": acc.account_currency,
					"debit_in_account_currency": abs(flt(acc.balance_in_account_currency)) \
						if flt(acc.balance_in_account_currency) < 0 else 0,
					"debit": abs(flt(acc.balance_in_company_currency)) \
						if flt(acc.balance_in_company_currency) < 0 else 0,
					"credit_in_account_currency": abs(flt(acc.balance_in_account_currency)) \
						if flt(acc.balance_in_account_currency) > 0 else 0,
					"credit": abs(flt(acc.balance_in_company_currency)) \
						if flt(acc.balance_in_company_currency) > 0 else 0
				}))

				net_pl_balance += flt(acc.balance_in_company_currency)

		if net_pl_balance:
			gl_entries.append(self.get_gl_dict({
				"account": self.closing_account_head,
				"debit_in_account_currency": abs(net_pl_balance) if net_pl_balance > 0 else 0,
				"debit": abs(net_pl_balance) if net_pl_balance > 0 else 0,
				"credit_in_account_currency": abs(net_pl_balance) if net_pl_balance < 0 else 0,
				"credit": abs(net_pl_balance) if net_pl_balance < 0 else 0
			}))

		from erpnext.accounts.general_ledger import make_gl_entries
		make_gl_entries(gl_entries)
예제 #2
0
	def make_gl_entries(self, repost_future_gle=True):
		gl_entries = self.get_gl_entries()

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries

			# if POS and amount is written off, there's no outstanding and hence no need to update it
			update_outstanding = cint(self.is_pos) and self.write_off_account \
				and 'No' or 'Yes'

			make_gl_entries(gl_entries, cancel=(self.docstatus == 2),
				update_outstanding=update_outstanding, merge_entries=False)

			if update_outstanding == "No":
				from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
				update_outstanding_amt(self.debit_to, "Customer", self.customer, self.doctype, self.name)

			if repost_future_gle and cint(self.update_stock) \
				and cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
					items, warehouses = self.get_items_and_warehouses()
					update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items)
		elif self.docstatus == 2 and cint(self.update_stock) \
			and cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
				from erpnext.accounts.general_ledger import delete_gl_entries
				delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
예제 #3
0
	def make_gl_entries(self, cancel=0, adv_adj=0):
		from erpnext.accounts.general_ledger import make_gl_entries

		gl_map = []
		for d in self.get("accounts"):
			if d.debit or d.credit:
				gl_map.append(
					self.get_gl_dict({
						"account": d.account,
						"party_type": d.party_type,
						"party": d.party,
						"against": d.against_account,
						"debit": flt(d.debit, self.precision("debit", "accounts")),
						"credit": flt(d.credit, self.precision("credit", "accounts")),
						"against_voucher_type": (("Purchase Invoice" if d.against_voucher else None)
							or ("Sales Invoice" if d.against_invoice else None)
							or ("Journal Entry" if d.against_jv else None)
							or ("Sales Order" if d.against_sales_order else None)
							or ("Purchase Order" if d.against_purchase_order else None)),
						"against_voucher": d.against_voucher or d.against_invoice or d.against_jv
							or d.against_sales_order or d.against_purchase_order,
						"remarks": self.remark,
						"cost_center": d.cost_center
					})
				)

		if gl_map:
			make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
예제 #4
0
	def make_gl_entries(self, repost_future_gle=True):
		if not self.grand_total:
			return
		gl_entries = self.get_gl_entries()

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries

			# if POS and amount is written off, updating outstanding amt after posting all gl entries
			update_outstanding = "No" if (cint(self.is_pos) or self.write_off_account) else "Yes"

			make_gl_entries(gl_entries, cancel=(self.docstatus == 2),
				update_outstanding=update_outstanding, merge_entries=False)

			if update_outstanding == "No":
				from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
				update_outstanding_amt(self.debit_to, "Customer", self.customer,
					self.doctype, self.return_against if cint(self.is_return) else self.name)

			if repost_future_gle and cint(self.update_stock) \
				and cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
					items, warehouses = self.get_items_and_warehouses()
					update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items)
		elif self.docstatus == 2 and cint(self.update_stock) \
			and cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
				from erpnext.accounts.general_ledger import delete_gl_entries
				delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
예제 #5
0
	def make_adjustment_entry(self, expected_gle, voucher_obj):
		from erpnext.accounts.utils import get_stock_and_account_difference
		account_list = [d.account for d in expected_gle]
		acc_diff = get_stock_and_account_difference(account_list, expected_gle[0].posting_date)

		cost_center = self.get_company_default("cost_center")
		stock_adjustment_account = self.get_company_default("stock_adjustment_account")

		gl_entries = []
		for account, diff in acc_diff.items():
			if diff:
				gl_entries.append([
					# stock in hand account
					voucher_obj.get_gl_dict({
						"account": account,
						"against": stock_adjustment_account,
						"debit": diff,
						"remarks": "Adjustment Accounting Entry for Stock",
					}),

					# account against stock in hand
					voucher_obj.get_gl_dict({
						"account": stock_adjustment_account,
						"against": account,
						"credit": diff,
						"cost_center": cost_center or None,
						"remarks": "Adjustment Accounting Entry for Stock",
					}),
				])

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries)
예제 #6
0
	def make_gl_entries(self, cancel=0, adv_adj=0):
		gl_entries = []
		self.add_party_gl_entries(gl_entries)
		self.add_bank_gl_entries(gl_entries)
		self.add_deductions_gl_entries(gl_entries)

		make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)
예제 #7
0
	def make_gl_entries(self, cancel=0, adv_adj=0):
		from erpnext.accounts.general_ledger import make_gl_entries

		gl_map = []
		for d in self.get("accounts"):
			if d.debit or d.credit:
				gl_map.append(
					self.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": self.remark,
						"cost_center": d.cost_center,
						"project": d.project
					})
				)

		if gl_map:
			make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
예제 #8
0
파일: asset.py 프로젝트: frappe/erpnext
	def make_gl_entries(self):
		gl_entries = []

		if ((self.purchase_receipt or (self.purchase_invoice and
			frappe.db.get_value('Purchase Invoice', self.purchase_invoice, 'update_stock')))
			and self.purchase_receipt_amount and self.available_for_use_date <= nowdate()):
			fixed_aseet_account = get_asset_category_account(self.name, 'fixed_asset_account',
					asset_category = self.asset_category, company = self.company)

			cwip_account = get_asset_account("capital_work_in_progress_account",
				self.name, self.asset_category, self.company)

			gl_entries.append(self.get_gl_dict({
				"account": cwip_account,
				"against": fixed_aseet_account,
				"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
				"posting_date": self.available_for_use_date,
				"credit": self.purchase_receipt_amount,
				"credit_in_account_currency": self.purchase_receipt_amount
			}))

			gl_entries.append(self.get_gl_dict({
				"account": fixed_aseet_account,
				"against": cwip_account,
				"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
				"posting_date": self.available_for_use_date,
				"debit": self.purchase_receipt_amount,
				"debit_in_account_currency": self.purchase_receipt_amount
			}))

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries

			make_gl_entries(gl_entries)
			self.db_set('booked_fixed_asset', 1)
예제 #9
0
    def make_gl_entries(self):
        gl_entries = []
        net_pl_balance = 0
        pl_accounts = self.get_pl_balances()
        for acc in pl_accounts:
            if flt(acc.balance):
                gl_entries.append(
                    self.get_gl_dict(
                        {
                            "account": acc.account,
                            "debit": abs(flt(acc.balance)) if flt(acc.balance) < 0 else 0,
                            "credit": abs(flt(acc.balance)) if flt(acc.balance) > 0 else 0,
                        }
                    )
                )

                net_pl_balance += flt(acc.balance)

        if net_pl_balance:
            gl_entries.append(
                self.get_gl_dict(
                    {
                        "account": self.closing_account_head,
                        "debit": abs(net_pl_balance) if net_pl_balance > 0 else 0,
                        "credit": abs(net_pl_balance) if net_pl_balance < 0 else 0,
                    }
                )
            )

        from erpnext.accounts.general_ledger import make_gl_entries

        make_gl_entries(gl_entries)
예제 #10
0
	def make_gl_entries(self, cancel=0, adv_adj=0):
		if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"):
			self.setup_party_account_field()
			
		gl_entries = []
		self.add_party_gl_entries(gl_entries)
		self.add_bank_gl_entries(gl_entries)
		self.add_deductions_gl_entries(gl_entries)

		make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)
	def on_submit(self):
		assets=frappe.db.sql("""select name,asset_value,book_value,deprecation_value,counter,against,account,cost_center from `tabAsset` where counter>0 and last_deprecated<="{0}" and docstatus=1 """.format(self.posting_date),as_list=1)
		#frappe.throw(assets)
		for asset in assets:
			new_value=flt(asset[2])-flt(asset[3])
			if new_value<0:
				new_value=0
			#frappe.throw("""update `tabAsset` set counter=counter-1 and book_value='{0}' and last_deprecated="{1}" where name = '{2}' """.format(new_value,self.posting_date,asset[0]))
			asset_record=frappe.get_doc({
				"doctype":"Asset Depreciation Record",
				"parent":self.name,
				"asset_depreciation":self.name,
				"posting_date":self.posting_date,
				"last_book_value":asset[2],
				"depreciation_value":asset[3],
				"new_book_value":new_value,
				"asset":asset[0]
			})
			asset_record.insert()
			
			data=[{"debit":asset[3],"credit":0,"account":asset[6],"against_account":asset[5],"name":asset[0]},
			{"debit":0,"credit":asset[3],"account":asset[5],"against_account":asset[6],"name":asset[0]}]
			from erpnext.accounts.general_ledger import make_gl_entries

			gl_map = []
			for d in data:
				if d.get("debit") or d.get("credit"):
					gl_map.append(
						frappe._dict({
							'company': self.company,
							'posting_date': self.posting_date,
							'transaction_date': self.posting_date,
							'voucher_type': self.doctype,
							'voucher_no': self.name,
							'aging_date': self.get("aging_date") or self.posting_date,
							'remarks': asset[0],
							'fiscal_year': self.fiscal_year,
							'debit': 0,
							'credit': 0,
							'cost_center':asset[7],
							'is_opening': self.get("is_opening") or "No",
							"account": d.get("account"),
							"against": d.get("against_account"),
							"debit": flt(d.get("debit")),
							"credit": flt(d.get("credit"))
						})
					)

			if gl_map:
				make_gl_entries(gl_map, 0,0)
			asset_record.submit()
			
			frappe.db.sql("""update `tabAsset` set counter=counter-1 , book_value='{0}' , last_deprecated="{1}" where name = '{2}' """.format(new_value,self.posting_date,asset[0]))
예제 #12
0
    def make_gl_entries(self, repost_future_gle=True):
        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()

            if self.docstatus == 1:
                gl_entries = self.get_gl_entries(warehouse_account)
                make_gl_entries(gl_entries)

            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)
예제 #13
0
    def make_gl_entries(self, repost_future_gle=True):
        if not self.grand_total:
            return

        self.auto_accounting_for_stock = \
         cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))

        self.stock_received_but_not_billed = self.get_company_default(
            "stock_received_but_not_billed")
        self.expenses_included_in_valuation = self.get_company_default(
            "expenses_included_in_valuation")
        self.negative_expense_to_be_booked = 0.0
        gl_entries = []

        self.make_supplier_gl_entry(gl_entries)
        self.make_item_gl_entries(gl_entries)
        self.make_tax_gl_entries(gl_entries)

        gl_entries = merge_similar_entries(gl_entries)

        self.make_payment_gl_entries(gl_entries)

        self.make_write_off_gl_entry(gl_entries)

        if gl_entries:
            update_outstanding = "No" if (cint(self.is_paid)
                                          or self.write_off_account) else "Yes"

            make_gl_entries(gl_entries,
                            cancel=(self.docstatus == 2),
                            update_outstanding=update_outstanding,
                            merge_entries=False)

            if update_outstanding == "No":
                update_outstanding_amt(
                    self.credit_to, "Supplier", self.supplier, self.doctype,
                    self.return_against if cint(self.is_return) else self.name)

            if repost_future_gle and cint(
                    self.update_stock) and self.auto_accounting_for_stock:
                from erpnext.controllers.stock_controller import update_gl_entries_after
                items, warehouses = self.get_items_and_warehouses()
                update_gl_entries_after(self.posting_date, self.posting_time,
                                        warehouses, items)

        elif self.docstatus == 2 and cint(
                self.update_stock) and self.auto_accounting_for_stock:
            delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
    def make_gl_entries(self, repost_future_gle=True):
        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()

            if self.docstatus == 1:
                gl_entries = self.get_gl_entries(warehouse_account)
                make_gl_entries(gl_entries)

            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)
예제 #15
0
 def make_gl_entries(self, cancel=0):
     payment_account = get_bank_cash_account(
         self.mode_of_payment, self.company
     )
     gl_entries = [
         self.get_gl_dict({
             'account': self.loan_account,
             'debit': self.principal,
         }),
         self.get_gl_dict({
             'account': payment_account.get('account'),
             'credit': self.principal,
             'against': self.customer,
         })
     ]
     make_gl_entries(gl_entries, cancel=cancel, adv_adj=0)
예제 #16
0
    def make_gl_entries(self, update_gl_entries_after=True):
        gl_entries = self.get_gl_entries()

        if gl_entries:
            from erpnext.accounts.general_ledger import make_gl_entries

            update_outstanding = cint(self.doc.is_pos) and self.doc.write_off_account \
             and 'No' or 'Yes'
            make_gl_entries(gl_entries,
                            cancel=(self.doc.docstatus == 2),
                            update_outstanding=update_outstanding,
                            merge_entries=False)

            if update_gl_entries_after and cint(self.doc.update_stock) \
             and cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
                self.update_gl_entries_after()
def execute():
	for name in frappe.db.sql("""
		SELECT name
		FROM `tabIndent Invoice`
		WHERE docstatus = 1;
		"""):
		name = name[0]

		if cint(name) < 1000:
			continue

		invoice = frappe.get_doc("Indent Invoice", name)
		gl_entries = invoice.get_gl_entries()

		delete_gl_entries(voucher_type="Indent Invoice", voucher_no=name)
		make_gl_entries(gl_entries)
예제 #18
0
	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)
예제 #19
0
	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)
예제 #20
0
def make_gl_entries(doc, credit_account, debit_account, against, amount,
                    base_amount, posting_date, project, account_currency,
                    cost_center, voucher_detail_no):
    # GL Entry for crediting the amount in the deferred expense
    from erpnext.accounts.general_ledger import make_gl_entries

    gl_entries = []
    gl_entries.append(
        doc.get_gl_dict(
            {
                "account": credit_account,
                "against": against,
                "credit": base_amount,
                "credit_in_account_currency": amount,
                "cost_center": cost_center,
                "voucher_detail_no": voucher_detail_no,
                'posting_date': posting_date,
                'project': project
            }, account_currency))
    # GL Entry to debit the amount from the expense
    gl_entries.append(
        doc.get_gl_dict(
            {
                "account": debit_account,
                "against": against,
                "debit": base_amount,
                "debit_in_account_currency": amount,
                "cost_center": cost_center,
                "voucher_detail_no": voucher_detail_no,
                'posting_date': posting_date,
                'project': project
            }, account_currency))

    if gl_entries:
        try:
            make_gl_entries(gl_entries,
                            cancel=(doc.docstatus == 2),
                            merge_entries=True)
            frappe.db.commit()
        except:
            frappe.db.rollback()
            title = _(
                "Error while processing deferred accounting for {0}").format(
                    doc.name)
            traceback = frappe.get_traceback()
            frappe.log_error(message=traceback, title=title)
            sendmail_to_system_managers(title, traceback)
예제 #21
0
 def make_gl_entry(self):
     settings = frappe.get_single("Wire Transfer Settings")
     sign = -1 if self.workflow_action in [RETURN, REVERSE] else 1
     if self.workflow_action in [ACCEPT, RETURN]:
         make_gl_entries(
             mapr(
                 self.get_gl_dict,
                 [
                     {
                         "account": self.cash_account,
                         "against": self.account,
                         "debit": self.total * sign,
                     },
                     {
                         "account": settings.income_account,
                         "against": self.account,
                         "credit": self.fees * sign,
                         "cost_center": settings.cost_center,
                     },
                     {
                         "account": settings.transit_account,
                         "party": self.account,
                         "credit": self.amount * sign,
                     },
                 ],
             )
         )
     elif self.workflow_action in [TRANSFER, REVERSE]:
         make_gl_entries(
             mapr(
                 self.get_gl_dict,
                 [
                     {
                         "account": self.bank_account,
                         "against": self.account,
                         "credit": self.amount * sign,
                         "remarks": self._get_remarks(),
                     },
                     {
                         "account": settings.transit_account,
                         "against": self.bank_account,
                         "debit": self.amount * sign,
                     },
                 ],
             )
         )
예제 #22
0
    def make_gl_entries(self, cancel=False, adv_adj=False):
        from erpnext.accounts.general_ledger import make_gl_entries
        from erpnext.accounts.utils import get_company_default

        loan_doc = frappe.get_doc(
            self.meta.get_field("loan").options, self.loan)

        income_account = get_company_default(loan_doc.company,
                                             "default_income_account")

        gl_map = loan_doc.get_double_matched_entry(self.total_amount,
                                                   income_account)

        make_gl_entries(gl_map,
                        cancel=cancel,
                        adv_adj=adv_adj,
                        merge_entries=False)
예제 #23
0
 def make_gl_entries(self, cancel=0):
     payment_account = get_bank_cash_account(
         self.mode_of_payment, self.company
     )
     gl_entries = map(self.get_gl_dict, [
         {
             'account': self.loan_account,
             'debit': self.principal,
         },
         {
             'account': payment_account.get('account'),
             'credit': self.principal,
             'against': self.customer,
             'remarks': 'Loan disbursed',
         },
     ])
     make_gl_entries(gl_entries, cancel=cancel, adv_adj=0)
예제 #24
0
파일: loan.py 프로젝트: clixsoftware/fimax
    def make_gl_entries(self, cancel=False, adv_adj=False):
        from erpnext.accounts.general_ledger import make_gl_entries

        # amount that was disbursed from the bank account
        lent_amount = self.get_lent_amount()

        gl_map = self.get_double_matched_entry(lent_amount,
                                               self.disbursement_account)
        gl_map += self.get_double_matched_entry(self.legal_expenses_amount,
                                                self.income_account)
        gl_map += self.get_double_matched_entry(self.total_interest_amount,
                                                self.income_account)

        make_gl_entries(gl_map,
                        cancel=cancel,
                        adv_adj=adv_adj,
                        merge_entries=False)
예제 #25
0
def make_gl_entries(company, posting_date, fiscal_year):
    gl_entries = []
    net_pl_balance = 0
    from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year

    year_start_date = get_fiscal_year(posting_date, fiscal_year, company)[1]

    pl_accounts = get_pl_balances(company, posting_date, year_start_date)

    for acc in pl_accounts:
        if flt(acc.balance_in_company_currency):
            gl_entries.append(get_gl_dict(company,posting_date,fiscal_year,{
             "account": acc.account,
             "cost_center": acc.cost_center,
             "account_currency": acc.account_currency,
             "debit_in_account_currency": abs(flt(acc.balance_in_account_currency)) \
              if flt(acc.balance_in_account_currency) < 0 else 0,
             "debit": abs(flt(acc.balance_in_company_currency)) \
              if flt(acc.balance_in_company_currency) < 0 else 0,
             "credit_in_account_currency": abs(flt(acc.balance_in_account_currency)) \
              if flt(acc.balance_in_account_currency) > 0 else 0,
             "credit": abs(flt(acc.balance_in_company_currency)) \
              if flt(acc.balance_in_company_currency) > 0 else 0
            }))

            net_pl_balance += flt(acc.balance_in_company_currency)

    if net_pl_balance:
        gl_entries.append(
            get_gl_dict(
                company, posting_date, fiscal_year, {
                    "account":
                    "رأس المال - SPO",
                    "debit_in_account_currency":
                    abs(net_pl_balance) if net_pl_balance > 0 else 0,
                    "debit":
                    abs(net_pl_balance) if net_pl_balance > 0 else 0,
                    "credit_in_account_currency":
                    abs(net_pl_balance) if net_pl_balance < 0 else 0,
                    "credit":
                    abs(net_pl_balance) if net_pl_balance < 0 else 0
                }))

    from erpnext.accounts.general_ledger import make_gl_entries
    make_gl_entries(gl_entries)
예제 #26
0
파일: asset.py 프로젝트: ankush/erpnext
	def make_gl_entries(self):
		gl_entries = []

		purchase_document = self.get_purchase_document()
		fixed_asset_account, cwip_account = self.get_fixed_asset_account(), self.get_cwip_account()

		if (
			purchase_document and self.purchase_receipt_amount and self.available_for_use_date <= nowdate()
		):

			gl_entries.append(
				self.get_gl_dict(
					{
						"account": cwip_account,
						"against": fixed_asset_account,
						"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
						"posting_date": self.available_for_use_date,
						"credit": self.purchase_receipt_amount,
						"credit_in_account_currency": self.purchase_receipt_amount,
						"cost_center": self.cost_center,
					},
					item=self,
				)
			)

			gl_entries.append(
				self.get_gl_dict(
					{
						"account": fixed_asset_account,
						"against": cwip_account,
						"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
						"posting_date": self.available_for_use_date,
						"debit": self.purchase_receipt_amount,
						"debit_in_account_currency": self.purchase_receipt_amount,
						"cost_center": self.cost_center,
					},
					item=self,
				)
			)

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries

			make_gl_entries(gl_entries)
			self.db_set("booked_fixed_asset", 1)
예제 #27
0
	def make_gl_entries(self):
		company_currency = frappe.get_cached_value('Company',  self.company, "default_currency")


		gl_entries = []
		invoice_fields = ["debit_to", "party_account_currency", "conversion_rate", "cost_center"]
		accounting_dimensions = get_accounting_dimensions()

		invoice_fields.extend(accounting_dimensions)

		for d in self.invoices:
			inv = frappe.db.get_value("Sales Invoice", d.sales_invoice, invoice_fields, as_dict=1)

			if d.outstanding_amount:
				outstanding_in_company_currency = flt(d.outstanding_amount * inv.conversion_rate,
					d.precision("outstanding_amount"))
				ar_credit_account_currency = frappe.get_cached_value("Account", self.accounts_receivable_credit, "currency")

				gl_entries.append(self.get_gl_dict({
					"account": inv.debit_to,
					"party_type": "Customer",
					"party": d.customer,
					"against": self.accounts_receivable_credit,
					"credit": outstanding_in_company_currency,
					"credit_in_account_currency": outstanding_in_company_currency \
						if inv.party_account_currency==company_currency else d.outstanding_amount,
					"cost_center": inv.cost_center,
					"against_voucher": d.sales_invoice,
					"against_voucher_type": "Sales Invoice"
				}, inv.party_account_currency, item=inv))

				gl_entries.append(self.get_gl_dict({
					"account": self.accounts_receivable_credit,
					"party_type": "Customer",
					"party": d.customer,
					"against": inv.debit_to,
					"debit": outstanding_in_company_currency,
					"debit_in_account_currency": outstanding_in_company_currency \
						if ar_credit_account_currency==company_currency else d.outstanding_amount,
					"cost_center": inv.cost_center,
					"against_voucher": d.sales_invoice,
					"against_voucher_type": "Sales Invoice"
				}, ar_credit_account_currency, item=inv))

		make_gl_entries(gl_entries, cancel=(self.docstatus == 2), update_outstanding='No')
예제 #28
0
    def make_gl_entries(self, cancel=0, adv_adj=0):
        gl_entries = []

        if self.billing_period:
            unbilled = self.get_unbilled()
            if unbilled:
                self.add_billing_gl_entries(gl_entries, unbilled)
        if self.interest:
            self.add_party_gl_entries(gl_entries)
        if self.principal:
            self.add_loan_gl_entries(gl_entries)
        if len(self.loan_charges) > 0:
            self.add_charges_gl_entries(gl_entries)

        make_gl_entries(gl_entries,
                        cancel=cancel,
                        adv_adj=adv_adj,
                        merge_entries=False)
예제 #29
0
	def make_gl_entries(self, gl_entries=None):
		if not gl_entries:
			gl_entries = self.get_gl_entries()

		if gl_entries:
			update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"

			if self.docstatus == 1:
				make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False)
			elif self.docstatus == 2:
				make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)

			if update_outstanding == "No":
				update_outstanding_amt(self.credit_to, "Supplier", self.supplier,
					self.doctype, self.return_against if cint(self.is_return) and self.return_against else self.name)

		elif self.docstatus == 2 and cint(self.update_stock) and self.auto_accounting_for_stock:
			make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
예제 #30
0
	def make_gl_entries(self, cancel=0, adv_adj=0):
		gle_map = []

		if self.interest_amount:
			gle_map.append(
				self.get_gl_dict(
					{
						"account": self.loan_account,
						"party_type": self.applicant_type,
						"party": self.applicant,
						"against": self.interest_income_account,
						"debit": self.interest_amount,
						"debit_in_account_currency": self.interest_amount,
						"against_voucher_type": "Loan",
						"against_voucher": self.loan,
						"remarks": _("Interest accrued from {0} to {1} against loan: {2}").format(
							self.last_accrual_date, self.posting_date, self.loan
						),
						"cost_center": erpnext.get_default_cost_center(self.company),
						"posting_date": self.posting_date,
					}
				)
			)

			gle_map.append(
				self.get_gl_dict(
					{
						"account": self.interest_income_account,
						"against": self.loan_account,
						"credit": self.interest_amount,
						"credit_in_account_currency": self.interest_amount,
						"against_voucher_type": "Loan",
						"against_voucher": self.loan,
						"remarks": ("Interest accrued from {0} to {1} against loan: {2}").format(
							self.last_accrual_date, self.posting_date, self.loan
						),
						"cost_center": erpnext.get_default_cost_center(self.company),
						"posting_date": self.posting_date,
					}
				)
			)

		if gle_map:
			make_gl_entries(gle_map, cancel=cancel, adv_adj=adv_adj)
예제 #31
0
    def make_gl_entries(self, cancel=0, adv_adj=0):
        from erpnext.accounts.general_ledger import make_gl_entries

        gl_map = []
        for d in self.get("accounts"):
            if d.debit or d.credit:
                gl_map.append(
                    self.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":
                        self.remark,
                        "cost_center":
                        d.cost_center,
                        "project":
                        d.project,
                        "narration":
                        d.narration
                    }))

        if gl_map:
            make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
예제 #32
0
파일: dunning.py 프로젝트: giangdn/teama
    def make_gl_entries(self):
        if not self.dunning_amount:
            return
        gl_entries = []
        invoice_fields = ["project", "cost_center", "debit_to",
                          "party_account_currency", "conversion_rate", "cost_center"]
        inv = frappe.db.get_value(
            "Sales Invoice", self.sales_invoice, invoice_fields, as_dict=1)

        accounting_dimensions = get_accounting_dimensions()
        invoice_fields.extend(accounting_dimensions)

        dunning_in_company_currency = flt(
            self.dunning_amount * inv.conversion_rate)
        default_cost_center = frappe.get_cached_value(
            'Company',  self.company,  'cost_center')

        gl_entries.append(
            self.get_gl_dict({
                "account": inv.debit_to,
                "party_type": "Customer",
                "party": self.customer,
                "due_date": self.due_date,
                "against": self.income_account,
                "debit": dunning_in_company_currency,
                "debit_in_account_currency": self.dunning_amount,
                "against_voucher": self.name,
                "against_voucher_type": "Dunning",
                "cost_center": inv.cost_center or default_cost_center,
                "project": inv.project
            }, inv.party_account_currency, item=inv)
        )
        gl_entries.append(
            self.get_gl_dict({
                "account": self.income_account,
                "against": self.customer,
                "credit": dunning_in_company_currency,
                "cost_center": inv.cost_center or default_cost_center,
                "credit_in_account_currency": self.dunning_amount,
                "project": inv.project
            }, item=inv)
        )
        make_gl_entries(gl_entries, cancel=(self.docstatus == 2),
                        update_outstanding="No", merge_entries=False)
    def make_gl_entries(self):
        gl_entries = []
        net_pl_balance = 0
        pl_accounts = self.get_pl_balances()

        for acc in pl_accounts:
            if flt(acc.balance_in_company_currency):
                gl_entries.append(self.get_gl_dict({
                 "account": acc.account,
                 "cost_center": acc.cost_center,
                 "account_currency": acc.account_currency,
                 "debit_in_account_currency": abs(flt(acc.balance_in_account_currency)) \
                  if flt(acc.balance_in_account_currency) < 0 else 0,
                 "debit": abs(flt(acc.balance_in_company_currency)) \
                  if flt(acc.balance_in_company_currency) < 0 else 0,
                 "credit_in_account_currency": abs(flt(acc.balance_in_account_currency)) \
                  if flt(acc.balance_in_account_currency) > 0 else 0,
                 "credit": abs(flt(acc.balance_in_company_currency)) \
                  if flt(acc.balance_in_company_currency) > 0 else 0
                }))

                net_pl_balance += flt(acc.balance_in_company_currency)

        if net_pl_balance:
            cost_center = frappe.db.get_value("Company", self.company,
                                              "cost_center")
            gl_entries.append(
                self.get_gl_dict({
                    "account":
                    self.closing_account_head,
                    "debit_in_account_currency":
                    abs(net_pl_balance) if net_pl_balance > 0 else 0,
                    "debit":
                    abs(net_pl_balance) if net_pl_balance > 0 else 0,
                    "credit_in_account_currency":
                    abs(net_pl_balance) if net_pl_balance < 0 else 0,
                    "credit":
                    abs(net_pl_balance) if net_pl_balance < 0 else 0,
                    "cost_center":
                    cost_center
                }))

        from erpnext.accounts.general_ledger import make_gl_entries
        make_gl_entries(gl_entries)
    def make_adjustment_entry(self, expected_gle, voucher_obj):
        from erpnext.accounts.utils import get_stock_and_account_difference
        account_list = [d.account for d in expected_gle]
        acc_diff = get_stock_and_account_difference(
            account_list, expected_gle[0].posting_date)

        cost_center = self.get_company_default("cost_center")
        stock_adjustment_account = self.get_company_default(
            "stock_adjustment_account")

        gl_entries = []
        for account, diff in acc_diff.items():
            if diff:
                gl_entries.append([
                    # stock in hand account
                    voucher_obj.get_gl_dict({
                        "account":
                        account,
                        "against":
                        stock_adjustment_account,
                        "debit":
                        diff,
                        "remarks":
                        "Adjustment Accounting Entry for Stock",
                    }),

                    # account against stock in hand
                    voucher_obj.get_gl_dict({
                        "account":
                        stock_adjustment_account,
                        "against":
                        account,
                        "credit":
                        diff,
                        "cost_center":
                        cost_center or None,
                        "remarks":
                        "Adjustment Accounting Entry for Stock",
                    }),
                ])

        if gl_entries:
            from erpnext.accounts.general_ledger import make_gl_entries
            make_gl_entries(gl_entries)
예제 #35
0
    def update_gl(self):
        buyer_account = get_party_account(self.company, self.to_customer,
                                          "Customer")
        seller_account = get_party_account(self.company, self.from_customer,
                                           "Customer")

        gl_entries = []
        remark = "Sale of {} {} from {} to {}".format(self.qty, self.item,
                                                      self.from_customer,
                                                      self.to_customer)

        gl_entries.append(
            self.get_gl_dict({
                "account": buyer_account,
                "debit": self.sale_amount,
                "remarks": remark
            }))

        gl_entries.append(
            self.get_gl_dict({
                "account": seller_account,
                "credit": self.purchase_amount,
                "remarks": remark
            }))

        income = self.sale_amount - self.purchase_amount

        if income != 0:

            adjustment_gl_entry = self.get_gl_dict({
                "account": "Sales - AL",
                "remarks": remark,
                "cost_center": "Main - AL"
            })

            adjustment_gl_entry['credit' if income else 'debit'] = income

            gl_entries.append(adjustment_gl_entry)

        make_gl_entries(gl_entries,
                        cancel=(self.docstatus == 2),
                        update_outstanding='Yes',
                        merge_entries=False)
예제 #36
0
	def make_gl_entries(self, repost_future_gle=True):
		gl_entries = self.get_gl_entries()

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries

			update_outstanding = cint(self.is_pos) and self.write_off_account \
				and 'No' or 'Yes'
			make_gl_entries(gl_entries, cancel=(self.docstatus == 2),
				update_outstanding=update_outstanding, merge_entries=False)

			if update_outstanding == "No":
				from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
				update_outstanding_amt(self.debit_to, self.doctype, self.name)

			if repost_future_gle and cint(self.update_stock) \
				and cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
					items, warehouses = self.get_items_and_warehouses()
					update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items)
예제 #37
0
	def make_gl_entries(self, repost_future_gle=True, allow_negative_stock=False):
		gl_entries = self.get_gl_entries(allow_negative_stock=allow_negative_stock)

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries

			update_outstanding = cint(self.is_pos) and self.write_off_account \
				and 'No' or 'Yes'
			make_gl_entries(gl_entries, cancel=(self.docstatus == 2),
				update_outstanding=update_outstanding, merge_entries=False)

			if update_outstanding == "No":
				from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
				update_outstanding_amt(self.debit_to, self.doctype, self.name)

			if repost_future_gle and cint(self.update_stock) \
				and cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
					items, warehouses = self.get_items_and_warehouses()
					update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items)
예제 #38
0
    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)
예제 #39
0
def make_gl_entries(doc, credit_account, debit_account, against,
	amount, base_amount, posting_date, project, account_currency, cost_center, voucher_detail_no):
	# GL Entry for crediting the amount in the deferred expense
	from erpnext.accounts.general_ledger import make_gl_entries

	gl_entries = []
	gl_entries.append(
		doc.get_gl_dict({
			"account": credit_account,
			"against": against,
			"credit": base_amount,
			"credit_in_account_currency": amount,
			"cost_center": cost_center,
			"voucher_detail_no": voucher_detail_no,
			'posting_date': posting_date,
			'project': project
		}, account_currency)
	)
	# GL Entry to debit the amount from the expense
	gl_entries.append(
		doc.get_gl_dict({
			"account": debit_account,
			"against": against,
			"debit": base_amount,
			"debit_in_account_currency": amount,
			"cost_center": cost_center,
			"voucher_detail_no": voucher_detail_no,
			'posting_date': posting_date,
			'project': project
		}, account_currency)
	)

	if gl_entries:
		try:
			make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True)
			frappe.db.commit()
		except:
			frappe.db.rollback()
			title = _("Error while processing deferred accounting for {0}").format(doc.name)
			traceback = frappe.get_traceback()
			frappe.log_error(message=traceback , title=title)
			sendmail_to_system_managers(title, traceback)
 def make_gl_entries(self, cancel=0, adv_adj=0):
     cost_center, write_off_account = frappe.db.get_value(
         "Microfinance Loan Settings", None,
         ["cost_center", "write_off_account"])
     gl_entries = [
         self.get_gl_dict({
             "account": self.loan_account,
             "credit": self.amount
         }),
         self.get_gl_dict({
             "account": write_off_account,
             "debit": self.amount,
             "cost_center": cost_center,
             "remarks": self.reason,
         }),
     ]
     make_gl_entries(gl_entries,
                     cancel=cancel,
                     adv_adj=adv_adj,
                     merge_entries=False)
예제 #41
0
	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 or self.flags.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)
예제 #42
0
    def make_interest(self, posting_date, amount, cancel=0, adv_adj=0):
        # does nothin reqd for FiscalYearError
        self.posting_date = posting_date

        periods = get_billing_periods(self.name, posting_date, 1)
        if len(periods) != 1:
            return None
        if amount:
            billing_period = periods[0].get('as_text')

            # check whether entries to recvble are already present
            owed_amount = self.get_owed(billing_period)
            if not amount - owed_amount > 0:
                return None
            gl_entries = [
                self.get_gl_dict({
                    'posting_date': posting_date,
                    'account': self.interest_receivable_account,
                    'debit': amount - owed_amount,
                    'party_type': 'Customer',
                    'party': self.customer,
                    'against': self.interest_income_account,
                    'period': billing_period,
                }),
                self.get_gl_dict({
                    'posting_date':
                    posting_date,
                    'account':
                    self.interest_income_account,
                    'credit':
                    amount - owed_amount,
                    'against':
                    self.customer,
                    'cost_center':
                    frappe.db.get_value('Loan Settings', None, 'cost_center'),
                    'remarks':
                    'Interest for period: {}'.format(
                        humanify_period(billing_period)),
                })
            ]
            make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)
	def on_submit(self):
		gl_map = []
		fiscal_years = get_fiscal_years(self.posting_date, company='RIGPL')
		if len(fiscal_years) > 1:
			frappe.throw(_("Multiple fiscal years exist for the date {0}. \
				Please set company in Fiscal Year").format(formatdate(self.posting_date)))
		else:
			fiscal_year = fiscal_years[0][0]
		
		for emp in self.employee_loan_detail:
			if emp.loan_amount:
				gl_dict = frappe._dict({
					'company': 'RIGPL',
					'posting_date' : self.posting_date,
					'fiscal_year': fiscal_year,
					'voucher_type': 'Employee Advance',
					'voucher_no': self.name,
					'account': self.debit_account,
					'debit': flt(emp.loan_amount),
					'debit_in_account_currency': flt(emp.loan_amount),
					'party_type': 'Employee',
					'party': emp.employee,
					'against': self.credit_account
				})
				gl_map.append(gl_dict)
		if gl_map:
			gl_dict = frappe._dict({
				'company': 'RIGPL',
				'posting_date' : self.posting_date,
				'fiscal_year': fiscal_year,
				'voucher_type': 'Employee Advance',
				'voucher_no': self.name,
				'account': self.credit_account,
				'debit': 0,
				'credit': flt(self.total_loan),
				'credit_in_account_currency' : flt(self.total_loan),
				'debit_in_account_currency': 0,
				'against': self.debit_account
			})
			gl_map.append(gl_dict)
			make_gl_entries(gl_map, cancel=0, adv_adj=0)
    def make_gl_entries(self,
                        gl_entries=None,
                        repost_future_gle=True,
                        from_repost=False):
        auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(
            self.company)

        if not self.grand_total:
            return

        if not gl_entries:
            gl_entries = self.get_gl_entries()

        if gl_entries:
            from erpnext.accounts.general_ledger import make_gl_entries

            # if POS and amount is written off, updating outstanding amt after posting all gl entries
            update_outstanding = "No" if (cint(self.is_pos)
                                          or self.write_off_account) else "Yes"

            make_gl_entries(gl_entries,
                            cancel=(self.docstatus == 2),
                            update_outstanding=update_outstanding,
                            merge_entries=False)

            if update_outstanding == "No":
                from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
                update_outstanding_amt(
                    self.debit_to, "Customer", self.customer, self.doctype,
                    self.return_against if cint(self.is_return) else self.name)

            if repost_future_gle and cint(self.update_stock) \
                and cint(auto_accounting_for_stock):
                items, warehouses = self.get_items_and_warehouses()
                update_gl_entries_after(self.posting_date, self.posting_time,
                                        warehouses, items)
        elif self.docstatus == 2 and cint(self.update_stock) \
            and cint(auto_accounting_for_stock):
            from erpnext.accounts.general_ledger import delete_gl_entries
            delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
예제 #45
0
	def make_gl_entries(self, repost_future_gle=True):
		if not self.grand_total:
			return
		
		self.auto_accounting_for_stock = \
			cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))

		self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
		self.expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
		self.negative_expense_to_be_booked = 0.0
		gl_entries = []


		self.make_supplier_gl_entry(gl_entries)
		self.make_item_gl_entries(gl_entries)
		self.make_tax_gl_entries(gl_entries)

		gl_entries = merge_similar_entries(gl_entries)

		self.make_payment_gl_entries(gl_entries)

		self.make_write_off_gl_entry(gl_entries)

		if gl_entries:
			update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"

			make_gl_entries(gl_entries,  cancel=(self.docstatus == 2),
				update_outstanding=update_outstanding, merge_entries=False)

			if update_outstanding == "No":
				update_outstanding_amt(self.credit_to, "Supplier", self.supplier,
					self.doctype, self.return_against if cint(self.is_return) else self.name)

			if repost_future_gle and cint(self.update_stock) and self.auto_accounting_for_stock:
				from erpnext.controllers.stock_controller import update_gl_entries_after
				items, warehouses = self.get_items_and_warehouses()
				update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items)

		elif self.docstatus == 2 and cint(self.update_stock) and self.auto_accounting_for_stock:
			delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
예제 #46
0
	def make_gl_entries(self, cancel=0, adv_adj=0):
		from erpnext.accounts.general_ledger import make_gl_entries

		gl_map = []
		for d in self.get("entries"):
			if d.debit or d.credit:
				gl_map.append(
					self.get_gl_dict({
						"account": d.account,
						"against": d.against_account,
						"debit": flt(d.debit, self.precision("debit", "entries")),
						"credit": flt(d.credit, self.precision("credit", "entries")),
						"against_voucher_type": ((d.against_voucher and "Purchase Invoice")
							or (d.against_invoice and "Sales Invoice")
							or (d.against_jv and "Journal Voucher")),
						"against_voucher": d.against_voucher or d.against_invoice or d.against_jv,
						"remarks": self.remark,
						"cost_center": d.cost_center
					})
				)
		if gl_map:
			make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
예제 #47
0
 def make_gl_entries(self, amount, posting_date=None, remarks=""):
     self.company = frappe.get_value("Microfinance Loan", self.loan, "company")
     if posting_date:
         self.posting_date = posting_date
     interest_income_account, loan_account = frappe.get_value(
         "Microfinance Loan", self.loan, ["interest_income_account", "loan_account"]
     )
     cost_center = frappe.db.get_value(
         "Microfinance Loan Settings", None, "cost_center"
     )
     gl_entries = [
         self.get_gl_dict({"account": loan_account, "debit": amount}),
         self.get_gl_dict(
             {
                 "account": interest_income_account,
                 "credit": amount,
                 "cost_center": cost_center,
                 "remarks": remarks,
             }
         ),
     ]
     make_gl_entries(gl_entries, merge_entries=False)
예제 #48
0
파일: fees.py 프로젝트: PawanMeh/erpnext
	def make_gl_entries(self):
		if not self.grand_total:
			return
		student_gl_entries =  self.get_gl_dict({
			"account": self.receivable_account,
			"party_type": "Student",
			"party": self.student,
			"against": self.income_account,
			"debit": self.grand_total,
			"debit_in_account_currency": self.grand_total,
			"against_voucher": self.name,
			"against_voucher_type": self.doctype
		})
		fee_gl_entry = self.get_gl_dict({
			"account": self.income_account,
			"against": self.student,
			"credit": self.grand_total,
			"credit_in_account_currency": self.grand_total,
			"cost_center": self.cost_center
		})
		from erpnext.accounts.general_ledger import make_gl_entries
		make_gl_entries([student_gl_entries, fee_gl_entry], cancel=(self.docstatus == 2),
			update_outstanding="Yes", merge_entries=False)
예제 #49
0
	def _book_deferred_revenue_or_expense(item):
		start_date, end_date, last_gl_entry = get_booking_dates(doc, item, posting_date=posting_date)
		if not (start_date and end_date): return

		account_currency = get_account_currency(item.expense_account)
		if doc.doctype == "Sales Invoice":
			against, project = doc.customer, doc.project
			credit_account, debit_account = item.income_account, item.deferred_revenue_account
		else:
			against, project = doc.supplier, item.project
			credit_account, debit_account = item.deferred_expense_account, item.expense_account

		total_days = date_diff(item.service_end_date, item.service_start_date) + 1
		total_booking_days = date_diff(end_date, start_date) + 1

		amount, base_amount = calculate_amount(doc, item, last_gl_entry,
			total_days, total_booking_days, account_currency)

		make_gl_entries(doc, credit_account, debit_account, against,
			amount, base_amount, end_date, project, account_currency, item.cost_center, item.name)

		if getdate(end_date) < getdate(posting_date) and not last_gl_entry:
			_book_deferred_revenue_or_expense(item)
예제 #50
0
	def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False):
		if not self.grand_total:
			return
		if not gl_entries:
			gl_entries = self.get_gl_entries()

		if gl_entries:
			update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"

			make_gl_entries(gl_entries,  cancel=(self.docstatus == 2),
				update_outstanding=update_outstanding, merge_entries=False)

			if update_outstanding == "No":
				update_outstanding_amt(self.credit_to, "Supplier", self.supplier,
					self.doctype, self.return_against if cint(self.is_return) else self.name)

			if repost_future_gle and cint(self.update_stock) and self.auto_accounting_for_stock:
				from erpnext.controllers.stock_controller import update_gl_entries_after
				items, warehouses = self.get_items_and_warehouses()
				update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items)

		elif self.docstatus == 2 and cint(self.update_stock) and self.auto_accounting_for_stock:
			delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
예제 #51
0
	def make_gl_entries(self, cancel=0, adv_adj=0):
		from erpnext.accounts.general_ledger import make_gl_entries

		gl_map = []
		for d in self.get("accounts"):
			if d.debit or d.credit:
				account_report_type = frappe.db.get_value("Account", d.account, "report_type")
				if account_report_type == "Profit and Loss":
					project_name=d.project_name
                    			support_ticket=d.support_ticket
                    		else:
                    			project_name=''
                    			support_ticket=''

				gl_map.append(
					self.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": self.remark,
						"cost_center": d.cost_center,
						"project_name": project_name,
						"support_ticket": support_ticket
					})
				)

		if gl_map:
			make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
예제 #52
0
	def make_gl_entries(self):
		auto_accounting_for_stock = \
			cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))

		stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
		expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")

		gl_entries = []

		# parent's gl entry
		if self.base_grand_total:
			gl_entries.append(
				self.get_gl_dict({
					"account": self.credit_to,
					"party_type": "Supplier",
					"party": self.supplier,
					"against": self.against_expense_account,
					"credit": self.total_amount_to_pay,
					"remarks": self.remarks,
					"against_voucher": self.name,
					"against_voucher_type": self.doctype,
				})
			)

		# tax table gl entries
		valuation_tax = {}
		for tax in self.get("taxes"):
			if tax.category in ("Total", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
				gl_entries.append(
					self.get_gl_dict({
						"account": tax.account_head,
						"against": self.credit_to,
						"debit": tax.add_deduct_tax == "Add" and tax.base_tax_amount_after_discount_amount or 0,
						"credit": tax.add_deduct_tax == "Deduct" and tax.base_tax_amount_after_discount_amount or 0,
						"remarks": self.remarks,
						"cost_center": tax.cost_center
					})
				)

			# accumulate valuation tax
			if self.is_opening == "No" and tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
				if auto_accounting_for_stock and not tax.cost_center:
					frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
				valuation_tax.setdefault(tax.cost_center, 0)
				valuation_tax[tax.cost_center] += \
					(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)

		# item gl entries
		negative_expense_to_be_booked = 0.0
		stock_items = self.get_stock_items()
		for item in self.get("items"):
			if flt(item.base_net_amount):
				gl_entries.append(
					self.get_gl_dict({
						"account": item.expense_account,
						"against": self.credit_to,
						"debit": item.base_net_amount,
						"remarks": self.remarks,
						"cost_center": item.cost_center
					})
				)

			if 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
					negative_expense_booked_in_pi = None
					if item.purchase_receipt:
						negative_expense_booked_in_pi = frappe.db.sql("""select name from `tabGL Entry`
							where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""",
							(item.purchase_receipt, expenses_included_in_valuation))

					if not negative_expense_booked_in_pi:
						gl_entries.append(
							self.get_gl_dict({
								"account": stock_received_but_not_billed,
								"against": self.credit_to,
								"debit": flt(item.item_tax_amount, self.precision("item_tax_amount", item)),
								"remarks": self.remarks or "Accounting Entry for Stock"
							})
						)

						negative_expense_to_be_booked += flt(item.item_tax_amount, self.precision("item_tax_amount", item))

		if self.is_opening == "No" and negative_expense_to_be_booked and valuation_tax:
			# credit valuation tax amount in "Expenses Included In Valuation"
			# this will balance out valuation amount included in cost of goods sold

			total_valuation_amount = sum(valuation_tax.values())
			amount_including_divisional_loss = negative_expense_to_be_booked
			i = 1
			for cost_center, amount in valuation_tax.items():
				if i == len(valuation_tax):
					applicable_amount = amount_including_divisional_loss
				else:
					applicable_amount = negative_expense_to_be_booked * (amount / total_valuation_amount)
					amount_including_divisional_loss -= applicable_amount

				gl_entries.append(
					self.get_gl_dict({
						"account": expenses_included_in_valuation,
						"cost_center": cost_center,
						"against": self.credit_to,
						"credit": applicable_amount,
						"remarks": self.remarks or "Accounting Entry for Stock"
					})
				)

				i += 1

		# writeoff account includes petty difference in the invoice amount
		# and the amount that is paid
		if self.write_off_account and flt(self.write_off_amount):
			gl_entries.append(
				self.get_gl_dict({
					"account": self.write_off_account,
					"against": self.credit_to,
					"credit": flt(self.write_off_amount),
					"remarks": self.remarks,
					"cost_center": self.write_off_cost_center
				})
			)

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries, cancel=(self.docstatus == 2))
	def make_gl(self, account_currency=None):
		from erpnext.accounts.general_ledger import make_gl_entries
		gl_map = []
		ds_settings = get_drop_ship_settings(self.company)

		ia = ds_settings["income_account"]
		ra = ds_settings["receivable_account"]
		pa = ds_settings["payable_account"]
		cc = ds_settings["cost_center"]
		gl_dict = frappe._dict({
			'company': self.company,
			'posting_date': self.posting_date,
			'voucher_type': self.doctype,
			'voucher_no': self.name,
			'remarks': self.get("remarks"),
			'fiscal_year': self.fiscal_year,
			'account': ia,
			'cost_center': cc,
			'debit': flt(0),
			'credit': flt(flt(self.total_commission) - flt(self.purchase_tax_total)), # if self.purchase_tax_total else flt(self.total_commission)
			'debit_in_account_currency': 0,
			'credit_in_account_currency': 0,
			'is_opening': "No", # or self.get("is_opening")
			'party_type': "Supplier",
			'party': self.supplier
		})
		if not account_currency:
			account_currency = get_account_currency(gl_dict.account)
		set_balance_in_account_currency(gl_dict, account_currency, self.conversion_rate, self.company_currency)
		gl_map.append(gl_dict)

		gl_dict = frappe._dict({
			'company': self.company,
			'posting_date': self.posting_date,
			'voucher_type': self.doctype,
			'voucher_no': self.name,
			'remarks': self.get("remarks"),
			'fiscal_year': self.fiscal_year,
			'account': ra,
			'debit': flt(self.total),
			'credit': flt(0),
			'debit_in_account_currency': 0,
			'credit_in_account_currency': 0,
			'is_opening': "No", # or self.get("is_opening")
			'party_type': "Customer",
			'party': self.customer
		})
		if not account_currency:
			account_currency = get_account_currency(gl_dict.account)
		set_balance_in_account_currency(gl_dict, account_currency, self.conversion_rate, self.company_currency)
		gl_map.append(gl_dict)

		gl_dict = frappe._dict({
			'company': self.company,
			'posting_date': self.posting_date,
			'voucher_type': self.doctype,
			'voucher_no': self.name,
			'remarks': self.get("remarks"),
			'fiscal_year': self.fiscal_year,
			'account': pa,
			'debit': flt(0),
			'credit': flt(flt(self.purchase_total)  + flt(self.purchase_tax_total)), # if self.purchase_tax_total else flt(self.purchase_total),
			'debit_in_account_currency': 0,
			'credit_in_account_currency': 0,
			'is_opening': "No", # or self.get("is_opening")
			'party_type': "Supplier",
			'party': self.supplier
		})
		if not account_currency:
			account_currency = get_account_currency(gl_dict.account)

		set_balance_in_account_currency(gl_dict, account_currency, self.conversion_rate, self.company_currency)
		gl_map.append(gl_dict)

		if gl_map:
			make_gl_entries(gl_map, cancel=0, adv_adj=0)
예제 #54
0
def post_gl_entry(doc):
	comp_doc = frappe.get_doc("Company", doc.company)
	gl_map = []
	fiscal_year = get_fy(doc)
	ec_ded = 0
	
	for earn in doc.earnings:
		earn_doc = frappe.get_doc("Salary Component", earn.salary_component)
		if earn.amount != 0 and earn.expense_claim is None and earn_doc.only_for_deductions != 1:
			#Condition for Earning Posting which is actually paid and not just for calculation
			gl_dict = frappe._dict({
				'company': doc.company,
				'posting_date' : doc.posting_date,
				'fiscal_year': fiscal_year,
				'voucher_type': 'Salary Slip',
				'voucher_no': doc.name,
				'account': earn_doc.account,
				'cost_center': comp_doc.cost_center,
				'debit': flt(earn.amount),
				'debit_in_account_currency': flt(earn.amount),
				'against': comp_doc.default_payroll_payable_account
			})
			gl_map.append(gl_dict)
		elif earn.expense_claim and earn.amount > 0:
			ec_gl_map = []
			ec_ded += earn.amount
			#Check if the expense claim is already posted if not then post the expense claim
			#separately
			ec_posted = frappe.db.sql("""SELECT name FROM `tabGL Entry` WHERE docstatus =1 AND
				voucher_type = 'Expense Claim' AND voucher_no = '%s'
				"""%(earn.expense_claim), as_list=1)
			if not ec_posted:
				
				#Post the Expense Claim Separately.	
				ec_doc = frappe.get_doc("Expense Claim", earn.expense_claim)
				for exp in ec_doc.expenses:
					ecfy = get_fy(ec_doc)
					ec_gl_dict = frappe._dict({
						'company': ec_doc.company,
						'posting_date' : ec_doc.posting_date,
						'fiscal_year': ecfy,
						'voucher_type': 'Expense Claim',
						'voucher_no': ec_doc.name,
						'account': exp.default_account,
						'cost_center': comp_doc.cost_center,
						'debit': flt(exp.sanctioned_amount),
						'debit_in_account_currency': flt(exp.sanctioned_amount),
						'against': ec_doc.employee
					})
					ec_gl_map.append(ec_gl_dict)
				ec_gl_dict = frappe._dict({
					'company': ec_doc.company,
					'posting_date' : ec_doc.posting_date,
					'fiscal_year': ecfy,
					'voucher_type': 'Expense Claim',
					'voucher_no': ec_doc.name,
					'account': (ec_doc.payable_account or comp_doc.default_payroll_payable_account),
					'cost_center': (ec_doc.cost_center or comp_doc.cost_center),
					'party_type': 'Employee',
					'party': ec_doc.employee,
					'credit': flt(ec_doc.total_sanctioned_amount),
					'credit_in_account_currency': flt(ec_doc.total_sanctioned_amount)
				})
				ec_gl_map.append(ec_gl_dict)
				make_gl_entries(ec_gl_map, cancel=0, adv_adj=0)
				frappe.msgprint(("Posted Expense Claim # {0}").format(earn.expense_claim))
				
	for ded in doc.deductions:
		ded_doc = frappe.get_doc("Salary Component", ded.salary_component)
		if flt(ded.amount) > 0 and ded.employee_loan is None:
			gl_dict = frappe._dict({
				'company': doc.company,
				'posting_date' : doc.posting_date,
				'fiscal_year': fiscal_year,
				'voucher_type': 'Salary Slip',
				'voucher_no': doc.name,
				'account': ded_doc.account,
				'credit': flt(ded.amount),
				'credit_in_account_currency': flt(ded.amount),
				'against': comp_doc.default_payroll_payable_account
			})
			gl_map.append(gl_dict)
		elif flt(ded.amount) > 0 and ded.employee_loan is not None:
			gl_dict = frappe._dict({
				'company': doc.company,
				'posting_date' : doc.posting_date,
				'fiscal_year': fiscal_year,
				'voucher_type': 'Salary Slip',
				'voucher_no': doc.name,
				'account': ded_doc.account,
				'credit': flt(ded.amount),
				'credit_in_account_currency': flt(ded.amount),
				'party_type': 'Employee',
				'party': doc.employee,
				'against': ded.employee_loan
			})
			gl_map.append(gl_dict)
	if gl_map:	
		gl_dict = frappe._dict({
			'company': doc.company,
			'posting_date' : doc.posting_date,
			'fiscal_year': fiscal_year,
			'voucher_type': 'Salary Slip',
			'voucher_no': doc.name,
			'account': comp_doc.default_payroll_payable_account,
			'credit': flt(doc.rounded_total - ec_ded),
			'credit_in_account_currency': flt(doc.rounded_total - ec_ded),
			'party_type': 'Employee',
			'party': doc.employee,
			'against': comp_doc.default_payroll_payable_account
		})
		gl_map.append(gl_dict)
		gl_dict = frappe._dict({
			'company': doc.company,
			'posting_date' : doc.posting_date,
			'fiscal_year': fiscal_year,
			'voucher_type': 'Salary Slip',
			'voucher_no': doc.name,
			'account': comp_doc.round_off_account,
			'cost_center': comp_doc.round_off_cost_center,
			'debit': flt(doc.rounded_total - doc.net_pay),
			'debit_in_account_currency': flt(doc.rounded_total - doc.net_pay),
			'against': comp_doc.default_payroll_payable_account
		})
		gl_map.append(gl_dict)
			
	for cont in doc.contributions:
		if cont.amount > 0:
			cont_doc = frappe.get_doc("Salary Component", cont.salary_component)
			gl_dict = frappe._dict({
				'company': doc.company,
				'posting_date' : doc.posting_date,
				'fiscal_year': fiscal_year,
				'voucher_type': 'Salary Slip',
				'voucher_no': doc.name,
				'account': cont_doc.account,
				'cost_center': comp_doc.cost_center,
				'debit': flt(cont.amount),
				'debit_in_account_currency': flt(cont.amount),
				'against': cont_doc.liability_account
			})
			gl_map.append(gl_dict)
			gl_dict = frappe._dict({
				'company': doc.company,
				'posting_date' : doc.posting_date,
				'fiscal_year': fiscal_year,
				'voucher_type': 'Salary Slip',
				'voucher_no': doc.name,
				'account': cont_doc.liability_account,
				'credit': flt(cont.amount),
				'credit_in_account_currency': flt(cont.amount),
				'against': cont_doc.account
			})
			gl_map.append(gl_dict)
	make_gl_entries(gl_map, cancel=0, adv_adj=0)
def execute():
	'''
	This patch is to cancel the JV associated with Employee Loan and Employee Advance and
	then repost the Employee Advance in GL Entry
	'''
	gl_adv_list = frappe.db.sql("""SELECT name, voucher_no, against_voucher FROM `tabGL Entry` 
		WHERE docstatus = 1 AND (against_voucher_type = 'Employee Loan' OR 
		against_voucher_type = 'Employee Advance') AND voucher_type = 'Journal Entry'
		GROUP BY voucher_no""", as_list=1)
		
	for jv in gl_adv_list:
		jv_doc = frappe.get_doc("Journal Entry", jv[1])
		jv_doc.cancel()
		print ("Journal Entry #" + jv[1] + " Cancelled.")
		
		#Check and post the employee advance directly into the GL
		from erpnext.accounts.general_ledger import make_gl_entries
		from erpnext.accounts.utils import get_fiscal_years, validate_fiscal_year, get_account_currency
		
		#Check if emp_adv_doc already posted into the GL or NOT
		gl_entry_adv = frappe.db.sql("""SELECT name FROM `tabGL Entry` WHERE
			docstatus = 1 AND voucher_type = 'Employee Advance' 
			AND voucher_no = '%s'""" % (jv[2]), as_list=1)
			
		if gl_entry_adv:
			pass
			#donot post gl if already exists
		else:		
			emp_adv_doc = frappe.get_doc("Employee Advance", jv[2])
			gl_map = []
		
			fiscal_years = get_fiscal_years(emp_adv_doc.posting_date, company='RIGPL')
			if len(fiscal_years) > 1:
				frappe.throw(_("Multiple fiscal years exist for the date {0}. \
					Please set company in Fiscal Year").format(formatdate(self.posting_date)))
			else:
				fiscal_year = fiscal_years[0][0]
		
			for emp in emp_adv_doc.employee_loan_detail:
				if emp.loan_amount:
					gl_dict = frappe._dict({
						'company': 'RIGPL',
						'posting_date' : emp_adv_doc.posting_date,
						'fiscal_year': fiscal_year,
						'voucher_type': 'Employee Advance',
						'voucher_no': emp_adv_doc.name,
						'account': emp_adv_doc.debit_account,
						'debit': flt(emp.loan_amount),
						'debit_in_account_currency': flt(emp.loan_amount),
						'party_type': 'Employee',
						'party': emp.employee,
						'against': emp_adv_doc.credit_account
					})
					gl_map.append(gl_dict)
			if gl_map:
				gl_dict = frappe._dict({
					'company': 'RIGPL',
					'posting_date' : emp_adv_doc.posting_date,
					'fiscal_year': fiscal_year,
					'voucher_type': 'Employee Advance',
					'voucher_no': emp_adv_doc.name,
					'account': emp_adv_doc.credit_account,
					'debit': 0,
					'credit': flt(emp_adv_doc.total_loan),
					'credit_in_account_currency' : flt(emp_adv_doc.total_loan),
					'debit_in_account_currency': 0,
					'against': emp_adv_doc.debit_account
				})
				gl_map.append(gl_dict)
				make_gl_entries(gl_map, cancel=0, adv_adj=0)
				print ("Employee Advance #" + emp_adv_doc.name + " Posted to GL Entry")
예제 #56
0
	def make_gl_entries(self, cancel = False):
		if flt(self.total_sanctioned_amount) > 0:
			gl_entries = self.get_gl_entries()
			make_gl_entries(gl_entries, cancel)
예제 #57
0
	def make_gl_entries(self):
		auto_accounting_for_stock = \
			cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))

		gl_entries = []

		# parent's gl entry
		if self.grand_total:
			gl_entries.append(
				self.get_gl_dict({
					"account": self.credit_to,
					"against": self.against_expense_account,
					"credit": self.total_amount_to_pay,
					"remarks": self.remarks,
					"against_voucher": self.name,
					"against_voucher_type": self.doctype,
				})
			)

		# tax table gl entries
		valuation_tax = {}
		for tax in self.get("other_charges"):
			if tax.category in ("Total", "Valuation and Total") and flt(tax.tax_amount):
				gl_entries.append(
					self.get_gl_dict({
						"account": tax.account_head,
						"against": self.credit_to,
						"debit": tax.add_deduct_tax == "Add" and tax.tax_amount or 0,
						"credit": tax.add_deduct_tax == "Deduct" and tax.tax_amount or 0,
						"remarks": self.remarks,
						"cost_center": tax.cost_center
					})
				)

			# accumulate valuation tax
			if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount):
				if auto_accounting_for_stock and not tax.cost_center:
					frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
				valuation_tax.setdefault(tax.cost_center, 0)
				valuation_tax[tax.cost_center] += \
					(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)

		# item gl entries
		stock_item_and_auto_accounting_for_stock = False
		stock_items = self.get_stock_items()
		for item in self.get("entries"):
			if auto_accounting_for_stock and item.item_code in stock_items:
				if flt(item.valuation_rate):
					# if auto inventory accounting enabled and stock item,
					# then do stock related gl entries
					# expense will be booked in sales invoice
					stock_item_and_auto_accounting_for_stock = True

					valuation_amt = flt(item.base_amount + item.item_tax_amount,
						self.precision("base_amount", item))

					gl_entries.append(
						self.get_gl_dict({
							"account": item.expense_account,
							"against": self.credit_to,
							"debit": valuation_amt,
							"remarks": self.remarks or "Accounting Entry for Stock"
						})
					)

			elif flt(item.base_amount):
				# if not a stock item or auto inventory accounting disabled, book the expense
				gl_entries.append(
					self.get_gl_dict({
						"account": item.expense_account,
						"against": self.credit_to,
						"debit": item.base_amount,
						"remarks": self.remarks,
						"cost_center": item.cost_center
					})
				)

		if stock_item_and_auto_accounting_for_stock and valuation_tax:
			# credit valuation tax amount in "Expenses Included In Valuation"
			# this will balance out valuation amount included in cost of goods sold
			expenses_included_in_valuation = \
				self.get_company_default("expenses_included_in_valuation")

			for cost_center, amount in valuation_tax.items():
				gl_entries.append(
					self.get_gl_dict({
						"account": expenses_included_in_valuation,
						"cost_center": cost_center,
						"against": self.credit_to,
						"credit": amount,
						"remarks": self.remarks or "Accounting Entry for Stock"
					})
				)

		# writeoff account includes petty difference in the invoice amount
		# and the amount that is paid
		if self.write_off_account and flt(self.write_off_amount):
			gl_entries.append(
				self.get_gl_dict({
					"account": self.write_off_account,
					"against": self.credit_to,
					"credit": flt(self.write_off_amount),
					"remarks": self.remarks,
					"cost_center": self.write_off_cost_center
				})
			)

		if gl_entries:
			from erpnext.accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries, cancel=(self.docstatus == 2))