Пример #1
0
def sync_folder(site,older_than,sourcepath, destfolder,did_not_upload,error_log):
	# destpath = "gdrive:" + destfolder + " --drive-use-trash"
	rclone_remote_directory=frappe.db.get_value('Backup Settings', None, 'rclone_remote_directory_path')
	from frappe.utils import get_bench_path
	sourcepath=get_bench_path()+"/sites"+sourcepath.replace("./", "/")
#	final_dest = rclone_remote_directory+"/"+str(site) + "/" + destfolder

	final_dest = rclone_remote_directory+"/"+str(site)
	final_dest = final_dest.replace(" ", "_")
	rclone_remote_name=frappe.db.get_value('Backup Settings', None, 'rclone_remote_name')
	# rclone_remote_directory=frappe.db.get_value('Backup Settings', None, 'rclone_remote_directory_path')

	# destpath = rclone_remote_name+":"+rclone_remote_directory+'/'+final_dest
	destpath = rclone_remote_name+":"+final_dest

	BASE_DIR = os.path.join( get_backups_path(), '../file_backups' )
	Backup_DIR = os.path.join(BASE_DIR, "private/files")

	# print older_than
	# delete_temp_backups(older_than,sourcepath)
	sourcepath = get_bench_path()+"/sites"+get_backups_path().replace("./", "/")
	cmd_string = "rclone sync " + sourcepath + " " + destpath
	
	# frappe.errprint(cmd_string)
	try:
		err, out = frappe.utils.execute_in_shell(cmd_string)
		if err: raise Exception
	except Exception:
		did_not_upload  = True
		error_log.append(Exception)
Пример #2
0
def create_tortal_user_csv(filename):
    EmpIdentifier = frappe.db.get_value("Tortal LMS System Settings", None,
                                        "emp_identifier")

    # list of system users
    system_user_details = frappe.db.sql(
        """select first_name,middle_name,last_name,email,username,
	tortal_lms_password,'','','','','','',frappe_userid,is_active_tortal_lms_user 
	from `tabUser` 
    where frappe_userid IS NOT NULL 
    and is_active_tortal_lms_user=1
    and user_type='System User' """,
        as_list=1)
    private_files = get_files_path().replace("/public/", "/private/")
    private_files_path = get_bench_path() + "/sites" + private_files.replace(
        "./", "/")

    # list of website users having company
    website_user_details = frappe.db.sql(
        """select first_name,middle_name,last_name,email,username,
	tortal_lms_password,'','','','','','',frappe_userid,is_active_tortal_lms_user 
	from `tabUser` 
    where frappe_userid IS NOT NULL and is_active_tortal_lms_user=1
    and user_type='Website User' 
    and frappe_userid in(
			select user.frappe_userid
            from `tabContact` contact
            inner join `tabDynamic Link` customer on
            customer.parent=contact.name
            inner join `tabCustomer` cust on
            cust.name=customer.link_name
            inner join `tabUser` user on
            contact.user=user.name
            where customer.link_doctype='Customer' 
            and customer.parenttype='Contact' 
            and user.frappe_userid is not null
            and user_type='Website User'           
            and customer_type in ('Company','Individual'))""",
        as_list=1)
    private_files = get_files_path().replace("/public/", "/private/")
    private_files_path = get_bench_path() + "/sites" + private_files.replace(
        "./", "/")

    with open(private_files_path + '/' + filename, 'wb') as f_handle:
        writer = csv.writer(f_handle)
        # Add the header/column names
        # header = ['First Name','Middle Name','Last Name','Email','Username','Password','Company','Address1','Address2','City','State','Postal Code','Identifier','IsActive']
        # writer.writerow(header)
        for row in system_user_details:
            writer.writerow(row)
        for row in website_user_details:
            writer.writerow(row)
    return os.path.realpath(f_handle.name)
Пример #3
0
def run_tests(context, app=None, module=None, doctype=None, test=(),
	driver=None, profile=False, coverage=False, junit_xml_output=False, ui_tests = False,
	doctype_list_path=None, skip_test_records=False, skip_before_tests=False, failfast=False):

	"Run tests"
	import frappe.test_runner
	tests = test

	site = get_site(context)
	frappe.init(site=site)

	frappe.flags.skip_before_tests = skip_before_tests
	frappe.flags.skip_test_records = skip_test_records

	if coverage:
		# Generate coverage report only for app that is being tested
		source_path = os.path.join(get_bench_path(), 'apps', app or 'frappe')
		cov = Coverage(source=[source_path], omit=['*.html', '*.js', '*.xml', '*.css', '*/doctype/*/*_dashboard.py', '*/patches/*'])
		cov.start()

	ret = frappe.test_runner.main(app, module, doctype, context.verbose, tests=tests,
		force=context.force, profile=profile, junit_xml_output=junit_xml_output,
		ui_tests = ui_tests, doctype_list_path = doctype_list_path, failfast=failfast)

	if coverage:
		cov.stop()
		cov.save()

	if len(ret.failures) == 0 and len(ret.errors) == 0:
		ret = 0

	if os.environ.get('CI'):
		sys.exit(ret)
Пример #4
0
def run_tests(context, app=None, module=None, doctype=None, test=(),
	driver=None, profile=False, coverage=False, junit_xml_output=False, ui_tests = False,
	doctype_list_path=None, skip_test_records=False, skip_before_tests=False, failfast=False):

	"Run tests"
	import frappe.test_runner
	tests = test

	site = get_site(context)
	frappe.init(site=site)

	frappe.flags.skip_before_tests = skip_before_tests
	frappe.flags.skip_test_records = skip_test_records

	if coverage:
		# Generate coverage report only for app that is being tested
		source_path = os.path.join(get_bench_path(), 'apps', app or 'frappe')
		cov = Coverage(source=[source_path], omit=['*.html', '*.js', '*.css'])
		cov.start()

	ret = frappe.test_runner.main(app, module, doctype, context.verbose, tests=tests,
		force=context.force, profile=profile, junit_xml_output=junit_xml_output,
		ui_tests = ui_tests, doctype_list_path = doctype_list_path, failfast=failfast)

	if coverage:
		cov.stop()
		cov.save()

	if len(ret.failures) == 0 and len(ret.errors) == 0:
		ret = 0

	if os.environ.get('CI'):
		sys.exit(ret)
Пример #5
0
def get_messages_from_file(path: str) -> List[Tuple[str, str, str, str]]:
	"""Returns a list of transatable strings from a code file

	:param path: path of the code file
	"""
	frappe.flags.setdefault('scanned_files', [])
	# TODO: Find better alternative
	# To avoid duplicate scan
	if path in set(frappe.flags.scanned_files):
		return []

	frappe.flags.scanned_files.append(path)

	bench_path = get_bench_path()
	if os.path.exists(path):
		with open(path, 'r') as sourcefile:
			try:
				file_contents = sourcefile.read()
			except Exception:
				print("Could not scan file for translation: {0}".format(path))
				return []

			return [
				(os.path.relpath(path, bench_path), message, context, line)
				for (line, message, context) in extract_messages_from_code(file_contents)
			]
	else:
		return []
Пример #6
0
def run_tests(context, app=None, module=None, doctype=None, test=(), profile=False,
		coverage=False, junit_xml_output=False, ui_tests = False, doctype_list_path=None,
		skip_test_records=False, skip_before_tests=False, failfast=False):

	"Run tests"
	import frappe.test_runner
	tests = test

	site = get_site(context)

	allow_tests = frappe.get_conf(site).allow_tests

	if not (allow_tests or os.environ.get('CI')):
		click.secho('Testing is disabled for the site!', bold=True)
		click.secho('You can enable tests by entering following command:')
		click.secho('bench --site {0} set-config allow_tests true'.format(site), fg='green')
		return

	frappe.init(site=site)

	frappe.flags.skip_before_tests = skip_before_tests
	frappe.flags.skip_test_records = skip_test_records

	if coverage:
		from coverage import Coverage

		# Generate coverage report only for app that is being tested
		source_path = os.path.join(get_bench_path(), 'apps', app or 'frappe')
		cov = Coverage(source=[source_path], omit=[
			'*.html',
			'*.js',
			'*.xml',
			'*.css',
			'*.less',
			'*.scss',
			'*.vue',
			'*/doctype/*/*_dashboard.py',
			'*/patches/*'
		])
		cov.start()

	ret = frappe.test_runner.main(app, module, doctype, context.verbose, tests=tests,
		force=context.force, profile=profile, junit_xml_output=junit_xml_output,
		ui_tests=ui_tests, doctype_list_path=doctype_list_path, failfast=failfast)

	if coverage:
		cov.stop()
		cov.save()

	if len(ret.failures) == 0 and len(ret.errors) == 0:
		ret = 0

	if os.environ.get('CI'):
		sys.exit(ret)
Пример #7
0
	def __enter__(self):
		if self.with_coverage:
			import os
			from coverage import Coverage
			from frappe.utils import get_bench_path

			# Generate coverage report only for app that is being tested
			source_path = os.path.join(get_bench_path(), 'apps', self.app)
			omit = STANDARD_EXCLUSIONS[:]

			if self.app == 'frappe':
				omit.extend(FRAPPE_EXCLUSIONS)

			self.coverage = Coverage(source=[source_path], omit=omit, include=STANDARD_INCLUSIONS)
			self.coverage.start()
Пример #8
0
def import_coa(company=False, file_path=False):
    # Validate company
    if not company:
        frappe.throw('Missing company')

    try:
        company = frappe.get_doc("Company", company)
    except:
        frappe.throw('Company ({company}) not found'.format(company=company))

    print("Company found")

    # Remove old company account defaults (company Settings)
    print("removing old company account defaults...")
    remove_old_company_account_defaults(company.name)

    # Delete old chart of accounts from company
    print("deleting old chart of accounts from company...")
    delete_old_accounts(company.name)

    # Create new chart of accounts incl. company account defaults (based on csv template)
    # read accounts template csv
    if not file_path:
        file_path = "{0}/apps/erpnextswiss/erpnextswiss/erpnextswiss/coa_import/accounts_template.csv".format(
            get_bench_path())
    df = pd.read_csv(file_path)
    qty = len(df.index)
    print("found {qty} entries in template csv".format(qty=qty))

    # loop trough accounts template and create new accounts
    loop = 1
    for index, row in df.iterrows():
        print("create account No. {loop} of {qty}".format(loop=loop, qty=qty))
        create_account(company.name, company.abbr, row)
        loop += 1
    print("finish")
Пример #9
0
def get_absolute_path(filename):
	file_path = os.path.join(get_backups_path()[2:], filename)
	return "{0}/sites/{1}".format(get_bench_path(), file_path)
Пример #10
0
def download_uva_pdf(uva):
    doc = frappe.get_doc("AT VAT Declaration", uva)
    # generate content
    company_address = get_company_address(doc.company)
    settings = frappe.get_doc("ERPNextAustria Settings", "ERPNextAustria Settings")
    tax_codes = settings.fastnr.split(".") if settings.fastnr else ['00', '000', '0000']
    data = {
        'Text01': settings.finanzamt,
        'Checkbox00a': 1,
        'Zahl03': tax_codes[0],
        'Zahl02_1': tax_codes[1],
        'Zahl02_2': tax_codes[2],
        'Text01_m': "{0}".format(doc.start_date)[5:7],         # month
        'Text03': doc.company,
        'Text05': company_address.address_line1 if company_address else "",
        'Text07b': 'AT',
        'Text07c': company_address.phone if company_address else "",
        'Text07d': company_address.pincode if company_address else "",
        'Text07e': company_address.city if company_address else "",
        'Zahl101': get_at_value(doc.revenue),                  # 000
        'Zahl102': get_at_value(doc.self_consumption),         # 001
        'Zahl103': get_at_value(doc.receiver_vat),             # 021
        'Zahl104': get_at_value(doc.total_revenue),            # (4.4)
        'Zahl105': get_at_value(doc.exports),                  # 011
        'Zahl106': get_at_value(doc.subcontracting),           # 012
        'Zahl107': get_at_value(doc.cross_border),             # 015
        'Zahl108': get_at_value(doc.inner_eu),                 # 017
        'Zahl109': get_at_value(doc.vehicles_without_uid),     # 018
        'Zahl110': get_at_value(doc.property_revenue),         # 019
        'Zahl111': get_at_value(doc.small_businesses),         # 016
        'Zahl113': get_at_value(doc.tax_free_revenue),         # 020
        'Zahl114': get_at_value(doc.total_amount),             # (4.13)
        'Zahl115a': get_at_value(doc.amount_normal),           # 022
        'Zahl115b': get_at_value(doc.tax_normal),              # 022
        'Zahl116a': get_at_value(doc.reduced_amount),          # 029
        'Zahl116b': get_at_value(doc.tax_reduced_rate_1),      # 029
        'Zahl117a': get_at_value(doc.reduced_amount_2),        # 006
        'Zahl117b': get_at_value(doc.tax_reduced_rate_2),      # 006
        'Zahl118a': get_at_value(doc.reduced_amount_3),        # 037
        'Zahl118b': get_at_value(doc.tax_reduced_rate_3),      # 037
        'Zahl119a': get_at_value(doc.amount_additional_1),     # 052
        'Zahl119b': get_at_value(doc.tax_additional_1),        # 052
        'Zahl120a': get_at_value(doc.amount_additional_2),     # 007
        'Zahl120b': get_at_value(doc.tax_additional_2),        # 007
        'Zahl121a': get_at_value(0),                           # 009
        'Zahl121b': get_at_value(0),                           # 009
        'Zahl123': get_at_value(doc.tax_056),                  # 056
        'Zahl124': get_at_value(doc.tax_057),                  # 057
        'Zahl125': get_at_value(doc.tax_048),                  # 048
        'Zahl125a': get_at_value(doc.tax_044),                 # 044
        'Zahl125b': get_at_value(doc.tax_032),                 # 032
        'Zahl126': get_at_value(doc.intercommunal_revenue),    # 070
        'Zahl127': get_at_value(doc.taxfree_intercommunal),    # 071
        'Zahl127a': get_at_value(doc.total_intercommunal),     # (4.28)
        'Zahl128a': get_at_value(doc.amount_inter_normal),     # 072
        'Zahl128b': get_at_value(doc.tax_inter_normal),        # 072
        'Zahl129a': get_at_value(doc.amount_inter_reduced_1),  # 073
        'Zahl129b': get_at_value(doc.tax_inter_reduced_1),     # 073
        'Zahl129a_1': get_at_value(doc.amount_inter_reduced_2),# 008
        'Zahl129b_1': get_at_value(doc.tax_inter_reduced_2),   # 008
        'Zahl130a': get_at_value(doc.amount_inter_reduced_3),  # 088
        'Zahl130b': get_at_value(doc.tax_inter_reduced_3),     # 088
        'Zahl130aa': get_at_value(0),                          # 010
        'Zahl130bb': get_at_value(0),                          # 010
        'Zahl131': get_at_value(doc.external_taxation),        # 076
        'Zahl132': get_at_value(doc.internal_taxation),        # 077
        'Zahl133': get_at_value(doc.total_pretax),             # 060
        'Zahl134': get_at_value(doc.import_pretax),            # 061
        'Zahl134a': get_at_value(doc.import_charge_pretax),    # 083
        'Zahl135': get_at_value(doc.intercommunal_pretax),     # 065
        'Zahl136': get_at_value(doc.taxation_pretax),          # 066
        'Zahl136a': get_at_value(doc.taxation_building_pretax),# 082
        'Zahl137': get_at_value(doc.taxation_pretax_other_1),  # 087
        'Zahl137a': get_at_value(doc.taxation_pretax_other_2), # 089
        'Zahl138': get_at_value(doc.vehicles_pretax),          # 064
        'Zahl139': get_at_value(doc.non_deductable_pretax),    # 062
        'Zahl140': get_at_value(doc.corrections_1),            # 063
        'Zahl141': get_at_value(doc.corrections_2),            # 067
        'Zahl142': get_at_value(doc.total_deductable_pretax),  # (5.13)
        'Text143': doc.description_other_correction,
        'Zahl143': get_at_value(doc.tax_other_corrections),    # 090
        'Zahl144': get_at_value(doc.total_tax_due),            # 095
        'Checkbox100X': 2 if doc.total_tax_due > 0 else 0,      # (7.1)
        'Tagesdatum2': datetime.now().strftime("%d.%m.%Y")     # date
    }
    # generate pdf
    generated_pdf = pypdftk.fill_form(get_bench_path() + '/apps/erpnextaustria/erpnextaustria/templates/pdf/U30.pdf', data)
    with open(generated_pdf, mode='rb') as file:
        pdf_data = file.read()
    # return content
    frappe.local.response.filename = "{name}.pdf".format(name=uva.replace(" ", "-").replace("/", "-"))
    frappe.local.response.filecontent = pdf_data
    frappe.local.response.type = "download"
    return
Пример #11
0
def create_tortal_group_user_csv(filename):
    GroupIdentifier = frappe.db.get_value("Tortal LMS System Settings", None,
                                          "group_name")
    GroupAdmin = frappe.db.get_value("Tortal LMS System Settings", None,
                                     "emp_identifier")

    # system user - group admin
    parent_admin_details = frappe.db.sql(
        """select frappe_userid,'{group}','{groupadmin}' from `tabUser` 
	where frappe_userid IS NOT NULL 
	and user_type='System User' 
	and is_active_tortal_lms_user=1 
	and name =%s""".format(group=GroupIdentifier, groupadmin='1'),
        GroupAdmin,
        as_list=1)

    # system user - non group admin
    parent_normal_details = frappe.db.sql(
        """select frappe_userid,'{group}','{groupadmin}' from `tabUser` 
	where frappe_userid IS NOT NULL 
	and user_type='System User' 
	and is_active_tortal_lms_user=1 
	and name  !=%s """.format(group=GroupIdentifier, groupadmin='0'),
        GroupAdmin,
        as_list=1)

    # website user - group admin for their particular company
    website_admin_details = frappe.db.sql(
        """select user.frappe_userid,replace(customer.link_name,' ','_') as company,'{groupadmin}'
            from `tabContact` contact
            inner join `tabDynamic Link` customer on
            customer.parent=contact.name
            inner join `tabCustomer` cust on
            cust.name=customer.link_name
            inner join `tabUser` user on
            contact.user=user.name
            where customer.link_doctype='Customer' 
            and customer.parenttype='Contact' 
            and user.frappe_userid is not null
            and user_type='Website User'
            and user.is_active_tortal_lms_user=1
			and contact.is_primary_contact=1
            and customer_type in ('Company','Individual')""".format(
            groupadmin='1'),
        as_list=1)

    # website user - non group admin for their particular company
    website_normal_details = frappe.db.sql(
        """select user.frappe_userid,replace(customer.link_name,' ','_') as company,'{groupadmin}'
            from `tabContact` contact
            inner join `tabDynamic Link` customer on
            customer.parent=contact.name
            inner join `tabCustomer` cust on
            cust.name=customer.link_name
            inner join `tabUser` user on
            contact.user=user.name
            where customer.link_doctype='Customer' 
            and customer.parenttype='Contact' 
            and user.frappe_userid is not null
            and user_type='Website User'
            and user.is_active_tortal_lms_user=1
			and contact.is_primary_contact=0
            and customer_type in ('Company','Individual')""".format(
            groupadmin='0'),
        as_list=1)

    # website user - group admin/normal user give access to parent company
    website_parent_admin_normal_details = frappe.db.sql(
        """select user.frappe_userid,'{group}','{groupadmin}'
            from `tabContact` contact
            inner join `tabDynamic Link` customer on
            customer.parent=contact.name
            inner join `tabCustomer` cust on
            cust.name=customer.link_name
            inner join `tabUser` user on
            contact.user=user.name
            where customer.link_doctype='Customer' 
            and customer.parenttype='Contact' 
            and user.frappe_userid is not null
            and user_type='Website User'
            and user.is_active_tortal_lms_user=1
            and customer_type in ('Company','Individual')""".format(
            group=GroupIdentifier, groupadmin='0'),
        as_list=1)

    private_files = get_files_path().replace("/public/", "/private/")
    private_files_path = get_bench_path() + "/sites" + private_files.replace(
        "./", "/")

    with open(private_files_path + '/' + filename, 'wb') as f_handle:
        writer = csv.writer(f_handle)
        # Add the header/column names
        # header = ['EmpIdentifier', 'GroupName', 'GroupAdmin']
        for row in parent_admin_details:
            writer.writerow(row)
        for row in parent_normal_details:
            writer.writerow(row)
        for row in website_admin_details:
            writer.writerow(row)
        for row in website_normal_details:
            writer.writerow(row)
        for row in website_parent_admin_normal_details:
            writer.writerow(row)

    return os.path.realpath(f_handle.name)
Пример #12
0
from __future__ import unicode_literals
import frappe, json, subprocess
from frappe.utils import get_bench_path

site_app = "egd_site"
path_bench = get_bench_path()
path_site_app = "{0}/apps/{1}/".format(path_bench, site_app)


# Called when pushing to: https://github.com/Ayuda-Efectiva/egd_site
# /api/method/egd_site.deploy.github_site
@frappe.whitelist(allow_guest=True)
def github_site():
    return github_signature_deploy("site")


def github_signature_deploy(type="site"):
    import hashlib
    import hmac

    if "payload" not in frappe.form_dict:
        return {"error": "Call without \"payload\" key"}

    payload = frappe.request.data
    payload_obj = dict()
    github_webhooks_secret = bytes(frappe.local.conf.GITHUB_WEBHOOKS_SECRET,
                                   'latin-1')
    signature = hmac.new(github_webhooks_secret, payload,
                         hashlib.sha1).hexdigest()
    header_signature = frappe.request.headers.get('X-Hub-Signature')
    if header_signature:
Пример #13
0
		click.secho("You can enable tests by entering following command:")
		click.secho("bench --site {0} set-config allow_tests true".format(site), fg="green")
		return

	frappe.init(site=site)

	frappe.flags.skip_before_tests = skip_before_tests
	frappe.flags.skip_test_records = skip_test_records

	if coverage:
		from coverage import Coverage

		from frappe.coverage import FRAPPE_EXCLUSIONS, STANDARD_EXCLUSIONS, STANDARD_INCLUSIONS

		# Generate coverage report only for app that is being tested
		source_path = os.path.join(get_bench_path(), "apps", app or "frappe")
		omit = STANDARD_EXCLUSIONS[:]

		if not app or app == "frappe":
			omit.extend(FRAPPE_EXCLUSIONS)

		ret = frappe.test_runner.main(
			app,
			module,
			doctype,
			context.verbose,
			tests=tests,
			force=context.force,
			profile=profile,
			junit_xml_output=junit_xml_output,
			ui_tests=ui_tests,