Exemple #1
0
    def create_cost_center(self):
        """
		Create cost center with the name of the property under the selected parent cost center
		"""
        if self.vehicle_registration in (None, ""):
            frappe.msgprint(_("Please set vehicle registration first."))
            self.parent_cost_center = ""
            return
        from erpnext.setup.doctype.company.company import get_name_with_abbr

        real_name = get_name_with_abbr(self.vehicle_registration, self.company)
        # Check if the cost center exists before creating
        if frappe.db.exists("Cost Center", real_name):
            cost_c = frappe.get_doc("Cost Center", real_name)
            if cost_c.parent_cost_center == self.parent_cost_center:
                self.vehicle_cost_center = cost_c.name
                return
            frappe.msgprint(
                _("A Cost Center with this vehicle exists under another parent. You can make changes only in Cost Centers."
                  ))
            self.parent_cost_center = cost_c.parent_cost_center
            return

        cost_c = frappe.get_doc({
            "doctype": "Cost Center",
            "cost_center_name": self.vehicle_registration,
            "parent_cost_center": self.parent_cost_center,
            "company": self.company,
            "is_group": 0,
        })
        frappe.db.begin()
        cost_c = cost_c.insert()
        frappe.db.commit()
        self.vehicle_cost_center = cost_c.name
Exemple #2
0
    def before_rename(self, old, new, merge=False):
        # Add company abbr if not provided
        from erpnext.setup.doctype.company.company import get_name_with_abbr
        new_account = get_name_with_abbr(new, self.company)

        # Validate properties before merging
        if merge:
            if not frappe.db.exists("Account", new):
                throw(_("Account {0} does not exist").format(new))

            val = list(
                frappe.db.get_value("Account", new_account,
                                    ["is_group", "root_type", "company"]))

            if val != [self.is_group, self.root_type, self.company]:
                throw(
                    _("""Merging is only possible if following properties are same in both records. Is Group, Root Type, Company"""
                      ))

            if self.is_group and frappe.db.get_value("Account", new,
                                                     "parent_account") == old:
                frappe.db.set_value(
                    "Account", new, "parent_account",
                    frappe.db.get_value("Account", old, "parent_account"))

        return new_account
Exemple #3
0
	def before_rename(self, olddn, newdn, merge=False):
		# Add company abbr if not provided
		from erpnext.setup.doctype.company.company import get_name_with_abbr
		new_cost_center = get_name_with_abbr(newdn, self.company)

		# Validate properties before merging
		super(CostCenter, self).before_rename(olddn, new_cost_center, merge, "is_group")

		return new_cost_center
Exemple #4
0
	def before_rename(self, olddn, newdn, merge=False):
		# Add company abbr if not provided
		from erpnext.setup.doctype.company.company import get_name_with_abbr
		new_cost_center = get_name_with_abbr(newdn, self.company)

		# Validate properties before merging
		super(CostCenter, self).before_rename(olddn, new_cost_center, merge, "is_group")

		return new_cost_center
Exemple #5
0
	def before_rename(self, olddn, newdn, merge=False):
		# Add company abbr if not provided
		from erpnext.setup.doctype.company.company import get_name_with_abbr
		new_warehouse = get_name_with_abbr(newdn, self.company)

		if merge:
			if not frappe.db.exists("Warehouse", new_warehouse):
				frappe.throw(_("Warehouse {0} does not exist").format(new_warehouse))

			if self.company != frappe.db.get_value("Warehouse", new_warehouse, "company"):
				frappe.throw(_("Both Warehouse must belong to same Company"))

		self.rename_account_for(olddn, new_warehouse, merge)

		return new_warehouse
	def before_rename(self, old, new, merge=False):
		# Add company abbr if not provided
		from erpnext.setup.doctype.company.company import get_name_with_abbr
		new_account = get_name_with_abbr(new, self.company)

		# Validate properties before merging
		if merge:
			if not frappe.db.exists("Account", new):
				throw(_("Account {0} does not exist").format(new))

			val = list(frappe.db.get_value("Account", new_account,
				["group_or_ledger", "root_type", "company"]))

			if val != [self.group_or_ledger, self.root_type, self.company]:
				throw(_("""Merging is only possible if following properties are same in both records. Group or Ledger, Root Type, Company"""))

		return new_account
Exemple #7
0
    def before_rename(self, olddn, newdn, merge=False):
        # Add company abbr if not provided
        from erpnext.setup.doctype.company.company import get_name_with_abbr
        new_warehouse = get_name_with_abbr(newdn, self.company)

        if merge:
            if not frappe.db.exists("Warehouse", new_warehouse):
                frappe.throw(
                    _("Warehouse {0} does not exist").format(new_warehouse))

            if self.company != frappe.db.get_value("Warehouse", new_warehouse,
                                                   "company"):
                frappe.throw(_("Both Warehouse must belong to same Company"))

        self.rename_account_for(olddn, new_warehouse, merge)

        return new_warehouse
Exemple #8
0
	def before_rename(self, old, new, merge=False):
		# Add company abbr if not provided
		from erpnext.setup.doctype.company.company import get_name_with_abbr
		new_account = get_name_with_abbr(new, self.doc.company)
		
		# Validate properties before merging
		if merge:
			if not frappe.db.exists("Account", new):
				throw(_("Account ") + new +_(" does not exists"))
				
			val = list(frappe.db.get_value("Account", new_account, 
				["group_or_ledger", "debit_or_credit", "is_pl_account", "company"]))
			
			if val != [self.doc.group_or_ledger, self.doc.debit_or_credit, self.doc.is_pl_account, self.doc.company]:
				throw(_("""Merging is only possible if following \
					properties are same in both records.
					Group or Ledger, Debit or Credit, Is PL Account"""))
					
		return new_account
Exemple #9
0
	def before_rename(self, old, new, merge=False):
		# Add company abbr if not provided
		from erpnext.setup.doctype.company.company import get_name_with_abbr
		new_account = get_name_with_abbr(new, self.company)
		if not merge:
			new_account = get_name_with_number(new_account, self.account_number)
		else:
			# Validate properties before merging
			if not frappe.db.exists("Account", new):
				throw(_("Account {0} does not exist").format(new))

			val = list(frappe.db.get_value("Account", new_account,
				["is_group", "root_type", "company"]))

			if val != [self.is_group, self.root_type, self.company]:
				throw(_("""Merging is only possible if following properties are same in both records. Is Group, Root Type, Company"""))

			if self.is_group and frappe.db.get_value("Account", new, "parent_account") == old:
				frappe.db.set_value("Account", new, "parent_account",
					frappe.db.get_value("Account", old, "parent_account"))

		return new_account
Exemple #10
0
def update_opening_balance(source):
    import_doc = frappe.get_doc("CM Data Import Tool", source)
    je = frappe.new_doc("Journal Entry")
    je.voucher_type = "Opening Entry"
    je.remark = "Updating Opening Balance"
    je.posting_date = import_doc.posting_date
    je.is_opening = "Yes"
    from erpnext.setup.doctype.company.company import get_name_with_abbr
    temp_account = get_name_with_abbr("Temporary Opening",
                                      frappe.defaults.get_defaults().company)
    temp_balance = 0

    for account_item in import_doc.account_items:
        if (is_sales_or_purchase(account_item.account_type)): continue
        if (account_item.mapped_account is not None
                and account_item.opening_balance != 0):
            temp_balance += account_item.opening_balance
            update_journal_entry_balance(je, account_item.mapped_account,
                                         account_item.opening_balance)
            print("Setting temp balance to {0} from {1}".format(
                temp_balance, account_item.opening_balance))
    update_journal_entry_balance(je, temp_account, temp_balance * -1)
    return je.as_dict()
Exemple #11
0
 def add_abbr_if_missing(self, dn):
     from erpnext.setup.doctype.company.company import get_name_with_abbr
     return get_name_with_abbr(dn, self.company)
def add_abbr_if_missing(dn, company):
	from erpnext.setup.doctype.company.company import get_name_with_abbr
	return get_name_with_abbr(dn, company)