def work(): dataent.set_user(dataent.db.get_global('demo_manufacturing_user')) make_purchase_receipt() make_delivery_note() make_stock_reconciliation() submit_draft_stock_entries() make_sales_return_records() make_purchase_return_records()
def create_dn_against_so(so, delivered_qty=0): dataent.db.set_value("Stock Settings", None, "allow_negative_stock", 1) dn = make_delivery_note(so) dn.get("items")[0].qty = delivered_qty or 5 dn.insert() dn.submit() return dn
def test_block_delivery_note_against_cancelled_sales_order(self): so = make_sales_order() dn = make_delivery_note(so.name) dn.insert() so.cancel() self.assertRaises(dataent.CancelledLinkError, dn.submit)
def test_make_delivery_note(self): so = make_sales_order(do_not_submit=True) self.assertRaises(dataent.ValidationError, make_delivery_note, so.name) so.submit() dn = make_delivery_note(so.name) self.assertEqual(dn.doctype, "Delivery Note") self.assertEqual(len(dn.get("items")), len(so.get("items")))
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 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 create_delivery_note(shopify_order, shopify_settings, so): if not cint(shopify_settings.sync_delivery_note): return for fulfillment in shopify_order.get("fulfillments"): if not dataent.db.get_value("Delivery Note", {"shopify_fulfillment_id": fulfillment.get("id")}, "name")\ and so.docstatus==1: dn = make_delivery_note(so.name) dn.shopify_order_id = fulfillment.get("order_id") dn.shopify_fulfillment_id = fulfillment.get("id") dn.naming_series = shopify_settings.delivery_note_series or "DN-Shopify-" dn.items = get_fulfillment_items(dn.items, fulfillment.get("line_items"), shopify_settings) dn.flags.ignore_mandatory = True dn.save() dataent.db.commit()
def test_create_quotation_with_margin(self): from epaas.selling.doctype.quotation.quotation import make_sales_order from epaas.selling.doctype.sales_order.sales_order \ import make_delivery_note, make_sales_invoice rate_with_margin = flt((1500 * 18.75) / 100 + 1500) test_records[0]['items'][0]['price_list_rate'] = 1500 test_records[0]['items'][0]['margin_type'] = 'Percentage' test_records[0]['items'][0]['margin_rate_or_amount'] = 18.75 quotation = dataent.copy_doc(test_records[0]) quotation.transaction_date = nowdate() quotation.valid_till = add_months(quotation.transaction_date, 1) quotation.insert() self.assertEqual(quotation.get("items")[0].rate, rate_with_margin) self.assertRaises(dataent.ValidationError, make_sales_order, quotation.name) quotation.submit() sales_order = make_sales_order(quotation.name) sales_order.naming_series = "_T-Quotation-" sales_order.transaction_date = "2016-01-01" sales_order.delivery_date = "2016-01-02" sales_order.insert() self.assertEqual(quotation.get("items")[0].rate, rate_with_margin) sales_order.submit() dn = make_delivery_note(sales_order.name) self.assertEqual(quotation.get("items")[0].rate, rate_with_margin) dn.save() si = make_sales_invoice(sales_order.name) self.assertEqual(quotation.get("items")[0].rate, rate_with_margin) si.save()
def make_delivery_note(): # make purchase requests # make delivery notes (if possible) if random.random() < 0.6: from epaas.selling.doctype.sales_order.sales_order import make_delivery_note report = "Ordered Items To Be Delivered" for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="'Total'"]))[:random.randint(1, 3)]: dn = dataent.get_doc(make_delivery_note(so)) dn.posting_date = dataent.flags.current_date for d in dn.get("items"): if not d.expense_account: d.expense_account = ("Cost of Goods Sold - {0}".format( dataent.get_cached_value('Company', dn.company, 'abbr'))) try: dn.insert() dn.submit() dataent.db.commit() except (NegativeStockError, SerialNoRequiredError, SerialNoQtyError, UnableToSelectBatchError): dataent.db.rollback()
def test_serial_no_based_delivery(self): dataent.set_value("Stock Settings", None, "automatically_set_serial_nos_based_on_fifo", 1) from epaas.stock.doctype.item.test_item import make_item item = make_item( "_Reserved_Serialized_Item", { "is_stock_item": 1, "maintain_stock": 1, "has_serial_no": 1, "serial_no_series": "SI.####", "valuation_rate": 500, "item_defaults": [{ "default_warehouse": "_Test Warehouse - _TC", "company": "_Test Company" }] }) dataent.db.sql("""delete from `tabSerial No` where item_code=%s""", (item.item_code)) make_item( "_Test Item A", { "maintain_stock": 1, "valuation_rate": 100, "item_defaults": [{ "default_warehouse": "_Test Warehouse - _TC", "company": "_Test Company" }] }) make_item( "_Test Item B", { "maintain_stock": 1, "valuation_rate": 200, "item_defaults": [{ "default_warehouse": "_Test Warehouse - _TC", "company": "_Test Company" }] }) from epaas.manufacturing.doctype.production_plan.test_production_plan import make_bom make_bom(item=item.item_code, rate=1000, raw_materials=['_Test Item A', '_Test Item B']) so = make_sales_order( **{ "item_list": [{ "item_code": item.item_code, "ensure_delivery_based_on_produced_serial_no": 1, "qty": 1, "rate": 1000 }] }) so.submit() from epaas.manufacturing.doctype.work_order.test_work_order import \ make_wo_order_test_record work_order = make_wo_order_test_record(item=item.item_code, qty=1, do_not_save=True) work_order.fg_warehouse = "_Test Warehouse - _TC" work_order.sales_order = so.name work_order.submit() make_stock_entry(item_code=item.item_code, target="_Test Warehouse - _TC", qty=1) item_serial_no = dataent.get_doc("Serial No", {"item_code": item.item_code}) from epaas.manufacturing.doctype.work_order.work_order import \ make_stock_entry as make_production_stock_entry se = dataent.get_doc( make_production_stock_entry(work_order.name, "Manufacture", 1)) se.submit() reserved_serial_no = se.get("items")[2].serial_no serial_no_so = dataent.get_value("Serial No", reserved_serial_no, "sales_order") self.assertEqual(serial_no_so, so.name) dn = make_delivery_note(so.name) dn.save() self.assertEqual(reserved_serial_no, dn.get("items")[0].serial_no) item_line = dn.get("items")[0] item_line.serial_no = item_serial_no.name self.assertRaises(dataent.ValidationError, dn.submit) item_line = dn.get("items")[0] item_line.serial_no = reserved_serial_no self.assertTrue(dn.submit) dn.load_from_db() dn.cancel() si = make_sales_invoice(so.name) si.update_stock = 1 si.save() self.assertEqual(si.get("items")[0].serial_no, reserved_serial_no) item_line = si.get("items")[0] item_line.serial_no = item_serial_no.name self.assertRaises(dataent.ValidationError, dn.submit) item_line = si.get("items")[0] item_line.serial_no = reserved_serial_no self.assertTrue(si.submit) si.submit() si.load_from_db() si.cancel() si = make_sales_invoice(so.name) si.update_stock = 0 si.submit() from epaas.accounts.doctype.sales_invoice.sales_invoice import \ make_delivery_note as make_delivery_note_from_invoice dn = make_delivery_note_from_invoice(si.name) dn.save() dn.submit() self.assertEqual(dn.get("items")[0].serial_no, reserved_serial_no) dn.load_from_db() dn.cancel() si.load_from_db() si.cancel() se.load_from_db() se.cancel() self.assertFalse( dataent.db.exists("Serial No", {"sales_order": so.name}))