From 256a14714542f213cda7c05e27d804937d9dbf18 Mon Sep 17 00:00:00 2001 From: KNVx Date: Mon, 16 Oct 2023 12:04:46 +0200 Subject: [PATCH] [IMP] connector_woocommerce: new field woocommerce_enabled to export products. Simplified domains in products. --- .../models/product_product/binding.py | 20 ++++------------- .../models/product_product/product.py | 11 +++++++--- .../models/product_template/binding.py | 10 ++++++--- .../product_template/product_template.py | 22 +++++++++++++++---- .../views/product_template.xml | 5 +++++ 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/connector_woocommerce/models/product_product/binding.py b/connector_woocommerce/models/product_product/binding.py index 7fb267896..58d636fd0 100644 --- a/connector_woocommerce/models/product_product/binding.py +++ b/connector_woocommerce/models/product_product/binding.py @@ -2,7 +2,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) from odoo import api, fields, models -from odoo.osv import expression class WooCommerceProductProduct(models.Model): @@ -33,30 +32,19 @@ class WooCommerceProductProduct(models.Model): ), ] - # TODO: REFACTOR THIS GET_BASE_DOMAIN TO DO IT MORE SIMPLE @api.model def _get_base_domain(self): return [ - ("variant_is_published", "=", True), - ("woocommerce_write_date", "=", False), + ("product_tmpl_id.woocommerce_enabled", "=", True), ("product_tmpl_id.has_attributes", "=", True), ] def export_products_since(self, backend_record=None, since_date=None): domain = self._get_base_domain() if since_date: - domain = expression.OR( - [ - domain, - [ - ( - "woocommerce_write_date", - ">", - fields.Datetime.to_string(since_date), - ) - ], - ] - ) + domain = [ + ("woocommerce_write_date", ">", fields.Datetime.to_string(since_date)) + ] self.export_batch(backend_record, domain=domain) return True diff --git a/connector_woocommerce/models/product_product/product.py b/connector_woocommerce/models/product_product/product.py index 1fdffc0c9..d3cc74d5d 100644 --- a/connector_woocommerce/models/product_product/product.py +++ b/connector_woocommerce/models/product_product/product.py @@ -19,13 +19,11 @@ class ProductProduct(models.Model): ) @api.depends( - "woocommerce_bind_ids", "is_published", "lst_price", "type", "default_code", "image_1920", - "product_tmpl_id", "default_code", "qty_available", "product_template_attribute_value_ids", @@ -33,10 +31,17 @@ class ProductProduct(models.Model): "alternative_product_ids", "accessory_product_ids", "variant_inventory_availability", + "product_tmpl_id", + "product_tmpl_id.has_attributes", + "product_tmpl_id.woocommerce_enabled", ) def _compute_woocommerce_write_date(self): for rec in self: - if rec.is_published or rec.woocommerce_write_date: + if ( + rec.product_tmpl_id.woocommerce_enabled + or rec.variant_is_published + or rec.woocommerce_write_date + ): rec.woocommerce_write_date = fields.Datetime.now() variant_public_description = fields.Text( diff --git a/connector_woocommerce/models/product_template/binding.py b/connector_woocommerce/models/product_template/binding.py index 553ba5fdb..310d7b921 100644 --- a/connector_woocommerce/models/product_template/binding.py +++ b/connector_woocommerce/models/product_template/binding.py @@ -32,15 +32,19 @@ class WooCommerceProductTemplate(models.Model): @api.model def _get_base_domain(self): return [ - ("is_published", "=", True), + ("woocommerce_enabled", "=", True), ("has_attributes", "=", False), ] def export_product_tmpl_since(self, backend_record=None, since_date=None): domain = self._get_base_domain() if since_date: - domain += [ - ("woocommerce_write_date", ">", fields.Datetime.to_string(since_date)), + domain = [ + ( + "woocommerce_write_date", + ">", + fields.Datetime.to_string(since_date), + ) ] self.export_batch(backend_record, domain=domain) return True diff --git a/connector_woocommerce/models/product_template/product_template.py b/connector_woocommerce/models/product_template/product_template.py index 415401163..e0acf9eb1 100644 --- a/connector_woocommerce/models/product_template/product_template.py +++ b/connector_woocommerce/models/product_template/product_template.py @@ -29,23 +29,28 @@ def _compute_has_attributes(self): rec.has_attributes = bool(rec.attribute_line_ids) @api.depends( - "woocommerce_bind_ids", "is_published", "name", "lst_price", "active", - "product_variant_id.qty_available", + "qty_available", "image_1920", "default_code", - "qty_available", "description", "public_categ_ids", "attribute_line_ids", "public_description", + "inventory_availability", + "has_attributes", + "woocommerce_enabled", ) def _compute_woocommerce_write_date(self): for rec in self: - if rec.is_published or rec.woocommerce_write_date: + if ( + rec.woocommerce_enabled + or rec.is_published + or rec.woocommerce_write_date + ): rec.woocommerce_write_date = fields.Datetime.now() public_description = fields.Text( @@ -60,6 +65,15 @@ def _compute_woocommerce_write_date(self): button_is_published = fields.Boolean( related="is_published", ) + woocommerce_enabled = fields.Boolean( + compute="_compute_woocommerce_enabled", + store=True, + readonly=False, + ) + + def _compute_woocommerce_enabled(self): + for rec in self: + rec.woocommerce_enabled = rec.is_published @api.depends("product_variant_ids.variant_is_published") def _compute_template_is_published(self): diff --git a/connector_woocommerce/views/product_template.xml b/connector_woocommerce/views/product_template.xml index c72d38b1e..5a28b8f47 100644 --- a/connector_woocommerce/views/product_template.xml +++ b/connector_woocommerce/views/product_template.xml @@ -46,6 +46,11 @@ + +