[fix] party status updating bug, fixes #5794, #5796

This commit is contained in:
Rushabh Mehta 2016-07-20 12:08:47 +05:30
parent c0cc9902d9
commit fc8e589295
6 changed files with 126 additions and 90 deletions

View File

@ -181,8 +181,8 @@ def update_outstanding_amt(account, party_type, party, against_voucher_type, aga
# Update outstanding amt on against voucher
if against_voucher_type in ["Sales Invoice", "Purchase Invoice"]:
frappe.db.sql("update `tab%s` set outstanding_amount=%s where name=%s" %
(against_voucher_type, '%s', '%s'), (bal, against_voucher))
ref_doc = frappe.get_doc(against_voucher_type, against_voucher)
ref_doc.db_set('outstanding_amount', bal)
def validate_frozen_account(account, adv_adj=None):
frozen_account = frappe.db.get_value("Account", account, "freeze_account")

View File

@ -9,7 +9,6 @@ from frappe.model.document import Document
from frappe.utils import flt, get_url, nowdate
from erpnext.accounts.party import get_party_account
from erpnext.accounts.utils import get_account_currency
from erpnext.setup.utils import get_exchange_rate
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry, get_company_defaults
class PaymentRequest(Document):
@ -69,8 +68,8 @@ class PaymentRequest(Document):
def send_payment_request(self):
self.payment_url = get_url("/api/method/erpnext.accounts.doctype.payment_request.payment_request.generate_payment_request?name={0}".format(self.name))
if self.payment_url:
frappe.db.set_value(self.doctype, self.name, "payment_url", self.payment_url)
frappe.db.set_value(self.doctype, self.name, "status", "Initiated")
self.db_set('payment_url', self.payment_url)
self.db_set('status', 'Initiated')
def set_as_paid(self):
if frappe.session.user == "Guest":
@ -123,7 +122,7 @@ class PaymentRequest(Document):
payment_entry.submit()
#set status as paid for Payment Request
frappe.db.set_value(self.doctype, self.name, "status", "Paid")
self.db_set('status', 'Paid')
return payment_entry
@ -147,7 +146,7 @@ class PaymentRequest(Document):
pass
def set_as_cancelled(self):
frappe.db.set_value(self.doctype, self.name, "status", "Cancelled")
self.db_set("status", "Cancelled")
def make_communication_entry(self):
"""Make communication entry"""
@ -268,4 +267,3 @@ def generate_payment_request(name):
@frappe.whitelist(allow_guest=True)
def resend_payment_email(docname):
return frappe.get_doc("Payment Request", docname).send_email()

View File

@ -952,6 +952,40 @@ class TestSalesInvoice(unittest.TestCase):
self.assertNotEquals(si.get("items")[0].rate, flt((price_list_rate*25)/100 + price_list_rate))
def test_party_status(self):
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
from frappe.utils import random_string
customer_name = 'test customer for status'
if frappe.db.exists('Customer', customer_name):
customer = frappe.get_doc('Customer', customer_name)
customer.db_set('status', 'Active')
else:
customer = frappe.get_doc({
'doctype': 'Customer',
'customer_name': customer_name,
'customer_group': 'Commercial',
'customer_type': 'Individual',
'territory': 'Rest of the World'
}).insert()
self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
invoice = create_sales_invoice(customer="test customer for status",
debit_to="_Test Receivable - _TC",
currency="USD", conversion_rate=50)
self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Open')
pe = get_payment_entry(invoice.doctype, invoice.name)
pe.reference_no = random_string(10)
pe.reference_date = invoice.posting_date
pe.insert()
pe.submit()
self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
def create_sales_invoice(**args):
si = frappe.new_doc("Sales Invoice")
args = frappe._dict(args)

View File

@ -19,7 +19,7 @@ default_status = {
'Supplier': None
}
def notify_status(doc, method):
def notify_status(doc, method=None):
'''Notify status to customer, supplier'''
party_type = None
@ -59,6 +59,7 @@ def notify_status(doc, method):
update_status(party)
party.update_modified()
party.notify_update()
def get_party_status(doc):
'''return party status based on open documents'''

View File

@ -6,6 +6,7 @@ import frappe
from frappe.utils import flt, comma_or
from frappe import _
from frappe.model.document import Document
from erpnext.accounts.party_status import notify_status
def validate_status(status, options):
if status not in options:
@ -106,8 +107,7 @@ class StatusUpdater(Document):
self.add_comment("Label", _(self.status))
if update:
frappe.db.set_value(self.doctype, self.name, "status", self.status,
update_modified=update_modified)
self.db_set('status', self.status, update_modified = update_modified)
def validate_qty(self):
"""Validates qty at row level"""
@ -263,6 +263,7 @@ class StatusUpdater(Document):
target = frappe.get_doc(args["target_parent_dt"], args["name"])
target.set_status(update=True)
target.notify_update()
notify_status(target)
def _update_modified(self, args, update_modified):
args['update_modified'] = ''
@ -296,14 +297,16 @@ class StatusUpdater(Document):
per_billed = ((ref_doc_qty if billed_qty > ref_doc_qty else billed_qty)\
/ ref_doc_qty)*100
frappe.db.set_value(ref_dt, ref_dn, "per_billed", per_billed)
ref_doc = frappe.get_doc(ref_dt, ref_dn)
ref_doc.db_set("per_billed", per_billed)
if frappe.get_meta(ref_dt).get_field("billing_status"):
if per_billed < 0.001: billing_status = "Not Billed"
elif per_billed >= 99.99: billing_status = "Fully Billed"
else: billing_status = "Partly Billed"
frappe.db.set_value(ref_dt, ref_dn, "billing_status", billing_status)
ref_doc.db_set('billing_status', billing_status)
def get_tolerance_for(item_code, item_tolerance={}, global_tolerance=None):
"""

View File

@ -298,7 +298,7 @@ class SalesOrder(SellingController):
delivered_qty += item.delivered_qty
tot_qty += item.qty
frappe.db.set_value("Sales Order", self.name, "per_delivered", flt(delivered_qty/tot_qty) * 100,
self.db_set("per_delivered", flt(delivered_qty/tot_qty) * 100,
update_modified=False)
def set_indicator(self):