[fix] Multi currency advance payment against Order

This commit is contained in:
Nabin Hait 2016-01-27 15:43:12 +05:30
parent c54e25b5c7
commit b2206d1155
5 changed files with 83 additions and 16 deletions

View File

@ -42,6 +42,10 @@ frappe.ui.form.on("Payment Tool", "refresh", function(frm) {
frappe.ui.form.trigger("Payment Tool", "party_type");
});
frappe.ui.form.on("Payment Tool", "party_type", function(frm) {
frm.set_value("received_or_paid", frm.doc.party_type=="Customer" ? "Received" : "Paid");
});
frappe.ui.form.on("Payment Tool", "party", function(frm) {
if(frm.doc.party_type && frm.doc.party) {
return frappe.call({

View File

@ -71,7 +71,9 @@ class PaymentTool(Document):
d2.account = self.payment_account
d2.account_currency = bank_account_currency
d2.account_type = bank_account_type
d2.exchange_rate = get_exchange_rate(self.payment_account, self.company)
d2.exchange_rate = get_exchange_rate(self.payment_account, bank_account_currency, self.company,
debit=(abs(total_payment_amount) if total_payment_amount < 0 else 0),
credit=(total_payment_amount if total_payment_amount > 0 else 0))
d2.account_balance = get_balance_on(self.payment_account)
amount_field_bank = 'debit_in_account_currency' if total_payment_amount < 0 \

View File

@ -1610,6 +1610,7 @@
"label": "Advance Paid",
"length": 0,
"no_copy": 1,
"options": "party_account_currency",
"permlevel": 0,
"print_hide": 1,
"print_hide_if_no_value": 0,
@ -1968,6 +1969,31 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "party_account_currency",
"fieldtype": "Link",
"hidden": 1,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Party Account Currency",
"length": 0,
"no_copy": 1,
"options": "Currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -2508,7 +2534,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-01-15 04:13:35.179163",
"modified": "2016-01-27 15:15:05.213016",
"modified_by": "Administrator",
"module": "Buying",
"name": "Purchase Order",

View File

@ -386,27 +386,37 @@ class AccountsController(TransactionBase):
def set_total_advance_paid(self):
if self.doctype == "Sales Order":
dr_or_cr = "credit_in_account_currency"
party = self.customer
else:
dr_or_cr = "debit_in_account_currency"
party = self.supplier
advance_paid = frappe.db.sql("""
advance = frappe.db.sql("""
select
sum({dr_or_cr})
account_currency, sum({dr_or_cr}) as amount
from
`tabJournal Entry Account`
where
reference_type = %s and reference_name = %s
reference_type = %s and reference_name = %s and party=%s
and docstatus = 1 and is_advance = "Yes"
""".format(dr_or_cr=dr_or_cr), (self.doctype, self.name))
""".format(dr_or_cr=dr_or_cr), (self.doctype, self.name, party), as_dict=1)
if advance_paid:
advance_paid = flt(advance_paid[0][0], self.precision("advance_paid"))
if flt(self.base_grand_total) >= advance_paid:
if advance:
advance_paid = flt(advance[0].amount, self.precision("advance_paid"))
frappe.db.set_value(self.doctype, self.name, "party_account_currency",
advance[0].account_currency)
if advance[0].account_currency == self.currency:
order_total = self.grand_total
else:
order_total = self.base_grand_total
if order_total >= advance_paid:
frappe.db.set_value(self.doctype, self.name, "advance_paid", advance_paid)
else:
frappe.throw(_("Total advance ({0}) against Order {1} cannot be greater \
than the Grand Total ({2})")
.format(advance_paid, self.name, self.base_grand_total))
frappe.throw(_("Total advance ({0}) against Order {1} cannot be greater than the Grand Total ({2})")
.format(advance_paid, self.name, order_total))
@property
def company_abbr(self):

View File

@ -1569,7 +1569,7 @@
"label": "Advance Paid",
"length": 0,
"no_copy": 1,
"options": "Company:company:default_currency",
"options": "party_account_currency",
"permlevel": 0,
"print_hide": 1,
"print_hide_if_no_value": 0,
@ -1959,6 +1959,31 @@
"unique": 0,
"width": "150px"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "party_account_currency",
"fieldtype": "Link",
"hidden": 1,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Party Account Currency",
"length": 0,
"no_copy": 1,
"options": "Currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -2802,7 +2827,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2015-12-29 12:32:45.649349",
"modified": "2016-01-27 15:16:00.560261",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order",