Merge branch 'develop' into fix/github-issue/29006
This commit is contained in:
commit
cd5836243d
@ -5,7 +5,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.tests.utils import FrappeTestCase
|
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||||
from frappe.utils import add_days, flt, getdate, nowdate
|
from frappe.utils import add_days, flt, getdate, nowdate
|
||||||
from frappe.utils.data import today
|
from frappe.utils.data import today
|
||||||
|
|
||||||
@ -709,13 +709,10 @@ class TestPurchaseOrder(FrappeTestCase):
|
|||||||
pi.insert()
|
pi.insert()
|
||||||
self.assertTrue(pi.get("payment_schedule"))
|
self.assertTrue(pi.get("payment_schedule"))
|
||||||
|
|
||||||
|
@change_settings("Accounts Settings", {"unlink_advance_payment_on_cancelation_of_order": 1})
|
||||||
def test_advance_payment_entry_unlink_against_purchase_order(self):
|
def test_advance_payment_entry_unlink_against_purchase_order(self):
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||||
|
|
||||||
frappe.db.set_value(
|
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 1
|
|
||||||
)
|
|
||||||
|
|
||||||
po_doc = create_purchase_order()
|
po_doc = create_purchase_order()
|
||||||
|
|
||||||
pe = get_payment_entry("Purchase Order", po_doc.name, bank_account="_Test Bank - _TC")
|
pe = get_payment_entry("Purchase Order", po_doc.name, bank_account="_Test Bank - _TC")
|
||||||
@ -735,9 +732,31 @@ class TestPurchaseOrder(FrappeTestCase):
|
|||||||
pe_doc = frappe.get_doc("Payment Entry", pe.name)
|
pe_doc = frappe.get_doc("Payment Entry", pe.name)
|
||||||
pe_doc.cancel()
|
pe_doc.cancel()
|
||||||
|
|
||||||
frappe.db.set_value(
|
@change_settings("Accounts Settings", {"unlink_advance_payment_on_cancelation_of_order": 1})
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0
|
def test_advance_paid_upon_payment_entry_cancellation(self):
|
||||||
)
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||||
|
|
||||||
|
po_doc = create_purchase_order()
|
||||||
|
|
||||||
|
pe = get_payment_entry("Purchase Order", po_doc.name, bank_account="_Test Bank - _TC")
|
||||||
|
pe.reference_no = "1"
|
||||||
|
pe.reference_date = nowdate()
|
||||||
|
pe.paid_from_account_currency = po_doc.currency
|
||||||
|
pe.paid_to_account_currency = po_doc.currency
|
||||||
|
pe.source_exchange_rate = 1
|
||||||
|
pe.target_exchange_rate = 1
|
||||||
|
pe.paid_amount = po_doc.grand_total
|
||||||
|
pe.save(ignore_permissions=True)
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
po_doc.reload()
|
||||||
|
self.assertEqual(po_doc.advance_paid, po_doc.base_grand_total)
|
||||||
|
|
||||||
|
pe_doc = frappe.get_doc("Payment Entry", pe.name)
|
||||||
|
pe_doc.cancel()
|
||||||
|
|
||||||
|
po_doc.reload()
|
||||||
|
self.assertEqual(po_doc.advance_paid, 0)
|
||||||
|
|
||||||
def test_schedule_date(self):
|
def test_schedule_date(self):
|
||||||
po = create_purchase_order(do_not_submit=True)
|
po = create_purchase_order(do_not_submit=True)
|
||||||
|
@ -7,7 +7,7 @@ import json
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, throw
|
from frappe import _, throw
|
||||||
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
|
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Abs, Sum
|
||||||
from frappe.utils import (
|
from frappe.utils import (
|
||||||
add_days,
|
add_days,
|
||||||
add_months,
|
add_months,
|
||||||
@ -1334,30 +1334,20 @@ class AccountsController(TransactionBase):
|
|||||||
return stock_items
|
return stock_items
|
||||||
|
|
||||||
def set_total_advance_paid(self):
|
def set_total_advance_paid(self):
|
||||||
if self.doctype == "Sales Order":
|
ple = frappe.qb.DocType("Payment Ledger Entry")
|
||||||
dr_or_cr = "credit_in_account_currency"
|
party = self.customer if self.doctype == "Sales Order" else self.supplier
|
||||||
rev_dr_or_cr = "debit_in_account_currency"
|
advance = (
|
||||||
party = self.customer
|
frappe.qb.from_(ple)
|
||||||
else:
|
.select(ple.account_currency, Abs(Sum(ple.amount)).as_("amount"))
|
||||||
dr_or_cr = "debit_in_account_currency"
|
.where(
|
||||||
rev_dr_or_cr = "credit_in_account_currency"
|
(ple.against_voucher_type == self.doctype)
|
||||||
party = self.supplier
|
& (ple.against_voucher_no == self.name)
|
||||||
|
& (ple.party == party)
|
||||||
advance = frappe.db.sql(
|
& (ple.delinked == 0)
|
||||||
"""
|
& (ple.company == self.company)
|
||||||
select
|
)
|
||||||
account_currency, sum({dr_or_cr}) - sum({rev_dr_cr}) as amount
|
.run(as_dict=True)
|
||||||
from
|
)
|
||||||
`tabGL Entry`
|
|
||||||
where
|
|
||||||
against_voucher_type = %s and against_voucher = %s and party=%s
|
|
||||||
and docstatus = 1
|
|
||||||
""".format(
|
|
||||||
dr_or_cr=dr_or_cr, rev_dr_cr=rev_dr_or_cr
|
|
||||||
),
|
|
||||||
(self.doctype, self.name, party),
|
|
||||||
as_dict=1,
|
|
||||||
) # nosec
|
|
||||||
|
|
||||||
if advance:
|
if advance:
|
||||||
advance = advance[0]
|
advance = advance[0]
|
||||||
|
@ -6,7 +6,7 @@ import json
|
|||||||
import frappe
|
import frappe
|
||||||
import frappe.permissions
|
import frappe.permissions
|
||||||
from frappe.core.doctype.user_permission.test_user_permission import create_user
|
from frappe.core.doctype.user_permission.test_user_permission import create_user
|
||||||
from frappe.tests.utils import FrappeTestCase
|
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||||
from frappe.utils import add_days, flt, getdate, nowdate, today
|
from frappe.utils import add_days, flt, getdate, nowdate, today
|
||||||
|
|
||||||
from erpnext.controllers.accounts_controller import update_child_qty_rate
|
from erpnext.controllers.accounts_controller import update_child_qty_rate
|
||||||
@ -1346,6 +1346,33 @@ class TestSalesOrder(FrappeTestCase):
|
|||||||
|
|
||||||
self.assertRaises(frappe.LinkExistsError, so_doc.cancel)
|
self.assertRaises(frappe.LinkExistsError, so_doc.cancel)
|
||||||
|
|
||||||
|
@change_settings("Accounts Settings", {"unlink_advance_payment_on_cancelation_of_order": 1})
|
||||||
|
def test_advance_paid_upon_payment_cancellation(self):
|
||||||
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||||
|
|
||||||
|
so = make_sales_order()
|
||||||
|
|
||||||
|
pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Bank - _TC")
|
||||||
|
pe.reference_no = "1"
|
||||||
|
pe.reference_date = nowdate()
|
||||||
|
pe.paid_from_account_currency = so.currency
|
||||||
|
pe.paid_to_account_currency = so.currency
|
||||||
|
pe.source_exchange_rate = 1
|
||||||
|
pe.target_exchange_rate = 1
|
||||||
|
pe.paid_amount = so.grand_total
|
||||||
|
pe.save(ignore_permissions=True)
|
||||||
|
pe.submit()
|
||||||
|
so.reload()
|
||||||
|
|
||||||
|
self.assertEqual(so.advance_paid, so.base_grand_total)
|
||||||
|
|
||||||
|
# cancel advance payment
|
||||||
|
pe.reload()
|
||||||
|
pe.cancel()
|
||||||
|
|
||||||
|
so.reload()
|
||||||
|
self.assertEqual(so.advance_paid, 0)
|
||||||
|
|
||||||
def test_cancel_sales_order_after_cancel_payment_entry(self):
|
def test_cancel_sales_order_after_cancel_payment_entry(self):
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
|||||||
batches = get_batches(item_code, warehouse, qty, throw, serial_no)
|
batches = get_batches(item_code, warehouse, qty, throw, serial_no)
|
||||||
|
|
||||||
for batch in batches:
|
for batch in batches:
|
||||||
if cint(qty) <= cint(batch.qty):
|
if flt(qty) <= flt(batch.qty):
|
||||||
batch_no = batch.batch_id
|
batch_no = batch.batch_id
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user