Skip to content

Commit

Permalink
[IMP]storage_image_product: main image of the variant
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHForgeFlow committed Sep 1, 2021
1 parent e6d1b34 commit 0f4ae9a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions storage_image_product/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def _compute_main_image_id(self):
record.main_image_id = record._get_main_image()

def _get_main_image(self):
match_image = self.variant_image_ids.filtered(
lambda i: i.attribute_value_ids
== self.mapped(
"product_template_attribute_value_ids.product_attribute_value_id"
)
)
if match_image:
return fields.first(
match_image.sorted(key=lambda i: (i.sequence, i.image_id))
).image_id
return fields.first(
self.variant_image_ids.sorted(key=lambda i: (i.sequence, i.image_id))
).image_id

0 comments on commit 0f4ae9a

Please sign in to comment.