Exemplo n.º 1
0
def create_file_list():
    should_exist = [
        'Website Settings', 'Web Page', 'Timesheet', 'Task', 'Support Ticket',
        'Supplier', 'Style Settings', 'Stock Reconciliation', 'Stock Entry',
        'Serial No', 'Sales Order', 'Sales Invoice', 'Quotation', 'Question',
        'Purchase Receipt', 'Purchase Order', 'Project', 'Profile',
        'Production Order', 'Product', 'Print Format', 'Price List',
        'Purchase Invoice', 'Page', 'Maintenance Visit',
        'Maintenance Schedule', 'Letter Head', 'Leave Application', 'Lead',
        'Journal Voucher', 'Item', 'Purchase Request', 'Expense Claim',
        'Opportunity', 'Employee', 'Delivery Note', 'Customer Issue',
        'Customer', 'Contact Us Settings', 'Company', 'Bulk Rename Tool',
        'Blog', 'BOM', 'About Us Settings'
    ]

    from webnotes.model.code import get_obj

    for dt in should_exist:
        obj = get_obj('DocType', dt, with_children=1)
        obj.doc.allow_attach = 1
        obj.doc.save()
        obj.make_file_list()
        from webnotes.model.db_schema import updatedb
        updatedb(obj.doc.name)
        from webnotes.utils.cache import CacheItem
        CacheItem(obj.doc.name).clear()
Exemplo n.º 2
0
    def update_permissions(self, args=''):
        args = eval(args)
        di = args['perm_dict']
        doctype_keys = di.keys()  # ['Opportunity','Competitor','Zone','State']
        for parent in doctype_keys:
            for permlevel in di[parent].keys():
                for role in di[parent][permlevel].keys():

                    if role:

                        # check if Permissions for that perm level and Role exists
                        exists = sql(
                            "select name from tabDocPerm where parent = %s and role = %s and ifnull(permlevel, 0) = %s",
                            (parent, role, cint(permlevel)))

                        # Get values of dictionary of Perm Level
                        pd = di[parent][permlevel][role]

                        # update
                        if exists and (1 in pd.values()):
                            sql(
                                "update tabDocPerm set `read` = %s, `write` = %s, `create` = %s, `submit` = %s, `cancel` = %s, `amend` = %s, `match`=%s where parent = %s and role = %s and permlevel = %s",
                                (pd['read'], pd['write'], pd['create'],
                                 pd['submit'], pd['cancel'], pd['amend'],
                                 pd.get('match'), parent, role, permlevel))

                        # new
                        elif not exists and (1 in pd.values()):

                            ch = Document('DocPerm')
                            ch.parentfield = 'permissions'
                            ch.parenttype = 'DocType'
                            ch.parent = parent
                            ch.role = role
                            ch.permlevel = cint(permlevel)
                            for key in pd.keys():
                                ch.fields[key] = pd.get(key, None)
                            ch.save(1)

                        # delete
                        elif exists and (1 not in pd.values()):
                            sql(
                                "delete from tabDocPerm where parent = %s and role = %s and ifnull(permlevel,0) = %s",
                                (parent, role, cint(permlevel)))

                        sql(
                            "update tabDocType set modified = %s where name = %s",
                            (now(), parent))

        from webnotes.utils.cache import CacheItem
        CacheItem(parent).clear()

        msgprint("Permissions Updated")
Exemplo n.º 3
0
def get_top_tags(args=''):
	"returns the top 10 tags for the doctype from fields (7) and users (3)"
	tl = None
	dt = webnotes.form_dict['doctype']
	
	from webnotes.utils.cache import CacheItem
	
	# if not reload, try and load from cache
	if not cint(webnotes.form_dict.get('refresh')):
		tl = CacheItem('tags-' + dt).get()
	
	if tl:
		return eval(tl)
	else:
		tl = TagCounter(dt).load_top() + get_top_field_tags(dt)
		if tl:
			tl.sort(lambda x, y: y[1]-x[1])
			tl = tl[:20]
			
		# set in cache and don't reload for an hour
		CacheItem('tags-' + dt).set(tl, 3600)
	
		return tl
Exemplo n.º 4
0
    def set_series_for(self, doctype, ol):
        options = self.scrub_options_list(ol)

        # validate names
        for i in options:
            self.validate_series_name(i)

        if self.doc.user_must_always_select:
            options = [''] + options
            default = ''
        else:
            default = options[0]

        # update in property setter
        from webnotes.model.doc import Document
        prop_dict = {'options': "\n".join(options), 'default': default}
        for prop in prop_dict:
            ps_exists = webnotes.conn.sql(
                """SELECT name FROM `tabProperty Setter`
					WHERE doc_type = %s AND field_name = 'naming_series'
					AND property = %s""", (doctype, prop))
            if ps_exists:
                ps = Document('Property Setter', ps_exists[0][0])
                ps.value = prop_dict[prop]
                ps.save()
            else:
                ps = Document('Property Setter',
                              fielddata={
                                  'doctype_or_field': 'DocField',
                                  'doc_type': doctype,
                                  'field_name': 'naming_series',
                                  'property': prop,
                                  'value': prop_dict[prop],
                                  'property_type': 'Select',
                                  'select_doctype': doctype
                              })
                ps.save(1)

        self.doc.set_options = "\n".join(options)

        from webnotes.utils.cache import CacheItem
        CacheItem(doctype).clear()
Exemplo n.º 5
0
def move_customizations():
    import webnotes.model.doc
    import webnotes.model.doctype

    res = webnotes.conn.sql("""\
		delete from `tabProperty Setter`
		where property='previous_field'
		and doc_type = 'Communication Log'""")

    res = webnotes.conn.sql("""\
		select name from `tabCustom Field`
		where dt='Communication Log'""")
    for r in res:
        d = webnotes.model.doc.Document('Custom Field', r[0])
        d.dt = 'Communication'
        d.save()
    from webnotes.model.db_schema import updatedb
    updatedb('Communication')

    res = webnotes.conn.sql("""\
		select field_name from `tabProperty Setter`
		where doc_type='Communication Log' and field_name is not null""")

    doclist = webnotes.model.doctype.get('Communication', 0)
    field_list = [d.fieldname for d in doclist if d.doctype == 'DocField']
    for r in res:
        if r[0] in field_list:
            webnotes.conn.sql(
                """\
				update `tabProperty Setter`
				set doc_type = 'Communication'
				where field_name=%s and doc_type='Communication Log'""", r[0])

    webnotes.conn.sql("""\
		delete from `tabProperty Setter`
		where doc_type='Communication Log'""")

    from webnotes.utils.cache import CacheItem
    CacheItem('Communication').clear()
Exemplo n.º 6
0
def run():
    sys.path.append('lib')
    sys.path.append('lib/py')
    import webnotes
    import webnotes.defs
    sys.path.append(webnotes.defs.modules_path)

    (options, args) = setup_options()

    from webnotes.db import Database
    import webnotes.modules.patch_handler

    # connect
    if options.db_name is not None:
        webnotes.connect(options.db_name)

    # build
    if options.build:
        import build.project
        build.project.build()

    elif options.clear:
        from build.project import increment_version
        print "Version:" + str(increment_version())

    # code replace
    elif options.replace:
        replace_code('.', options.replace[0], options.replace[1],
                     options.replace[2])

    # git
    elif options.status:
        os.system('git status')
        os.chdir('lib')
        os.system('git status')

    elif options.pull:
        os.system('git pull %s %s' % (options.pull[0], options.pull[1]))
        os.chdir('lib')
        os.system('git pull %s %s' % (options.pull[0], options.pull[1]))

    elif options.push:
        os.system('git commit -a -m "%s"' % options.push[2])
        os.system('git push %s %s' % (options.push[0], options.push[1]))
        os.chdir('lib')
        os.system('git commit -a -m "%s"' % options.push[2])
        os.system('git push %s %s' % (options.push[0], options.push[1]))

    # patch
    elif options.patch_list:
        # clear log
        webnotes.modules.patch_handler.log_list = []

        # run individual patches
        for patch in options.patch_list:
            webnotes.modules.patch_handler.run_single(\
             patchmodule = patch, force = options.force)

        print '\n'.join(webnotes.modules.patch_handler.log_list)

        # reload
    elif options.reload_doc:
        webnotes.modules.patch_handler.reload_doc(\
         {"module":options.reload_doc[0], "dt":options.reload_doc[1], "dn":options.reload_doc[2]})
        print '\n'.join(webnotes.modules.patch_handler.log_list)

    elif options.export_doc:
        from webnotes.modules import export_doc
        export_doc(options.export_doc[0], options.export_doc[1])

    # run all pending
    elif options.run_latest:
        webnotes.modules.patch_handler.run_all()
        print '\n'.join(webnotes.modules.patch_handler.log_list)

    elif options.install:
        from webnotes.install_lib.install import Installer
        inst = Installer('root', options.install[0])
        inst.import_from_db(options.install[1], source_path=options.install[2], \
         password='******', verbose = 1)

    elif options.sync_with_gateway:
        if int(options.sync_with_gateway[0]) in [0, 1]:
            webnotes.conn.begin()
            webnotes.conn.sql(
                """\
				UPDATE `tabSingles` SET value=%s
				WHERE field='sync_with_gateway' AND doctype='Control Panel'""",
                int(options.sync_with_gateway[0]))
            webnotes.conn.commit()
            webnotes.message_log.append("sync_with_gateway set to %s" %
                                        options.sync_with_gateway[0])
        else:
            webnotes.message_log.append(
                "ERROR: sync_with_gateway can be either 0 or 1")

    elif options.diff_ref_file is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_file()

    elif options.diff_ref_db is not None:
        import webnotes.modules.diff
        webnotes.modules.diff.diff_ref_db()

    elif options.run_scheduler:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.execute()

    elif options.run_scheduler_event is not None:
        import webnotes.utils.scheduler
        print webnotes.utils.scheduler.trigger('execute_' +
                                               options.run_scheduler_event)

    elif options.cci is not None:
        if options.cci == 'all':
            webnotes.conn.sql("DELETE FROM __CacheItem")
        else:
            from webnotes.utils.cache import CacheItem
            CacheItem(options.cci).clear()

    # print messages
    if webnotes.message_log:
        print '\n'.join(webnotes.message_log)