Exemple #1
0
    def test_encode_company_abbr(self):
        company = dataent.new_doc("Company")
        company.company_name = "New from Existing Company For Test"
        company.abbr = "NFECT"
        company.default_currency = "INR"
        company.save()

        abbr = company.abbr

        names = [
            "Warehouse Name", "EPAAS Foundation India",
            "Gold - Member - {a}".format(a=abbr), " - {a}".format(a=abbr),
            "EPAAS - Foundation - India",
            "EPAAS Foundation India - {a}".format(a=abbr),
            "No-Space-{a}".format(a=abbr), "- Warehouse"
        ]

        expected_names = [
            "Warehouse Name - {a}".format(a=abbr),
            "EPAAS Foundation India - {a}".format(a=abbr),
            "Gold - Member - {a}".format(a=abbr), " - {a}".format(a=abbr),
            "EPAAS - Foundation - India - {a}".format(a=abbr),
            "EPAAS Foundation India - {a}".format(a=abbr),
            "No-Space-{a} - {a}".format(a=abbr),
            "- Warehouse - {a}".format(a=abbr)
        ]

        for i in range(len(names)):
            enc_name = encode_company_abbr(names[i], company.name)
            self.assertTrue(
                enc_name == expected_names[i],
                "{enc} is not same as {exp}".format(enc=enc_name,
                                                    exp=expected_names[i]))
Exemple #2
0
	def _save_customer(self, customer):
		try:
			if not dataent.db.exists({"doctype": "Customer", "quickbooks_id": customer["Id"], "company": self.company}):
				try:
					receivable_account = dataent.get_all("Account", filters={
						"account_type": "Receivable",
						"account_currency": customer["CurrencyRef"]["value"],
						"company": self.company,
					})[0]["name"]
				except Exception as e:
					receivable_account = None
				erpcustomer = dataent.get_doc({
					"doctype": "Customer",
					"quickbooks_id": customer["Id"],
					"customer_name" : encode_company_abbr(customer["DisplayName"], self.company),
					"customer_type" : "Individual",
					"customer_group" : "Commercial",
					"default_currency": customer["CurrencyRef"]["value"],
					"accounts": [{"company": self.company, "account": receivable_account}],
					"territory" : "All Territories",
					"company": self.company,
				}).insert()
				if "BillAddr" in customer:
					self._create_address(erpcustomer, "Customer", customer["BillAddr"], "Billing")
				if "ShipAddr" in customer:
					self._create_address(erpcustomer, "Customer", customer["ShipAddr"], "Shipping")
		except Exception as e:
			self._log_error(e, customer)
Exemple #3
0
	def _get_unique_account_name(self, quickbooks_name, number=0):
		if number:
			quickbooks_account_name = "{} - {} - QB".format(quickbooks_name, number)
		else:
			quickbooks_account_name = "{} - QB".format(quickbooks_name)
		company_encoded_account_name = encode_company_abbr(quickbooks_account_name, self.company)
		if dataent.db.exists({"doctype": "Account", "name": company_encoded_account_name, "company": self.company}):
			unique_account_name = self._get_unique_account_name(quickbooks_name, number + 1)
		else:
			unique_account_name = quickbooks_account_name
		return unique_account_name
Exemple #4
0
	def _save_tax_rate(self, tax_rate):
		try:
			if not dataent.db.exists({"doctype": "Account", "quickbooks_id": "TaxRate - {}".format(tax_rate["Id"]), "company": self.company}):
				dataent.get_doc({
					"doctype": "Account",
					"quickbooks_id": "TaxRate - {}".format(tax_rate["Id"]),
					"account_name": "{} - QB".format(tax_rate["Name"]),
					"root_type": "Liability",
					"parent_account": encode_company_abbr("{} - QB".format("Liability"), self.company),
					"is_group": "0",
					"company": self.company,
				}).insert()
		except Exception as e:
			self._log_error(e, tax_rate)
Exemple #5
0
	def _make_root_accounts(self):
		roots = ["Asset", "Equity", "Expense", "Liability", "Income"]
		for root in roots:
			try:
				if not dataent.db.exists({"doctype": "Account", "name": encode_company_abbr("{} - QB".format(root), self.company), "company": self.company}):
					dataent.get_doc({
						"doctype": "Account",
						"account_name": "{} - QB".format(root),
						"root_type": root,
						"is_group": "1",
						"company": self.company,
					}).insert(ignore_mandatory=True)
			except Exception as e:
				self._log_error(e, root)
		dataent.db.commit()
Exemple #6
0
    def before_rename(self, old_name, new_name, merge=False):
        super(Warehouse, self).before_rename(old_name, new_name, merge)

        # Add company abbr if not provided
        new_warehouse = epaas.encode_company_abbr(new_name, self.company)

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

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

        return new_warehouse
Exemple #7
0
	def _save_vendor(self, vendor):
		try:
			if not dataent.db.exists({"doctype": "Supplier", "quickbooks_id": vendor["Id"], "company": self.company}):
				erpsupplier = dataent.get_doc({
					"doctype": "Supplier",
					"quickbooks_id": vendor["Id"],
					"supplier_name" : encode_company_abbr(vendor["DisplayName"], self.company),
					"supplier_group" : "All Supplier Groups",
					"company": self.company,
				}).insert()
				if "BillAddr" in vendor:
					self._create_address(erpsupplier, "Supplier", vendor["BillAddr"], "Billing")
				if "ShipAddr" in vendor:
					self._create_address(erpsupplier, "Supplier",vendor["ShipAddr"], "Shipping")
		except Exception as e:
			self._log_error(e)
Exemple #8
0
def create_warehouse(warehouse_name, properties=None, company=None):
    if not company:
        company = "_Test Company"

    warehouse_id = epaas.encode_company_abbr(warehouse_name, company)
    if not dataent.db.exists("Warehouse", warehouse_id):
        w = dataent.new_doc("Warehouse")
        w.warehouse_name = warehouse_name
        w.parent_warehouse = "_Test Warehouse Group - _TC"
        w.company = company
        make_account_for_warehouse(warehouse_name, w)
        w.account = warehouse_id
        if properties:
            w.update(properties)
        w.save()
        return w.name
    else:
        return warehouse_id
Exemple #9
0
	def _save_item(self, item):
		try:
			if not dataent.db.exists({"doctype": "Item", "quickbooks_id": item["Id"], "company": self.company}):
				if item["Type"] in ("Service", "Inventory"):
					item_dict = {
						"doctype": "Item",
						"quickbooks_id": item["Id"],
						"item_code" : encode_company_abbr(item["Name"], self.company),
						"stock_uom": "Unit",
						"is_stock_item": 0,
						"item_group": "All Item Groups",
						"company": self.company,
						"item_defaults": [{"company": self.company, "default_warehouse": self.default_warehouse}]
					}
					if "ExpenseAccountRef" in item:
						expense_account = self._get_account_name_by_id(item["ExpenseAccountRef"]["value"])
						item_dict["item_defaults"][0]["expense_account"] = expense_account
					if "IncomeAccountRef" in item:
						income_account = self._get_account_name_by_id(item["IncomeAccountRef"]["value"])
						item_dict["item_defaults"][0]["income_account"] = income_account
					dataent.get_doc(item_dict).insert()
		except Exception as e:
			self._log_error(e, item)
Exemple #10
0
	def _save_account(self, account):
		mapping = {
			"Bank": "Asset",
			"Other Current Asset": "Asset",
			"Fixed Asset": "Asset",
			"Other Asset": "Asset",
			"Accounts Receivable": "Asset",

			"Equity": "Equity",

			"Expense": "Expense",
			"Other Expense": "Expense",
			"Cost of Goods Sold": "Expense",

			"Accounts Payable": "Liability",
			"Credit Card": "Liability",
			"Long Term Liability": "Liability",
			"Other Current Liability": "Liability",

			"Income": "Income",
			"Other Income": "Income",
		}
		# Map Quickbooks Account Types to EPAAS root_accunts and and root_type
		try:
			if not dataent.db.exists({"doctype": "Account", "quickbooks_id": account["Id"], "company": self.company}):
				is_child = account["SubAccount"]
				is_group = account["is_group"]
				# Create Two Accounts for every Group Account
				if is_group:
					account_id = "Group - {}".format(account["Id"])
				else:
					account_id = account["Id"]

				if is_child:
					parent_account = self._get_account_name_by_id("Group - {}".format(account["ParentRef"]["value"]))
				else:
					parent_account = encode_company_abbr("{} - QB".format(mapping[account["AccountType"]]), self.company)

				dataent.get_doc({
					"doctype": "Account",
					"quickbooks_id": account_id,
					"account_name": self._get_unique_account_name(account["Name"]),
					"root_type": mapping[account["AccountType"]],
					"account_type": self._get_account_type(account),
					"account_currency": account["CurrencyRef"]["value"],
					"parent_account": parent_account,
					"is_group": is_group,
					"company": self.company,
				}).insert()

				if is_group:
					# Create a Leaf account corresponding to the group account
					dataent.get_doc({
						"doctype": "Account",
						"quickbooks_id": account["Id"],
						"account_name": self._get_unique_account_name(account["Name"]),
						"root_type": mapping[account["AccountType"]],
						"account_type": self._get_account_type(account),
						"account_currency": account["CurrencyRef"]["value"],
						"parent_account": self._get_account_name_by_id(account_id),
						"is_group": 0,
						"company": self.company,
					}).insert()
				if account.get("AccountSubType") == "UndepositedFunds":
					self.undeposited_funds_account = self._get_account_name_by_id(account["Id"])
					self.save()
		except Exception as e:
			self._log_error(e, account)