mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 08:24:47 +00:00
test: fix NegativeStockError (#24936)
This commit is contained in:
@@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
import unittest, os, json
|
||||
from frappe.utils import cstr
|
||||
from frappe.utils import cstr, cint
|
||||
from erpnext.erpnext_integrations.connectors.shopify_connection import create_order
|
||||
from erpnext.erpnext_integrations.doctype.shopify_settings.sync_product import make_item
|
||||
from erpnext.erpnext_integrations.doctype.shopify_settings.sync_customer import create_customer
|
||||
@@ -13,9 +13,14 @@ from frappe.core.doctype.data_import.data_import import import_doc
|
||||
|
||||
|
||||
class ShopifySettings(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
cls.allow_negative_stock = cint(frappe.db.get_value('Stock Settings', None, 'allow_negative_stock'))
|
||||
if not cls.allow_negative_stock:
|
||||
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 1)
|
||||
|
||||
# use the fixture data
|
||||
import_doc(frappe.get_app_path("erpnext", "erpnext_integrations/doctype/shopify_settings/test_data/custom_field.json"))
|
||||
|
||||
@@ -24,9 +29,15 @@ class ShopifySettings(unittest.TestCase):
|
||||
frappe.reload_doctype("Delivery Note")
|
||||
frappe.reload_doctype("Sales Invoice")
|
||||
|
||||
self.setup_shopify()
|
||||
cls.setup_shopify()
|
||||
|
||||
def setup_shopify(self):
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
if not cls.allow_negative_stock:
|
||||
frappe.db.set_value('Stock Settings', None, 'allow_negative_stock', 0)
|
||||
|
||||
@classmethod
|
||||
def setup_shopify(cls):
|
||||
shopify_settings = frappe.get_doc("Shopify Settings")
|
||||
shopify_settings.taxes = []
|
||||
|
||||
@@ -56,21 +67,20 @@ class ShopifySettings(unittest.TestCase):
|
||||
"delivery_note_series": "DN-"
|
||||
}).save(ignore_permissions=True)
|
||||
|
||||
self.shopify_settings = shopify_settings
|
||||
cls.shopify_settings = shopify_settings
|
||||
|
||||
def test_order(self):
|
||||
### Create Customer ###
|
||||
# Create Customer
|
||||
with open (os.path.join(os.path.dirname(__file__), "test_data", "shopify_customer.json")) as shopify_customer:
|
||||
shopify_customer = json.load(shopify_customer)
|
||||
create_customer(shopify_customer.get("customer"), self.shopify_settings)
|
||||
|
||||
### Create Item ###
|
||||
# Create Item
|
||||
with open (os.path.join(os.path.dirname(__file__), "test_data", "shopify_item.json")) as shopify_item:
|
||||
shopify_item = json.load(shopify_item)
|
||||
make_item("_Test Warehouse - _TC", shopify_item.get("product"))
|
||||
|
||||
|
||||
### Create Order ###
|
||||
# Create Order
|
||||
with open (os.path.join(os.path.dirname(__file__), "test_data", "shopify_order.json")) as shopify_order:
|
||||
shopify_order = json.load(shopify_order)
|
||||
|
||||
@@ -80,17 +90,17 @@ class ShopifySettings(unittest.TestCase):
|
||||
|
||||
self.assertEqual(cstr(shopify_order.get("order").get("id")), sales_order.shopify_order_id)
|
||||
|
||||
#check for customer
|
||||
# Check for customer
|
||||
shopify_order_customer_id = cstr(shopify_order.get("order").get("customer").get("id"))
|
||||
sales_order_customer_id = frappe.get_value("Customer", sales_order.customer, "shopify_customer_id")
|
||||
|
||||
self.assertEqual(shopify_order_customer_id, sales_order_customer_id)
|
||||
|
||||
#check sales invoice
|
||||
# Check sales invoice
|
||||
sales_invoice = frappe.get_doc("Sales Invoice", {"shopify_order_id": sales_order.shopify_order_id})
|
||||
self.assertEqual(sales_invoice.rounded_total, sales_order.rounded_total)
|
||||
|
||||
#check delivery note
|
||||
# Check delivery note
|
||||
delivery_note_count = frappe.db.sql("""select count(*) from `tabDelivery Note`
|
||||
where shopify_order_id = %s""", sales_order.shopify_order_id)[0][0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user