Skip to content

Commit

Permalink
Add product image management functionality
Browse files Browse the repository at this point in the history
Introduced a new `ImageMixin` for handling product image attributes and actions. Also, added a new view for product images with search filters and a menu entry in the inventory control section. Updated `__manifest__.py` to include the newly added views.
  • Loading branch information
cbusillo committed Jul 24, 2024
1 parent 4ce69d9 commit 8d28f9d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions product_connect/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"views/product_import_wizard.xml",
"views/product_product_views.xml",
"views/product_template_views.xml",
"views/product_image_views.xml",
"views/product_type_views.xml",
"views/product_manufacturer_views.xml",
"views/project_task_views.xml",
Expand Down
2 changes: 1 addition & 1 deletion product_connect/mixins/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import label_mixin, notification_manager_mixin
from . import image_mixin, label_mixin, notification_manager_mixin
21 changes: 21 additions & 0 deletions product_connect/mixins/image_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from odoo import models, fields


class ImageMixin(models.AbstractModel):
_name = "image.mixin"
_description = "Image Mixin"
_inherit = "image.mixin"

file_size = fields.Integer(compute="_compute_file_size", store=True, group_operator="sum")

def _compute_file_size(self) -> None:
for record in self:
record.file_size = len(record.image_1920 or b'')

def action_open_full_image(self) -> dict:
self.ensure_one()
return {
'type': 'ir.actions.act_url',
'url': '/web/image?model=product.image&id=%s&field=image_1920' % self.id,
'target': 'new',
}
52 changes: 52 additions & 0 deletions product_connect/views/product_image_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<odoo>
<record id="product_image_edit_tree" model="ir.ui.view">
<field name="name">product.image.edit.tree</field>
<field name="model">product.image</field>
<field name="arch" type="xml">
<tree string="Product Images">
<field name="name"/>
<field name="file_size"/>
<field name="image_1920" widget="image_upload"/>
<button name="action_open_full_image" type="object" string="View Full Image" class="btn btn-primary"/>
</tree>
</field>
</record>

<record id="view_product_image_edit_search" model="ir.ui.view">
<field name="name">product.image.edit.search</field>
<field name="model">product.image</field>
<field name="arch" type="xml">
<search string="Product Images">
<filter string="Very Small Image" name="filter_very_small_image"
domain="[('file_size', '&lt;=', 1024 * 20)]"/>
<filter string="Small Image" name="filter_small_image"
domain="[('file_size', '&gt;', 1024 * 20), ('file_size', '&lt;=', 1024 * 100)]"/>
<filter string="Medium Image" name="filter_medium_image"
domain="[('file_size', '&gt;', 1024 * 100), ('file_size', '&lt;=', 1024 * 200)]"/>
<filter string="Large Image" name="filter_large_image"
domain="[('file_size', '&gt;', 1024 * 200), ('file_size', '&lt;=', 1024 * 500)]"/>
<filter string="Very Large Image" name="filter_very_large_image"
domain="[('file_size', '&gt;', 1024 * 500)]"/>
<separator/>
<group expand="0" string="Group By">
<filter string="Product" name="groupby_product" context="{'group_by': 'product_tmpl_id'}"/>
</group>
<separator/>
</search>

</field>
</record>


<record id="action_product_image_edit" model="ir.actions.act_window">
<field name="name">Product Images</field>
<field name="res_model">product.image</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="product_image_edit_tree"/>
<field name="search_view_id" ref="view_product_image_edit_search"/>
</record>

<menuitem id="menu_product_image_edit" name="Product Images"
parent="stock.menu_stock_inventory_control" sequence="3"
action="action_product_image_edit"/>
</odoo>
2 changes: 1 addition & 1 deletion product_connect/views/product_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<menuitem id="menu_product_template_edit" name="Product Edit" action="action_product_template_tree_edit"
parent="stock.menu_stock_inventory_control" sequence="2"/>
<menuitem id="menu_product_template_dimensions_form" name="Product Dimensions"
parent="stock.menu_stock_inventory_control" sequence="3"
parent="stock.menu_stock_inventory_control" sequence="4"
action="action_product_template_dimensions_form"/>

<!-- reorder configuration menu items -->
Expand Down

0 comments on commit 8d28f9d

Please sign in to comment.