Esempio n. 1
0
	def on_update(self):
		create_payment_gateway(
			"Stripe-" + self.gateway_name, settings="Stripe Settings", controller=self.gateway_name
		)
		call_hook_method("payment_gateway_enabled", gateway="Stripe-" + self.gateway_name)
		if not self.flags.ignore_mandatory:
			self.validate_stripe_credentails()
Esempio n. 2
0
    def save_file(self, content=None, decode=False):
        file_exists = False
        self.content = content
        if decode:
            if isinstance(content, text_type):
                self.content = content.encode("utf-8")

            if b"," in self.content:
                self.content = self.content.split(b",")[1]
            self.content = base64.b64decode(self.content)

        if not self.is_private:
            self.is_private = 0
        self.file_size = self.check_max_file_size()
        self.content_hash = get_content_hash(self.content)
        self.content_type = mimetypes.guess_type(self.file_name)[0]

        _file = frappe.get_value("File", {"content_hash": self.content_hash},
                                 ["file_url"])
        if _file:
            self.file_url = _file
            file_exists = True

        if not file_exists:
            if os.path.exists(encode(get_files_path(self.file_name))):
                self.file_name = get_file_name(self.file_name,
                                               self.content_hash[-6:])

            call_hook_method("before_write_file", file_size=self.file_size)
            write_file_method = get_hook_method('write_file')
            if write_file_method:
                return write_file_method(self)
            return self.save_file_on_filesystem()
Esempio n. 3
0
def move():
	"""Plant moving api"""
	items = json.loads(frappe.form_dict.get('items'))
	target = frappe.form_dict.get('target')
	device = frappe.form_dict.get('device')
	plant_room = frappe.get_doc("Plant Room", target)

	plants = []
	invalid_plants = []

	for name in items:
		if device == "mobile":
			filters = {"bio_barcode": name}
		else:
			filters = {"name": name}

		if frappe.db.exists("Plant", filters):
			plants.append(filters)
		else:
			invalid_plants.append(name)

	if len(invalid_plants) == 0:
		moved = []
		for f in plants:
			plant = frappe.get_doc("Plant", f)
			plant.move_to(plant_room)
			moved.append(plant)

		call_hook_method("plant_events", None, "on_plant_move", plants=moved, plant_room=plant_room)
	else:
		frappe.throw("Scanned list have some plants that are not in system. They are: {}".format(", ".join(invalid_plants)))
Esempio n. 4
0
 def on_update(self):
     name = 'Paystack-{0}'.format(self.gateway_name)
     create_payment_gateway(
         name,
         settings='Paystack Settings',
         controller=self.gateway_name
     )
     call_hook_method('payment_gateway_enabled', gateway=name)
Esempio n. 5
0
def do_payment_done(tx_ref, transaction_id, status):
    try:
        call_hook_method('on_payment_authorized',
                         tx_ref=tx_ref,
                         transaction_id=transaction_id,
                         status=status)
    except Exception as e:
        print(e)
Esempio n. 6
0
	def on_update(self):
		create_custom_pos_fields()
		create_payment_gateway('Mpesa-' + self.payment_gateway_name, settings='Mpesa Settings', controller=self.payment_gateway_name)
		call_hook_method('payment_gateway_enabled', gateway='Mpesa-' + self.payment_gateway_name, payment_channel="Phone")

		# required to fetch the bank account details from the payment gateway account
		frappe.db.commit()
		create_mode_of_payment('Mpesa-' + self.payment_gateway_name, payment_type="Phone")
Esempio n. 7
0
    def save_file(self,
                  content=None,
                  decode=False,
                  ignore_existing_file_check=False):
        file_exists = False
        self.content = content

        if decode:
            if isinstance(content, text_type):
                self.content = content.encode("utf-8")

            if b"," in self.content:
                self.content = self.content.split(b",")[1]
            self.content = base64.b64decode(self.content)

        if not self.is_private:
            self.is_private = 0

        self.content_type = mimetypes.guess_type(self.file_name)[0]

        self.file_size = self.check_max_file_size()

        if (self.content_type and "image" in self.content_type
                and frappe.get_system_settings(
                    "strip_exif_metadata_from_uploaded_images")):
            self.content = strip_exif_data(self.content, self.content_type)

        self.content_hash = get_content_hash(self.content)

        duplicate_file = None

        # check if a file exists with the same content hash and is also in the same folder (public or private)
        if not ignore_existing_file_check:
            duplicate_file = frappe.get_value("File", {
                "content_hash": self.content_hash,
                "is_private": self.is_private
            }, ["file_url", "name"],
                                              as_dict=True)

        if duplicate_file:
            file_doc = frappe.get_cached_doc('File', duplicate_file.name)
            if file_doc.exists_on_disk():
                self.file_url = duplicate_file.file_url
                file_exists = True

        if os.path.exists(
                encode(
                    get_files_path(self.file_name,
                                   is_private=self.is_private))):
            self.file_name = get_file_name(self.file_name,
                                           self.content_hash[-6:])

        if not file_exists:
            call_hook_method("before_write_file", file_size=self.file_size)
            write_file_method = get_hook_method('write_file')
            if write_file_method:
                return write_file_method(self)
            return self.save_file_on_filesystem()
Esempio n. 8
0
def harvest_schedule():
	items = json.loads(frappe.form_dict.get('items'))

	plants = []
	for name in items:
		plant = frappe.get_doc("Plant", name)
		if not plant.harvest_scheduled:
			plant.flags.ignore_hooks = True
			plant.harvest_schedule()
			plants.append(plant)

	call_hook_method("plant_events", None, "on_harvest_schedule", plants=plants)
Esempio n. 9
0
def save_file(fname,
              content,
              dt,
              dn,
              folder=None,
              decode=False,
              is_private=0,
              df=None):
    if decode:
        if isinstance(content, text_type):
            content = content.encode("utf-8")

        if b"," in content:
            content = content.split(b",")[1]
        content = base64.b64decode(content)

    file_size = check_max_file_size(content)
    content_hash = get_content_hash(content)
    content_type = mimetypes.guess_type(fname)[0]
    fname = get_file_name(fname, content_hash[-6:])
    file_data = get_file_data_from_hash(content_hash, is_private=is_private)
    if not file_data:
        call_hook_method("before_write_file", file_size=file_size)

        write_file_method = get_hook_method('write_file',
                                            fallback=save_file_on_filesystem)
        file_data = write_file_method(fname,
                                      content,
                                      content_type=content_type,
                                      is_private=is_private)
        file_data = copy(file_data)

    file_data.update({
        "doctype": "File",
        "attached_to_doctype": dt,
        "attached_to_name": dn,
        "attached_to_field": df,
        "folder": folder,
        "file_size": file_size,
        "content_hash": content_hash,
        "is_private": is_private
    })

    f = frappe.get_doc(file_data)
    f.flags.ignore_permissions = True
    try:
        f.insert()
    except frappe.DuplicateEntryError:
        return frappe.get_doc("File", f.duplicate_entry)

    return f
Esempio n. 10
0
def destroy_schedule():
	items = json.loads(frappe.form_dict.get('items'))
	reason = frappe.form_dict.get('reason')
	reason_txt = frappe.form_dict.get('reason_txt')
	override = frappe.form_dict.get('override')
	reason_type = removal_reasons.keys()[removal_reasons.values().index(reason)]

	plants = []
	for name in items:
		plant = frappe.get_doc("Plant", name)
		plant.flags.ignore_hooks = True
		plant.destroy_schedule(reason=reason, reason_txt=reason_txt, override=override)
		plants.append(plant)

	call_hook_method("plant_events", None, "on_destroy_schedule", plants=plants, reason_type=reason_type, reason=reason_txt, override=override)
Esempio n. 11
0
def save_file(fname, content, dt, dn, folder=None, decode=False, is_private=0):
    if decode:
        if isinstance(content, unicode):
            content = content.encode("utf-8")

        if "," in content:
            content = content.split(",")[1]
        content = base64.b64decode(content)

    file_size = check_max_file_size(content)
    content_hash = get_content_hash(content)
    content_type = mimetypes.guess_type(fname)[0]
    fname = get_file_name(fname, content_hash[-6:])
    file_data = get_file_data_from_hash(content_hash, is_private=is_private)
    if not file_data:
        call_hook_method("before_write_file", file_size=file_size)

        write_file_method = get_hook_method("write_file", fallback=save_file_on_filesystem)
        file_data = write_file_method(fname, content, content_type=content_type, is_private=is_private)
        file_data = copy(file_data)

    file_data.update(
        {
            "doctype": "File",
            "attached_to_doctype": dt,
            "attached_to_name": dn,
            "folder": folder,
            "file_size": file_size,
            "content_hash": content_hash,
            "is_private": is_private,
        }
    )

    f = frappe.get_doc(file_data)
    f.flags.ignore_permissions = True
    try:
        f.insert()
    except frappe.DuplicateEntryError:
        return frappe.get_doc("File", f.duplicate_entry)

    return f
Esempio n. 12
0
	def on_update(self):
		create_payment_gateway('Stripe-' + self.gateway_name, settings='Stripe Settings', controller=self.gateway_name)
		call_hook_method('payment_gateway_enabled', gateway='Stripe-' + self.gateway_name)
		if not self.flags.ignore_mandatory:
			self.validate_stripe_credentails()
Esempio n. 13
0
 def enable(self):
     call_hook_method("payment_gateway_enabled", gateway=self.service_name)
	def on_update(self):
		create_payment_gateway('Braintree-' + self.gateway_name, settings='Braintree Settings', controller=self.gateway_name)
		call_hook_method('payment_gateway_enabled', gateway='Braintree-' + self.gateway_name)
Esempio n. 15
0
	def enable(self):
		call_hook_method('payment_gateway_enabled', gateway=self.service_name)
		if not self.flags.ignore_mandatory:
			self.validate_paypal_credentails()
Esempio n. 16
0
 def validate(self):
     create_payment_gateway('Razorpay')
     call_hook_method('payment_gateway_enabled', gateway='Razorpay')
     if not self.flags.ignore_mandatory:
         self.validate_razorpay_credentails()
Esempio n. 17
0
	def on_update(self):
		create_payment_gateway('GoCardless-' + self.gateway_name, settings='GoCardLess Settings', controller=self.gateway_name)
		call_hook_method('payment_gateway_enabled', gateway='GoCardless-' + self.gateway_name)
Esempio n. 18
0
 def enable(self):
     call_hook_method('payment_gateway_enabled', gateway=self.service_name)
     if not self.flags.ignore_mandatory:
         self.validate_paypal_credentails()
Esempio n. 19
0
	def validate(self):
		create_payment_gateway("PayPal")
		call_hook_method('payment_gateway_enabled', gateway="PayPal")
		if not self.flags.ignore_mandatory:
			self.validate_paypal_credentails()
Esempio n. 20
0
 def validate(self):
     create_payment_gateway("Midtrans")
     call_hook_method('payment_gateway_enabled', gateway="Midtrans")
 def validate(self):
     create_payment_gateway("AuthorizeNet")
     call_hook_method("payment_gateway_enabled", gateway=self.service_name)
     if not self.flags.ignore_mandatory:
         self.validate_authorizenet_credentails()
Esempio n. 22
0
	def on_update(self):
		create_payment_gateway('Stripe-' + self.gateway_name, settings='Stripe Settings', controller=self.gateway_name)
		call_hook_method('payment_gateway_enabled', gateway='Stripe-' + self.gateway_name)
		if not self.flags.ignore_mandatory:
			self.validate_stripe_credentials()
Esempio n. 23
0
 def validate(self):
     create_payment_gateway("Gateway Selector")
     call_hook_method("payment_gateway_enabled", gateway=self.service_name)
Esempio n. 24
0
 def validate(self):
     create_payment_gateway('Paytm')
     call_hook_method('payment_gateway_enabled', gateway='Paytm')
Esempio n. 25
0
 def validate(self):
     create_payment_gateway('Authorizenet')
     call_hook_method('payment_gateway_enabled', gateway="Authorizenet")
Esempio n. 26
0
 def on_update(self):
     create_payment_gateway('GoCardless-' + self.gateway_name,
                            settings='GoCardLess Settings',
                            controller=self.gateway_name)
     call_hook_method('payment_gateway_enabled',
                      gateway='GoCardless-' + self.gateway_name)
Esempio n. 27
0
 def validate(self):
     create_payment_gateway("Affirm")
     call_hook_method('payment_gateway_enabled', gateway=self.service_name)
Esempio n. 28
0
	def on_update(self):
		create_payment_gateway('Braintree-' + self.gateway_name, settings='Braintree Settings', controller=self.gateway_name)
		call_hook_method('payment_gateway_enabled', gateway='Braintree-' + self.gateway_name)
Esempio n. 29
0
	def on_update(self):
		create_payment_gateway(
			"GoCardless-" + self.gateway_name, settings="GoCardLess Settings", controller=self.gateway_name
		)
		call_hook_method("payment_gateway_enabled", gateway="GoCardless-" + self.gateway_name)
Esempio n. 30
0
	def sync_file(self, fname, template_path, priority, app):
		'''sync file into Web Page'''
		title = None
		route = os.path.relpath(template_path, self.statics_path).rsplit(".", 1)[0]
		generated = False

		if fname.rsplit(".", 1)[0]=="index" and \
			os.path.dirname(template_path) != self.statics_path:
			route = os.path.dirname(route)

		parent_web_page = frappe.db.sql("""select name from `tabWeb Page` where
			page_name=%s and ifnull(parent_website_route, '')=ifnull(%s, '')""",
				(os.path.basename(os.path.dirname(route)), os.path.dirname(os.path.dirname(route))))

		parent_web_page = parent_web_page and parent_web_page[0][0] or ""

		page_name = os.path.basename(route)

		published = 1
		idx = priority

		if (parent_web_page, page_name) in self.synced:
			return

		with open(template_path, "r") as f:
			content = unicode(f.read().strip(), "utf-8")
			if template_path.endswith('.json'):
				content = json.loads(content)
				title = content.get('title')
				content['page_name'] = page_name
				content = call_hook_method('build_json_page', content)
				generated = True

		if not title:
			title = self.get_title(template_path, content)

		relative_template_path = os.path.join(app, os.path.relpath(template_path, frappe.get_app_path(app)))
		if not frappe.db.get_value("Web Page", {"template_path":relative_template_path}):
			web_page = frappe.new_doc("Web Page")
			web_page.page_name = page_name
			web_page.parent_web_page = parent_web_page
			if not generated:
				web_page.template_path = relative_template_path
			web_page.main_section = content
			web_page.title = title
			web_page.published = published
			web_page.idx = idx
			web_page.from_website_sync = True
			web_page.insert()
			if self.verbose: print "Inserted: " + web_page.name

		else:
			web_page = frappe.get_doc("Web Page", {"template_path":relative_template_path})
			dirty = False
			for key in ("parent_web_page", "title", "published", "idx"):
				if web_page.get(key) != locals().get(key):
					web_page.set(key, locals().get(key))
					dirty = True

			if web_page.template_path != relative_template_path:
				web_page.template_path = relative_template_path
				dirty = True

			if dirty:
				web_page.from_website_sync = True
				web_page.save()
				if self.verbose: print "Updated: " + web_page.name

		self.synced.append((parent_web_page, page_name))
Esempio n. 31
0
	def validate(self):
		create_payment_gateway('Razorpay')
		call_hook_method('payment_gateway_enabled', gateway='Razorpay')
		if not self.flags.ignore_mandatory:
			self.validate_razorpay_credentails()
Esempio n. 32
0
 def validate(self):
     create_payment_gateway("MokaPay")
     call_hook_method("payment_gateway_enabled", gateway=self.service_name)
     if not self.flags.ignore_mandatory:
         self.validate_mokapay_credentails()
Esempio n. 33
0
def handle_subscription_notification(doctype, docname):
	call_hook_method("handle_subscription_notification", doctype=doctype, docname=docname)
Esempio n. 34
0
 def validate(self):
     create_payment_gateway("Paynow")
     call_hook_method('payment_gateway_enabled', gateway="Paynow")
Esempio n. 35
0
 def validate(self):
     create_payment_gateway("PayPal")
     call_hook_method('payment_gateway_enabled', gateway="PayPal")
     if not self.flags.ignore_mandatory:
         self.validate_paypal_credentails()
Esempio n. 36
0
def handle_subscription_notification(doctype, docname):
	call_hook_method("handle_subscription_notification", doctype=doctype, docname=docname)
Esempio n. 37
0
 def validate(self):
     create_payment_gateway("Razorpay")
     call_hook_method("payment_gateway_enabled", gateway="Razorpay")
     if not self.flags.ignore_mandatory:
         self.validate_razorpay_credentails()
Esempio n. 38
0
 def validate(self):
     create_payment_gateway("AFS Payment")
     call_hook_method("payment_gateway_enabled", gateway="AFS Payment")
Esempio n. 39
0
	def on_update(self):
		create_payment_gateway(
			"Braintree-" + self.gateway_name, settings="Braintree Settings", controller=self.gateway_name
		)
		call_hook_method("payment_gateway_enabled", gateway="Braintree-" + self.gateway_name)
Esempio n. 40
0
def sync_if(frequency, default='Daily'):
	settings = frappe.get_doc("BioTrack Settings")
	if settings.is_sync_down_enabled() and (settings.sync_frequency or default) == frequency:
		from erpnext_biotrack.biotrackthc import sync
		sync()
		call_hook_method('biotrack_synced')