[enhance] set customer payable account to new customer as per payment gateway account currency via cart if cart and checkout is enable
This commit is contained in:
parent
2dc2d671da
commit
3a2682919a
@ -33,54 +33,6 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"fieldname": "base_rounded_total",
|
|
||||||
"fieldtype": "Currency",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"label": "Base Rounded Total",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "2",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"fieldname": "rounded_total",
|
|
||||||
"fieldtype": "Float",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"label": "Rounded Total",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "2",
|
|
||||||
"print_hide": 0,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -91,7 +43,7 @@
|
|||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
"in_list_view": 0,
|
"in_list_view": 0,
|
||||||
"label": "Currency",
|
"label": "Transaction Currency",
|
||||||
"length": 0,
|
"length": 0,
|
||||||
"no_copy": 0,
|
"no_copy": 0,
|
||||||
"options": "Currency",
|
"options": "Currency",
|
||||||
@ -110,18 +62,44 @@
|
|||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
"collapsible": 0,
|
"collapsible": 0,
|
||||||
"depends_on": "eval:doc.reference_doctype==\"Sales Order\"",
|
"description": "Amount in customer's currency",
|
||||||
"fieldname": "make_sales_invoice",
|
"fieldname": "grand_total",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Currency",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
"in_list_view": 0,
|
"in_list_view": 0,
|
||||||
"label": "Make Sales Invoice",
|
"label": "Grand Total",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"options": "currency",
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "2",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"description": "Amount in company's currency",
|
||||||
|
"fieldname": "base_grand_total",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"label": "Base Grand Total",
|
||||||
"length": 0,
|
"length": 0,
|
||||||
"no_copy": 0,
|
"no_copy": 0,
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
"precision": "",
|
"precision": "2",
|
||||||
"print_hide": 0,
|
"print_hide": 0,
|
||||||
"print_hide_if_no_value": 0,
|
"print_hide_if_no_value": 0,
|
||||||
"read_only": 0,
|
"read_only": 0,
|
||||||
@ -180,6 +158,31 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"depends_on": "eval:doc.reference_doctype==\"Sales Order\"",
|
||||||
|
"fieldname": "make_sales_invoice",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"label": "Make Sales Invoice",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -603,8 +606,8 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2016-02-16 12:29:45.290729",
|
"modified": "2016-02-19 16:19:55.933694",
|
||||||
"modified_by": "saurabh@erpnext.com",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Request",
|
"name": "Payment Request",
|
||||||
"name_case": "",
|
"name_case": "",
|
||||||
|
@ -87,12 +87,12 @@ class PaymentRequest(Document):
|
|||||||
debit_in_account_currency = 0.0
|
debit_in_account_currency = 0.0
|
||||||
|
|
||||||
if party_account_currency == ref_doc.company_currency:
|
if party_account_currency == ref_doc.company_currency:
|
||||||
amount = self.base_rounded_total
|
amount = self.base_grand_total
|
||||||
if self.currency != ref_doc.company_currency:
|
if self.currency != ref_doc.company_currency:
|
||||||
debit_in_account_currency = self.rounded_total
|
debit_in_account_currency = self.grand_total
|
||||||
|
|
||||||
else:
|
else:
|
||||||
amount = self.rounded_total
|
amount = self.grand_total
|
||||||
|
|
||||||
if self.reference_doctype == "Sales Order":
|
if self.reference_doctype == "Sales Order":
|
||||||
jv = get_payment_entry_against_order(self.reference_doctype, self.reference_name,
|
jv = get_payment_entry_against_order(self.reference_doctype, self.reference_name,
|
||||||
@ -160,7 +160,8 @@ def make_payment_request(**args):
|
|||||||
|
|
||||||
gateway_account = get_gateway_details(args)
|
gateway_account = get_gateway_details(args)
|
||||||
|
|
||||||
base_rounded_total, rounded_total = get_amount(ref_doc, args.dt)
|
base_grand_total, grand_total = get_amount(ref_doc, args.dt)
|
||||||
|
|
||||||
existing_payment_request = frappe.db.get_value("Payment Request",
|
existing_payment_request = frappe.db.get_value("Payment Request",
|
||||||
{"reference_doctype": args.dt, "reference_name": args.dn})
|
{"reference_doctype": args.dt, "reference_name": args.dn})
|
||||||
|
|
||||||
@ -175,8 +176,8 @@ def make_payment_request(**args):
|
|||||||
"payment_account": gateway_account.payment_account,
|
"payment_account": gateway_account.payment_account,
|
||||||
"currency": ref_doc.currency,
|
"currency": ref_doc.currency,
|
||||||
"make_sales_invoice": args.cart or 0,
|
"make_sales_invoice": args.cart or 0,
|
||||||
"base_rounded_total": base_rounded_total,
|
"base_grand_total": base_grand_total,
|
||||||
"rounded_total": rounded_total,
|
"grand_total": grand_total,
|
||||||
"mute_email": args.mute_email or 0,
|
"mute_email": args.mute_email or 0,
|
||||||
"email_to": args.recipient_id or "",
|
"email_to": args.recipient_id or "",
|
||||||
"subject": "Payment Request for %s"%args.dn,
|
"subject": "Payment Request for %s"%args.dn,
|
||||||
@ -207,15 +208,15 @@ def make_payment_request(**args):
|
|||||||
def get_amount(ref_doc, dt):
|
def get_amount(ref_doc, dt):
|
||||||
"""get amount based on doctype"""
|
"""get amount based on doctype"""
|
||||||
if dt == "Sales Order":
|
if dt == "Sales Order":
|
||||||
base_rounded_total = flt(ref_doc.base_grand_total)
|
base_grand_total = flt(ref_doc.base_grand_total)
|
||||||
rounded_total = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
|
grand_total = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
|
||||||
|
|
||||||
if dt == "Sales Invoice":
|
if dt == "Sales Invoice":
|
||||||
base_rounded_total = flt(ref_doc.base_grand_total)
|
base_grand_total = flt(ref_doc.base_grand_total)
|
||||||
rounded_total = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
|
grand_total = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
|
||||||
|
|
||||||
if base_rounded_total > 0 and rounded_total > 0 :
|
if base_grand_total > 0 and grand_total > 0 :
|
||||||
return base_rounded_total, rounded_total
|
return base_grand_total, grand_total
|
||||||
|
|
||||||
else:
|
else:
|
||||||
frappe.throw(_("Payment Entry is already created"))
|
frappe.throw(_("Payment Entry is already created"))
|
||||||
|
@ -477,3 +477,17 @@ def get_outstanding_invoices(party_type, party, account, condition=None):
|
|||||||
})
|
})
|
||||||
|
|
||||||
return outstanding_invoices
|
return outstanding_invoices
|
||||||
|
|
||||||
|
|
||||||
|
def get_account(account_type=None, root_type=None, is_group=None, account_name=None):
|
||||||
|
"""return account based on matching conditions"""
|
||||||
|
if account_name:
|
||||||
|
if not frappe.db.get_value("Account", {"account_name": account_name}):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return frappe.get_doc("Account", {
|
||||||
|
"account_type": account_type or '',
|
||||||
|
"root_type": root_type or '',
|
||||||
|
"is_group": is_group or 0,
|
||||||
|
"account_name": account_name or ''
|
||||||
|
})
|
@ -9,6 +9,7 @@ from frappe.utils import cint, flt, get_fullname, cstr
|
|||||||
from erpnext.utilities.doctype.address.address import get_address_display
|
from erpnext.utilities.doctype.address.address import get_address_display
|
||||||
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import get_shopping_cart_settings
|
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import get_shopping_cart_settings
|
||||||
from frappe.utils.nestedset import get_root_of
|
from frappe.utils.nestedset import get_root_of
|
||||||
|
from erpnext.accounts.utils import get_account
|
||||||
|
|
||||||
class WebsitePriceListMissingError(frappe.ValidationError): pass
|
class WebsitePriceListMissingError(frappe.ValidationError): pass
|
||||||
|
|
||||||
@ -280,6 +281,12 @@ def get_customer(user=None):
|
|||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
|
|
||||||
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
||||||
|
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
||||||
|
|
||||||
|
debtors_account = ''
|
||||||
|
|
||||||
|
if cart_settings.enable_checkout:
|
||||||
|
debtors_account = get_debtors_account(cart_settings)
|
||||||
|
|
||||||
if customer:
|
if customer:
|
||||||
return frappe.get_doc("Customer", customer)
|
return frappe.get_doc("Customer", customer)
|
||||||
@ -293,6 +300,15 @@ def get_customer(user=None):
|
|||||||
"customer_group": get_shopping_cart_settings().default_customer_group,
|
"customer_group": get_shopping_cart_settings().default_customer_group,
|
||||||
"territory": get_root_of("Territory")
|
"territory": get_root_of("Territory")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if debtors_account:
|
||||||
|
customer.update({
|
||||||
|
"accounts": [{
|
||||||
|
"company": cart_settings.company,
|
||||||
|
"account": debtors_account.name
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
|
||||||
customer.flags.ignore_mandatory = True
|
customer.flags.ignore_mandatory = True
|
||||||
customer.insert(ignore_permissions=True)
|
customer.insert(ignore_permissions=True)
|
||||||
|
|
||||||
@ -307,6 +323,32 @@ def get_customer(user=None):
|
|||||||
|
|
||||||
return customer
|
return customer
|
||||||
|
|
||||||
|
def get_debtors_account(cart_settings):
|
||||||
|
payment_gateway_account_currency = \
|
||||||
|
frappe.get_doc("Payment Gateway Account", cart_settings.payment_gateway_account).currency
|
||||||
|
|
||||||
|
account_name = _("Debtors ({0})".format(payment_gateway_account_currency))
|
||||||
|
|
||||||
|
debtors_account = get_account("Receivable", "Asset", is_group=0, account_name=account_name)
|
||||||
|
|
||||||
|
if not debtors_account:
|
||||||
|
debtors_account = frappe.get_doc({
|
||||||
|
"doctype": "Account",
|
||||||
|
"account_type": "Receivable",
|
||||||
|
"root_type": "Asset",
|
||||||
|
"is_group": 0,
|
||||||
|
"parent_account": get_account(root_type="Asset", is_group=1, \
|
||||||
|
account_name=_("Accounts Receivable")).name,
|
||||||
|
"account_name": account_name,
|
||||||
|
"currency": payment_gateway_account_currency
|
||||||
|
}).insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
return debtors_account
|
||||||
|
|
||||||
|
else:
|
||||||
|
return debtors_account
|
||||||
|
|
||||||
|
|
||||||
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
|
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
|
||||||
if not party:
|
if not party:
|
||||||
party = get_customer()
|
party = get_customer()
|
||||||
|
@ -6,5 +6,19 @@ $.extend(cur_frm.cscript, {
|
|||||||
if(cur_frm.doc.__onload && cur_frm.doc.__onload.quotation_series) {
|
if(cur_frm.doc.__onload && cur_frm.doc.__onload.quotation_series) {
|
||||||
cur_frm.fields_dict.quotation_series.df.options = cur_frm.doc.__onload.quotation_series;
|
cur_frm.fields_dict.quotation_series.df.options = cur_frm.doc.__onload.quotation_series;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
refresh: function(){
|
||||||
|
toggle_mandatory(cur_frm)
|
||||||
|
},
|
||||||
|
enable_checkout: function(){
|
||||||
|
toggle_mandatory(cur_frm)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function toggle_mandatory (cur_frm){
|
||||||
|
cur_frm.toggle_reqd("payment_gateway_account", false);
|
||||||
|
if(cur_frm.doc.enabled && cur_frm.doc.enable_checkout) {
|
||||||
|
cur_frm.toggle_reqd("payment_gateway_account", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user