fix: create custom pos fields
This commit is contained in:
parent
757fa5d010
commit
27f81e06ea
@ -0,0 +1,44 @@
|
||||
import frappe
|
||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||
|
||||
def create_custom_pos_fields():
|
||||
"""
|
||||
Create custom fields corresponding to POS Settings and POS Invoice
|
||||
"""
|
||||
pos_field = {
|
||||
"POS Invoice": [
|
||||
{
|
||||
"fieldname": "request_for_payment",
|
||||
"label": "Request for Payment",
|
||||
"fieldtype": "Button",
|
||||
"hidden": 1,
|
||||
"insert_after": "contact_email"
|
||||
},
|
||||
]
|
||||
}
|
||||
if not frappe.get_meta("POS Invoice").has_field("request_for_payment"):
|
||||
create_custom_fields(pos_field)
|
||||
|
||||
record_dict = [{
|
||||
"doctype": "POS Field",
|
||||
"fieldname": "contact_mobile",
|
||||
"label": "Mobile No",
|
||||
"fieldtype": "Data",
|
||||
"options": "Phone",
|
||||
"parent": "POS Settings"
|
||||
},
|
||||
{
|
||||
"doctype": "POS Field",
|
||||
"fieldname": "request_for_payment",
|
||||
"label": "Request for Payment",
|
||||
"fieldtype": "Button",
|
||||
"parent": "POS Settings"
|
||||
}
|
||||
]
|
||||
create_pos_settings(record_dict)
|
||||
|
||||
def create_pos_settings(record_dict):
|
||||
for record in record_dict:
|
||||
if frappe.db.exists("POS Field", {"fieldname": record.get("fieldname")}):
|
||||
continue
|
||||
frappe.get_doc(record).insert()
|
@ -15,15 +15,21 @@ from frappe.utils import get_url, call_hook_method, cint, flt, cstr
|
||||
from frappe.integrations.utils import create_request_log, create_payment_gateway
|
||||
from frappe.utils import get_request_site_address
|
||||
from frappe.utils.password import get_decrypted_password
|
||||
from erpnext.erpnext_integrations.utils import create_mode_of_payment
|
||||
from erpnext.erpnext_integrations.doctype.mpesa_settings.mpesa_connector import MpesaConnector
|
||||
from erpnext.erpnext_integrations.doctype.mpesa_settings.mpesa_custom_fields import create_custom_pos_fields
|
||||
|
||||
class MpesaSettings(Document):
|
||||
supported_currencies = ["KSh"]
|
||||
|
||||
def validate(self):
|
||||
create_payment_gateway('Mpesa-' + self.payment_gateway_name, settings='Mpesa Settings', controller=self.payment_gateway_name)
|
||||
create_mode_of_payment('Mpesa-' + self.payment_gateway_name)
|
||||
call_hook_method('payment_gateway_enabled', gateway='Mpesa-' + self.payment_gateway_name)
|
||||
|
||||
def validate_transaction_currency(self, currency):
|
||||
if currency not in self.supported_currencies:
|
||||
frappe.throw(_("Please select another payment method. Mpesa does not support transactions in currency '{0}'").format(currency))
|
||||
|
||||
def on_update(self):
|
||||
create_custom_pos_fields()
|
@ -3,6 +3,7 @@ import frappe
|
||||
from frappe import _
|
||||
import base64, hashlib, hmac
|
||||
from six.moves.urllib.parse import urlparse
|
||||
from erpnext import get_default_company
|
||||
|
||||
def validate_webhooks_request(doctype, hmac_key, secret_key='secret'):
|
||||
def innerfn(fn):
|
||||
@ -41,3 +42,22 @@ def get_webhook_address(connector_name, method, exclude_uri=False):
|
||||
server_url = '{uri.scheme}://{uri.netloc}/api/method/{endpoint}'.format(uri=urlparse(url), endpoint=endpoint)
|
||||
|
||||
return server_url
|
||||
|
||||
def create_mode_of_payment(gateway):
|
||||
payment_gateway_account = frappe.db.get_value("Payment Gateway Account", {
|
||||
"payment_gateway": gateway
|
||||
}, ['payment_account'])
|
||||
|
||||
if not frappe.db.exists("Mode of Payment", gateway) and payment_gateway_account:
|
||||
mode_of_payment = frappe.get_doc({
|
||||
"doctype": "Mode of Payment",
|
||||
"mode_of_payment": gateway,
|
||||
"enabled": 1,
|
||||
"type": "General",
|
||||
"account": {
|
||||
"doctype": "Mode of Payment Account",
|
||||
"company": get_default_company(),
|
||||
"default_account": payment_gateway_account
|
||||
}
|
||||
})
|
||||
mode_of_payment.insert(ignore_permissions=True)
|
Loading…
x
Reference in New Issue
Block a user