mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] connector_opencart: fields to opt backends into auto import, per-store
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Opencart Connector',
|
'name': 'Opencart Connector',
|
||||||
'version': '12.0.1.1.0',
|
'version': '12.0.1.2.0',
|
||||||
'category': 'Connector',
|
'category': 'Connector',
|
||||||
'depends': [
|
'depends': [
|
||||||
'account',
|
'account',
|
||||||
|
|||||||
@@ -76,6 +76,17 @@ class OpencartBackend(models.Model):
|
|||||||
so_require_product_setup = fields.Boolean(string='SO Require Product Setup',
|
so_require_product_setup = fields.Boolean(string='SO Require Product Setup',
|
||||||
help='Prevents SO from being confirmed (failed queue job), if one or more products has an open checkpoint.')
|
help='Prevents SO from being confirmed (failed queue job), if one or more products has an open checkpoint.')
|
||||||
|
|
||||||
|
scheduler_order_import_running = fields.Boolean(string='Auctomatic Sale Order Import is Running',
|
||||||
|
compute='_compute_scheduler_order_import_running',
|
||||||
|
compute_sudo=True)
|
||||||
|
scheduler_order_import = fields.Boolean(string='Automatic Sale Order Import',
|
||||||
|
help='Individual stores should also be enabled for import.')
|
||||||
|
|
||||||
|
def _compute_scheduler_order_import_running(self):
|
||||||
|
sched_action = self.env.ref('connector_opencart.ir_cron_import_sale_orders', raise_if_not_found=False)
|
||||||
|
for backend in self:
|
||||||
|
backend.scheduler_order_import_running = bool(sched_action.active)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
@api.multi
|
@api.multi
|
||||||
def work_on(self, model_name, **kwargs):
|
def work_on(self, model_name, **kwargs):
|
||||||
@@ -124,6 +135,7 @@ class OpencartBackend(models.Model):
|
|||||||
('base_url', '!=', False),
|
('base_url', '!=', False),
|
||||||
('restadmin_token', '!=', False),
|
('restadmin_token', '!=', False),
|
||||||
('import_orders_after_id', '!=', False),
|
('import_orders_after_id', '!=', False),
|
||||||
|
('scheduler_order_import', '=', True),
|
||||||
])
|
])
|
||||||
return backends.import_sale_orders()
|
return backends.import_sale_orders()
|
||||||
|
|
||||||
@@ -140,6 +152,3 @@ class OpencartBackend(models.Model):
|
|||||||
backend,
|
backend,
|
||||||
filters={'after_id': after_id}
|
filters={'after_id': after_id}
|
||||||
)
|
)
|
||||||
# TODO !!!!!
|
|
||||||
# cannot update the ID because we don't know what Ids would be returned.
|
|
||||||
# this MUST be updated by the SO importer.
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class OpencartStore(models.Model):
|
|||||||
)
|
)
|
||||||
coupon_product_id = fields.Many2one(comodel_name='product.product', string='Coupon Product',
|
coupon_product_id = fields.Many2one(comodel_name='product.product', string='Coupon Product',
|
||||||
help='Product to represent coupon discounts.')
|
help='Product to represent coupon discounts.')
|
||||||
|
enable_order_import = fields.Boolean(string='Enable Sale Order Import', default=True,
|
||||||
|
help='If not enabled, then stores will be skipped during order imiport.')
|
||||||
|
|
||||||
|
|
||||||
class OpencartStoreAdapter(Component):
|
class OpencartStoreAdapter(Component):
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
# © 2019 Hibou Corp.
|
# © 2019 Hibou Corp.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from copy import deepcopy, copy
|
from copy import copy
|
||||||
from html import unescape
|
from html import unescape
|
||||||
|
import logging
|
||||||
|
|
||||||
from odoo import fields, _
|
from odoo import fields, _
|
||||||
from odoo.addons.component.core import Component
|
from odoo.addons.component.core import Component
|
||||||
@@ -11,6 +12,9 @@ from odoo.exceptions import ValidationError
|
|||||||
from odoo.addons.queue_job.exception import RetryableJobError
|
from odoo.addons.queue_job.exception import RetryableJobError
|
||||||
|
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SaleOrderBatchImporter(Component):
|
class SaleOrderBatchImporter(Component):
|
||||||
_name = 'opencart.sale.order.batch.importer'
|
_name = 'opencart.sale.order.batch.importer'
|
||||||
_inherit = 'opencart.delayed.batch.importer'
|
_inherit = 'opencart.delayed.batch.importer'
|
||||||
@@ -24,10 +28,13 @@ class SaleOrderBatchImporter(Component):
|
|||||||
}
|
}
|
||||||
if store_id is not None:
|
if store_id is not None:
|
||||||
store_binder = self.binder_for('opencart.store')
|
store_binder = self.binder_for('opencart.store')
|
||||||
store = store_binder.to_internal(store_id)
|
store = store_binder.to_internal(store_id).sudo()
|
||||||
user = store.sudo().warehouse_id.company_id.user_tech_id
|
if not store.enable_order_import:
|
||||||
|
_logger.warning('Store (%s) is not enabled for Sale Order import (%s).' % (store.name, external_id))
|
||||||
|
return
|
||||||
|
user = store.warehouse_id.company_id.user_tech_id
|
||||||
if user and user != self.env.user:
|
if user and user != self.env.user:
|
||||||
# Note that this is a component, which has an env through it's 'colletion'
|
# Note that this is a component, which has an env through it's 'collection'
|
||||||
# however, when importing the 'model' is actually what runs the delayed job
|
# however, when importing the 'model' is actually what runs the delayed job
|
||||||
env = self.env(user=user)
|
env = self.env(user=user)
|
||||||
self.collection.env = env
|
self.collection.env = env
|
||||||
|
|||||||
@@ -34,6 +34,14 @@
|
|||||||
<field name="fiscal_position_id"/>
|
<field name="fiscal_position_id"/>
|
||||||
<field name="team_id"/>
|
<field name="team_id"/>
|
||||||
<field name="sale_prefix"/>
|
<field name="sale_prefix"/>
|
||||||
|
<field name="scheduler_order_import_running" invisible="1" />
|
||||||
|
<field name="scheduler_order_import"/>
|
||||||
|
<p attrs="{'invisible': [('scheduler_order_import_running', '=', True)]}" class="text-danger" colspan="2">
|
||||||
|
The automatic scheduler is not currently enabled.
|
||||||
|
</p>
|
||||||
|
<p attrs="{'invisible': [('scheduler_order_import_running', '=', False)]}" class="text-success" colspan="2">
|
||||||
|
The automatic scheduler is enabled.
|
||||||
|
</p>
|
||||||
</group>
|
</group>
|
||||||
<group name="product_configuration" string="Product Defaults">
|
<group name="product_configuration" string="Product Defaults">
|
||||||
<field name="product_categ_id"/>
|
<field name="product_categ_id"/>
|
||||||
@@ -128,6 +136,7 @@
|
|||||||
</h1>
|
</h1>
|
||||||
<group name="main_configuration" string="Override Configuration">
|
<group name="main_configuration" string="Override Configuration">
|
||||||
<group name="order_configuration" string="Order Defaults">
|
<group name="order_configuration" string="Order Defaults">
|
||||||
|
<field name="enable_order_import" />
|
||||||
<field name="warehouse_id"/>
|
<field name="warehouse_id"/>
|
||||||
<field name="analytic_account_id"/>
|
<field name="analytic_account_id"/>
|
||||||
<field name="fiscal_position_id"/>
|
<field name="fiscal_position_id"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user