[Fix] Opportunity status has not changed after making of quotation against it if items has not added in the opportunity (#10351)

This commit is contained in:
rohitwaghchaure
2017-08-10 11:15:50 +05:30
committed by Nabin Hait
parent 5999ade43a
commit 35438b6fc0
4 changed files with 101 additions and 10 deletions

View File

@@ -84,11 +84,19 @@ class Opportunity(TransactionBase):
self.delete_events()
def has_active_quotation(self):
return frappe.db.sql("""
select q.name
from `tabQuotation` q, `tabQuotation Item` qi
where q.name = qi.parent and q.docstatus=1 and qi.prevdoc_docname =%s
and q.status not in ('Lost', 'Closed')""", self.name)
if not self.with_items:
return frappe.get_all('Quotation',
{
'opportunity': self.name,
'status': ("not in", ['Lost', 'Closed']),
'docstatus': 1
}, 'name')
else:
return frappe.db.sql("""
select q.name
from `tabQuotation` q, `tabQuotation Item` qi
where q.name = qi.parent and q.docstatus=1 and qi.prevdoc_docname =%s
and q.status not in ('Lost', 'Closed')""", self.name)
def has_ordered_quotation(self):
return frappe.db.sql("""
@@ -212,6 +220,8 @@ def make_quotation(source_name, target_doc=None):
quotation.run_method("set_missing_values")
quotation.run_method("calculate_taxes_and_totals")
if not source.with_items:
quotation.opportunity = source.name
doclist = get_mapped_doc("Opportunity", source_name, {
"Opportunity": {

View File

@@ -3,9 +3,50 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import today
from erpnext.crm.doctype.opportunity.opportunity import make_quotation
import unittest
test_records = frappe.get_test_records('Opportunity')
class TestOpportunity(unittest.TestCase):
pass
def test_opportunity_status(self):
doc = make_opportunity(with_items=0)
quotation = make_quotation(doc.name)
quotation.append('items', {
"item_code": "_Test Item",
"qty": 1
})
quotation.run_method("set_missing_values")
quotation.run_method("calculate_taxes_and_totals")
quotation.submit()
doc = frappe.get_doc('Opportunity', doc.name)
self.assertEquals(doc.status, "Quotation")
def make_opportunity(**args):
args = frappe._dict(args)
opp_doc = frappe.get_doc({
"doctype": "Opportunity",
"enquiry_from": "Customer" or args.enquiry_from,
"enquiry_type": "Sales",
"with_items": args.with_items or 0,
"transaction_date": today()
})
if opp_doc.enquiry_from == 'Customer':
opp_doc.customer = args.customer or "_Test Customer"
if opp_doc.enquiry_from == 'Lead':
opp_doc.customer = args.lead or "_T-Lead-00001"
if args.with_items:
opp_doc.append('items', {
"item_code": args.item_code or "_Test Item",
"qty": args.qty or 1
})
opp_doc.insert()
return opp_doc