Example #1
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:
			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)
Example #2
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)
Example #3
0
def delete_gl_entries(gl_entries=None,
                      voucher_type=None,
                      voucher_no=None,
                      adv_adj=False,
                      update_outstanding="Yes"):

    from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \
     check_freezing_date, update_outstanding_amt, validate_frozen_account

    if not gl_entries:
        gl_entries = frappe.db.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)

    frappe.db.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)
        validate_balance_type(entry["account"], adv_adj)
        validate_expense_against_budget(entry)

        if entry.get("against_voucher") and update_outstanding == 'Yes':
            update_outstanding_amt(entry["account"],
                                   entry.get("party_type"),
                                   entry.get("party"),
                                   entry.get("against_voucher_type"),
                                   entry.get("against_voucher"),
                                   on_cancel=True)
    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)
Example #5
0
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None,
		adv_adj=False, update_outstanding="Yes"):

	from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \
		check_freezing_date, update_outstanding_amt, validate_frozen_account

	if not gl_entries:
		gl_entries = frappe.db.sql("""
			select account, posting_date, party_type, party, cost_center, fiscal_year,
			voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center
			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)

	frappe.db.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)
		validate_balance_type(entry["account"], adv_adj)
		
		if entry.get("against_voucher") and update_outstanding == 'Yes':
			update_outstanding_amt(entry["account"], entry.get("party_type"), entry.get("party"), entry.get("against_voucher_type"),
				entry.get("against_voucher"), on_cancel=True)
	
		#reset the committed budget too
		acc_type = frappe.db.get_value("Account", entry["account"], "account_type")
		if acc_type == "Expense Account" or acc_type == "Fixed Asset":
			frappe.db.sql("delete from `tabCommitted Budget` where po_no = %s", entry["voucher_no"])
			frappe.db.sql("delete from `tabConsumed Budget` where po_no = %s", entry["voucher_no"])
Example #6
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)
def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
    if not from_repost:
        validate_account_for_perpetual_inventory(gl_map)

    round_off_debit_credit(gl_map)

    vouchers_for_balance_update = set()
    for entry in gl_map:
        make_entry(entry, adv_adj, from_repost)

        # check against budget
        if not from_repost:
            validate_expense_against_budget(entry)

        if update_outstanding and not from_repost and entry.get(
                "party_type") and entry.get("party"):
            if entry.get("against_voucher_type") and entry.get(
                    "against_voucher"):
                vouchers_for_balance_update.add(
                    (entry.get("against_voucher_type"),
                     entry.get("against_voucher"), entry.get("account"),
                     entry.get("party_type"), entry.get("party")))
            else:
                vouchers_for_balance_update.add(
                    (entry.get("voucher_type"), entry.get("voucher_no"),
                     entry.get("account"), entry.get("party_type"),
                     entry.get("party")))

    from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
    for voucher_type, voucher_no, account, party_type, party in vouchers_for_balance_update:
        update_outstanding_amt(voucher_type, voucher_no, account, party_type,
                               party)
Example #8
0
def delete_gl_entries(gl_entries=None, voucher_type=None, voucher_no=None,
		adv_adj=False, update_outstanding="Yes"):

	from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \
		check_freezing_date, update_outstanding_amt, validate_frozen_account

	if not gl_entries:
		gl_entries = frappe.db.sql("""
			select account, posting_date, party_type, party, cost_center, fiscal_year,voucher_type,
			voucher_no, against_voucher_type, against_voucher, cost_center, company
			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)

	frappe.db.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)
		validate_balance_type(entry["account"], adv_adj)
		validate_expense_against_budget(entry)
		
		if entry.get("against_voucher") and update_outstanding == 'Yes':
			update_outstanding_amt(entry["account"], entry.get("party_type"), entry.get("party"), entry.get("against_voucher_type"),
				entry.get("against_voucher"), on_cancel=True)
Example #9
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)
Example #10
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)
def execute():
	for dt, party_field, account_field in (("Sales Invoice", "customer", "debit_to"), 
			("Purchase Invoice", "supplier", "credit_to")):
			
		wrong_invoices = frappe.db.sql("""select name, {0} as account from `tab{1}` 
			where docstatus=1 and ifnull({2}, '')=''""".format(account_field, dt, party_field))
			
		for invoice, account in wrong_invoices:
			update_outstanding_amt(account, party_field.title(), None, dt, invoice)
Example #12
0
def execute():
    frappe.reload_doctype("Sales Invoice")
    return_entries = frappe.get_list(
        "Sales Invoice",
        filters={
            "is_return": 1,
            "docstatus": 1
        },
        fields=["debit_to", "customer", "return_against"])
    for d in return_entries:
        update_outstanding_amt(d.debit_to, "Customer", d.customer,
                               "Sales Invoice", d.return_against)
def delete_gl_entries(gl_entries=None,
                      voucher_type=None,
                      voucher_no=None,
                      adv_adj=False,
                      update_outstanding="Yes"):

    from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \
     check_freezing_date, update_outstanding_amt, validate_frozen_account

    if not gl_entries:
        gl_entries = frappe.db.sql("""
			select account, posting_date, party_type, party, cost_center, fiscal_year,voucher_type,
			voucher_no, against_voucher_type, against_voucher, cost_center, company
			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)

    frappe.db.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"]))

    vouchers_for_balance_update = set()
    for entry in gl_entries:
        validate_frozen_account(entry["account"], adv_adj)
        validate_balance_type(entry["account"], adv_adj)
        if not adv_adj:
            validate_expense_against_budget(entry)

        if update_outstanding and not adv_adj and entry.get(
                "party_type") and entry.get("party"):
            if entry.get("against_voucher_type") and entry.get(
                    "against_voucher"):
                vouchers_for_balance_update.add(
                    (entry.get("against_voucher_type"),
                     entry.get("against_voucher"), entry.get("account"),
                     entry.get("party_type"), entry.get("party")))
            else:
                vouchers_for_balance_update.add(
                    (entry.get("voucher_type"), entry.get("voucher_no"),
                     entry.get("account"), entry.get("party_type"),
                     entry.get("party")))

    for voucher_type, voucher_no, account, party_type, party in vouchers_for_balance_update:
        update_outstanding_amt(voucher_type,
                               voucher_no,
                               account,
                               party_type,
                               party,
                               on_cancel=True)
def execute():
    for dt, party_field, account_field in (("Sales Invoice", "customer",
                                            "debit_to"),
                                           ("Purchase Invoice", "supplier",
                                            "credit_to")):

        wrong_invoices = frappe.db.sql(
            """select name, {0} as account from `tab{1}` 
			where docstatus=1 and ifnull({2}, '')=''""".format(account_field, dt,
                                                      party_field))

        for invoice, account in wrong_invoices:
            update_outstanding_amt(account, party_field.title(), None, dt,
                                   invoice)
Example #15
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)
Example #16
0
def delete_gl_entries(gl_entries=None,
                      voucher_type=None,
                      voucher_no=None,
                      adv_adj=False,
                      update_outstanding="Yes"):

    from erpnext.accounts.doctype.gl_entry.gl_entry import validate_balance_type, \
     check_freezing_date, update_outstanding_amt, validate_frozen_account

    if not gl_entries:
        gl_entries = frappe.db.sql("""
			select account, posting_date, party_type, party, cost_center, fiscal_year,
			voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center
			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)

    frappe.db.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)
        validate_balance_type(entry["account"], adv_adj)

        if entry.get("against_voucher") and update_outstanding == 'Yes':
            update_outstanding_amt(entry["account"],
                                   entry.get("party_type"),
                                   entry.get("party"),
                                   entry.get("against_voucher_type"),
                                   entry.get("against_voucher"),
                                   on_cancel=True)

        #reset the committed budget too
        acc_type = frappe.db.get_value("Account", entry["account"],
                                       "account_type")
        if acc_type == "Expense Account" or acc_type == "Fixed Asset":
            frappe.db.sql("delete from `tabCommitted Budget` where po_no = %s",
                          entry["voucher_no"])
            frappe.db.sql("delete from `tabConsumed Budget` where po_no = %s",
                          entry["voucher_no"])
Example #17
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)
Example #18
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)
Example #19
0
def make_gl_entries_sales_invoice(doc, method):
    self = doc
    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:

        # 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_gl2_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) and self.return_against 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):
        delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
Example #20
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 purchase_invoice_on_update_after_submit(doc, method):
    doc.validate()
    frappe.db.sql("""delete from `tabGL Entry` where voucher_no=%(vname)s""", {
            'vname': doc.name })
    doc.update_valuation_rate("items")
    doc.update_children()
    doc.db_update()

    if cint(doc.update_stock):
        for i in doc.items:
            update_incoming_rate_serial_no(get_serial_nos(i.serial_no), i.valuation_rate)

        frappe.db.sql("""delete from `tabStock Ledger Entry` where voucher_no=%(vname)s""", {
            'vname': doc.name })

        #raw_input("Press Enter to continue...")
        doc.update_stock_ledger()

    doc.make_gl_entries(repost_future_gle=False)

    if cint(doc.update_stock):
        for i in doc.items:
            update_entries_after({
					"item_code": i.item_code, 
					"warehouse": i.warehouse,
                    "posting_time": doc.posting_time,
					"posting_date": doc.posting_date #get_fiscal_year(today())[1]
				}, allow_zero_rate=True)

    if cint(doc.update_stock):
        for i in doc.items:
            repost_se(i.item_code)
            repost_si(i.item_code)
            repost_dn(i.item_code)

    update_outstanding_amt(doc.credit_to, "Supplier", doc.supplier,doc.doctype, doc.name)

    frappe.db.commit()
Example #22
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)
def execute():
	frappe.reload_doctype("Sales Invoice")
	return_entries = frappe.get_list("Sales Invoice", filters={"is_return": 1, "docstatus": 1}, 
		fields=["debit_to", "customer", "return_against"])
	for d in return_entries:
		update_outstanding_amt(d.debit_to, "Customer", d.customer, "Sales Invoice", d.return_against)