def delete_gl_entries(gl_entries=None,
                      voucher_type=None,
                      voucher_no=None,
                      adv_adj=False,
                      update_outstanding="Yes"):

    from accounts.doctype.gl_entry.gl_entry import check_negative_balance, \
     check_freezing_date, update_outstanding_amt, validate_frozen_account

    if not gl_entries:
        gl_entries = webnotes.conn.sql("""select * from `tabGL Entry` 
			where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no),
                                       as_dict=True)
    if gl_entries:
        check_freezing_date(gl_entries[0]["posting_date"], adv_adj)

    webnotes.conn.sql(
        """delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""",
        (voucher_type or gl_entries[0]["voucher_type"], voucher_no
         or gl_entries[0]["voucher_no"]))

    for entry in gl_entries:
        validate_frozen_account(entry["account"], adv_adj)
        check_negative_balance(entry["account"], adv_adj)
        validate_expense_against_budget(entry)

        if entry.get("against_voucher") and entry.get("against_voucher_type") != "POS" \
         and update_outstanding == 'Yes':
            update_outstanding_amt(entry["account"],
                                   entry.get("against_voucher_type"),
                                   entry.get("against_voucher"),
                                   on_cancel=True)
Exemple #2
0
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None, adv_adj=False, update_outstanding="Yes"):

    from accounts.doctype.gl_entry.gl_entry import (
        check_negative_balance,
        check_freezing_date,
        update_outstanding_amt,
        validate_frozen_account,
    )

    if not gl_entries:
        gl_entries = webnotes.conn.sql(
            """select * from `tabGL Entry` 
			where voucher_type=%s and voucher_no=%s""",
            (voucher_type, voucher_no),
            as_dict=True,
        )
    if gl_entries:
        check_freezing_date(gl_entries[0]["posting_date"], adv_adj)

    webnotes.conn.sql(
        """delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s""",
        (voucher_type or gl_entries[0]["voucher_type"], voucher_no or gl_entries[0]["voucher_no"]),
    )

    for entry in gl_entries:
        validate_frozen_account(entry["account"], adv_adj)
        check_negative_balance(entry["account"], adv_adj)
        validate_expense_against_budget(entry)

        if entry.get("against_voucher") and entry.get("against_voucher_type") != "POS" and update_outstanding == "Yes":
            update_outstanding_amt(
                entry["account"], entry.get("against_voucher_type"), entry.get("against_voucher"), on_cancel=True
            )
Exemple #3
0
    def make_gl_entries(self, repost_future_gle=True):
        gl_entries = self.get_gl_entries()

        if gl_entries:
            from 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_outstanding == "No":
                from accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
                update_outstanding_amt(self.doc.debit_to, self.doc.doctype,
                                       self.doc.name)

            if repost_future_gle and cint(self.doc.update_stock) \
             and cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
                items, warehouse_account = self.get_items_and_warehouse_accounts(
                )
                from controllers.stock_controller import update_gl_entries_after
                update_gl_entries_after(self.doc.posting_date,
                                        self.doc.posting_time,
                                        warehouse_account, items)
Exemple #4
0
	def make_gl_entries(self, repost_future_gle=True):
		gl_entries = self.get_gl_entries()

		if gl_entries:
			from 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_outstanding == "No":
				from accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
				update_outstanding_amt(self.doc.debit_to, self.doc.doctype, self.doc.name)

			if repost_future_gle and cint(self.doc.update_stock) \
				and cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
					items, warehouse_account = self.get_items_and_warehouse_accounts()
					from controllers.stock_controller import update_gl_entries_after
					update_gl_entries_after(self.doc.posting_date, self.doc.posting_time,
						warehouse_account, items)