def work(): frappe.set_user(frappe.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 test_dn_billing_status_case3(self): # SO -> DN1 -> SI and SO -> SI and SO -> DN2 from erpbee.selling.doctype.sales_order.sales_order \ import make_delivery_note, make_sales_invoice as make_sales_invoice_from_so frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) so = make_sales_order() dn1 = make_delivery_note(so.name) dn1.get("items")[0].qty = 2 dn1.submit() # Testing if Customer's Purchase Order No was rightly copied self.assertEqual(dn1.po_no, so.po_no) si1 = make_sales_invoice(dn1.name) si1.submit() # Testing if Customer's Purchase Order No was rightly copied self.assertEqual(dn1.po_no, si1.po_no) 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() # Testing if Customer's Purchase Order No was rightly copied self.assertEqual(si2.po_no, so.po_no) dn2 = make_delivery_note(so.name) dn2.get("items")[0].qty = 5 dn2.submit() # Testing if Customer's Purchase Order No was rightly copied self.assertEqual(dn2.po_no, so.po_no) 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_make_sales_invoice_from_dn_for_returned_qty(self): from erpbee.selling.doctype.sales_order.sales_order import make_delivery_note from erpbee.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.items[0].dn_detail = dn.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 frappe.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_order_number = shopify_order.get("name") dn.set_posting_time = 1 dn.posting_date = getdate(fulfillment.get("created_at")) 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() dn.submit() frappe.db.commit()
def test_create_quotation_with_margin(self): from erpbee.selling.doctype.quotation.quotation import make_sales_order from erpbee.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 = frappe.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(frappe.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 test_dn_billing_status_case4(self): # SO -> SI -> DN from erpbee.selling.doctype.sales_order.sales_order import make_sales_invoice from erpbee.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note so = make_sales_order() si = make_sales_invoice(so.name) si.submit() # Testing if Customer's Purchase Order No was rightly copied self.assertEqual(so.po_no, si.po_no) dn = make_delivery_note(si.name) dn.submit() # Testing if Customer's Purchase Order No was rightly copied self.assertEqual(dn.po_no, si.po_no) self.assertEqual(dn.get("items")[0].billed_amt, 1000) self.assertEqual(dn.per_billed, 100) self.assertEqual(dn.status, "Completed")
def make_delivery_note(): # make purchase requests # make delivery notes (if possible) if random.random() < 0.6: from erpbee.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 = frappe.get_doc(make_delivery_note(so)) dn.posting_date = frappe.flags.current_date for d in dn.get("items"): if not d.expense_account: d.expense_account = ("Cost of Goods Sold - {0}".format( frappe.get_cached_value('Company', dn.company, 'abbr'))) try: dn.insert() dn.submit() frappe.db.commit() except (NegativeStockError, SerialNoRequiredError, SerialNoQtyError, UnableToSelectBatchError): frappe.db.rollback()