Ejemplo n.º 1
0
        def voucher_to_invoice(voucher):
            if voucher.VOUCHERTYPENAME.string.strip() in [
                    "Sales", "Credit Note"
            ]:
                doctype = "Sales Invoice"
                party_field = "customer"
                account_field = "debit_to"
                account_name = encode_company_abbr(self.tally_debtors_account,
                                                   self.erpbee_company)
                price_list_field = "selling_price_list"
            elif voucher.VOUCHERTYPENAME.string.strip() in [
                    "Purchase", "Debit Note"
            ]:
                doctype = "Purchase Invoice"
                party_field = "supplier"
                account_field = "credit_to"
                account_name = encode_company_abbr(
                    self.tally_creditors_account, self.erpbee_company)
                price_list_field = "buying_price_list"
            else:
                # Do not handle vouchers other than "Purchase", "Debit Note", "Sales" and "Credit Note"
                # Do not handle Custom Vouchers either
                return

            invoice = {
                "doctype":
                doctype,
                party_field:
                voucher.PARTYNAME.string.strip(),
                "tally_guid":
                voucher.GUID.string.strip(),
                "tally_voucher_no":
                voucher.VOUCHERNUMBER.string.strip()
                if voucher.VOUCHERNUMBER else "",
                "posting_date":
                voucher.DATE.string.strip(),
                "due_date":
                voucher.DATE.string.strip(),
                "items":
                get_voucher_items(voucher, doctype),
                "taxes":
                get_voucher_taxes(voucher),
                account_field:
                account_name,
                price_list_field:
                "Tally Price List",
                "set_posting_time":
                1,
                "disable_rounded_total":
                1,
                "company":
                self.erpbee_company,
            }
            return invoice
Ejemplo n.º 2
0
 def get_party(party):
     if frappe.db.exists({
             "doctype": "Supplier",
             "supplier_name": party
     }):
         return "Supplier", encode_company_abbr(
             self.tally_creditors_account, self.erpbee_company)
     elif frappe.db.exists({
             "doctype": "Customer",
             "customer_name": party
     }):
         return "Customer", encode_company_abbr(
             self.tally_debtors_account, self.erpbee_company)
Ejemplo n.º 3
0
    def test_encode_company_abbr(self):
        company = frappe.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", "ERPBee Foundation India",
            "Gold - Member - {a}".format(a=abbr), " - {a}".format(a=abbr),
            "ERPBee - Foundation - India",
            "ERPBee Foundation India - {a}".format(a=abbr),
            "No-Space-{a}".format(a=abbr), "- Warehouse"
        ]

        expected_names = [
            "Warehouse Name - {a}".format(a=abbr),
            "ERPBee Foundation India - {a}".format(a=abbr),
            "Gold - Member - {a}".format(a=abbr), " - {a}".format(a=abbr),
            "ERPBee - Foundation - India - {a}".format(a=abbr),
            "ERPBee 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]))
Ejemplo n.º 4
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 = erpbee.encode_company_abbr(new_name, 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"))

        return new_warehouse
Ejemplo n.º 5
0
def create_warehouse(warehouse_name, properties=None, company=None):
    if not company:
        company = "_Test Company"

    warehouse_id = erpbee.encode_company_abbr(warehouse_name, company)
    if not frappe.db.exists("Warehouse", warehouse_id):
        w = frappe.new_doc("Warehouse")
        w.warehouse_name = warehouse_name
        w.parent_warehouse = "_Test Warehouse Group - _TC"
        w.company = company
        w.account = get_warehouse_account(warehouse_name, company)
        if properties:
            w.update(properties)
        w.save()
        return w.name
    else:
        return warehouse_id
Ejemplo n.º 6
0
 def get_voucher_taxes(voucher):
     ledger_entries = voucher.find_all(
         "ALLLEDGERENTRIES.LIST") + voucher.find_all(
             "LEDGERENTRIES.LIST")
     taxes = []
     for entry in ledger_entries:
         if entry.ISPARTYLEDGER.string.strip() == "No":
             tax_account = encode_company_abbr(
                 entry.LEDGERNAME.string.strip(), self.erpbee_company)
             taxes.append({
                 "charge_type": "Actual",
                 "account_head": tax_account,
                 "description": tax_account,
                 "tax_amount": entry.AMOUNT.string.strip(),
                 "cost_center": self.default_cost_center,
             })
     return taxes
Ejemplo n.º 7
0
        def voucher_to_journal_entry(voucher):
            accounts = []
            ledger_entries = voucher.find_all(
                "ALLLEDGERENTRIES.LIST") + voucher.find_all(
                    "LEDGERENTRIES.LIST")
            for entry in ledger_entries:
                account = {
                    "account":
                    encode_company_abbr(entry.LEDGERNAME.string.strip(),
                                        self.erpbee_company),
                    "cost_center":
                    self.default_cost_center
                }
                if entry.ISPARTYLEDGER.string.strip() == "Yes":
                    party_details = get_party(entry.LEDGERNAME.string.strip())
                    if party_details:
                        party_type, party_account = party_details
                        account["party_type"] = party_type
                        account["account"] = party_account
                        account["party"] = entry.LEDGERNAME.string.strip()
                amount = Decimal(entry.AMOUNT.string.strip())
                if amount > 0:
                    account["credit_in_account_currency"] = str(abs(amount))
                else:
                    account["debit_in_account_currency"] = str(abs(amount))
                accounts.append(account)

            journal_entry = {
                "doctype":
                "Journal Entry",
                "tally_guid":
                voucher.GUID.string.strip(),
                "tally_voucher_no":
                voucher.VOUCHERNUMBER.string.strip()
                if voucher.VOUCHERNUMBER else "",
                "posting_date":
                voucher.DATE.string.strip(),
                "company":
                self.erpbee_company,
                "accounts":
                accounts,
            }
            return journal_entry
Ejemplo n.º 8
0
 def get_voucher_items(voucher, doctype):
     inventory_entries = voucher.find_all(
         "INVENTORYENTRIES.LIST") + voucher.find_all(
             "ALLINVENTORYENTRIES.LIST") + voucher.find_all(
                 "INVENTORYENTRIESIN.LIST") + voucher.find_all(
                     "INVENTORYENTRIESOUT.LIST")
     if doctype == "Sales Invoice":
         account_field = "income_account"
     elif doctype == "Purchase Invoice":
         account_field = "expense_account"
     items = []
     for entry in inventory_entries:
         qty, uom = entry.ACTUALQTY.string.strip().split()
         items.append({
             "item_code":
             entry.STOCKITEMNAME.string.strip(),
             "description":
             entry.STOCKITEMNAME.string.strip(),
             "qty":
             qty.strip(),
             "uom":
             uom.strip(),
             "conversion_factor":
             1,
             "price_list_rate":
             entry.RATE.string.strip().split("/")[0],
             "cost_center":
             self.default_cost_center,
             "warehouse":
             self.default_warehouse,
             account_field:
             encode_company_abbr(
                 entry.find_all("ACCOUNTINGALLOCATIONS.LIST")
                 [0].LEDGERNAME.string.strip(), self.erpbee_company),
         })
     return items
Ejemplo n.º 9
0
    def _import_day_book_data(self):
        def create_fiscal_years(vouchers):
            from frappe.utils.data import add_years, getdate
            earliest_date = getdate(
                min(voucher["posting_date"] for voucher in vouchers))
            oldest_year = frappe.get_all(
                "Fiscal Year",
                fields=["year_start_date", "year_end_date"],
                order_by="year_start_date")[0]
            while earliest_date < oldest_year.year_start_date:
                new_year = frappe.get_doc({"doctype": "Fiscal Year"})
                new_year.year_start_date = add_years(
                    oldest_year.year_start_date, -1)
                new_year.year_end_date = add_years(oldest_year.year_end_date,
                                                   -1)
                if new_year.year_start_date.year == new_year.year_end_date.year:
                    new_year.year = new_year.year_start_date.year
                else:
                    new_year.year = "{}-{}".format(
                        new_year.year_start_date.year,
                        new_year.year_end_date.year)
                new_year.save()
                oldest_year = new_year

        def create_custom_fields(doctypes):
            tally_guid_df = {
                "fieldtype": "Data",
                "fieldname": "tally_guid",
                "read_only": 1,
                "label": "Tally GUID"
            }
            tally_voucher_no_df = {
                "fieldtype": "Data",
                "fieldname": "tally_voucher_no",
                "read_only": 1,
                "label": "Tally Voucher Number"
            }
            for df in [tally_guid_df, tally_voucher_no_df]:
                for doctype in doctypes:
                    create_custom_field(doctype, df)

        def create_price_list():
            frappe.get_doc({
                "doctype": "Price List",
                "price_list_name": "Tally Price List",
                "selling": 1,
                "buying": 1,
                "enabled": 1,
                "currency": "INR"
            }).insert()

        try:
            frappe.db.set_value(
                "Account",
                encode_company_abbr(self.tally_creditors_account,
                                    self.erpbee_company), "account_type",
                "Payable")
            frappe.db.set_value(
                "Account",
                encode_company_abbr(self.tally_debtors_account,
                                    self.erpbee_company), "account_type",
                "Receivable")
            frappe.db.set_value("Company", self.erpbee_company,
                                "round_off_account",
                                self.default_round_off_account)

            vouchers_file = frappe.get_doc("File", {"file_url": self.vouchers})
            vouchers = json.loads(vouchers_file.get_content())

            create_fiscal_years(vouchers)
            create_price_list()
            create_custom_fields(
                ["Journal Entry", "Purchase Invoice", "Sales Invoice"])

            total = len(vouchers)
            is_last = False

            for index in range(0, total, VOUCHER_CHUNK_SIZE):
                if index + VOUCHER_CHUNK_SIZE >= total:
                    is_last = True
                frappe.enqueue_doc(self.doctype,
                                   self.name,
                                   "_import_vouchers",
                                   queue="long",
                                   timeout=3600,
                                   start=index + 1,
                                   total=total,
                                   is_last=is_last)

        except:
            self.log()

        finally:
            self.set_status()