Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao committed Oct 12, 2023
1 parent b9d7d8d commit 6e73599
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion wms_connector/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "AGPL-3",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "https://www.akretion.com",
"depends": ["stock", "sale", "attachment_synchronize", "pydantic", "extendable"],
"depends": ["stock", "sale", "attachment_synchronize"],
"data": [
"security/wms_product_sync.xml",
"views/wms_product_sync.xml",
Expand Down
10 changes: 8 additions & 2 deletions wms_connector/data/cron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

<odoo noupdate="1">

<record model="ir.cron" id="errors_email_alert">
<field name="name">WMS: Errors email alert</field>
<record model="ir.cron" id="refresh_wms_products">
<field name="name">WMS: refresh products</field>
<field name="active" eval="True" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="state">code</field>
<field name="code">env["stock.warehouse"].search([("active_wms_sync", "=", True)]).refresh_wms_products()</field>
</record>

</odoo>
1 change: 0 additions & 1 deletion wms_connector/models/attachment_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ def _run_wms_reception_confirmed(self):

def _run_wms_delivery_confirmed(self):
raise NotImplementedError

1 change: 0 additions & 1 deletion wms_connector/models/attachment_synchronize_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ def scheduler_export(self, model, domain=False):
("delivery_confirmed", "Delivery confirmed"),
]
)

1 change: 0 additions & 1 deletion wms_connector/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ class ProductProduct(models.Model):
_inherit = "product.product"

wms_sync_ids = fields.One2many("wms.product.sync", "product_id")

4 changes: 0 additions & 4 deletions wms_connector/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
from odoo import _, api, fields, models



class StockPicking(models.Model):
_inherit = ["stock.picking", "synchronize.exportable.mixin"]

def button_create_aq(self):
self.synchronize_export()

def _get_export_name(self):
if self.file_creation_mode == "per_record":
return self.name + ".csv"
Expand Down
13 changes: 10 additions & 3 deletions wms_connector/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ class StockWarehouse(models.Model):
wms_import_confirm_delivery_cron_id = fields.Many2one("ir.cron", readonly=True)
wms_product_filter_id = fields.Many2one(
"ir.filters",
required=True,
default=lambda r: r.env.ref("wms_connector.default_empty_filter"),
)
wms_picking_ar_filter_id = fields.Many2one(
"ir.filters",
required=True,
default=lambda r: r.env.ref("wms_connector.default_empty_filter"),
)
wms_picking_prp_filter_id = fields.Many2one(
"ir.filters",
required=True,
default=lambda r: r.env.ref("wms_connector.default_empty_filter"),
)
wms_product_sync_ids = fields.One2many("product.product", "warehouse_id")
Expand Down Expand Up @@ -104,3 +101,13 @@ def _deactivate_crons_tasks(self):
def action_open_flows(self):
raise NotImplementedError
return {"type": "ir.action"}

def refresh_wms_products(self):
for rec in self:
rec.wms_product_sync_ids.unlink()
for prd in self.env["product.product"].search(
rec.wms_product_filter_id._get_eval_domain()
):
self.env["wms.product.sync"].create(
{"product_id": prd.id, "warehouse_id": rec.id}
)
3 changes: 3 additions & 0 deletions wms_connector/models/synchronize_exportable_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class SynchronizeExportableMixin(models.AbstractModel):
default="per_record",
)

def button_trigger_export(self):
self.synchronize_export()

def synchronize_export(self):
if self.file_creation_mode == "per_record":
res = self.env["attachment.queue"]
Expand Down
6 changes: 3 additions & 3 deletions wms_connector/models/wms_product_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class WmsProductSync(models.Model):
_name = "wms.product.sync"
_description = "Wms Product Sync"

name = fields.Char()
product_id = fields.Many2one("product.product")
warehouse_id = fields.Many2one("stock.warehouse")
name = fields.Char(related="product_id.name")
product_id = fields.Many2one("product.product", required=True)
warehouse_id = fields.Many2one("stock.warehouse", required=True)
8 changes: 7 additions & 1 deletion wms_connector/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@


class WmsConnectorCommon(TransactionCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.backend = cls.env.ref("wms_connector.demo_wms_backend")
cls.backend.directory_path = str(uuid.uuid1()) + "/"
cls.aq_before = cls.env["attachment.queue"].search([])
# cls.loader = FakeModelLoader(cls.env, cls.__module__)
# cls.loader.backup_registry()
#
Expand All @@ -30,3 +30,9 @@ def tearDown(self):
def tearDownClass(cls):
# cls.loader.restore_registry()
super().tearDownClass()

@classmethod
def assertNewAttachmentQueue(cls):
aq_after = cls.env["attachment.queue"].search([])
cls.assertEqual(len(aq_after - cls.aq_before), 1)
return aq_after
5 changes: 1 addition & 4 deletions wms_connector/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@


class TestExportFile(TransactionCase):

def setUp(self):
super().setUp()
self.warehouse = self.env.ref("stock.warehouse0")
self.warehouse.active_wms_sync = True

def test_run_export_cron(self):
self.warehouse.wms_export_cron_id.run()
pass

self.warehouse.wms_export_cron_id.method_direct_trigger()
1 change: 0 additions & 1 deletion wms_connector/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class TestImport(TransactionCase):

def setUp(self):
super().setUp()

Expand Down

0 comments on commit 6e73599

Please sign in to comment.