mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] connector_opencart: Add option on backend to require all SO products to not have checkpoints before importing order.
Additionally, allow users to re-bind product templates (understandably risky).
This commit is contained in:
@@ -88,7 +88,8 @@ class OpencartImporter(AbstractComponent):
|
||||
if not external_id:
|
||||
return
|
||||
binder = self.binder_for(binding_model)
|
||||
if always or not binder.to_internal(external_id):
|
||||
record = binder.to_internal(external_id)
|
||||
if always or not record:
|
||||
if importer is None:
|
||||
importer = self.component(usage='record.importer',
|
||||
model_name=binding_model)
|
||||
@@ -99,6 +100,13 @@ class OpencartImporter(AbstractComponent):
|
||||
'Dependency import of %s(%s) has been ignored.',
|
||||
binding_model._name, external_id
|
||||
)
|
||||
return True
|
||||
if binding_model == 'opencart.product.template' and record.backend_id.so_require_product_setup:
|
||||
# Though this is not the "right" place to do this,
|
||||
# we need to return True if there is a checkpoint for a product.
|
||||
if record.backend_id.find_checkpoint(record):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _import_dependencies(self):
|
||||
""" Import the dependencies for the record
|
||||
|
||||
@@ -73,6 +73,9 @@ class OpencartBackend(models.Model):
|
||||
string='Import sale orders after id',
|
||||
)
|
||||
|
||||
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.')
|
||||
|
||||
@contextmanager
|
||||
@api.multi
|
||||
def work_on(self, model_name, **kwargs):
|
||||
@@ -89,6 +92,20 @@ class OpencartBackend(models.Model):
|
||||
return add_checkpoint(self.env, record._name, record.id,
|
||||
self._name, self.id)
|
||||
|
||||
@api.multi
|
||||
def find_checkpoint(self, record):
|
||||
self.ensure_one()
|
||||
record.ensure_one()
|
||||
checkpoint_model = self.env['connector.checkpoint']
|
||||
model_model = self.env['ir.model']
|
||||
model = model_model.search([('model', '=', record._name)], limit=1)
|
||||
return checkpoint_model.search([
|
||||
('backend_id', '=', '%s,%s' % (self._name, self.id)),
|
||||
('model_id', '=', model.id),
|
||||
('record_id', '=', record.id),
|
||||
('state', '=', 'need_review'),
|
||||
], limit=1)
|
||||
|
||||
@api.multi
|
||||
def synchronize_metadata(self):
|
||||
try:
|
||||
|
||||
@@ -8,6 +8,7 @@ from odoo import fields, _
|
||||
from odoo.addons.component.core import Component
|
||||
from odoo.addons.connector.components.mapper import mapping
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.addons.queue_job.exception import RetryableJobError
|
||||
|
||||
|
||||
class SaleOrderBatchImporter(Component):
|
||||
@@ -363,9 +364,16 @@ class SaleOrderImporter(Component):
|
||||
def _import_dependencies(self):
|
||||
record = self.opencart_record
|
||||
self._import_addresses()
|
||||
products_need_setup = []
|
||||
for product in record.get('products', []):
|
||||
if 'product_id' in product and product['product_id']:
|
||||
self._import_dependency(product['product_id'], 'opencart.product.template')
|
||||
needs_product_setup = self._import_dependency(product['product_id'], 'opencart.product.template')
|
||||
if needs_product_setup:
|
||||
products_need_setup.append(product['product_id'])
|
||||
|
||||
if products_need_setup and self.backend_record.so_require_product_setup:
|
||||
# There are products that were either just imported, or
|
||||
raise RetryableJobError('Products need setup. OpenCart Product IDs:' + str(products_need_setup), seconds=3600)
|
||||
|
||||
|
||||
class SaleOrderLineImportMapper(Component):
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<group name="product_configuration" string="Product Defaults">
|
||||
<field name="product_categ_id"/>
|
||||
<field name="coupon_product_id"/>
|
||||
<field name="so_require_product_setup"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook name="import_config">
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<header/>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="odoo_id" readonly="1"/>
|
||||
<field name="odoo_id"/>
|
||||
<field name="opencart_attribute_value_ids" options="{'no_create': True}">
|
||||
<tree editable="top" decoration-warning="not odoo_id">
|
||||
<field name="external_id" readonly="1"/>
|
||||
|
||||
Reference in New Issue
Block a user