Skip to content

Commit

Permalink
verify that a fresh po is created for every dropshipping order
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Dobbelaere committed Oct 15, 2024
1 parent c325118 commit addc319
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
29 changes: 29 additions & 0 deletions OneSila/products/demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
SUPPLIER_BLACK_TIGER_FABRIC = '1911'

DROPSHIP_PRODUCT_VISCONTI_SKU = 'DR-2029'
DROPSHIP_PRODUCT_JAMES_SKU = 'DR-20292123'

BUNDLE_PEN_AND_INK_SKU = "B-PAI-2"
SIMPLE_PEN_SKU = 'S-P-1291'
SIMPLE_INK_SKU = 'S-I-391'
SUPPLIER_PEN_SKU_ONE = 'SUPP-PA-191'
SUPPLIER_PEN_SKU_TWO = 'SUPP-PA-192'
SUPPLIER_INK_SKU = 'SUPP-I-291'
SUPPLIER_JAMES_SKU = 'ADADF-ADFA223'

SUPPLIER_VISCONTI_SKU_ONE = 'SUPP-PA-292'
SUPPLIER_VISCONTI_SKU_TWO = 'SUPP-PA-293'
Expand Down Expand Up @@ -117,6 +119,17 @@ def get_structure(self):
'name': "Fountain Pen Visconti",
},
},
{
'instance_data': {
'sku': DROPSHIP_PRODUCT_JAMES_SKU,
'active': True,
'for_sale': True,
'vat_rate': self.get_vat_rate(),
},
'post_data': {
'name': "James Dean Cup",
},
},
]


Expand Down Expand Up @@ -222,6 +235,22 @@ def get_structure(self):
}
},
},
{
'instance_data': {
'sku': SUPPLIER_JAMES_SKU,
'active': True,
'supplier': self.get_supplier(PEN_SUPPLIER_NAME_ONE),
},
'post_data': {
'name': 'James Dean Cup',
'base_products_skus': [DROPSHIP_PRODUCT_JAMES_SKU],
'price_info': {
'quantity': 3,
'unit_price': 399,
'unit': self.get_unit(UNIT_PIECE),
}
},
},
]

def post_data_generate(self, instance, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from core.tests import TestCase, TestCaseDemoDataMixin
from products.demo_data import DROPSHIP_PRODUCT_VISCONTI_SKU
from products.demo_data import DROPSHIP_PRODUCT_VISCONTI_SKU, DROPSHIP_PRODUCT_JAMES_SKU
from orders.tests.tests_factories.mixins import CreateTestOrderMixin
from purchasing.flows.dropshipping_purchases import buy_dropshippingproducts_flow
from products.models import DropshipProduct
Expand All @@ -16,3 +16,36 @@ def test_buydropshippingproducts_flow(self):

self.assertEqual(order.purchaseorder_set.all().count(), 1)
self.assertTrue(all([i.is_to_order() for i in order.purchaseorder_set.all()]))

def test_dropshipping_multi_client(self):
"""
Imagine this case:
- 2 orders, each with 1 product to a different client but from the same supplier
When a PO is created, does it create 2 PO’s or does it try to condense them to the open PO?
- consended = not ok for dropshipping. Will get goods delivered to the wrong adress
- not consdensed = ok
"""
product = DropshipProduct.objects.get(
sku=DROPSHIP_PRODUCT_VISCONTI_SKU, multi_tenant_company=self.multi_tenant_company)
product_two = DropshipProduct.objects.get(
sku=DROPSHIP_PRODUCT_JAMES_SKU, multi_tenant_company=self.multi_tenant_company)

self.assertEqual(product.supplier_products.last().supplier, product_two.supplier_products.last().supplier)

order = self.create_test_order('test_dropshipping_multi_client_one', product, 1)
order.set_status_pending_processing()

order_bis = self.create_test_order('test_dropshipping_multi_client_two', product_two, 1)
order_bis.set_status_pending_processing()

buy_dropshippingproducts_flow(order)
buy_dropshippingproducts_flow(order_bis)

self.assertEqual(order.purchaseorder_set.all().count(), 1)
self.assertTrue(all([i.is_to_order() for i in order.purchaseorder_set.all()]))

self.assertEqual(order.purchaseorder_set.count(), 1)
self.assertEqual(order_bis.purchaseorder_set.count(), 1)

self.assertFalse(order_bis.purchaseorder_set.last() == order.purchaseorder_set.last())

0 comments on commit addc319

Please sign in to comment.