From bd2dbecdadfc243ea8568b224b5ece1fa3335ffb Mon Sep 17 00:00:00 2001 From: KerollesFathy Date: Mon, 13 Feb 2023 11:42:38 +0200 Subject: [PATCH 1/3] Added New child table Payment Gateways & when create PE against Si map bank_account to gateway_account. --- .../doctype/payment_gateways/__init__.py | 0 .../payment_gateways/payment_gateways.json | 38 +++++++++++++++++++ .../payment_gateways/payment_gateways.py | 8 ++++ ecommerce_integrations/shopify/invoice.py | 16 ++++++-- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/__init__.py create mode 100644 ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/payment_gateways.json create mode 100644 ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/payment_gateways.py diff --git a/ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/__init__.py b/ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/payment_gateways.json b/ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/payment_gateways.json new file mode 100644 index 00000000..445fdfa1 --- /dev/null +++ b/ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/payment_gateways.json @@ -0,0 +1,38 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2023-02-13 11:37:44.390686", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "gateway_name", + "gateway_account" + ], + "fields": [ + { + "fieldname": "gateway_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Gateway Name" + }, + { + "fieldname": "gateway_account", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Gateway Account", + "options": "Account" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2023-02-13 11:37:44.390686", + "modified_by": "Administrator", + "module": "Ecommerce Integrations", + "name": "Payment Gateways", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/payment_gateways.py b/ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/payment_gateways.py new file mode 100644 index 00000000..ff64b4f9 --- /dev/null +++ b/ecommerce_integrations/ecommerce_integrations/doctype/payment_gateways/payment_gateways.py @@ -0,0 +1,8 @@ +# Copyright (c) 2023, Frappe and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class PaymentGateways(Document): + pass diff --git a/ecommerce_integrations/shopify/invoice.py b/ecommerce_integrations/shopify/invoice.py index 26afb825..9732e96d 100644 --- a/ecommerce_integrations/shopify/invoice.py +++ b/ecommerce_integrations/shopify/invoice.py @@ -52,7 +52,7 @@ def create_sales_invoice(shopify_order, setting, so): sales_invoice.insert(ignore_mandatory=True) sales_invoice.submit() if sales_invoice.grand_total > 0: - make_payament_entry_against_sales_invoice(sales_invoice, setting, posting_date) + make_payament_entry_against_sales_invoice(sales_invoice, setting, shopify_order, posting_date) if shopify_order.get("note"): sales_invoice.add_comment(text=f"Order Note: {shopify_order.get('note')}") @@ -63,13 +63,23 @@ def set_cost_center(items, cost_center): item.cost_center = cost_center -def make_payament_entry_against_sales_invoice(doc, setting, posting_date=None): +def make_payament_entry_against_sales_invoice(doc, settings, shopify_order, posting_date=None): from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry + _bank_account = setting.get('cash_bank_account') + + if len(shopify_order.get('payment_gateway_names')): + doc_gatewaty = shopify_order.get('payment_gateway_names')[0] - payment_entry = get_payment_entry(doc.doctype, doc.name, bank_account=setting.cash_bank_account) + if len(setting.get("payment_gateways")): + for gateway in setting.get("payment_gateways"): + if doc_gatewaty == gateway.get("gateway_name"): + _bank_account = gateway.get("gateway_account") + + payment_entry = get_payment_entry(doc.doctype, doc.name, bank_account=_bank_account) payment_entry.flags.ignore_mandatory = True payment_entry.reference_no = doc.name payment_entry.posting_date = posting_date or nowdate() payment_entry.reference_date = posting_date or nowdate() payment_entry.insert(ignore_permissions=True) payment_entry.submit() + frappe.db.commit() From a4462a3e3ddd5d5fabfa4995e8ee4c36162d3fde Mon Sep 17 00:00:00 2001 From: KerollesFathy Date: Mon, 13 Feb 2023 11:54:22 +0200 Subject: [PATCH 2/3] fix param name. --- ecommerce_integrations/shopify/invoice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ecommerce_integrations/shopify/invoice.py b/ecommerce_integrations/shopify/invoice.py index 9732e96d..b9c264bc 100644 --- a/ecommerce_integrations/shopify/invoice.py +++ b/ecommerce_integrations/shopify/invoice.py @@ -63,10 +63,10 @@ def set_cost_center(items, cost_center): item.cost_center = cost_center -def make_payament_entry_against_sales_invoice(doc, settings, shopify_order, posting_date=None): +def make_payament_entry_against_sales_invoice(doc, setting, shopify_order, posting_date=None): from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry _bank_account = setting.get('cash_bank_account') - + if len(shopify_order.get('payment_gateway_names')): doc_gatewaty = shopify_order.get('payment_gateway_names')[0] From 572a76ab9ea84d5501dcf117d24e230ffcada913 Mon Sep 17 00:00:00 2001 From: KerollesFathy Date: Mon, 13 Feb 2023 12:26:54 +0200 Subject: [PATCH 3/3] Added Payment Gateways Table on Shopify Setting dt. --- .../doctype/shopify_setting/shopify_setting.json | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ecommerce_integrations/shopify/doctype/shopify_setting/shopify_setting.json b/ecommerce_integrations/shopify/doctype/shopify_setting/shopify_setting.json index d6534057..f06b896b 100644 --- a/ecommerce_integrations/shopify/doctype/shopify_setting/shopify_setting.json +++ b/ecommerce_integrations/shopify/doctype/shopify_setting/shopify_setting.json @@ -35,6 +35,8 @@ "section_break_22", "html_16", "taxes", + "payment_gateways_section", + "payment_gateways", "erpnext_to_shopify_sync_section", "upload_erpnext_items", "update_shopify_item_on_update", @@ -347,12 +349,23 @@ "fieldname": "sync_new_item_as_active", "fieldtype": "Check", "label": "Sync New Items as Active" + }, + { + "fieldname": "payment_gateways_section", + "fieldtype": "Section Break", + "label": "Payment Gateways" + }, + { + "fieldname": "payment_gateways", + "fieldtype": "Table", + "label": "Payment Gateways", + "options": "Payment Gateways" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2022-11-01 16:09:42.685577", + "modified": "2023-02-13 12:24:10.208168", "modified_by": "Administrator", "module": "shopify", "name": "Shopify Setting", @@ -371,6 +384,5 @@ ], "sort_field": "modified", "sort_order": "DESC", - "states": [], "track_changes": 1 } \ No newline at end of file