Skip to content

Commit

Permalink
[IMP] connector_woocommerce: new field woocommerce_enabled to export …
Browse files Browse the repository at this point in the history
…products. Simplified domains in products.
  • Loading branch information
KNVx committed Oct 19, 2023
1 parent 7c94278 commit 2469e7c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
20 changes: 4 additions & 16 deletions connector_woocommerce/models/product_product/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 [

Check warning on line 37 in connector_woocommerce/models/product_product/binding.py

View check run for this annotation

Codecov / codecov/patch

connector_woocommerce/models/product_product/binding.py#L37

Added line #L37 was not covered by tests
("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()

Check warning on line 43 in connector_woocommerce/models/product_product/binding.py

View check run for this annotation

Codecov / codecov/patch

connector_woocommerce/models/product_product/binding.py#L43

Added line #L43 was not covered by tests
if since_date:
domain = expression.OR(
[
domain,
[
(
"woocommerce_write_date",
">",
fields.Datetime.to_string(since_date),
)
],
]
)
domain = [

Check warning on line 45 in connector_woocommerce/models/product_product/binding.py

View check run for this annotation

Codecov / codecov/patch

connector_woocommerce/models/product_product/binding.py#L45

Added line #L45 was not covered by tests
("woocommerce_write_date", ">", fields.Datetime.to_string(since_date))
]
self.export_batch(backend_record, domain=domain)
return True

Check warning on line 49 in connector_woocommerce/models/product_product/binding.py

View check run for this annotation

Codecov / codecov/patch

connector_woocommerce/models/product_product/binding.py#L48-L49

Added lines #L48 - L49 were not covered by tests

Expand Down
11 changes: 8 additions & 3 deletions connector_woocommerce/models/product_product/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,29 @@ 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",
"variant_public_description",
"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(
Expand Down
10 changes: 7 additions & 3 deletions connector_woocommerce/models/product_template/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ class WooCommerceProductTemplate(models.Model):
@api.model
def _get_base_domain(self):
return [

Check warning on line 34 in connector_woocommerce/models/product_template/binding.py

View check run for this annotation

Codecov / codecov/patch

connector_woocommerce/models/product_template/binding.py#L34

Added line #L34 was not covered by tests
("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()

Check warning on line 40 in connector_woocommerce/models/product_template/binding.py

View check run for this annotation

Codecov / codecov/patch

connector_woocommerce/models/product_template/binding.py#L40

Added line #L40 was not covered by tests
if since_date:
domain += [
("woocommerce_write_date", ">", fields.Datetime.to_string(since_date)),
domain = [

Check warning on line 42 in connector_woocommerce/models/product_template/binding.py

View check run for this annotation

Codecov / codecov/patch

connector_woocommerce/models/product_template/binding.py#L42

Added line #L42 was not covered by tests
(
"woocommerce_write_date",
">",
fields.Datetime.to_string(since_date),
)
]
self.export_batch(backend_record, domain=domain)
return True

Check warning on line 50 in connector_woocommerce/models/product_template/binding.py

View check run for this annotation

Codecov / codecov/patch

connector_woocommerce/models/product_template/binding.py#L49-L50

Added lines #L49 - L50 were not covered by tests
Expand Down
22 changes: 18 additions & 4 deletions connector_woocommerce/models/product_template/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions connector_woocommerce/views/product_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
</xpath>
<field name="website_sequence" position="before">
<field name="is_published" />
<field
name="woocommerce_enabled"
attrs="{'readonly': [('woocommerce_enabled', '=', True), ('woocommerce_bind_ids', '!=', [])]}"
/>
<field name="woocommerce_bind_ids" invisible="1" />
</field>
<field name="website_ribbon_id" position="after">
<field name="public_description" />
Expand Down

0 comments on commit 2469e7c

Please sign in to comment.