示例#1
0
    def update_gl_entries_after(self, warehouse_account=None):
        future_stock_vouchers = self.get_future_stock_vouchers()
        gle = self.get_voucherwise_gl_entries(future_stock_vouchers)
        if not warehouse_account:
            warehouse_account = self.get_warehouse_account()

        for voucher_type, voucher_no in future_stock_vouchers:
            existing_gle = gle.get((voucher_type, voucher_no), [])
            voucher_obj = webnotes.get_obj(voucher_type, voucher_no)
            expected_gle = voucher_obj.get_gl_entries_for_stock(
                warehouse_account)

            if expected_gle:
                matched = True
                if existing_gle:
                    for entry in expected_gle:
                        for e in existing_gle:
                            if entry.account==e.account \
                             and entry.against_account==e.against_account\
                             and entry.cost_center==e.cost_center:
                                if entry.debit != e.debit or entry.credit != e.credit:
                                    matched = False
                                    break
                else:
                    matched = False

                if not matched:
                    self.delete_gl_entries(voucher_type, voucher_no)
                    make_gl_entries(expected_gle)
            else:
                self.delete_gl_entries(voucher_type, voucher_no)
示例#2
0
 def make_gl_entries(self, cancel=0, adv_adj=0):
     from accounts.general_ledger import make_gl_entries
     gl_map = []
     for d in self.doclist.get({"parentfield": "entries"}):
         if d.debit or d.credit:
             gl_map.append(
                 self.get_gl_dict({
                     "account":
                     d.account,
                     "against":
                     d.against_account,
                     "debit":
                     d.debit,
                     "credit":
                     d.credit,
                     "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.doc.remark,
                     "cost_center":
                     d.cost_center
                 }))
     if gl_map:
         make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
    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.doc.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 accounts.general_ledger import make_gl_entries
        make_gl_entries(gl_entries)
示例#4
0
	def make_adjustment_entry(self, expected_gle, voucher_obj):
		from 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 accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries)
示例#5
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)
示例#6
0
	def update_gl_entries_after(self, warehouse_account=None):
		from accounts.utils import get_stock_and_account_difference
		future_stock_vouchers = self.get_future_stock_vouchers()
		gle = self.get_voucherwise_gl_entries(future_stock_vouchers)
		if not warehouse_account:
			warehouse_account = self.get_warehouse_account()
		
		for voucher_type, voucher_no in future_stock_vouchers:
			existing_gle = gle.get((voucher_type, voucher_no), [])
			voucher_obj = webnotes.get_obj(voucher_type, voucher_no)
			expected_gle = voucher_obj.get_gl_entries_for_stock(warehouse_account)
			
			if expected_gle:
				matched = True
				if existing_gle:
					for entry in expected_gle:
						for e in existing_gle:
							if entry.account==e.account \
								and entry.against_account==e.against_account\
								and entry.cost_center==e.cost_center:
									if entry.debit != e.debit or entry.credit != e.credit:
										matched = False
										break
				else:
					matched = False
									
				if not matched:
					self.delete_gl_entries(voucher_type, voucher_no)
					make_gl_entries(expected_gle)
			else:
				self.delete_gl_entries(voucher_type, voucher_no)
示例#7
0
	def make_gl_entries(self):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
		
		abbr = webnotes.conn.get_value("Company", self.doc.company, "abbr")
		stock_delivered_account = "Stock Delivered But Not Billed - %s" % (abbr,)
		stock_in_hand_account = self.get_stock_in_hand_account()
		
		total_buying_amount = self.get_total_buying_amount()
		if total_buying_amount:
			gl_entries = [
				# credit stock in hand account
				self.get_gl_dict({
					"account": stock_in_hand_account,
					"against": stock_delivered_account,
					"credit": total_buying_amount,
					"remarks": self.doc.remarks or "Accounting Entry for Stock",
				}, self.doc.docstatus == 2),
				
				# debit stock received but not billed account
				self.get_gl_dict({
					"account": stock_delivered_account,
					"against": stock_in_hand_account,
					"debit": total_buying_amount,
					"remarks": self.doc.remarks or "Accounting Entry for Stock",
				}, self.doc.docstatus == 2),
			]
			from accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
示例#8
0
def create_gl_entry(jv, remark, company,cancel=0, adv_adj=0):
	from accounts.general_ledger import make_gl_entries
	from webnotes.model.doc import get
	from webnotes.utils import today

	gl_map = []
	for d in get('Journal Voucher', jv).get({"parentfield": "entries"}):
		if d.debit or d.credit:
			gl_map.append(
				get_gl_dict({
					"account": d.account,
					"against": d.against_account,
					"debit": d.debit,
					"credit": d.credit,
					"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": remark,
					"cost_center": d.cost_center,
					'company': company,
					'posting_date': today(),
					'voucher_type': 'Journal Voucher',
					'voucher_no': jv,
					'aging_date': today(),
					'fiscal_year':  webnotes.conn.get_value('Global Defaults',None,'current_fiscal_year'),
				})
			)
	if gl_map:
		make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
示例#9
0
	def make_gl_entries(self):
		from accounts.general_ledger import make_gl_entries, 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)
		
		update_outstanding = cint(self.doc.is_pos) and self.doc.write_off_account and 'No' or 'Yes'
		
		if gl_entries:
			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2), 
				update_outstanding=update_outstanding, merge_entries=False)
				
			if cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")) \
					and cint(self.doc.update_stock):
				self.update_gl_entries_after()
示例#10
0
	def make_gl_entries(self):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
		
		from accounts.general_ledger import make_gl_entries
		
		against_stock_account = self.get_company_default("stock_received_but_not_billed")
		total_valuation_amount = self.get_total_valuation_amount()
		gl_entries = self.get_gl_entries_for_stock(against_stock_account, total_valuation_amount)
		
		if gl_entries:
			make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
示例#11
0
	def make_gl_entries(self):
		if self.doc.docstatus == 2:
			delete_gl_entries(voucher_type=self.doc.doctype, voucher_no=self.doc.name)
			
		if cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
			warehouse_account = self.get_warehouse_account()
		
			if self.doc.docstatus==1:
				gl_entries = self.get_gl_entries_for_stock(warehouse_account)
				make_gl_entries(gl_entries)

			self.update_gl_entries_after(warehouse_account)
示例#12
0
	def make_gl_entries(self):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
		
		from accounts.general_ledger import make_gl_entries
		
		against_stock_account = self.get_company_default("stock_received_but_not_billed")
		total_valuation_amount = self.get_total_valuation_amount()
		gl_entries = self.get_gl_entries_for_stock(against_stock_account, total_valuation_amount)
		
		if gl_entries:
			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
示例#13
0
	def make_gl_entries(self):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
		
		if not self.doc.expense_account:
			msgprint(_("Please enter Expense Account"), raise_exception=1)
			
		from accounts.general_ledger import make_gl_entries
				
		gl_entries = self.get_gl_entries_for_stock(self.doc.expense_account, 
			self.doc.stock_value_difference)
		if gl_entries:
			make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
示例#14
0
	def make_gl_entries(self, cancel=False):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
				
		from accounts.general_ledger import make_gl_entries
		against_stock_account = self.get_company_default("stock_adjustment_account")
		gl_entries = self.get_gl_entries_for_stock(against_stock_account, self.doc.purchase_rate)
		
		for entry in gl_entries:
			entry["posting_date"] = self.doc.purchase_date
			
		if gl_entries:
			make_gl_entries(gl_entries, cancel)
示例#15
0
	def make_gl_entries(self, update_gl_entries_after=True):
		if self.doc.docstatus == 2:
			delete_gl_entries(voucher_type=self.doc.doctype, voucher_no=self.doc.name)
			
		if cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
			warehouse_account = self.get_warehouse_account()
		
			if self.doc.docstatus==1:
				gl_entries = self.get_gl_entries(warehouse_account)
				make_gl_entries(gl_entries)

			if update_gl_entries_after:
				self.update_gl_entries_after(warehouse_account)
示例#16
0
	def make_gl_entries(self, cancel=False):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
				
		from accounts.general_ledger import make_gl_entries
		against_stock_account = self.get_company_default("stock_adjustment_account")
		gl_entries = self.get_gl_entries_for_stock(against_stock_account, self.doc.purchase_rate)
		
		for entry in gl_entries:
			entry["posting_date"] = self.doc.purchase_date or (self.doc.creation and 
				self.doc.creation.split(' ')[0]) or nowdate()
			
		if gl_entries:
			make_gl_entries(gl_entries, cancel)
示例#17
0
	def make_gl_entries(self, update_gl_entries_after=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_gl_entries_after and cint(self.doc.update_stock) \
				and cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
					self.update_gl_entries_after()
示例#18
0
	def make_gl_entries(self):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
			
		gl_entries = []	
		for item in self.doclist.get({"parentfield": "delivery_note_details"}):
			self.check_expense_account(item)
			
			gl_entries += self.get_gl_entries_for_stock(item.expense_account, -1*item.buying_amount, 
				cost_center=item.cost_center)
				
		if gl_entries:
			from accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries)
示例#19
0
    def make_gl_entries(self):
        if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
            return

        if not self.doc.expense_adjustment_account:
            webnotes.msgprint(_("Please enter Expense/Adjustment Account"), raise_exception=1)

        from accounts.general_ledger import make_gl_entries

        total_valuation_amount = self.get_total_valuation_amount()

        gl_entries = self.get_gl_entries_for_stock(self.doc.expense_adjustment_account, total_valuation_amount)
        if gl_entries:
            make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
示例#20
0
	def make_gl_entries(self):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
			
		gl_entries = []	
		for item in self.doclist.get({"parentfield": "delivery_note_details"}):
			self.check_expense_account(item)
			
			if item.buying_amount:
				gl_entries += self.get_gl_entries_for_stock(item.expense_account, -1*item.buying_amount, 
					cost_center=item.cost_center)
				
		if gl_entries:
			from accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
示例#21
0
	def make_gl_entries(self, repost_future_gle=True):
		if self.doc.docstatus == 2:
			delete_gl_entries(voucher_type=self.doc.doctype, voucher_no=self.doc.name)
			
		if cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
			warehouse_account = get_warehouse_account()
		
			if self.doc.docstatus==1:
				gl_entries = self.get_gl_entries(warehouse_account)
				make_gl_entries(gl_entries)

			if repost_future_gle:
				items, warehouse_account = self.get_items_and_warehouse_accounts(warehouse_account)
				update_gl_entries_after(self.doc.posting_date, self.doc.posting_time, 
					warehouse_account, items)
	def make_gl_entries(self):
		if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
			return
		
		if not self.doc.expense_adjustment_account:
			webnotes.msgprint(_("Please enter Expense/Adjustment Account"), raise_exception=1)
		
		from accounts.general_ledger import make_gl_entries
		
		total_valuation_amount = self.get_total_valuation_amount()
		
		gl_entries = self.get_gl_entries_for_stock(self.doc.expense_adjustment_account, 
			total_valuation_amount)
		if gl_entries:
			make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
示例#23
0
    def make_gl_entries(self, update_gl_entries_after=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_gl_entries_after and cint(self.doc.update_stock) \
             and cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
                self.update_gl_entries_after()
示例#24
0
def create_gl_entry(jv, remark, company, cancel=0, adv_adj=0):
    from accounts.general_ledger import make_gl_entries
    from webnotes.model.doc import get
    from webnotes.utils import today

    gl_map = []
    for d in get('Journal Voucher', jv).get({"parentfield": "entries"}):
        if d.debit or d.credit:
            gl_map.append(
                get_gl_dict({
                    "account":
                    d.account,
                    "against":
                    d.against_account,
                    "debit":
                    d.debit,
                    "credit":
                    d.credit,
                    "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":
                    remark,
                    "cost_center":
                    d.cost_center,
                    'company':
                    company,
                    'posting_date':
                    today(),
                    'voucher_type':
                    'Journal Voucher',
                    'voucher_no':
                    jv,
                    'aging_date':
                    today(),
                    'fiscal_year':
                    webnotes.conn.get_value('Global Defaults', None,
                                            'current_fiscal_year'),
                }))
    if gl_map:
        make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
示例#25
0
    def make_gl_entries(self, repost_future_gle=True):
        if self.doc.docstatus == 2:
            delete_gl_entries(voucher_type=self.doc.doctype,
                              voucher_no=self.doc.name)

        if cint(
                webnotes.defaults.get_global_default(
                    "auto_accounting_for_stock")):
            warehouse_account = get_warehouse_account()

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

            if repost_future_gle:
                items, warehouse_account = self.get_items_and_warehouse_accounts(
                    warehouse_account)
                update_gl_entries_after(self.doc.posting_date,
                                        self.doc.posting_time,
                                        warehouse_account, items)
示例#26
0
	def make_gl_entries(self, cancel=0, adv_adj=0):
		from accounts.general_ledger import make_gl_entries
		gl_map = []
		for d in self.doclist.get({"parentfield": "entries"}):
			if d.debit or d.credit:
				gl_map.append(
					self.get_gl_dict({
						"account": d.account,
						"against": d.against_account,
						"debit": d.debit,
						"credit": d.credit,
						"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.doc.remark,
						"cost_center": d.cost_center
					}, cancel)
				)
		if gl_map:
			make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj)
示例#27
0
	def make_gl_entries(self):
		from accounts.general_ledger import make_gl_entries, 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)
		
		update_outstanding = cint(self.doc.is_pos) and self.doc.write_off_account and 'No' or 'Yes'
		
		if gl_entries:
			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2), 
				update_outstanding=update_outstanding, merge_entries=False)
示例#28
0
	def make_gl_entries(self):
		from accounts.general_ledger import make_gl_entries, 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)
		
		update_outstanding = cint(self.doc.is_pos) and self.doc.write_off_account and 'No' or 'Yes'
		
		if gl_entries:
			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2), 
				update_outstanding=update_outstanding, merge_entries=False)
示例#29
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)
	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.doc.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 accounts.general_ledger import make_gl_entries
		make_gl_entries(gl_entries)
示例#31
0
	def make_gl_entries(self, against_stock_account, amount, cost_center=None):
		stock_in_hand_account = self.get_default_account("stock_in_hand_account")
		
		if amount:
			gl_entries = [
				# stock in hand account
				self.get_gl_dict({
					"account": stock_in_hand_account,
					"against": against_stock_account,
					"debit": amount,
					"remarks": self.doc.remarks or "Accounting Entry for Stock",
				}, self.doc.docstatus == 2),
				
				# account against stock in hand
				self.get_gl_dict({
					"account": against_stock_account,
					"against": stock_in_hand_account,
					"credit": amount,
					"cost_center": cost_center or None,
					"remarks": self.doc.remarks or "Accounting Entry for Stock",
				}, self.doc.docstatus == 2),
			]
			from accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
示例#32
0
	def make_gl_entries(self):
		from accounts.general_ledger import make_gl_entries
		auto_inventory_accounting = \
			cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))
		
		gl_entries = []
		
		# parent's gl entry
		if self.doc.grand_total:
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.credit_to,
					"against": self.doc.against_expense_account,
					"credit": self.doc.total_amount_to_pay,
					"remarks": self.doc.remarks,
					"against_voucher": self.doc.name,
					"against_voucher_type": self.doc.doctype,
				})
			)
	
		# tax table gl entries
		valuation_tax = 0
		for tax in self.doclist.get({"parentfield": "purchase_tax_details"}):
			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.doc.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.doc.remarks,
						"cost_center": tax.cost_center
					})
				)
			
			# accumulate valuation tax
			if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount):
				valuation_tax += (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
					
		# item gl entries
		stock_item_and_auto_inventory_accounting = False
		if auto_inventory_accounting:
			stock_account = self.get_company_default("stock_received_but_not_billed")
			
		for item in self.doclist.get({"parentfield": "entries"}):
			if auto_inventory_accounting and item.item_code in self.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_inventory_accounting = True
					
					valuation_amt = (flt(item.amount, self.precision.item.amount) + 
						flt(item.item_tax_amount, self.precision.item.item_tax_amount) + 
						flt(item.rm_supp_cost, self.precision.item.rm_supp_cost))
					
					gl_entries.append(
						self.get_gl_dict({
							"account": stock_account,
							"against": self.doc.credit_to,
							"debit": valuation_amt,
							"remarks": self.doc.remarks or "Accounting Entry for Stock"
						})
					)
			
			elif flt(item.amount):
				# if not a stock item or auto inventory accounting disabled, book the expense
				gl_entries.append(
					self.get_gl_dict({
						"account": item.expense_head,
						"against": self.doc.credit_to,
						"debit": item.amount,
						"remarks": self.doc.remarks,
						"cost_center": item.cost_center
					})
				)
				
		if stock_item_and_auto_inventory_accounting and valuation_tax:
			# credit valuation tax amount in "Expenses Included In Valuation"
			# this will balance out valuation amount included in cost of goods sold
			gl_entries.append(
				self.get_gl_dict({
					"account": self.get_company_default("expenses_included_in_valuation"),
					"cost_center": self.get_company_default("stock_adjustment_cost_center"),
					"against": self.doc.credit_to,
					"credit": valuation_tax,
					"remarks": self.doc.remarks or "Accounting Entry for Stock"
				})
			)
		
		# writeoff account includes petty difference in the invoice amount 
		# and the amount that is paid
		if self.doc.write_off_account and flt(self.doc.write_off_amount):
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.write_off_account,
					"against": self.doc.credit_to,
					"credit": flt(self.doc.write_off_amount),
					"remarks": self.doc.remarks,
					"cost_center": self.doc.write_off_cost_center
				})
			)
		
		if gl_entries:
			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
示例#33
0
	def make_gl_entries(self, is_cancel = 0):
		from accounts.general_ledger import make_gl_entries
		gl_entries = []
		valuation_tax = 0
		auto_inventory_accounting = webnotes.conn.get_value("Global Defaults", None, 
		 	"automatic_inventory_accounting")
		abbr = self.get_company_abbr()
		
		# parent's gl entry
		if self.doc.grand_total:
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.credit_to,
					"against": self.doc.against_expense_account,
					"credit": self.doc.grand_total,
					"remarks": self.doc.remarks,
					"against_voucher": self.doc.name,
					"against_voucher_type": self.doc.doctype,
				}, is_cancel)
			)
	
		# tax table gl entries
		for tax in getlist(self.doclist, "purchase_tax_details"):
			if tax.category in ("Total", "Valuation and Total") and flt(tax.tax_amount):
				valuation_tax += tax.add_deduct_tax == "Add" \
					and flt(tax.tax_amount) or -1 * flt(tax.tax_amount)
				
				gl_entries.append(
					self.get_gl_dict({
						"account": tax.account_head,
						"against": self.doc.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.doc.remarks,
						"cost_center": tax.cost_center
					}, is_cancel)
				)
					
		# item gl entries
		stock_item_and_auto_accounting = False
		for item in self.doclist.get({"parentfield": "entries"}):
			if auto_inventory_accounting and flt(item.valuation_rate) and \
					webnotes.conn.get_value("Item", item.item_code, "is_stock_item")=="Yes":
				# if auto inventory accounting enabled and stock item, 
				# then do stock related gl entries, expense will be booked in sales invoice
				gl_entries.append(
					self.get_gl_dict({
						"account": "Stock Received But Not Billed - %s" % (abbr,),
						"against": self.doc.credit_to,
						"debit": flt(item.valuation_rate) * flt(item.conversion_factor) \
							*  item.qty,
						"remarks": self.doc.remarks or "Accounting Entry for Stock"
					}, is_cancel)
				)
			
				stock_item_and_auto_accounting = True
			
			elif flt(item.amount):
				# if not a stock item or auto inventory accounting disabled, book the expense
				gl_entries.append(
					self.get_gl_dict({
						"account": item.expense_head,
						"against": self.doc.credit_to,
						"debit": item.amount,
						"remarks": self.doc.remarks,
						"cost_center": item.cost_center
					}, is_cancel)
				)
				
		if stock_item_and_auto_accounting and valuation_tax:
			# credit valuation tax amount in "Expenses Included In Valuation"
			# this will balance out valuation amount included in cost of goods sold
			gl_entries.append(
				self.get_gl_dict({
					"account": "Expenses Included In Valuation - %s" % (abbr,),
					"cost_center": "ERP - %s" % abbr, # to-do
					"against": self.doc.credit_to,
					"credit": valuation_tax,
					"remarks": self.doc.remarks or "Accounting Entry for Stock"
				}, is_cancel)
			)
		
		# writeoff account includes petty difference in the invoice amount 
		# and the amount that is paid
		if self.doc.write_off_account and self.doc.write_off_amount:
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.write_off_account,
					"against": self.doc.credit_to,
					"credit": self.doc.write_off_amount,
					"remarks": self.doc.remarks,
					"cost_center": self.doc.write_off_cost_center
				}, is_cancel)
			)
		
		if gl_entries:
			make_gl_entries(gl_entries, cancel=is_cancel)
示例#34
0
    def make_gl_entries(self):
        auto_accounting_for_stock = \
         cint(webnotes.defaults.get_global_default("auto_accounting_for_stock"))

        gl_entries = []

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

        # tax table gl entries
        valuation_tax = {}
        for tax in self.doclist.get({"parentfield": "purchase_tax_details"}):
            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.doc.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.doc.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:
                    webnotes.throw(
                        _("Row %(row)s: Cost Center is mandatory \
						if tax/charges category is Valuation or Valuation and Total" %
                          {"row": tax.idx}))
                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.doclist.get({"parentfield": "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.amount + item.item_tax_amount + item.rm_supp_cost,
                        self.precision("amount", item))

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

            elif flt(item.amount):
                # if not a stock item or auto inventory accounting disabled, book the expense
                gl_entries.append(
                    self.get_gl_dict({
                        "account": item.expense_head,
                        "against": self.doc.credit_to,
                        "debit": item.amount,
                        "remarks": self.doc.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.doc.credit_to,
                        "credit":
                        amount,
                        "remarks":
                        self.doc.remarks or "Accounting Entry for Stock"
                    }))

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

        if gl_entries:
            from accounts.general_ledger import make_gl_entries
            make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
示例#35
0
    def make_gl_entries(self):
        from accounts.general_ledger import make_gl_entries
        auto_inventory_accounting = \
         cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))

        gl_entries = []

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

        # tax table gl entries
        valuation_tax = 0
        for tax in self.doclist.get({"parentfield": "purchase_tax_details"}):
            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.doc.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.doc.remarks,
                        "cost_center":
                        tax.cost_center
                    }))

            # accumulate valuation tax
            if tax.category in ("Valuation", "Valuation and Total") and flt(
                    tax.tax_amount):
                valuation_tax += (tax.add_deduct_tax == "Add" and 1
                                  or -1) * flt(tax.tax_amount)

        # item gl entries
        stock_item_and_auto_inventory_accounting = False
        if auto_inventory_accounting:
            stock_account = self.get_company_default(
                "stock_received_but_not_billed")

        for item in self.doclist.get({"parentfield": "entries"}):
            if auto_inventory_accounting and item.item_code in self.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_inventory_accounting = True

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

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

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

        if stock_item_and_auto_inventory_accounting and valuation_tax:
            # credit valuation tax amount in "Expenses Included In Valuation"
            # this will balance out valuation amount included in cost of goods sold
            gl_entries.append(
                self.get_gl_dict({
                    "account":
                    self.get_company_default("expenses_included_in_valuation"),
                    "cost_center":
                    self.get_company_default("stock_adjustment_cost_center"),
                    "against":
                    self.doc.credit_to,
                    "credit":
                    valuation_tax,
                    "remarks":
                    self.doc.remarks or "Accounting Entry for Stock"
                }))

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

        if gl_entries:
            make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
示例#36
0
	def make_gl_entries(self):
		auto_accounting_for_stock = \
			cint(webnotes.defaults.get_global_default("auto_accounting_for_stock"))
		
		gl_entries = []
		
		# parent's gl entry
		if self.doc.grand_total:
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.credit_to,
					"against": self.doc.against_expense_account,
					"credit": self.doc.total_amount_to_pay,
					"remarks": self.doc.remarks,
					"against_voucher": self.doc.name,
					"against_voucher_type": self.doc.doctype,
				})
			)
	
		# tax table gl entries
		valuation_tax = {}
		for tax in self.doclist.get({"parentfield": "purchase_tax_details"}):
			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.doc.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.doc.remarks,
						"cost_center": tax.cost_center
					})
				)
			
			# accumulate valuation tax
			if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount) \
				and tax.cost_center:
					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()
		rounding_diff = 0.0
		for item in self.doclist.get({"parentfield": "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(flt(item.valuation_rate) * flt(item.qty) * \
						flt(item.conversion_factor), self.precision("valuation_rate", item))
					
					rounding_diff += (flt(item.amount, self.precision("amount", item)) + 
						flt(item.item_tax_amount, self.precision("item_tax_amount", item)) + 
						flt(item.rm_supp_cost, self.precision("rm_supp_cost", item)) - 
						valuation_amt)
					
					gl_entries.append(
						self.get_gl_dict({
							"account": item.expense_head,
							"against": self.doc.credit_to,
							"debit": valuation_amt,
							"remarks": self.doc.remarks or "Accounting Entry for Stock"
						})
					)
			
			elif flt(item.amount):
				# if not a stock item or auto inventory accounting disabled, book the expense
				gl_entries.append(
					self.get_gl_dict({
						"account": item.expense_head,
						"against": self.doc.credit_to,
						"debit": item.amount,
						"remarks": self.doc.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")
				
			if rounding_diff:
				import operator
				cost_center_with_max_value = max(valuation_tax.iteritems(), 
					key=operator.itemgetter(1))[0]
				valuation_tax[cost_center_with_max_value] -= flt(rounding_diff)
			
			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.doc.credit_to,
						"credit": amount,
						"remarks": self.doc.remarks or "Accounting Entry for Stock"
					})
				)
		
		# writeoff account includes petty difference in the invoice amount 
		# and the amount that is paid
		if self.doc.write_off_account and flt(self.doc.write_off_amount):
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.write_off_account,
					"against": self.doc.credit_to,
					"credit": flt(self.doc.write_off_amount),
					"remarks": self.doc.remarks,
					"cost_center": self.doc.write_off_cost_center
				})
			)
		
		if gl_entries:
			from accounts.general_ledger import make_gl_entries
			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
示例#37
0
	def make_gl_entries(self, is_cancel=0):
		from accounts.general_ledger import make_gl_entries
		gl_entries = []
		auto_inventory_accounting = webnotes.conn.get_value("Global Defaults", None, 
		 	"automatic_inventory_accounting")
		abbr = self.get_company_abbr()
		
		# parent's gl entry
		if self.doc.grand_total:
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.debit_to,
					"against": self.doc.against_income_account,
					"debit": self.doc.grand_total,
					"remarks": self.doc.remarks,
					"against_voucher": self.doc.name,
					"against_voucher_type": self.doc.doctype,
				}, is_cancel)
			)
	
		# tax table gl entries
		for tax in self.doclist.get({"parentfield": "other_charges"}):
			if flt(tax.tax_amount):
				gl_entries.append(
					self.get_gl_dict({
						"account": tax.account_head,
						"against": self.doc.debit_to,
						"credit": flt(tax.tax_amount),
						"remarks": self.doc.remarks,
						"cost_center": tax.cost_center_other_charges
					}, is_cancel)
				)
		
		# item gl entries
		for item in getlist(self.doclist, 'entries'):
			# income account gl entries
			if flt(item.amount):
				gl_entries.append(
					self.get_gl_dict({
						"account": item.income_account,
						"against": self.doc.debit_to,
						"credit": item.amount,
						"remarks": self.doc.remarks,
						"cost_center": item.cost_center
					}, is_cancel)
				)
			# if auto inventory accounting enabled and stock item, 
			# then do stock related gl entries
			if auto_inventory_accounting and item.delivery_note and \
					webnotes.conn.get_value("Item", item.item_code, "is_stock_item")=="Yes":
				# to-do
				purchase_rate = webnotes.conn.get_value("Delivery Note Item", 
					item.dn_detail, "purchase_rate")
				valuation_amount =  purchase_rate * item.qty
				# expense account gl entries
				if flt(valuation_amount):
					gl_entries.append(
						self.get_gl_dict({
							"account": item.expense_account,
							"against": "Stock Delivered But Not Billed - %s" % (abbr,),
							"debit": valuation_amount,
							"remarks": self.doc.remarks or "Accounting Entry for Stock"
						}, is_cancel)
					)
					gl_entries.append(
						self.get_gl_dict({
							"account": "Stock Delivered But Not Billed - %s" % (abbr,),
							"against": item.expense_account,
							"credit": valuation_amount,
							"remarks": self.doc.remarks or "Accounting Entry for Stock"
						}, is_cancel)
					)
		if self.doc.is_pos and self.doc.cash_bank_account and self.doc.paid_amount:
			# POS, make payment entries
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.debit_to,
					"against": self.doc.cash_bank_account,
					"credit": self.doc.paid_amount,
					"remarks": self.doc.remarks,
					"against_voucher": self.doc.name,
					"against_voucher_type": self.doc.doctype,
				}, is_cancel)
			)
			gl_entries.append(
				self.get_gl_dict({
					"account": self.doc.cash_bank_account,
					"against": self.doc.debit_to,
					"debit": self.doc.paid_amount,
					"remarks": self.doc.remarks,
				}, is_cancel)
			)
			# write off entries, applicable if only pos
			if self.doc.write_off_account and self.doc.write_off_amount:
				gl_entries.append(
					self.get_gl_dict({
						"account": self.doc.debit_to,
						"against": self.doc.write_off_account,
						"credit": self.doc.write_off_amount,
						"remarks": self.doc.remarks,
						"against_voucher": self.doc.name,
						"against_voucher_type": self.doc.doctype,
					}, is_cancel)
				)
				gl_entries.append(
					self.get_gl_dict({
						"account": self.doc.write_off_account,
						"against": self.doc.debit_to,
						"debit": self.doc.write_off_amount,
						"remarks": self.doc.remarks,
						"cost_center": self.doc.write_off_cost_center
					}, is_cancel)
				)
		
		
		update_outstanding = self.doc.is_pos and self.doc.write_off_account and 'No' or 'Yes'
		merge_entries=cint(self.doc.is_pos)!=1 and 1 or 0
		if gl_entries:
			make_gl_entries(gl_entries, cancel=is_cancel, 
				update_outstanding=update_outstanding, merge_entries=merge_entries)