Skip to content

Commit 77e9797

Browse files
[IMP] zort_connector
- Add page and limit for GET list order from zort - Add delay before call next API - Prevent create duplicate customer in case of auto create customer from zort - Display zort sale channel on tab Zort Info - Add param orderdateafter to limit amount of data
1 parent fc560f9 commit 77e9797

15 files changed

+323
-133
lines changed

zort_connector/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "Ecosoft, Odoo Community Association (OCA)",
1010
"maintainers": ["[email protected]"],
1111
"website": "https://github.com/ecosoft-odoo/ecosoft-addons",
12-
"depends": ["stock", "sale_management"],
12+
"depends": ["stock", "sale_management", "mrp"],
1313
"data": [
1414
"security/ir.model.access.csv",
1515
"data/ir_actions_server_data.xml",

zort_connector/data/ir_config_parameter_data.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
<field name="key">zort_connector.limit_timeout</field>
55
<field name="value">10</field>
66
</record>
7+
<record id="zort_connector_order_sync_days_back" model="ir.config_parameter">
8+
<field name="key">zort_connector.order_sync_days_back</field>
9+
<field name="value">10</field>
10+
</record>
711
</odoo>

zort_connector/data/ir_cron_data.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@
1717
<field name="interval_number">10</field>
1818
<field name="interval_type">minutes</field>
1919
</record>
20+
<record id="ir_cron_auto_update_bom_qty_available" model="ir.cron">
21+
<field name="name">Auto Update BOM Qty Available</field>
22+
<field name="model_id" ref="model_mrp_bom" />
23+
<field name="state">code</field>
24+
<field name="code">model.update_bom_qty_to_zort()</field>
25+
<field name="interval_number">1</field>
26+
<field name="interval_type">days</field>
27+
</record>
2028
</odoo>

zort_connector/data/product_data.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@
1818
<field name="standard_price">0.0</field>
1919
<field name="default_code">zort_discount</field>
2020
</record>
21+
<record id="voucher_amount_zort" model="product.template">
22+
<field name="name">Zort Voucher</field>
23+
<field name="type">service</field>
24+
<field name="purchase_ok" eval="False" />
25+
<field name="taxes_id" eval="False" />
26+
<field name="list_price">0.0</field>
27+
<field name="standard_price">0.0</field>
28+
<field name="default_code">zort_voucher</field>
29+
</record>
2130
</odoo>

zort_connector/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
from . import product_template
55
from . import res_partner
66
from . import stock_picking
7+
from . import mrp_bom

zort_connector/models/ecommerce_channel.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class ZortEcommerceChannel(models.Model):
1515
name = "Lazada"
1616
code = "lazada"
1717
use_dummy_customer = True
18-
use_customer_in_odoo = False
1918
auto_create_customer = False
2019
2120
Note:
@@ -43,10 +42,6 @@ class ZortEcommerceChannel(models.Model):
4342
string="Platform Customer",
4443
help="Platform customer to use if no match found",
4544
)
46-
use_customer_in_odoo = fields.Boolean(
47-
help="Use customer in Odoo if match found else use platform customer",
48-
default=True,
49-
)
5045
auto_create_customer = fields.Boolean(
5146
help="Auto create customer if no match found",
5247
default=False,

zort_connector/models/mrp_bom.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2025 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
import logging
5+
6+
from odoo import api, fields, models
7+
8+
_logger = logging.getLogger(__name__)
9+
10+
11+
class MrpBom(models.Model):
12+
_name = "mrp.bom"
13+
_inherit = ["mrp.bom", "zort.api"]
14+
15+
qty_available = fields.Float(
16+
related="product_tmpl_id.qty_available",
17+
string="On Hand Quantity",
18+
readonly=True,
19+
)
20+
21+
@api.model
22+
def update_bom_qty_to_zort(self):
23+
"""Update BOM quantity to Zort as the product's available quantity."""
24+
25+
warehousecode = (
26+
self.env["ir.config_parameter"]
27+
.sudo()
28+
.get_param("zort_connector.warehouse_code")
29+
or "W0001"
30+
)
31+
32+
stocks_dict = {}
33+
boms = self.search([("product_tmpl_id.zort_product_id", "!=", False)])
34+
for bom in boms:
35+
product_id = bom.product_tmpl_id.zort_product_id
36+
if product_id not in stocks_dict:
37+
stocks_dict[product_id] = {
38+
"productid": product_id,
39+
"stock": bom.qty_available,
40+
}
41+
42+
# Convert dictionary values to list
43+
all_stocks = list(stocks_dict.values())
44+
45+
if all_stocks:
46+
data = {"stocks": all_stocks}
47+
try:
48+
self._update_product_available_stock_list(warehousecode, data)
49+
_logger.info(
50+
"Updated %d products' available stock to Zort", len(all_stocks)
51+
)
52+
except Exception as e:
53+
_logger.error(
54+
"Failed to update products' available stock to Zort: %s", str(e)
55+
)

zort_connector/models/product_template.py

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2025 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
15
import base64
26
import json
37
import logging
@@ -142,47 +146,6 @@ def action_update_qty_to_zort(self):
142146
title="Success", message="Stock updated successfully on Zort.", data=data
143147
)
144148

145-
# @api.model
146-
# def batch_update_qty_to_zort_async(self):
147-
# """Schedule batch updates using queue jobs."""
148-
# batch_size = 200
149-
# offset = 0
150-
151-
# while True:
152-
# product_ids = self.search(
153-
# [("is_created_on_zort", "=", True)],
154-
# offset=offset,
155-
# limit=batch_size
156-
# )
157-
158-
# if not product_ids:
159-
# break
160-
161-
# # Schedule each batch as a separate job
162-
# self.with_delay()._process_stock_batch(product_ids.ids)
163-
# offset += batch_size
164-
165-
# def _process_stock_batch(self, product_ids):
166-
# """Process a single batch of products."""
167-
# products = self.browse(product_ids).read([
168-
# "default_code",
169-
# "virtual_available"
170-
# ])
171-
172-
# data = {
173-
# "stocks": [
174-
# {"sku": p["default_code"], "stock": p["virtual_available"]}
175-
# for p in products if p["default_code"]
176-
# ]
177-
# }
178-
179-
# if data["stocks"]:
180-
# response = self._update_product_available_stock_list(
181-
# warehousecode="W0001",
182-
# data=data
183-
# )
184-
# _logger.info("Batch processed: %d products", len(data["stocks"]))
185-
186149
def _add_lognote_and_reload(self, title: str, message: str, data: dict):
187150
"""Add a log note to the chatter and return reload action."""
188151
formatted_data = json.dumps(data, indent=2, ensure_ascii=False)

zort_connector/models/res_partner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2025 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
15
from odoo import fields, models
26

37

0 commit comments

Comments
 (0)