Beispiel #1
0
	def get_gl_entries(self, warehouse_account=None):
		from erpnext.accounts.general_ledger import merge_similar_entries

		gl_entries = []
		print ("custom GL Entries ")
		self.make_customer_gl_entry(gl_entries)
		print ("custom GL Entries ",gl_entries)

		print ("TAX GL Entries ")		
		self.make_tax_gl_entries(gl_entries)
		print ("TAX GL Entries ",gl_entries)

		print ("ITEM GL Entries ")
		self.make_item_gl_entries(gl_entries)
		print ("ITEM GL Entries ",gl_entries)

		# merge gl entries before adding pos entries
		gl_entries = merge_similar_entries(gl_entries)
		print ("MERGED GL Entries ",gl_entries)

		print ("POS GL Entries ")
		self.make_pos_gl_entries(gl_entries)
		print ("POS GL Entries ",gl_entries)

#pensa		self.make_gle_for_change_amount(gl_entries)

#pensa		self.make_write_off_gl_entry(gl_entries)

		return gl_entries
Beispiel #2
0
	def get_gl_entries(self, warehouse_account=None):
		self.auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company)
		if self.auto_accounting_for_stock:
			self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
		else:
			self.stock_received_but_not_billed = None
		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)

		if self.check_asset_cwip_enabled():
			self.get_asset_gl_entry(gl_entries)

		self.make_tax_gl_entries(gl_entries)

		gl_entries = make_regional_gl_entries(gl_entries, self)

		gl_entries = merge_similar_entries(gl_entries)

		self.make_payment_gl_entries(gl_entries)
		self.make_write_off_gl_entry(gl_entries)
		self.make_gle_for_rounding_adjustment(gl_entries)

		return gl_entries
    def get_gl_entries(self, warehouse_account=None):
        from erpnext.accounts.general_ledger import merge_similar_entries

        gl_entries = []

        self.make_customer_gl_entry(gl_entries)

        self.make_tax_gl_entries(gl_entries)

        self.make_item_gl_entries(gl_entries)

        # merge gl entries before adding pos entries
        gl_entries = merge_similar_entries(gl_entries)

        self.make_pos_gl_entries(gl_entries)

        self.make_gle_for_change_amount(gl_entries)

        self.make_write_off_gl_entry(gl_entries)

        # process for return
        for gl in gl_entries:
            if gl.debit:
                gl.debit *= -1
                gl.debit_in_account_currency *= -1
            elif gl.credit:
                gl.credit *= -1
                gl.credit_in_account_currency *= -1

        return gl_entries
Beispiel #4
0
	def get_gl_entries(self, warehouse_account=None):
		from erpnext.accounts.general_ledger import merge_similar_entries

		gl_entries = []

		self.make_customer_gl_entry(gl_entries)
		frappe.errprint(["make_customer_gl_entry", gl_entries])

		self.make_tax_gl_entries(gl_entries)
		frappe.errprint(["make_tax_gl_entries", gl_entries])

		self.make_item_gl_entries(gl_entries)
		frappe.errprint(["make_item_gl_entries", gl_entries])

		# merge gl entries before adding pos entries
		gl_entries = merge_similar_entries(gl_entries)
		frappe.errprint(["merge_similar_entries", gl_entries])
	
		self.make_pos_gl_entries(gl_entries)
		frappe.errprint(["make_pos_gl_entries", gl_entries])

		self.make_write_off_gl_entry(gl_entries)
		frappe.errprint(["make_write_off_gl_entry", gl_entries])

		return gl_entries
    def get_gl_entries(self, warehouse_account=None):
        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)

        print(gl_entries)
        gl_entries = merge_similar_entries(gl_entries)

        self.make_payment_gl_entries(gl_entries)
        self.make_write_off_gl_entry(gl_entries)

        # process for return
        for gl in gl_entries:
            if gl.debit:
                gl.debit *= -1
                gl.debit_in_account_currency *= -1
            elif gl.credit:
                gl.credit *= -1
                gl.credit_in_account_currency *= -1

        return gl_entries
Beispiel #6
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)
Beispiel #7
0
    def get_gl_entries(self, warehouse_account=None):
        from erpnext.accounts.general_ledger import merge_similar_entries

        gl_entries = []

        self.make_customer_gl_entry(gl_entries)

        self.make_tax_gl_entries(gl_entries)

        self.make_item_gl_entries(gl_entries)

        # merge gl entries before adding pos entries
        gl_entries = merge_similar_entries(gl_entries)

        self.make_pos_gl_entries(gl_entries)

        return gl_entries
Beispiel #8
0
	def get_gl_entries(self, warehouse_account=None):
		from erpnext.accounts.general_ledger import merge_similar_entries

		gl_entries = []

		self.make_customer_gl_entry(gl_entries)

		self.make_tax_gl_entries(gl_entries)

		self.make_item_gl_entries(gl_entries)

		# merge gl entries before adding pos entries
		gl_entries = merge_similar_entries(gl_entries)

		self.make_pos_gl_entries(gl_entries)

		return gl_entries
	def get_gl_entries(self, warehouse_account=None):
		self.auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company)
		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)

		return gl_entries
Beispiel #10
0
	def get_gl_entries(self, warehouse_account=None):
		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)

		return gl_entries
Beispiel #11
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 validate_with_delivery_note(self):
    # We are only doing this:
    # Make SLEs for changed qtys
    # Make the GL wrt abv
    # make_sl_entries & make_gl_entries handles cancellation

    # not stable
    return
    if self.update_stock == 1:
        # do nothing if updating stock
        return
    sl_entries = []
    changed_rows = []
    # everything wrt stock_qty
    for d in [
            x for x in self.items
            if x.validate_with_delivery_note and x.warehouse
    ]:
        if frappe.db.get_value("Item", d.item_code,
                               "is_stock_item") == 1 and flt(d.stock_qty):
            delivered_qty = 0
            if d.dn_detail:
                delivered_qty = frappe.get_value("Delivery Note Item",
                                                 d.dn_detail, "stock_qty")
            qty_change = d.stock_qty - delivered_qty
            # qty_change
            # -ve	: got return
            # +ve	: gave more
            # 0		: continue
            if qty_change == 0:
                continue

            # return rate- code copied from selling_controller.py
            return_rate = 0
            if cint(self.is_return
                    ) and self.return_against and self.docstatus == 1:
                return_rate = self.get_incoming_rate_for_sales_return(
                    d.item_code, self.return_against)

            sl_entries.append(
                self.get_sl_entries(
                    d, {
                        "actual_qty": -1 * flt(qty_change),
                        "incoming_rate": return_rate,
                        "parent": "consoleerp-{}".format(self.name)
                    }))
            changed_rows.append(d)
    self.make_sl_entries(sl_entries)
    # above method inserts the SLEs
    # stock_value_difference is made only after the above method

    # STOCK GL ENTRIES
    # Proceed if perpetual inventory is enabled
    import erpnext
    if not erpnext.is_perpetual_inventory_enabled(self.company):
        return

    #--- get stock ledger entries just made
    from erpnext.stock import get_warehouse_account_map
    warehouse_account = get_warehouse_account_map()
    sle_map = {}
    stock_ledger_entries = frappe.db.sql("""
		select
			name, warehouse, stock_value_difference, valuation_rate,
			voucher_detail_no, item_code, posting_date, posting_time,
			actual_qty, qty_after_transaction
		from
			`tabStock Ledger Entry`
		where
			voucher_type=%s and voucher_no=%s and parent=%s
	""", (self.doctype, self.name, "consoleerp-{}".format(self.name)),
                                         as_dict=True)

    for sle in stock_ledger_entries:
        sle_map.setdefault(sle.voucher_detail_no, []).append(sle)

    warehouse_with_no_account = []
    gl_list = []

    # loop it again
    # stock_controller.get_gl_entries()
    for item_row in changed_rows:
        sle_list = sle_map.get(item_row.name)
        if sle_list:
            for sle in sle_list:
                if warehouse_account.get(sle.warehouse):
                    # from warehouse account

                    self.check_expense_account(item_row)

                    # If the item does not have the allow zero valuation rate flag set
                    # and ( valuation rate not mentioned in an incoming entry
                    # or incoming entry not found while delivering the item),
                    # try to pick valuation rate from previous sle or Item master and update in SLE
                    # Otherwise, throw an exception

                    if not sle.stock_value_difference and self.doctype != "Stock Reconciliation" \
                     and not item_row.get("allow_zero_valuation_rate"):

                        sle = self.update_stock_ledger_entries(sle)

                    gl_list.append(
                        self.get_gl_dict(
                            {
                                "account":
                                warehouse_account[sle.warehouse]["account"],
                                "against":
                                item_row.expense_account,
                                "cost_center":
                                item_row.cost_center,
                                "remarks":
                                "Delivery Note Validation Entry",
                                "debit":
                                flt(sle.stock_value_difference, 2),
                            }, warehouse_account[sle.warehouse]
                            ["account_currency"]))

                    # to target warehouse / expense account
                    gl_list.append(
                        self.get_gl_dict({
                            "account":
                            item_row.expense_account,
                            "against":
                            warehouse_account[sle.warehouse]["account"],
                            "cost_center":
                            item_row.cost_center,
                            "remarks":
                            "Delivery Note Validation Entry",
                            "credit":
                            flt(sle.stock_value_difference, 2),
                            "project":
                            item_row.get("project") or self.get("project")
                        }))
                elif sle.warehouse not in warehouse_with_no_account:
                    warehouse_with_no_account.append(sle.warehouse)

    if warehouse_with_no_account:
        for wh in warehouse_with_no_account:
            if frappe.db.get_value("Warehouse", wh, "company"):
                frappe.throw(
                    _("Warehouse {0} is not linked to any account, please mention the account in  the warehouse record or set default inventory account in company {1}."
                      ).format(wh, self.company))

    from erpnext.accounts.general_ledger import process_gl_map
    gl_list = process_gl_map(gl_list)

    from erpnext.accounts.general_ledger import merge_similar_entries
    gl_list = merge_similar_entries(gl_list)

    self.make_gl_entries(gl_list)
Beispiel #13
0
def add_accounting_entries(doc, method):
    sales_items = doc.items
    gl_entries = []

    for sales_item in sales_items:
        reference_dt = sales_item.reference_dt
        reference_dn = sales_item.reference_dn
        item_code = sales_item.item_code
        qty = sales_item.qty
        amount = sales_item.amount
        party = None
        gl_amount = 0
        to_do_gl_entry = False

        if reference_dt in billable_healtcare_doctypes and reference_dt:

            healthcare_doc = frappe.get_doc(reference_dt, reference_dn)

            if healthcare_doc:
                if reference_dt == billable_healtcare_doctypes[0]:
                    pass
                elif reference_dt == billable_healtcare_doctypes[1]:
                    doctor = healthcare_doc.practitioner
                    party = doctor
                    sales_item.doctor_share = get_doctor_commission(
                        item_code, doctor, qty, amount)
                    gl_amount = sales_item.doctor_share
                    to_do_gl_entry = True
                elif reference_dt == billable_healtcare_doctypes[2]:
                    pass
                elif reference_dt == billable_healtcare_doctypes[3]:
                    doctor = healthcare_doc.practitioner
                    party = doctor
                    sales_item.doctor_share = get_doctor_commission(
                        item_code, doctor, qty, amount)
                    gl_amount = sales_item.doctor_share
                    to_do_gl_entry = True
                elif reference_dt == billable_healtcare_doctypes[
                        4] or reference_dt == billable_healtcare_doctypes[5]:
                    encounter = healthcare_doc.parent
                    if encounter:
                        encounter_doc = frappe.get_doc(
                            billable_healtcare_doctypes[1], encounter)
                        if encounter_doc:
                            doctor = encounter_doc.practitioner
                            party = doctor
                            sales_item.doctor_share = get_doctor_commission(
                                item_code, doctor, qty, amount)
                            gl_amount = sales_item.doctor_share
                            to_do_gl_entry = True
                else:
                    pass

        if to_do_gl_entry:
            oralcare_settings = frappe.get_doc('Oralcare Settings')
            commission_account = oralcare_settings.doctor_commission_payable_accont
            commission_sales_account = oralcare_settings.commission_sales_account
            party_type = oralcare_settings.party_type

            if commission_account and commission_sales_account and party_type:
                gl_entry_debit = doc.get_gl_dict(
                    {
                        "account": commission_sales_account,
                        "debit": gl_amount,
                        "debit_in_account_currency": gl_amount,
                        "against": party,
                        "against_voucher_type": doc.doctype,
                        "against_voucher": doc.name,
                        "cost_center": sales_item.cost_center
                    }, "INR")
                gl_entry_credit = doc.get_gl_dict(
                    {
                        "account": commission_account,
                        "credit": gl_amount,
                        "credit_in_account_currency": gl_amount,
                        "party_type": party_type,
                        "party": party,
                        "against": commission_sales_account,
                        "against_voucher_type": doc.doctype,
                        "against_voucher": doc.name,
                        "cost_center": sales_item.cost_center
                    }, "INR")

                gl_entries.append(gl_entry_debit)
                gl_entries.append(gl_entry_credit)
            else:
                frappe.throw(_("Please configure Oralcare Settings"))

    if gl_entries:
        from erpnext.accounts.general_ledger import merge_similar_entries
        gl_entries = merge_similar_entries(gl_entries)
        from erpnext.accounts.general_ledger import make_gl_entries
        make_gl_entries(gl_entries,
                        cancel=(doc.docstatus == 2),
                        update_outstanding="No",
                        merge_entries=False)

    return