def work(domain="Manufacturing"): frappe.set_user(frappe.db.get_global("demo_sales_user_2")) for i in range(random.randint(1, 7)): if random.random() < 0.5: make_opportunity(domain) for i in range(random.randint(1, 3)): if random.random() < 0.5: make_quotation(domain) try: lost_reason = frappe.get_doc({ "doctype": "Opportunity Lost Reason", "lost_reason": "Did not ask" }) lost_reason.save(ignore_permissions=True) except frappe.exceptions.DuplicateEntryError: pass # lost quotations / inquiries if random.random() < 0.3: for i in range(random.randint(1, 3)): quotation = get_random("Quotation", doc=True) if quotation and quotation.status == "Submitted": quotation.declare_order_lost([{"lost_reason": "Did not ask"}]) for i in range(random.randint(1, 3)): opportunity = get_random("Opportunity", doc=True) if opportunity and opportunity.status in ("Open", "Replied"): opportunity.declare_enquiry_lost([{ "lost_reason": "Did not ask" }]) for i in range(random.randint(1, 3)): if random.random() < 0.6: make_sales_order() if random.random() < 0.5: # make payment request against Sales Order sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) try: if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) if flt(so.per_billed) != 100: payment_request = make_payment_request( dt="Sales Order", dn=so.name, recipient_id=so.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True, ) payment_entry = frappe.get_doc( make_payment_entry(payment_request.name)) payment_entry.posting_date = frappe.flags.current_date payment_entry.submit() except Exception: pass
def work(): frappe.set_user(frappe.db.get_global('demo_sales_user_2')) if random.random() < 0.5: for i in xrange(random.randint(1, 7)): make_opportunity() if random.random() < 0.5: for i in xrange(random.randint(1, 3)): make_quotation() # lost quotations / inquiries if random.random() < 0.3: for i in xrange(random.randint(1, 3)): quotation = get_random('Quotation', doc=True) if quotation and quotation.status == 'Submitted': quotation.declare_order_lost('Did not ask') for i in xrange(random.randint(1, 3)): opportunity = get_random('Opportunity', doc=True) if opportunity and opportunity.status in ('Open', 'Replied'): opportunity.declare_enquiry_lost('Did not ask') if random.random() < 0.3: for i in xrange(random.randint(1, 3)): make_sales_order()
def work(): frappe.set_user(frappe.db.get_global('demo_sales_user_2')) if random.random() < 0.5: for i in xrange(random.randint(1,7)): make_opportunity() if random.random() < 0.5: for i in xrange(random.randint(1,3)): make_quotation() # lost quotations / inquiries if random.random() < 0.3: for i in xrange(random.randint(1,3)): quotation = get_random('Quotation', doc=True) if quotation and quotation.status == 'Submitted': quotation.declare_order_lost('Did not ask') for i in xrange(random.randint(1,3)): opportunity = get_random('Opportunity', doc=True) if opportunity and opportunity.status in ('Open', 'Replied'): opportunity.declare_enquiry_lost('Did not ask') if random.random() < 0.3: for i in xrange(random.randint(1,3)): make_sales_order()
def run_sales(current_date): if can_make("Opportunity"): for i in xrange(how_many("Opportunity")): make_opportunity(current_date) if can_make("Quotation"): for i in xrange(how_many("Quotation")): make_quotation(current_date) if can_make("Sales Order"): for i in xrange(how_many("Sales Order")): make_sales_order(current_date)
def work(domain="Manufacturing"): frappe.set_user(frappe.db.get_global('demo_sales_user_2')) for i in range(random.randint(1, 7)): if random.random() < 0.5: make_opportunity(domain) for i in range(random.randint(1, 3)): if random.random() < 0.5: make_quotation(domain) # lost quotations / inquiries if random.random() < 0.3: for i in range(random.randint(1, 3)): quotation = get_random('Quotation', doc=True) if quotation and quotation.status == 'Submitted': quotation.declare_order_lost('Did not ask') for i in range(random.randint(1, 3)): opportunity = get_random('Opportunity', doc=True) if opportunity and opportunity.status in ('Open', 'Replied'): opportunity.declare_enquiry_lost('Did not ask') for i in range(random.randint(1, 3)): if random.random() < 0.6: make_sales_order() if random.random() < 0.5: #make payment request against Sales Order sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) try: if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) if flt(so.per_billed) != 100: payment_request = make_payment_request( dt="Sales Order", dn=so.name, recipient_id=so.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True) payment_entry = frappe.get_doc( make_payment_entry(payment_request.name)) payment_entry.posting_date = frappe.flags.current_date payment_entry.submit() except Exception: pass
def make_quotation(current_date): # get open opportunites opportunity = get_random("Opportunity", {"status": "Open"}) if opportunity: from erpnext.crm.doctype.opportunity.opportunity import make_quotation qtn = frappe.get_doc(make_quotation(opportunity)) qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit() else: # make new directly qtn = frappe.get_doc({ "creation": current_date, "doctype": "Quotation", "quotation_to": "Customer", "customer": get_random("Customer"), "order_type": "Sales", "transaction_date": current_date, "fiscal_year": cstr(current_date.year) }) add_random_children(qtn, "items", rows=3, randomize = { "qty": (1, 5), "item_code": ("Item", {"is_sales_item": "Yes", "ifnull(has_variants,0)": "0"}) }, unique="item_code") qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
def make_quotation(current_date): # get open opportunites opportunity = get_random("Opportunity", {"status": "Open"}) if opportunity: from erpnext.crm.doctype.opportunity.opportunity import make_quotation qtn = frappe.get_doc(make_quotation(opportunity)) qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit() else: # make new directly qtn = frappe.get_doc({ "creation": current_date, "doctype": "Quotation", "quotation_to": "Customer", "customer": get_random("Customer"), "order_type": "Sales", "transaction_date": current_date, "fiscal_year": cstr(current_date.year) }) add_random_children(qtn, "items", rows=3, randomize = { "qty": (1, 5), "item_code": ("Item", {"is_sales_item": 1, "ifnull(has_variants,0)": "0"}) }, unique="item_code") qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
def make_quotation(domain): # get open opportunites opportunity = get_random("Opportunity", { "status": "Open", "with_items": 1 }) if opportunity: from erpnext.crm.doctype.opportunity.opportunity import make_quotation qtn = frappe.get_doc(make_quotation(opportunity)) qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit() else: # make new directly # get customer, currency and exchange_rate customer = get_random("Customer") company_currency = frappe.get_cached_value( 'Company', erpnext.get_default_company(), "default_currency") party_account_currency = get_party_account_currency( "Customer", customer, erpnext.get_default_company()) if company_currency == party_account_currency: exchange_rate = 1 else: exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_selling") qtn = frappe.get_doc({ "creation": frappe.flags.current_date, "doctype": "Quotation", "quotation_to": "Customer", "party_name": customer, "currency": party_account_currency or company_currency, "conversion_rate": exchange_rate, "order_type": "Sales", "transaction_date": frappe.flags.current_date, }) add_random_children(qtn, "items", rows=3, randomize={ "qty": (1, 5), "item_code": ("Item", { "has_variants": "0", "is_fixed_asset": 0, "domain": domain }) }, unique="item_code") qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
def work(): frappe.set_user(frappe.db.get_global("demo_sales_user_2")) if random.random() < 0.5: for i in xrange(random.randint(1, 7)): make_opportunity() if random.random() < 0.5: for i in xrange(random.randint(1, 3)): make_quotation() # lost quotations / inquiries if random.random() < 0.3: for i in xrange(random.randint(1, 3)): quotation = get_random("Quotation", doc=True) if quotation and quotation.status == "Submitted": quotation.declare_order_lost("Did not ask") for i in xrange(random.randint(1, 3)): opportunity = get_random("Opportunity", doc=True) if opportunity and opportunity.status in ("Open", "Replied"): opportunity.declare_enquiry_lost("Did not ask") if random.random() < 0.3: for i in xrange(random.randint(1, 3)): make_sales_order() if random.random() < 0.1: # make payment request against Sales Order sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) if flt(so.per_billed) != 100: payment_request = make_payment_request( dt="Sales Order", dn=so.name, recipient_id=so.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True, ) payment_entry = frappe.get_doc(make_payment_entry(payment_request.name)) payment_entry.posting_date = frappe.flags.current_date payment_entry.submit()
def work(domain="Manufacturing"): frappe.set_user(frappe.db.get_global('demo_sales_user_2')) for i in range(random.randint(1,7)): if random.random() < 0.5: make_opportunity(domain) for i in range(random.randint(1,3)): if random.random() < 0.5: make_quotation(domain) # lost quotations / inquiries if random.random() < 0.3: for i in range(random.randint(1,3)): quotation = get_random('Quotation', doc=True) if quotation and quotation.status == 'Submitted': quotation.declare_order_lost('Did not ask') for i in range(random.randint(1,3)): opportunity = get_random('Opportunity', doc=True) if opportunity and opportunity.status in ('Open', 'Replied'): opportunity.declare_enquiry_lost('Did not ask') for i in range(random.randint(1,3)): if random.random() < 0.6: make_sales_order() if random.random() < 0.5: #make payment request against Sales Order sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) try: if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) if flt(so.per_billed) != 100: payment_request = make_payment_request(dt="Sales Order", dn=so.name, recipient_id=so.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True) payment_entry = frappe.get_doc(make_payment_entry(payment_request.name)) payment_entry.posting_date = frappe.flags.current_date payment_entry.submit() except Exception: pass
def make_quotation(current_date): # get open opportunites opportunity = get_random("Opportunity", {"status": "Open"}) if opportunity: from erpnext.crm.doctype.opportunity.opportunity import make_quotation qtn = frappe.get_doc(make_quotation(opportunity)) qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit() else: # make new directly # get customer, currency and exchange_rate customer = get_random("Customer") company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency") party_account_currency = get_party_account_currency( "Customer", customer, "Wind Power LLC") if company_currency == party_account_currency: exchange_rate = 1 else: exchange_rate = get_exchange_rate(party_account_currency, company_currency) qtn = frappe.get_doc({ "creation": current_date, "doctype": "Quotation", "quotation_to": "Customer", "customer": customer, "currency": party_account_currency or company_currency, "conversion_rate": exchange_rate, "order_type": "Sales", "transaction_date": current_date, }) add_random_children(qtn, "items", rows=3, randomize={ "qty": (1, 5), "item_code": ("Item", { "is_sales_item": 1, "has_variants": "0" }) }, unique="item_code") qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
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.assertEqual(doc.status, "Quotation")
def make_quotation(): # get open opportunites opportunity = get_random("Opportunity", {"status": "Open", "with_items": 1}) if opportunity: from erpnext.crm.doctype.opportunity.opportunity import make_quotation qtn = frappe.get_doc(make_quotation(opportunity)) qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit() else: # make new directly # get customer, currency and exchange_rate customer = get_random("Customer") company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency") party_account_currency = get_party_account_currency("Customer", customer, "Wind Power LLC") if company_currency == party_account_currency: exchange_rate = 1 else: exchange_rate = get_exchange_rate(party_account_currency, company_currency) qtn = frappe.get_doc( { "creation": frappe.flags.current_date, "doctype": "Quotation", "quotation_to": "Customer", "customer": customer, "currency": party_account_currency or company_currency, "conversion_rate": exchange_rate, "order_type": "Sales", "transaction_date": frappe.flags.current_date, } ) add_random_children( qtn, "items", rows=3, randomize={"qty": (1, 5), "item_code": ("Item", {"has_variants": "0", "is_fixed_asset": 0})}, unique="item_code", ) qtn.insert() frappe.db.commit() qtn.submit() frappe.db.commit()
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 test_carry_forward_of_email_and_comments(self): frappe.db.set_value("CRM Settings", "CRM Settings", "carry_forward_communication_and_comments", 1) lead_doc = make_lead() lead_doc.add_comment("Comment", text="Test Comment 1") lead_doc.add_comment("Comment", text="Test Comment 2") create_communication(lead_doc.doctype, lead_doc.name, lead_doc.email_id) create_communication(lead_doc.doctype, lead_doc.name, lead_doc.email_id) opp_doc = make_opportunity(opportunity_from="Lead", lead=lead_doc.name) opportunity_comment_count = frappe.db.count( "Comment", { "reference_doctype": opp_doc.doctype, "reference_name": opp_doc.name }) opportunity_communication_count = len( get_linked_communication_list(opp_doc.doctype, opp_doc.name)) self.assertEqual(opportunity_comment_count, 2) self.assertEqual(opportunity_communication_count, 2) opp_doc.add_comment("Comment", text="Test Comment 3") opp_doc.add_comment("Comment", text="Test Comment 4") create_communication(opp_doc.doctype, opp_doc.name, opp_doc.contact_email) create_communication(opp_doc.doctype, opp_doc.name, opp_doc.contact_email) quotation_doc = make_quotation(opp_doc.name) quotation_doc.append("items", {"item_code": "_Test Item", "qty": 1}) quotation_doc.run_method("set_missing_values") quotation_doc.run_method("calculate_taxes_and_totals") quotation_doc.save() quotation_comment_count = frappe.db.count( "Comment", { "reference_doctype": quotation_doc.doctype, "reference_name": quotation_doc.name, "comment_type": "Comment", }, ) quotation_communication_count = len( get_linked_communication_list(quotation_doc.doctype, quotation_doc.name)) self.assertEqual(quotation_comment_count, 4) self.assertEqual(quotation_communication_count, 4)
def test_taxes_fetch_via_tax_rule(self): make_tax_rule(customer="_Test Customer", billing_city="_Test City", sales_tax_template="_Test Sales Taxes and Charges Template - _TC", save=1) # create opportunity for customer opportunity = make_opportunity(with_items=1) # make quotation from opportunity quotation = make_quotation(opportunity.name) quotation.save() self.assertEqual(quotation.taxes_and_charges, "_Test Sales Taxes and Charges Template - _TC") # Check if accounts heads and rate fetched are also fetched from tax template or not self.assertTrue(len(quotation.taxes) > 0)
def run(): frappe.set_user("*****@*****.**") frappe.set_user_lang("fr") for i in range(random.randint(1, 7)): if random.random() < 0.5: make_opportunity() for i in range(random.randint(1, 7)): if random.random() < 0.5: make_quotation() try: lost_reason = frappe.get_doc({ "doctype": "Opportunity Lost Reason", "lost_reason": _("Did not ask") }) lost_reason.save(ignore_permissions=True) except frappe.exceptions.DuplicateEntryError: pass # lost quotations / inquiries if random.random() < 0.3: for i in range(random.randint(1, 3)): quotation = get_random('Quotation', doc=True) if quotation and quotation.status == 'Submitted': quotation.declare_order_lost([{ 'lost_reason': _('Did not ask') }]) for i in range(random.randint(1, 3)): opportunity = get_random('Opportunity', doc=True) if opportunity and opportunity.status in ('Open', 'Replied'): opportunity.declare_enquiry_lost([{ 'lost_reason': _('Did not ask') }]) for i in range(random.randint(1, 7)): if random.random() < 0.6: make_sales_order() if random.random() < 0.5: #make payment request against Sales Order sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) try: if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) if flt(so.per_billed) != 100: payment_request = make_payment_request( dt="Sales Order", dn=so.name, recipient_id=so.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True) payment_entry = frappe.get_doc( make_payment_entry(payment_request.name)) payment_entry.posting_date = frappe.flags.current_date payment_entry.submit() except Exception: pass