Skip to content
2 changes: 1 addition & 1 deletion wms_connector/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"views/stock_warehouse.xml",
],
"demo": [
"demo/storage_backend.xml",
"demo/fs_storage.xml",
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="storage.backend" id="demo_wms_backend">
<record model="fs.storage" id="demo_wms_storage">
<field name="name">Demo WMS backend</field>
<field name="directory_path">/</field>
<field name="protocol">odoofs</field>
<field name="code">demo_wms_storage</field>
</record>

</odoo>
22 changes: 22 additions & 0 deletions wms_connector/models/attachment_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,32 @@
WMS_IMPORT_FILETYPES = [
("wms_reception_confirmed", "WMS Reception confirmed"),
("wms_delivery_confirmed", "WMS Delivery confirmed"),
("wms_update_inventory", "WMS inventory update"),
]


class AttachmentQueue(models.Model):
_inherit = "attachment.queue"

file_type = fields.Selection(selection_add=WMS_IMPORT_FILETYPES)
default_warehouse_id = fields.Many2one(
"stock.warehouse", compute="_compute_default_warehouse", store=True
)

def _compute_default_warehouse(self):
for rec in self:
task_queue_prefix = None
if rec.file_type == "wms_reception_confirmed":
task_queue_prefix = "wms_import_confirm_reception"
elif rec.file_type == "wms_delivery_confirmed":
task_queue_prefix = "wms_import_confirm_delivery"
elif rec.file_type == "wms_update_inventory":
task_queue_prefix = "wms_import_update_inventory"

if task_queue_prefix is not None:
rec.default_warehouse_id = rec.env["stock.warehouse"].search(
[(f"{task_queue_prefix}_task_id.attachment_ids", "=", rec.id)]
)

def _run(self):
for filetype in [el[0] for el in WMS_IMPORT_FILETYPES]:
Expand All @@ -25,3 +44,6 @@ def _run_wms_reception_confirmed(self):

def _run_wms_delivery_confirmed(self):
raise NotImplementedError

def _run_wms_update_inventory(self):
raise NotImplementedError
9 changes: 9 additions & 0 deletions wms_connector/models/attachment_synchronize_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
class AttachmentSynchronizeTask(models.Model):
_inherit = "attachment.synchronize.task"

default_warehouse_id = fields.Many2one("stock.warehouse")

file_type = fields.Selection(
selection_add=[
("export", "Export"),
("wms_reception_confirmed", "Reception confirmed"),
("wms_delivery_confirmed", "Delivery confirmed"),
("wms_update_inventory", "Inventory update"),
]
)

def _prepare_attachment_vals(self, data, filename):
self.ensure_one()
vals = super()._prepare_attachment_vals(data, filename)
vals["default_warehouse_id"] = self.default_warehouse_id.id
return vals
15 changes: 14 additions & 1 deletion wms_connector/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@
"name_fragment": "delivery confirmation",
"code": "env['stock.warehouse'].browse({}).{}.run_import()",
},
"inventory": {
"fieldname_task": "wms_import_update_inventory_task_id",
"fieldname_cron": "wms_import_update_inventory_cron_id",
"filetype": "wms_update_inventory",
"method_type": "import",
"filepath": "OUT/",
"name_fragment": "Update inventory",
"code": "env['stock.warehouse'].browse({}).{}.run_import()",
},
}


Expand All @@ -96,11 +105,15 @@ class StockWarehouse(models.Model):
wms_import_confirm_delivery_task_id = fields.Many2one(
"attachment.synchronize.task", readonly=True
)
wms_import_update_inventory_task_id = fields.Many2one(
"attachment.synchronize.task", 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_import_update_inventory_cron_id = fields.Many2one("ir.cron", readonly=True)
wms_export_product_filter_id = fields.Many2one("ir.filters")
wms_export_picking_in_filter_id = fields.Many2one("ir.filters")
wms_export_picking_out_filter_id = fields.Many2one("ir.filters")
Expand Down Expand Up @@ -185,8 +198,8 @@ def _prepare_wms_task_vals(
"name": "WMS task for {} {}".format(self.name, name_fragment),
"method_type": method_type,
"filepath": filepath,
"backend_id": self.env.ref("storage_backend.default_storage_backend").id,
"file_type": filetype,
"default_warehouse_id": self.id,
}

def _prepare_wms_cron_vals(self, code="", name_fragment=""):
Expand Down
13 changes: 7 additions & 6 deletions wms_connector/models/synchronize_exportable_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import datetime
from io import StringIO

from odoo import fields, models
from odoo import api, fields, models
from odoo.tools import config


Expand Down Expand Up @@ -56,7 +56,7 @@ def _get_export_data(self, raise_error=False):
def synchronize_export(self, raise_error=False):
attachments = self.env["attachment.queue"]
for records, data in self._get_export_data(raise_error=raise_error):
vals = self._format_to_exportfile(data)
vals = records._format_to_exportfile(data)
attachment = self.env["attachment.queue"].create(vals)
records.track_export(attachment)
attachments |= attachment
Expand All @@ -75,8 +75,8 @@ def _get_wms_export_task(self):
# TODO cleanup this code
# We should just have a method that return the data
# and a generic one that return the vals
def _format_to_exportfile(self, name, data):
return self._format_to_exportfile_csv(name, data)
def _format_to_exportfile(self, data):
return self._format_to_exportfile_csv(data)

def _format_to_exportfile_csv(self, data):
csv_file = StringIO()
Expand All @@ -98,10 +98,11 @@ def _format_to_exportfile_csv(self, data):
def _get_export_name(self):
raise NotImplementedError

@api.model
def _schedule_export(self, warehouse, domain=False):
if not domain:
domain = []
recs = self.search(domain)
if not recs:
return
recs.with_context(warehouse=warehouse).synchronize_export()
return self.env["attachment.queue"]
return recs.with_context(warehouse=warehouse).synchronize_export()
1 change: 1 addition & 0 deletions wms_connector/models/wms_product_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def _compute_to_export(self):
for record in self:
record.to_export = True

@api.model
def _schedule_export(self, warehouse, domain=False):
warehouse.refresh_wms_products()
return super()._schedule_export(warehouse, domain)
Expand Down
2 changes: 1 addition & 1 deletion wms_connector/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.backend = cls.env.ref("wms_connector.demo_wms_backend")
cls.backend = cls.env.ref("wms_connector.demo_wms_storage")
cls.backend.directory_path = str(uuid.uuid1()) + "/"
cls.aq_before = cls.env["attachment.queue"].search([])
cls.warehouse = cls.env.ref("stock.warehouse0")
Expand Down
2 changes: 2 additions & 0 deletions wms_connector/views/stock_warehouse.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@
<field name="wms_export_task_id" />
<field name="wms_import_confirm_delivery_task_id" />
<field name="wms_import_confirm_reception_task_id" />
<field name="wms_import_update_inventory_task_id" />
</group>
<group>
<field name="wms_export_product_cron_id" />
<field name="wms_export_picking_in_cron_id" />
<field name="wms_export_picking_out_cron_id" />
<field name="wms_import_confirm_delivery_cron_id" />
<field name="wms_import_confirm_reception_cron_id" />
<field name="wms_import_update_inventory_cron_id" />
</group>
<group>
<field name="wms_export_product_filter_id" />
Expand Down