[fixes] field renaming, cart checkout fixes, JE fixes for multi-currency payment

This commit is contained in:
Saurabh 2016-02-10 12:33:44 +05:30
parent 883cc04701
commit dca6302e15
8 changed files with 129 additions and 40 deletions

View File

@ -551,7 +551,7 @@ def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None, a
}
@frappe.whitelist()
def get_payment_entry_against_order(dt, dn, amount=None, journal_entry=False, bank_account=None):
def get_payment_entry_against_order(dt, dn, base_rounded_total=None, rounded_total=None, journal_entry=False, bank_account=None):
ref_doc = frappe.get_doc(dt, dn)
if flt(ref_doc.per_billed, 2) > 0:
@ -569,7 +569,7 @@ def get_payment_entry_against_order(dt, dn, amount=None, journal_entry=False, ba
party_account = get_party_account(party_type, ref_doc.get(party_type.lower()), ref_doc.company)
party_account_currency = get_account_currency(party_account)
if not amount:
if not base_rounded_total or not rounded_total:
if party_account_currency == ref_doc.company_currency:
amount = flt(ref_doc.base_grand_total) - flt(ref_doc.advance_paid)
else:
@ -581,7 +581,8 @@ def get_payment_entry_against_order(dt, dn, amount=None, journal_entry=False, ba
"party_account_currency": party_account_currency,
"amount_field_party": amount_field_party,
"amount_field_bank": amount_field_bank,
"amount": amount,
"amount": base_rounded_total or amount,
"rounded_total": rounded_total,
"remarks": 'Advance Payment received against {0} {1}'.format(dt, dn),
"is_advance": "Yes",
"bank_account": bank_account,
@ -589,7 +590,7 @@ def get_payment_entry_against_order(dt, dn, amount=None, journal_entry=False, ba
})
@frappe.whitelist()
def get_payment_entry_against_invoice(dt, dn, amount=None, journal_entry=False, bank_account=None):
def get_payment_entry_against_invoice(dt, dn, base_rounded_total=None, rounded_total=None, journal_entry=False, bank_account=None):
ref_doc = frappe.get_doc(dt, dn)
if dt == "Sales Invoice":
party_type = "Customer"
@ -613,7 +614,8 @@ def get_payment_entry_against_invoice(dt, dn, amount=None, journal_entry=False,
"party_account_currency": ref_doc.party_account_currency,
"amount_field_party": amount_field_party,
"amount_field_bank": amount_field_bank,
"amount": amount if amount else abs(ref_doc.outstanding_amount),
"amount": base_rounded_total if base_rounded_total else abs(ref_doc.outstanding_amount),
"rounded_total": rounded_total,
"remarks": 'Payment received against {0} {1}. {2}'.format(dt, dn, ref_doc.remarks),
"is_advance": "No",
"bank_account": bank_account,
@ -662,10 +664,11 @@ def get_payment_entry(ref_doc, args):
bank_row.cost_center = cost_center
amount = args.get("rounded_total") or args.get("amount")
if bank_row.account_currency == args.get("party_account_currency"):
bank_row.set(args.get("amount_field_bank"), args.get("amount"))
bank_row.set(args.get("amount_field_bank"), amount)
else:
bank_row.set(args.get("amount_field_bank"), args.get("amount") * exchange_rate)
bank_row.set(args.get("amount_field_bank"), amount * exchange_rate)
# set multi currency check
if party_row.account_currency != ref_doc.company_currency \

View File

@ -8,7 +8,7 @@ from frappe.model.document import Document
class PaymentGatewayAccount(Document):
def autoname(self):
self.name = self.gateway + " - " + self.currency
self.name = self.payment_gateway + " - " + self.currency
def validate(self):
self.currency = frappe.db.get_value("Account", self.payment_account, "account_currency")
@ -24,4 +24,4 @@ class PaymentGatewayAccount(Document):
def set_as_default_if_not_set(self):
if not frappe.db.get_value("Payment Gateway Account",
{"is_default": 1, "name": ("!=", self.name)}, "name"):
self.is_default = 1
self.is_default = 1

View File

@ -37,13 +37,13 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "amount",
"fieldname": "base_rounded_total",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Amount",
"label": "Base Rounded Total",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -57,6 +57,30 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "rounded_total",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Rounded Total",
"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,
"bold": 0,
@ -579,7 +603,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-01-21 11:44:04.920584",
"modified": "2016-02-09 21:15:55.153924",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Request",

View File

@ -8,7 +8,7 @@ from frappe import _
from frappe.model.document import Document
from frappe.utils import flt, nowdate, get_url, cstr
from erpnext.accounts.party import get_party_account
from erpnext.accounts.utils import get_account_currency, get_balance_on
from erpnext.accounts.utils import get_balance_on
from erpnext.accounts.doctype.journal_entry.journal_entry import (get_payment_entry_against_invoice,
get_payment_entry_against_order)
@ -80,29 +80,27 @@ class PaymentRequest(Document):
def create_journal_entry(self):
"""create entry"""
payment_details = {
"amount": self.amount,
"journal_entry": True,
"bank_account": self.payment_account
}
frappe.flags.ignore_account_permission = True
if self.reference_doctype == "Sales Order":
jv = get_payment_entry_against_order(self.reference_doctype, self.reference_name,\
amount=self.amount, journal_entry=True, bank_account=self.payment_account)
base_rounded_total=self.base_rounded_total, rounded_total= self.rounded_total,\
journal_entry=True, bank_account=self.payment_account)
if self.reference_doctype == "Sales Invoice":
jv = get_payment_entry_against_invoice(self.reference_doctype, self.reference_name,\
amount=self.amount, journal_entry=True, bank_account=self.payment_account)
base_rounded_total=self.base_rounded_total, rounded_total= self.rounded_total, \
journal_entry=True, bank_account=self.payment_account)
jv.update({
"voucher_type": "Journal Entry",
"posting_date": nowdate()
})
})
print jv.as_dict()
jv.insert(ignore_permissions=True)
jv.submit()
#set status as paid for Payment Request
frappe.db.set_value(self.doctype, self.name, "status", "Paid")
@ -148,20 +146,23 @@ def make_payment_request(**args):
ref_doc = frappe.get_doc(args.dt, args.dn)
gateway_account = get_gateway_details(args)
base_rounded_total, rounded_total = get_amount(ref_doc, args.dt)
existing_payment_request = frappe.db.get_value("Payment Request",
{"reference_doctype": args.dt, "reference_name": args.dn})
if existing_payment_request:
pr = frappe.get_doc("Payment Request", existing_payment_request)
else:
else:
pr = frappe.new_doc("Payment Request")
pr.update({
"payment_gateway": gateway_account.name,
"gateway": gateway_account.gateway,
"payment_gateway_account": gateway_account.name,
"payment_gateway": gateway_account.payment_gateway,
"payment_account": gateway_account.payment_account,
"currency": ref_doc.currency,
"make_sales_invoice": args.cart or 0,
"amount": get_amount(ref_doc, args.dt),
"base_rounded_total": base_rounded_total,
"rounded_total": rounded_total,
"mute_email": args.mute_email or 0,
"email_to": args.recipient_id or "",
"subject": "Payment Request for %s"%args.dn,
@ -178,11 +179,12 @@ def make_payment_request(**args):
if args.submit_doc:
pr.insert(ignore_permissions=True)
pr.submit()
if args.cart:
generate_payment_request(pr.name)
frappe.db.commit()
if not args.cart:
return pr
@ -191,13 +193,16 @@ def make_payment_request(**args):
def get_amount(ref_doc, dt):
"""get amount based on doctype"""
if dt == "Sales Order":
amount = flt(ref_doc.base_grand_total) - flt(ref_doc.advance_paid)
base_rounded_total = flt(ref_doc.base_grand_total)
rounded_total = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
if dt == "Sales Invoice":
amount = abs(ref_doc.outstanding_amount)
base_rounded_total = flt(ref_doc.base_grand_total)
rounded_total = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
if amount > 0:
return amount
if base_rounded_total > 0 and rounded_total > 0 :
return base_rounded_total, rounded_total
else:
frappe.throw(_("Payment Entry is already created"))

View File

@ -246,6 +246,6 @@ erpnext.patches.v6_16.update_billing_status_in_dn_and_pr
erpnext.patches.v6_16.create_manufacturer_records
execute:frappe.db.sql("update `tabPricing Rule` set title=name where title='' or title is null") #2016-01-27
erpnext.patches.v6_20.set_party_account_currency_in_orders
erpnext.patches.v6_19.comment_feed_communication
#erpnext.patches.v6_19.comment_feed_communication
erpnext.patches.v6_21.fix_reorder_level
erpnext.patches.v6_21.rename_material_request_fields

View File

@ -226,6 +226,7 @@
"bold": 0,
"collapsible": 0,
"default": "Orders",
"description": "After payment completion redirect user to selected page.",
"fieldname": "payment_success_url",
"fieldtype": "Select",
"hidden": 0,
@ -246,6 +247,54 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_11",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"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,
"bold": 0,
"collapsible": 0,
"fieldname": "payment_gateway_account",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Payment Gateway Account",
"length": 0,
"no_copy": 0,
"options": "Payment Gateway Account",
"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
}
],
"hide_heading": 0,
@ -258,7 +307,7 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"modified": "2016-02-01 11:58:39.741582",
"modified": "2016-02-09 15:45:03.389220",
"modified_by": "Administrator",
"module": "Shopping Cart",
"name": "Shopping Cart Settings",

View File

@ -1,12 +1,15 @@
{% from "erpnext/templates/includes/cart/cart_macros.html"
import show_address %}
<div class="row">
{% if addresses|length == 1%}
{% set select_address = True %}
{% endif %}
<div class="col-sm-6">
<h4>{{ _("Shipping Address") }}</h4>
<div id="cart-shipping-address" class="panel-group"
data-fieldname="shipping_address_name">
{% for address in addresses %}
{{ show_address(address, doc, "shipping_address_name") }}
{{ show_address(address, doc, "shipping_address_name", select_address) }}
{% endfor %}
</div>
<a class="btn btn-default btn-sm" href="/addresses">
@ -17,7 +20,7 @@
<div id="cart-billing-address" class="panel-group"
data-fieldname="customer_address">
{% for address in addresses %}
{{ show_address(address, doc, "customer_address") }}
{{ show_address(address, doc, "customer_address", select_address) }}
{% endfor %}
</div>
</div>

View File

@ -1,5 +1,10 @@
{% macro show_address(address, doc, fieldname) %}
{% set selected=address.name==doc.get(fieldname) %}
{% macro show_address(address, doc, fieldname, select_address=False) %}
{% if select_address %}
{% set selected=True %}
{% else %}
{% set selected=address.name==doc.get(fieldname) %}
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">