예제 #1
0
def add_custom_fields():
    hsn_sac_field = dict(fieldname='gst_hsn_code',
                         label='HSN/SAC',
                         fieldtype='Data',
                         options='item_code.gst_hsn_code',
                         insert_after='description')

    custom_fields = {
        'Address': [
            dict(fieldname='gst_state_number',
                 label='GST State Number',
                 fieldtype='Int',
                 insert_after='gst_state'),
        ],
        'Sales Invoice': [
            dict(
                fieldname='invoice_copy',
                label='Invoice Copy',
                fieldtype='Select',
                insert_after='project',
                print_hide=1,
                allow_on_submit=1,
                options=
                'ORIGINAL FOR RECIPIENT\nDUPLICATE FOR TRANSPORTER\nTRIPLICATE FOR SUPPLIER'
            ),
        ],
        'Sales Order Item': [hsn_sac_field],
        'Delivery Note Item': [hsn_sac_field],
        'Purchase Order Item': [hsn_sac_field],
        'Purchase Receipt Item': [hsn_sac_field]
    }

    for doctype, fields in custom_fields.items():
        for df in fields:
            create_custom_field(doctype, df)
예제 #2
0
def add_custom_fields():
    df = dict(fieldname='auto_repeat',
              label='Auto Repeat',
              fieldtype='Link',
              insert_after='sender',
              options='Auto Repeat')
    create_custom_field('ToDo', df)
예제 #3
0
def make_custom_fields(doctype, local_doc, original_doc):
    '''
		check fields and create a custom field equivalent for non standard fields
	'''
    local_fields, original_fields = get_fields_dict(
        local_doc), get_fields_dict(original_doc)
    local_fields = sorted(local_fields.items(), key=lambda x: x[1]['idx'])
    doctype_doc = dataent.get_doc('DocType', doctype)

    custom_docfield_properties, prev = get_custom_docfield_properties(), ""
    for field, field_dict in local_fields:
        df = {}
        if field not in original_fields:
            for prop in field_dict:
                if prop in custom_docfield_properties:
                    df[prop] = field_dict[prop]

            df['insert_after'] = prev if prev else ''

            doctype_doc.fields = [
                d for d in doctype_doc.fields if d.fieldname != df['fieldname']
            ]
            doctype_doc.update_children()

            create_custom_field(doctype, df)

        # set current field as prev field for next field
        prev = field
예제 #4
0
파일: install.py 프로젝트: dataent/epaas
def create_print_zero_amount_taxes_custom_field():
	create_custom_field('Print Settings', {
		'label': _('Print taxes with zero amount'),
		'fieldname': 'print_taxes_with_zero_amount',
		'fieldtype': 'Check',
		'default': 0,
		'insert_after': 'allow_print_for_cancelled'
	})
예제 #5
0
파일: install.py 프로젝트: dataent/epaas
def create_compact_item_print_custom_field():
	create_custom_field('Print Settings', {
		'label': _('Compact Item Print'),
		'fieldname': 'compact_item_print',
		'fieldtype': 'Check',
		'default': 1,
		'insert_after': 'with_letterhead'
	})
예제 #6
0
def create_custom_field_for_owner_match():
    docperm_meta = dataent.get_meta('DocPerm')
    if docperm_meta.get_field('apply_user_permissions'):
        dataent.db.sql(
            """update `tabDocPerm` set apply_user_permissions=1 where `match`='owner'"""
        )

    for dt in dataent.db.sql_list("""select distinct parent from `tabDocPerm`
		where `match`='owner' and permlevel=0 and parent != 'User'"""):

        # a link field pointing to User already exists
        if (dataent.db.get_value(
                "DocField", {
                    "parent": dt,
                    "fieldtype": "Link",
                    "options": "User",
                    "default": "__user"
                }) or dataent.db.get_value(
                    "Custom Field", {
                        "dt": dt,
                        "fieldtype": "Link",
                        "options": "User",
                        "default": "__user"
                    })):
            print("User link field already exists for", dt)
            continue

        fieldname = "{}_owner".format(dataent.scrub(dt))

        create_custom_field(
            dt,
            dataent._dict({
                "permlevel": 0,
                "label": "{} Owner".format(dt),
                "fieldname": fieldname,
                "fieldtype": "Link",
                "options": "User",
                "default": "__user"
            }))

        dataent.db.sql(
            """update `tab{doctype}` set `{fieldname}`=owner""".format(
                doctype=dt, fieldname=fieldname))

        # commit is required so that we don't lose these changes because of an error in next loop's ddl
        dataent.db.commit()
예제 #7
0
파일: test_db.py 프로젝트: dataent/dataent
    def test_log_touched_tables(self):
        dataent.flags.in_migrate = True
        dataent.flags.touched_tables = set()
        dataent.db.set_value('System Settings', 'System Settings',
                             'backup_limit', 5)
        self.assertIn('tabSingles', dataent.flags.touched_tables)

        dataent.flags.touched_tables = set()
        todo = dataent.get_doc({
            'doctype': 'ToDo',
            'description': 'Random Description'
        })
        todo.save()
        self.assertIn('tabToDo', dataent.flags.touched_tables)

        dataent.flags.touched_tables = set()
        todo.description = "Another Description"
        todo.save()
        self.assertIn('tabToDo', dataent.flags.touched_tables)

        dataent.flags.touched_tables = set()
        dataent.db.sql(
            "UPDATE tabToDo SET description = 'Updated Description'")
        self.assertNotIn('tabToDo SET', dataent.flags.touched_tables)
        self.assertIn('tabToDo', dataent.flags.touched_tables)

        dataent.flags.touched_tables = set()
        todo.delete()
        self.assertIn('tabToDo', dataent.flags.touched_tables)

        dataent.flags.touched_tables = set()
        create_custom_field('ToDo', {'label': 'ToDo Custom Field'})

        self.assertIn('tabToDo', dataent.flags.touched_tables)
        self.assertIn('tabCustom Field', dataent.flags.touched_tables)
        dataent.flags.in_migrate = False
        dataent.flags.touched_tables.clear()
예제 #8
0
	def make_custom_fields_for_mappings(self):
		dataent.flags.ignore_in_install = True
		label = self.name + ' ID'
		fieldname = dataent.scrub(label)

		df = {
			'label': label,
			'fieldname': fieldname,
			'fieldtype': 'Data',
			'hidden': 1,
			'read_only': 1,
			'unique': 1,
			'no_copy': 1
		}

		for m in self.mappings:
			mapping = dataent.get_doc('Data Migration Mapping', m.mapping)
			create_custom_field(mapping.local_doctype, df)
			mapping.migration_id_field = fieldname
			mapping.save()

		# Create custom field in Deleted Document
		create_custom_field('Deleted Document', df)
		dataent.flags.ignore_in_install = False