-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add product image management functionality
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
Showing
5 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', '<=', 1024 * 20)]"/> | ||
<filter string="Small Image" name="filter_small_image" | ||
domain="[('file_size', '>', 1024 * 20), ('file_size', '<=', 1024 * 100)]"/> | ||
<filter string="Medium Image" name="filter_medium_image" | ||
domain="[('file_size', '>', 1024 * 100), ('file_size', '<=', 1024 * 200)]"/> | ||
<filter string="Large Image" name="filter_large_image" | ||
domain="[('file_size', '>', 1024 * 200), ('file_size', '<=', 1024 * 500)]"/> | ||
<filter string="Very Large Image" name="filter_very_large_image" | ||
domain="[('file_size', '>', 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters