Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao committed Mar 18, 2024
1 parent 08f523b commit a871635
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 61 deletions.
2 changes: 1 addition & 1 deletion wms_connector/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# from . import test_activate_sync
from . import test_activate_sync
from . import test_export
1 change: 1 addition & 0 deletions wms_connector/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setUpClass(cls):
def setAllExported(self):
self.env["stock.picking"].search([]).export_date = datetime.date.today()
self.env["wms.product.sync"].search([]).export_date = datetime.date.today()
self.env["wms.product.sync"].search([]).to_export = False


class WmsConnectorCase(WmsConnectorCommon):
Expand Down
10 changes: 8 additions & 2 deletions wms_connector/tests/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class WmsProductSync(models.Model):
_inherit = ["wms.product.sync"]

def _prepare_export_data(self):
def _prepare_export_data(self, _):
res = []
for rec in self:
res += [
Expand All @@ -20,11 +20,14 @@ def _prepare_export_data(self):
def _get_export_name(self):
return self.name

def _get_export_task(self):
return self.warehouse_id.wms_export_task_id


class StockPicking(models.Model):
_inherit = "stock.picking"

def _prepare_export_data(self):
def _prepare_export_data(self, _):
return [
{
"name": rec.name,
Expand All @@ -34,3 +37,6 @@ def _prepare_export_data(self):

def _get_export_name(self):
return self.name

def _get_export_task(self):
return self.location_id.warehouse_id.wms_export_task_id
16 changes: 8 additions & 8 deletions wms_connector/tests/test_activate_sync.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# Copyright 2023 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestActivateSync(SavepointCase):
class TestActivateSync(TransactionCase):
def setUp(self):
super().setUp()
self.warehouse = self.env.ref("stock.warehouse0")

def test_active_deactivate_wms_sync(self):
self.warehouse.active_wms_sync = True
for field in (
"wms_export_cron_id",
"wms_import_confirm_reception_cron_id",
"wms_import_confirm_delivery_cron_id",
"wms_export_product_cron_id",
"wms_export_picking_in_cron_id",
"wms_export_picking_out_cron_id",
):
self.assertTrue(getattr(self.warehouse, field))
self.warehouse.active_wms_sync = False
for field in (
"wms_export_cron_id",
"wms_import_confirm_reception_cron_id",
"wms_import_confirm_delivery_cron_id",
"wms_export_product_cron_id",
"wms_export_picking_in_cron_id",
"wms_export_picking_out_cron_id",
):
self.assertFalse(getattr(self.warehouse, field).active)

Expand Down
102 changes: 52 additions & 50 deletions wms_connector/tests/test_export.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Copyright 2023 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from .common import WmsConnectorCommon
from .common import WmsConnectorCase

FN_EXPORT_VALS = (
"odoo.addons.wms_connector.tests.model.WmsProductSync._prepare_export_data"
)


class TestExportFile(WmsConnectorCommon):
class TestExportFile(WmsConnectorCase):
def setUp(self):
super().setUp()
self.warehouse.active_wms_sync = True
self.warehouse.wms_export_task_id.backend_id = self.backend
self.cron_export_product = self.warehouse.wms_export_product_cron_id
self.cron_export_picking_in = self.warehouse.wms_export_picking_in_cron_id
self.cron_export_picking_out = self.warehouse.wms_export_picking_out_cron_id
Expand All @@ -23,55 +24,56 @@ def test_export_filter(self):
prd = self.env["wms.product.sync"].search(
[("product_id", "=", self.demo_product.id)]
)
prd.export_date = False
prd.to_export = True
self.cron_export_product.method_direct_trigger()
self.assertTrue(prd.export_date)
self.assertNewAttachmentQueue()

# def test_export_error(self):
# self.warehouse.refresh_wms_products()
# self.setAllExported()
# self.env["wms.product.sync"].search(
# [("product_id", "=", self.demo_product.id)]
# ).export_date = False
# self.demo_product.name = "".rjust(110, "X")
# self.cron_export_product.method_direct_trigger()
# wms_product = self.env["wms.product.sync"].search(
# [("product_id", "=", self.demo_product.id)]
# )
# self.assertIn("Boom", wms_product.export_error)
#
# def test_export_repeat(self):
# self.warehouse.refresh_wms_products()
# self.cron_export_product.method_direct_trigger()
# n_products = len(self.env["wms.product.sync"].search([]).ids)
# self.assertNewAttachmentQueue(n_products)
# self.cron_export_product.method_direct_trigger()
# self.assertNewAttachmentQueue(n_products)
#
# def test_export_pickings(self):
# self.env["stock.picking"].search([]).state = "assigned"
# self.cron_export_picking_in.method_direct_trigger()
# aq_in = len(
# self.env["stock.picking"]
# .search(
# [
# ("export_date", "!=", False),
# ("picking_type_id", "=", self.warehouse.in_type_id.id),
# ]
# )
# .ids
# )
# self.assertNewAttachmentQueue(aq_in)
# self.cron_export_picking_out.method_direct_trigger()
# aq_out = len(
# self.env["stock.picking"]
# .search(
# [
# ("export_date", "!=", False),
# ("picking_type_id", "=", self.warehouse.out_type_id.id),
# ]
# )
# .ids
# )
# self.assertNewAttachmentQueue(aq_in + aq_out)
def test_export_error(self):
self.warehouse.refresh_wms_products()
self.setAllExported()
self.env["wms.product.sync"].search(
[("product_id", "=", self.demo_product.id)]
).to_export = True
self.demo_product.name = "".rjust(110, "X")
self.cron_export_product.method_direct_trigger()
wms_product = self.env["wms.product.sync"].search(
[("product_id", "=", self.demo_product.id)]
)
self.assertIn("Boom", wms_product.export_error)

def test_export_repeat(self):
self.warehouse.refresh_wms_products()
self.cron_export_product.method_direct_trigger()
n_products = len(self.env["wms.product.sync"].search([]).ids)
self.assertNewAttachmentQueue(n_products)
self.cron_export_product.method_direct_trigger()
self.assertNewAttachmentQueue(n_products)

def test_export_pickings(self):
self.env["stock.picking"].search([]).state = "assigned"
self.setAllExported()
self.env["stock.picking"].search(
[
("picking_type_id", "=", self.warehouse.in_type_id.id),
]
)[0:2].export_date = False
self.cron_export_picking_in.method_direct_trigger()
# aq_in = len(
# self.env["stock.picking"]
# .search(
# [
# ("export_date", "!=", False),
# ("picking_type_id", "=", self.warehouse.in_type_id.id),
# ]
# )
# .ids
# )
self.assertNewAttachmentQueue(2)
self.env["stock.picking"].search(
[
("picking_type_id", "=", self.warehouse.out_type_id.id),
]
)[0:2].export_date = False
self.cron_export_picking_out.method_direct_trigger()
self.assertNewAttachmentQueue(4)

0 comments on commit a871635

Please sign in to comment.