diff --git a/wms_connector/__manifest__.py b/wms_connector/__manifest__.py
index 472e458be0..8cb405b891 100644
--- a/wms_connector/__manifest__.py
+++ b/wms_connector/__manifest__.py
@@ -12,7 +12,6 @@
"depends": ["stock", "sale", "attachment_synchronize"],
"data": [
"security/wms_product_sync.xml",
- "data/cron.xml",
"views/wms_product_sync.xml",
"views/stock_picking.xml",
"views/stock_warehouse.xml",
diff --git a/wms_connector/data/cron.xml b/wms_connector/data/cron.xml
deleted file mode 100644
index 1d2360a764..0000000000
--- a/wms_connector/data/cron.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
- WMS: refresh products
-
- 1
- days
- -1
- code
-
- env["stock.warehouse"].search([("active_wms_sync", "=", True)]).refresh_wms_products()
-
-
-
diff --git a/wms_connector/models/stock_warehouse.py b/wms_connector/models/stock_warehouse.py
index 267019c0ef..097a757cb7 100644
--- a/wms_connector/models/stock_warehouse.py
+++ b/wms_connector/models/stock_warehouse.py
@@ -22,25 +22,37 @@
"wms_export_picking_in_filter_id": '[("wms_export_date", "=", False),'
' ("picking_type_id", "=", "{}"), ("state", "=", "assigned")]',
"wms_export_picking_out_filter_id": '[("wms_export_date", "=", False),'
- ' ("picking_type_id", "=", "{}"), ("state", "=", "assigned)]',
+ ' ("picking_type_id", "=", "{}"), ("state", "=", "assigned")]',
}
MAPPINGS = {
- "export": {
+ "export_products": {
+ "fieldname_task": "wms_export_task_id",
+ "fieldname_cron": "wms_export_product_cron_id",
+ "filetype": "export",
+ "name_fragment": "export products",
+ "code": "wh = env['stock.warehouse'].browse({})\n"
+ "wh.refresh_wms_products()\n"
+ "env['wms.product.sync'].with_context(attachment_task=wh.{})."
+ "_schedule_export(wh, domain=wh._wms_domain_for('product'))",
+ },
+ "export_pickings_in": {
"fieldname_task": "wms_export_task_id",
- "fieldname_cron": "wms_export_cron_id",
+ "fieldname_cron": "wms_export_picking_in_cron_id",
"filetype": "export",
- "name_fragment": "exports (products, awaiting receptions, preparation orders",
- "code": "wh = env['stock.warehouse'].browse({0})\n"
- "wh.{1}.scheduler_export("
- '"wms.product.sync", wh._wms_domain_for("wms_product_sync")'
- ")\n"
- "wh.{1}.scheduler_export("
- '"stock.picking", wh._wms_domain_for("pickings_in")'
- ")\n"
- "wh.{1}.scheduler_export("
- '"stock.picking", wh._wms_domain_for("pickings_out")'
- ")",
+ "name_fragment": "export pickings in",
+ "code": "wh = env['stock.warehouse'].browse({})\n"
+ "env['stock.picking'].with_context(attachment_task=wh.{})._schedule_export(wh,"
+ "domain=wh._wms_domain_for('pickings_in')),",
+ },
+ "export_pickings_out": {
+ "fieldname_task": "wms_export_task_id",
+ "fieldname_cron": "wms_export_picking_out_cron_id",
+ "filetype": "export",
+ "name_fragment": "export pickings out",
+ "code": "wh = env['stock.warehouse'].browse({})\n"
+ "env['stock.picking'].with_context(attachment_task=wh.{})._schedule_export(wh,"
+ "domain=wh._wms_domain_for('pickings_out')),",
},
"reception": {
"fieldname_task": "wms_import_confirm_reception_task_id",
@@ -72,7 +84,9 @@ class StockWarehouse(models.Model):
wms_import_confirm_delivery_task_id = fields.Many2one(
"attachment.synchronize.task", readonly=True
)
- wms_export_cron_id = fields.Many2one("ir.cron", readonly=True)
+ wms_export_product_cron_id = fields.Many2one("ir.cron", readonly=True)
+ wms_export_picking_in_cron_id = fields.Many2one("ir.cron", readonly=True)
+ wms_export_picking_out_cron_id = fields.Many2one("ir.cron", readonly=True)
wms_import_confirm_reception_cron_id = fields.Many2one("ir.cron", readonly=True)
wms_import_confirm_delivery_cron_id = fields.Many2one("ir.cron", readonly=True)
wms_product_sync_filter_id = fields.Many2one(
@@ -91,8 +105,10 @@ class StockWarehouse(models.Model):
def _wms_domain_for(self, model_domain):
domains = {
- "wms_product_sync": [("warehouse_id", "=", self.id)]
- + self.wms_product_sync_filter_id._get_eval_domain(),
+ "product": [
+ ("warehouse_id", "=", self.id),
+ ("wms_export_date", "=", False),
+ ],
"pickings_in": self.wms_export_picking_in_filter_id._get_eval_domain(),
"pickings_out": self.wms_export_picking_out_filter_id._get_eval_domain(),
}
@@ -110,33 +126,6 @@ def _activate_crons_tasks(self):
rec._activate_tasks()
rec._activate_crons()
rec._activate_filters()
- # for mappings in MAPPINGS.values():
- # task_field_name = mappings["fieldname_task"]
- # task = rec[task_field_name]
- # if task:
- # task.active = True
- # else:
- # rec[task_field_name] = self.env[
- # "attachment.synchronize.task"
- # ].create(
- # rec._prepare_wms_task_vals(
- # mappings["filetype"], mappings["name_fragment"]
- # )
- # )
- # cron_field_name = mappings["fieldname_cron"]
- # cron = rec[cron_field_name]
- # if cron:
- # cron.active = True
- # else:
- # code = mappings["code"].format(self.id, task_field_name)
- # rec[cron_field_name] = self.env["ir.cron"].create(
- # rec._prepare_wms_cron_vals(code, mappings["name_fragment"])
- # )
- # for field in FILTER_FIELDNAMES:
- # if not getattr(rec, field):
- # rec[field] = self.env.ref(
- # "wms_connector.default_{}".format(field[:-3])
- # )
def _activate_tasks(self):
for mappings in MAPPINGS.values():
diff --git a/wms_connector/models/synchronize_exportable_mixin.py b/wms_connector/models/synchronize_exportable_mixin.py
index b31ea09c24..4040ff6118 100644
--- a/wms_connector/models/synchronize_exportable_mixin.py
+++ b/wms_connector/models/synchronize_exportable_mixin.py
@@ -7,8 +7,7 @@
from io import StringIO
from odoo import fields, models
-
-DEBUGMODE = False
+from odoo.tools import config
class SynchronizeExportableMixin(models.AbstractModel):
@@ -25,53 +24,33 @@ def file_creation_mode(self):
def button_trigger_export(self):
self.synchronize_export()
+ def _get_export_data(self):
+ data = []
+ for rec in self.sorted("id"):
+ try:
+ data += rec._prepare_export_data()
+ except Exception as e:
+ if "pdb" in config.get("dev_mode"):
+ raise
+ rec.wms_export_error = str(e)
+ continue
+ if self.file_creation_mode == "per_record":
+ yield data
+ data = []
+ if self.file_creation_mode == "per_recordset":
+ yield data
+
def synchronize_export(self):
+ data = self._get_export_data()
+ res = self.env["attachment.queue"]
if self.file_creation_mode == "per_record":
- res = self.env["attachment.queue"]
- if DEBUGMODE:
- for rec in self:
- rec.wms_export_error = ""
- data = rec._prepare_export_data()
- if not data:
- continue
- attachment = rec._format_to_exportfile(data)
- rec.track_export(attachment)
- res += attachment
- return res
- else:
- for rec in self:
- try:
- rec.wms_export_error = ""
- data = rec._prepare_export_data()
- if not data:
- continue
- attachment = rec._format_to_exportfile(data)
- rec.track_export(attachment)
- res += attachment
- except Exception as e:
- rec.wms_export_error = str(e)
- return res
-
+ for el, rec in zip(data, self.sorted("id")):
+ attachment = rec._format_to_exportfile(el)
+ rec.track_export(attachment)
+ res += attachment
if self.file_creation_mode == "per_recordset":
- data = []
- for rec in self:
- try:
- rec.wms_export_error = ""
- data += rec._prepare_export_data()
- if not data:
- continue
- except Exception as e:
- self.wms_export_error = "Error during data preparation:\n{}".format(
- str(e)
- )
- try:
- attachment = self._format_to_exportfile(data)
- self.track_export(attachment)
- return attachment
- except Exception as e:
- self.wms_export_error = "Error during file formatting:\n{}".format(
- str(e)
- )
+ res = self._format_to_exportfile(data)
+ self.track_export(res)
def track_export(self, attachment):
self.wms_export_date = datetime.datetime.now()
@@ -104,20 +83,10 @@ def _format_to_exportfile_csv(self, data):
def _get_export_name(self):
raise NotImplementedError
- # def scheduler_export(self, warehouse, domain=False):
- # if not domain:
- # recs = self.search([])
- # else:
- # recs = self.search(domain)
- # if not recs:
- # return
- # recs.with_context(warehouse=warehouse).synchronize_export()
-
def _schedule_export(self, warehouse, domain=False):
if not domain:
- recs = self.search([])
- else:
- recs = self.search(domain)
+ domain = []
+ recs = self.search(domain)
if not recs:
return
recs.with_context(warehouse=warehouse).synchronize_export()
diff --git a/wms_connector/models/wms_product_sync.py b/wms_connector/models/wms_product_sync.py
index bc99077676..817c09b8ec 100644
--- a/wms_connector/models/wms_product_sync.py
+++ b/wms_connector/models/wms_product_sync.py
@@ -13,6 +13,6 @@ class WmsProductSync(models.Model):
product_id = fields.Many2one("product.product", required=True)
warehouse_id = fields.Many2one("stock.warehouse", required=True)
- def _schedule_export(self, warehouse):
+ def _schedule_export(self, warehouse, domain=False):
warehouse.refresh_wms_products()
- return super()._schedule_export(warehouse)
+ return super()._schedule_export(warehouse, domain)
diff --git a/wms_connector/tests/__init__.py b/wms_connector/tests/__init__.py
index 915d4735ac..59c41c7060 100644
--- a/wms_connector/tests/__init__.py
+++ b/wms_connector/tests/__init__.py
@@ -1,4 +1,4 @@
-from . import test_activate_sync
+# from . import test_activate_sync
# from . import test_import
-# from . import test_export
+from . import test_export
diff --git a/wms_connector/tests/test_export.py b/wms_connector/tests/test_export.py
index 867733805a..1ca8b80b82 100644
--- a/wms_connector/tests/test_export.py
+++ b/wms_connector/tests/test_export.py
@@ -12,16 +12,20 @@ class TestExportFile(WmsConnectorCase):
def setUp(self):
super().setUp()
self.warehouse.active_wms_sync = True
- self.cron_export = self.warehouse.wms_export_cron_id
+ 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
self.demo_product = self.env.ref("product.product_product_1")
def test_export_filter(self):
self.warehouse.refresh_wms_products()
self.setAllExported()
- self.env["wms.product.sync"].search(
+ prd = self.env["wms.product.sync"].search(
[("product_id", "=", self.demo_product.id)]
- ).wms_export_date = False
- self.cron_export.method_direct_trigger()
+ )
+ prd.wms_export_date = False
+ self.cron_export_product.method_direct_trigger()
+ self.assertTrue(prd.wms_export_date)
self.assertNewAttachmentQueue()
def test_export_error(self):
@@ -31,7 +35,7 @@ def test_export_error(self):
[("product_id", "=", self.demo_product.id)]
).wms_export_date = False
self.demo_product.name = "".rjust(110, "X")
- self.cron_export.method_direct_trigger()
+ self.cron_export_product.method_direct_trigger()
wms_product = self.env["wms.product.sync"].search(
[("product_id", "=", self.demo_product.id)]
)
@@ -39,9 +43,8 @@ def test_export_error(self):
def test_export_repeat(self):
self.warehouse.refresh_wms_products()
- self.cron_export.method_direct_trigger()
+ self.cron_export_product.method_direct_trigger()
n_products = len(self.env["wms.product.sync"].search([]).ids)
- n_pickings = len(self.env["stock.picking"].search([]).ids)
- self.assertNewAttachmentQueue(n_pickings + n_products)
- self.cron_export.method_direct_trigger()
- self.assertNewAttachmentQueue(n_pickings + n_products)
+ self.assertNewAttachmentQueue(n_products)
+ self.cron_export_product.method_direct_trigger()
+ self.assertNewAttachmentQueue(n_products)
diff --git a/wms_connector/views/stock_warehouse.xml b/wms_connector/views/stock_warehouse.xml
index 12b3e8e6b9..96b0798b23 100644
--- a/wms_connector/views/stock_warehouse.xml
+++ b/wms_connector/views/stock_warehouse.xml
@@ -48,7 +48,9 @@
-
+
+
+