Пример #1
0
def get_data(rows, company_abbr):
    start_row = 0
    data = []
    start_row_idx = 0
    for i in xrange(len(rows)):
        r = rows[i]
        if r[0]:
            if start_row and i >= start_row:
                if not start_row_idx: start_row_idx = i
                d, acc_dict = webnotes.DictObj(), webnotes.DictObj()
                for cidx in xrange(len(columns)):
                    d[columns[cidx]] = r[cidx]

                if accounts:
                    total_debit = total_credit = 0
                    for acc_idx in xrange(len(accounts)):
                        col_idx = len(columns) + acc_idx
                        if flt(r[col_idx]) != 0:
                            acc_dict[accounts[acc_idx]] = r[col_idx]
                        if flt(r[col_idx]) > 0:
                            total_debit += flt(r[col_idx])
                        else:
                            total_credit += abs(flt(r[col_idx]))

                    d['total_debit'] = total_debit
                    d['total_credit'] = total_credit

                data.append([d, acc_dict])

            if r[0] == "--------Data----------":
                start_row = i + 2
                columns = [
                    c.replace(" ", "_").lower() for c in rows[i + 1]
                    if not c.endswith(" - " + company_abbr)
                ]
                accounts = [
                    c for c in rows[i + 1] if c.endswith(" - " + company_abbr)
                ]

    return data, start_row_idx
Пример #2
0
def get_common_values(rows):
    start = False
    common_values = webnotes.DictObj()

    for r in rows:
        if start:
            if r[0].startswith("---"):
                break
            common_values[r[0][:-1].replace(" ", "_").lower()] = r[1]
        if r[0] == "-------Common Values-----------":
            start = True

    return common_values
Пример #3
0
    def fetch_as_dict(self, formatted=0, as_utf8=0):
        """
		      Internal - get results as dictionary
		"""
        result = self._cursor.fetchall()
        ret = []
        for r in result:
            row_dict = webnotes.DictObj({})
            for i in range(len(r)):
                val = self.convert_to_simple_type(r[i], formatted)
                if as_utf8 and type(val) is unicode:
                    val = val.encode('utf-8')
                row_dict[self._cursor.description[i][0]] = val
            ret.append(row_dict)
        return ret
Пример #4
0
def get_bootinfo():
    """build and return boot info"""
    bootinfo = webnotes.DictObj()
    doclist = []

    # profile
    get_profile(bootinfo)

    # control panel
    cp = webnotes.model.doc.getsingle('Control Panel')

    # system info
    bootinfo['control_panel'] = cp.copy()
    bootinfo['account_name'] = cp.get('account_id')
    bootinfo['sysdefaults'] = webnotes.utils.get_defaults()
    bootinfo['server_date'] = webnotes.utils.nowdate()

    if webnotes.session['user'] != 'Guest':
        bootinfo['user_info'] = get_fullnames()
        bootinfo['sid'] = webnotes.session['sid']

    # home page
    add_home_page(bootinfo, doclist)

    # ipinfo
    if webnotes.session['data'].get('ipinfo'):
        bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']

    # add docs
    bootinfo['docs'] = doclist

    # plugins
    try:
        from startup import event_handlers
        if getattr(event_handlers, 'boot_session', None):
            event_handlers.boot_session(bootinfo)

    except ImportError:
        pass

    from webnotes.model.utils import compress
    bootinfo['docs'] = compress(bootinfo['docs'])

    return bootinfo
Пример #5
0
	def load_profile(self):
		"""
	      	Return a dictionary of user properites to be stored in the session
		"""
		t = webnotes.conn.sql("""select email, first_name, last_name, 
			recent_documents, email_signature, theme, background_image 
			from tabProfile where name = %s""", self.name)[0]

		if not self.can_read:
			self.build_permissions()

		d = webnotes.DictObj({})
		d['name'] = self.name
		d['email'] = t[0] or ''
		d['first_name'] = t[1] or ''
		d['last_name'] = t[2] or ''
		d['recent'] = t[3] or ''
		d.email_signature = t[4] or ""
		d.theme = t[5] or "Default"
		d.background_image = t[6] or ""
		
		d['hide_tips'] = self.get_hide_tips()
		
		d['roles'] = self.roles
		d['defaults'] = self.get_defaults()
		
		d['can_create'] = self.can_create
		d['can_write'] = self.can_write
		d['can_read'] = list(set(self.can_read))
		d['can_cancel'] = list(set(self.can_cancel))
		d['can_get_report'] = list(set(self.can_get_report))
		d['allow_modules'] = self.allow_modules
		d['all_read'] = self.all_read
		d['can_search'] = list(set(self.can_search))
		
		d['in_create'] = self.in_create
		
		return d
Пример #6
0
    def fmap(self):
        if not hasattr(self, "_fmap"):
            if self.doc.doctype in [
                    "Lead", "Quotation", "Sales Order", "Sales Invoice",
                    "Delivery Note"
            ]:
                self._fmap = webnotes.DictObj({
                    "exchange_rate":
                    "conversion_rate",
                    "taxes_and_charges":
                    "other_charges",
                    "taxes_and_charges_master":
                    "charge",
                    "taxes_and_charges_total":
                    "other_charges_total",
                    "net_total_print":
                    "net_total_print",
                    "grand_total_print":
                    "grand_total_export",
                    "grand_total_in_words":
                    "grand_total_in_words",
                    "grand_total_in_words_print":
                    "grand_total_in_words_print",
                    "rounded_total_print":
                    "rounded_total_export",
                    "rounded_total_in_words":
                    "in_words",
                    "rounded_total_in_words_print":
                    "in_words_export",
                    "print_ref_rate":
                    "ref_rate",
                    "discount":
                    "adj_rate",
                    "print_rate":
                    "export_rate",
                    "print_amount":
                    "export_amount",
                    "ref_rate":
                    "base_ref_rate",
                    "rate":
                    "basic_rate",
                    "plc_exchange_rate":
                    "plc_conversion_rate",
                    "tax_calculation":
                    "other_charges_calculation",
                })
            else:
                self._fmap = webnotes.DictObj({
                    "exchange_rate":
                    "conversion_rate",
                    "taxes_and_charges":
                    "purchase_tax_details",
                    "taxes_and_charges_master":
                    "purchase_other_charges",
                    "taxes_and_charges_total":
                    "total_tax",
                    "net_total_print":
                    "net_total_import",
                    "grand_total_print":
                    "grand_total_import",
                    "grand_total_in_words":
                    "in_words",
                    "grand_total_in_words_print":
                    "in_words_import",
                    "rounded_total_print":
                    "rounded_total_print",
                    "rounded_total_in_words":
                    "rounded_total_in_words",
                    "rounded_total_in_words_print":
                    "rounded_total_in_words_print",
                    "print_ref_rate":
                    "import_ref_rate",
                    "discount":
                    "discount_rate",
                    "print_rate":
                    "import_rate",
                    "print_amount":
                    "import_amount",
                    "ref_rate":
                    "purchase_ref_rate",
                    "rate":
                    "purchase_rate",
                    "valuation_tax_amount":
                    "item_tax_amount"
                })

        return self._fmap or webnotes.DictObj()
Пример #7
0
                else:
                    raise e

            return r and (len(r[0]) > 1 and r[0] or r[0][0]) or None

        else:
            fieldname = isinstance(fieldname, basestring) and [fieldname
                                                               ] or fieldname

            r = self.sql(
                "select field, value from tabSingles where field in (%s) and \
				doctype=%s" % (', '.join(['%s'] * len(fieldname)), '%s'),
                tuple(fieldname) + (doctype, ),
                as_dict=False)
            if as_dict:
                return r and webnotes.DictObj(r) or None
            else:
                return r and (len(r) > 1 and [i[0]
                                              for i in r] or r[0][1]) or None

    def set_value(self, dt, dn, field, val, modified=None, modified_by=None):
        from webnotes.utils import now
        if dn and dt != dn:
            self.sql(
                """update `tab%s` set `%s`=%s, modified=%s, modified_by=%s
				where name=%s""" % (dt, field, "%s", "%s", "%s", "%s"),
                (val, modified or now(), modified_by
                 or webnotes.session["user"], dn))
        else:
            if self.sql(
                    "select value from tabSingles where field=%s and doctype=%s",
Пример #8
0
from __future__ import unicode_literals

import csv, cStringIO
import webnotes
import webnotes
import webnotes.model.doc
import webnotes.model.doctype
from webnotes.model.doc import Document
from webnotes.utils import encode
from webnotes.utils import cstr

data_keys = webnotes.DictObj({
    "data_separator": '----Start entering data below this line----',
    "main_table": "Table:",
    "parent_table": "Parent Table:",
    "columns": "Column Name:"
})

doctype_dl = None


@webnotes.whitelist()
def get_doctypes():
    return [
        r[0] for r in webnotes.conn.sql("""select name from `tabDocType` 
		where document_type = 'Master'""")
    ]


@webnotes.whitelist()
def get_doctype_options():