def get_customer_outstanding_amount(self): from epaas.selling.doctype.sales_order.test_sales_order import make_sales_order outstanding_amt = get_customer_outstanding('_Test Customer', '_Test Company') # If outstanding is negative make a transaction to get positive outstanding amount if outstanding_amt > 0.0: return outstanding_amt item_qty = int((abs(outstanding_amt) + 200) / 100) make_sales_order(qty=item_qty) return get_customer_outstanding('_Test Customer', '_Test Company')
def test_pricing_rule_for_stock_qty(self): test_record = { "doctype": "Pricing Rule", "title": "_Test Pricing Rule", "apply_on": "Item Code", "currency": "USD", "item_code": "_Test Item", "selling": 1, "rate_or_discount": "Discount Percentage", "rate": 0, "min_qty": 5, "max_qty": 7, "discount_percentage": 17.5, "company": "_Test Company" } dataent.get_doc(test_record.copy()).insert() if not dataent.db.get_value('UOM Conversion Detail', { 'parent': '_Test Item', 'uom': 'box' }): item = dataent.get_doc('Item', '_Test Item') item.append('uoms', {'uom': 'Box', 'conversion_factor': 5}) item.save(ignore_permissions=True) # With pricing rule so = make_sales_order(item_code="_Test Item", qty=1, uom="Box", do_not_submit=True) so.items[0].price_list_rate = 100 so.submit() so = dataent.get_doc('Sales Order', so.name) self.assertEqual(so.items[0].discount_percentage, 17.5) self.assertEqual(so.items[0].rate, 82.5) # Without pricing rule so = make_sales_order(item_code="_Test Item", qty=2, uom="Box", do_not_submit=True) so.items[0].price_list_rate = 100 so.submit() so = dataent.get_doc('Sales Order', so.name) self.assertEqual(so.items[0].discount_percentage, 0) self.assertEqual(so.items[0].rate, 100)
def test_result_for_partial_material_request(self): so = make_sales_order() mr=make_material_request(so.name) mr.items[0].qty = 4 mr.schedule_date = add_months(nowdate(),1) mr.submit() report = execute() l = len(report[1]) self.assertEqual((so.items[0].qty - mr.items[0].qty), report[1][l-1]['pending_qty'])
def test_production_plan_sales_orders(self): item = 'Test Production Item 1' so = make_sales_order(item_code=item, qty=5) sales_order = so.name sales_order_item = so.items[0].name pln = dataent.new_doc('Production Plan') pln.company = so.company pln.get_items_from = 'Sales Order' pln.append( 'sales_orders', { 'sales_order': so.name, 'sales_order_date': so.transaction_date, 'customer': so.customer, 'grand_total': so.grand_total }) pln.get_so_items() pln.submit() pln.make_work_order() work_order = dataent.db.get_value( 'Work Order', { 'sales_order': sales_order, 'production_plan': pln.name, 'sales_order_item': sales_order_item }, 'name') wo_doc = dataent.get_doc('Work Order', work_order) wo_doc.update({ 'wip_warehouse': '_Test Warehouse 1 - _TC', 'fg_warehouse': '_Test Warehouse - _TC' }) wo_doc.submit() so_wo_qty = dataent.db.get_value('Sales Order Item', sales_order_item, 'work_order_qty') self.assertTrue(so_wo_qty, 5) pln = dataent.new_doc('Production Plan') pln.update({ 'from_date': so.transaction_date, 'to_date': so.transaction_date, 'customer': so.customer, 'item_code': item }) sales_orders = get_sales_orders(pln) or {} sales_orders = [ d.get('name') for d in sales_orders if d.get('name') == sales_order ] self.assertEqual(sales_orders, [])
def test_customer_credit_limit(self): from epaas.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from epaas.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from epaas.selling.doctype.sales_order.test_sales_order import make_sales_order from epaas.selling.doctype.sales_order.sales_order import make_sales_invoice outstanding_amt = self.get_customer_outstanding_amount() credit_limit = get_credit_limit('_Test Customer', '_Test Company') if outstanding_amt <= 0.0: item_qty = int((abs(outstanding_amt) + 200) / 100) make_sales_order(qty=item_qty) if credit_limit == 0.0: dataent.db.set_value("Customer", '_Test Customer', 'credit_limit', outstanding_amt - 50.0) # Sales Order so = make_sales_order(do_not_submit=True) self.assertRaises(dataent.ValidationError, so.submit) # Delivery Note dn = create_delivery_note(do_not_submit=True) self.assertRaises(dataent.ValidationError, dn.submit) # Sales Invoice si = create_sales_invoice(do_not_submit=True) self.assertRaises(dataent.ValidationError, si.submit) if credit_limit > outstanding_amt: dataent.db.set_value("Customer", '_Test Customer', 'credit_limit', credit_limit) # Makes Sales invoice from Sales Order so.save(ignore_permissions=True) si = make_sales_invoice(so.name) si.save(ignore_permissions=True) self.assertRaises(dataent.ValidationError, make_sales_order)
def test_freezed_customer(self): make_test_records("Item") dataent.db.set_value("Customer", "_Test Customer", "is_frozen", 1) from epaas.selling.doctype.sales_order.test_sales_order import make_sales_order so = make_sales_order(do_not_save=True) self.assertRaises(PartyFrozen, so.save) dataent.db.set_value("Customer", "_Test Customer", "is_frozen", 0) so.save()
def test_dn_billing_status_case1(self): # SO -> DN -> SI so = make_sales_order() dn = create_dn_against_so(so.name, delivered_qty=2) self.assertEqual(dn.status, "To Bill") self.assertEqual(dn.per_billed, 0) si = make_sales_invoice(dn.name) si.submit() dn.load_from_db() self.assertEqual(dn.get("items")[0].billed_amt, 200) self.assertEqual(dn.per_billed, 100) self.assertEqual(dn.status, "Completed")
def test_payment_request_linkings(self): so_inr = make_sales_order(currency="INR") pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="*****@*****.**") self.assertEqual(pr.reference_doctype, "Sales Order") self.assertEqual(pr.reference_name, so_inr.name) self.assertEqual(pr.currency, "INR") conversion_rate = get_exchange_rate("USD", "INR") si_usd = create_sales_invoice(currency="USD", conversion_rate=conversion_rate) pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="*****@*****.**") self.assertEqual(pr.reference_doctype, "Sales Invoice") self.assertEqual(pr.reference_name, si_usd.name) self.assertEqual(pr.currency, "USD")
def test_dn_billing_status_case4(self): # SO -> SI -> DN from epaas.selling.doctype.sales_order.sales_order import make_sales_invoice from epaas.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note so = make_sales_order() si = make_sales_invoice(so.name) si.submit() dn = make_delivery_note(si.name) dn.submit() self.assertEqual(dn.get("items")[0].billed_amt, 1000) self.assertEqual(dn.per_billed, 100) self.assertEqual(dn.status, "Completed")
def test_make_sales_invoice_from_dn_for_returned_qty(self): from epaas.selling.doctype.sales_order.sales_order import make_delivery_note from epaas.stock.doctype.delivery_note.delivery_note import make_sales_invoice so = make_sales_order(qty=2) so.submit() dn = make_delivery_note(so.name) dn.submit() dn1 = create_delivery_note(is_return=1, return_against=dn.name, qty=-1, do_not_submit=True) dn1.items[0].against_sales_order = so.name dn1.items[0].so_detail = so.items[0].name dn1.submit() si = make_sales_invoice(dn.name) self.assertEquals(si.items[0].qty, 1)
def test_over_production_for_sales_order(self): so = make_sales_order(item_code="_Test FG Item", qty=2) allow_overproduction("overproduction_percentage_for_sales_order", 0) wo_order = make_wo_order_test_record(planned_start_date=now(), sales_order=so.name, qty=3, do_not_save=True) self.assertRaises(OverProductionError, wo_order.save) allow_overproduction("overproduction_percentage_for_sales_order", 50) wo_order = make_wo_order_test_record(planned_start_date=now(), sales_order=so.name, qty=3) wo_order.submit() self.assertEqual(wo_order.docstatus, 1) allow_overproduction("overproduction_percentage_for_sales_order", 0)
def test_payment_entry(self): dataent.db.set_value("Company", "_Test Company", "exchange_gain_loss_account", "_Test Exchange Gain/Loss - _TC") dataent.db.set_value("Company", "_Test Company", "write_off_account", "_Test Write Off - _TC") dataent.db.set_value("Company", "_Test Company", "cost_center", "_Test Cost Center - _TC") so_inr = make_sales_order(currency="INR") pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="*****@*****.**", mute_email=1, submit_doc=1, return_doc=1) pe = pr.set_as_paid() so_inr = dataent.get_doc("Sales Order", so_inr.name) self.assertEqual(so_inr.advance_paid, 1000) si_usd = create_sales_invoice(customer="_Test Customer USD", debit_to="_Test Receivable USD - _TC", currency="USD", conversion_rate=50) pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="*****@*****.**", mute_email=1, payment_gateway="_Test Gateway - USD", submit_doc=1, return_doc=1) pe = pr.set_as_paid() expected_gle = dict((d[0], d) for d in [ ["_Test Receivable USD - _TC", 0, 5000, si_usd.name], [pr.payment_account, 6290.0, 0, None], ["_Test Exchange Gain/Loss - _TC", 0, 1290, None] ]) gl_entries = dataent.db.sql("""select account, debit, credit, against_voucher from `tabGL Entry` where voucher_type='Payment Entry' and voucher_no=%s order by account asc""", pe.name, as_dict=1) self.assertTrue(gl_entries) for i, gle in enumerate(gl_entries): self.assertEqual(expected_gle[gle.account][0], gle.account) self.assertEqual(expected_gle[gle.account][1], gle.debit) self.assertEqual(expected_gle[gle.account][2], gle.credit) self.assertEqual(expected_gle[gle.account][3], gle.against_voucher)
def test_payment_entry_against_order(self): so = make_sales_order() pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Cash - _TC") pe.paid_from = "Debtors - _TC" pe.insert() pe.submit() expected_gle = dict((d[0], d) for d in [ ["Debtors - _TC", 0, 1000, so.name], ["_Test Cash - _TC", 1000.0, 0, None] ]) self.validate_gl_entries(pe.name, expected_gle) so_advance_paid = dataent.db.get_value("Sales Order", so.name, "advance_paid") self.assertEqual(so_advance_paid, 1000) pe.cancel() self.assertFalse(self.get_gle(pe.name)) so_advance_paid = dataent.db.get_value("Sales Order", so.name, "advance_paid") self.assertEqual(so_advance_paid, 0)
def test_dn_billing_status_case3(self): # SO -> DN1 -> SI and SO -> SI and SO -> DN2 from epaas.selling.doctype.sales_order.sales_order \ import make_delivery_note, make_sales_invoice as make_sales_invoice_from_so dataent.db.set_value("Stock Settings", None, "allow_negative_stock", 1) so = make_sales_order() dn1 = make_delivery_note(so.name) dn1.set_posting_time = 1 dn1.posting_time = "10:00" dn1.get("items")[0].qty = 2 dn1.submit() si1 = make_sales_invoice(dn1.name) si1.submit() dn1.load_from_db() self.assertEqual(dn1.per_billed, 100) si2 = make_sales_invoice_from_so(so.name) si2.get("items")[0].qty = 4 si2.submit() dn2 = make_delivery_note(so.name) dn2.posting_time = "08:00" dn2.get("items")[0].qty = 5 dn2.submit() dn1.load_from_db() self.assertEqual(dn1.get("items")[0].billed_amt, 200) self.assertEqual(dn1.per_billed, 100) self.assertEqual(dn1.status, "Completed") self.assertEqual(dn2.get("items")[0].billed_amt, 400) self.assertEqual(dn2.per_billed, 80) self.assertEqual(dn2.status, "To Bill")
def create_sales_orders(): dataent.set_user("Administrator") make_sales_order(company="_Test Company 2", qty=10, customer="_Test Customer 1", transaction_date='2018-02-10', warehouse='Finished Goods - _TC2', currency='EUR') make_sales_order(company="_Test Company 2", qty=10, customer="_Test Customer 1", transaction_date='2018-02-15', warehouse='Finished Goods - _TC2', currency='EUR') make_sales_order(company="_Test Company 2", qty=10, customer="_Test Customer 2", transaction_date='2017-10-10', warehouse='Finished Goods - _TC2', currency='EUR') make_sales_order(company="_Test Company 2", qty=15, customer="_Test Customer 2", transaction_date='2017-09-23', warehouse='Finished Goods - _TC2', currency='EUR') make_sales_order(company="_Test Company 2", qty=20, customer="_Test Customer 3", transaction_date='2017-06-15', warehouse='Finished Goods - _TC2', currency='EUR') make_sales_order(company="_Test Company 2", qty=10, customer="_Test Customer 3", transaction_date='2017-07-10', warehouse='Finished Goods - _TC2', currency='EUR')
def test_jv_against_sales_order(self): from epaas.selling.doctype.sales_order.test_sales_order import make_sales_order sales_order = make_sales_order(do_not_save=True) base_jv = dataent.copy_doc(test_records[0]) self.jv_against_voucher_testcase(base_jv, sales_order)
def test_result_for_so_item(self): so = make_sales_order() report = execute() l = len(report[1]) self.assertEqual(so.items[0].qty, report[1][l-1]['pending_qty'])