From 9572d634cf99aaab6f7eb07bfece384c45042aed Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Wed, 29 Sep 2021 14:04:35 -0700 Subject: [PATCH] [FIX] connector_opencart: bound template using archived variant --- connector_opencart/models/product/common.py | 2 ++ connector_opencart/models/sale_order/importer.py | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/connector_opencart/models/product/common.py b/connector_opencart/models/product/common.py index 0a5fb795..7b66edb5 100644 --- a/connector_opencart/models/product/common.py +++ b/connector_opencart/models/product/common.py @@ -18,6 +18,8 @@ class OpencartProductTemplate(models.Model): string='Opencart Product Attribute Values') def opencart_sale_get_combination(self, options, reentry=False): + if not options: + return self.odoo_id.product_variant_id selected_attribute_values = self.env['product.template.attribute.value'] for option in options: product_option_value_id = str(option['product_option_value_id']) diff --git a/connector_opencart/models/sale_order/importer.py b/connector_opencart/models/sale_order/importer.py index 336cc9a6..a4e834ec 100644 --- a/connector_opencart/models/sale_order/importer.py +++ b/connector_opencart/models/sale_order/importer.py @@ -443,9 +443,8 @@ class SaleOrderLineImportMapper(Component): product_id = record['product_id'] binder = self.binder_for('opencart.product.template') # do not unwrap, because it would be a product.template, but I need a specific variant - opencart_product_template = binder.to_internal(product_id, unwrap=False) - if record.get('option'): - product = opencart_product_template.opencart_sale_get_combination(record.get('option')) - else: - product = opencart_product_template.odoo_id.product_variant_id + # connector bindings are found with `active_test=False` but that also means computed fields + # like `product.template.product_variant_id` could find different products because of archived variants + opencart_product_template = binder.to_internal(product_id, unwrap=False).with_context(active_test=True) + product = opencart_product_template.opencart_sale_get_combination(record.get('option')) return {'product_id': product.id, 'product_uom': product.uom_id.id}