diff --git a/product_image_suggestion/README.rst b/product_image_suggestion/README.rst new file mode 100644 index 000000000..e3c060551 --- /dev/null +++ b/product_image_suggestion/README.rst @@ -0,0 +1,70 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============================ +Product Image Suggestion +============================ + +This module shortlists you with the most relevant product images on Bing Images that you are precisely looking for. + +Installation +============ + +- www.odoo.com/documentation/13.0/setup/install.html +- Install our custom addon + + +Configuration +============= + +* Before going to install, make sure "PIL" and "python-resize-image" python packages are installed on your server +* Linux commands to install packages - ('pip install pillow', 'pip install python-resize-image') +* After installing the module, go to product form. Search product image from page "Image suggestion". +* Use image number limit for searching. + + +Features +======== + +* A seamless and accurate search of product images from Bing. +* Prioritizing the image suggestions via setting the desired search limit. +* Easy image editing; Can automatically resize the image to 1024x1204 px + + +License +======= +GNU LESSER GENERAL PUBLIC LICENSE, Version 3 (AGPLv3) +(http://www.gnu.org/licenses/agpl.html) + +Bug Tracker +=========== +Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. + +Company +------- +* `Cybrosys Techno Solutions `__ + + +Bug Tracker +=========== +Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. + + +Credits +------- +* Developers: Cybrosys Techno Solutions odoo@cybrosys.com + +Author +------ + +Developer: RAHUL C K @ cybrosys, odoo@cybrosys.com + +Maintainer +---------- +.. image:: https://cybrosys.com/images/logo.png + :target: https://cybrosys.com + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit https://www.cybrosys.com. diff --git a/product_image_suggestion/__init__.py b/product_image_suggestion/__init__.py new file mode 100644 index 000000000..d835cf9c5 --- /dev/null +++ b/product_image_suggestion/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Rahul CK() +# you can modify it under the terms of the GNU AFFERO GENERAL +# PUBLIC LICENSE (AGPL v3), Version 3. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC +# LICENSE (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +from . import models diff --git a/product_image_suggestion/__manifest__.py b/product_image_suggestion/__manifest__.py new file mode 100644 index 000000000..110d3b716 --- /dev/null +++ b/product_image_suggestion/__manifest__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Rahul CK() +# you can modify it under the terms of the GNU AFFERO GENERAL +# PUBLIC LICENSE (AGPL v3), Version 3. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC +# LICENSE (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +{ + 'name': 'Product Image Suggestion', + 'version': '13.0.1.0.0', + 'summary': 'Suggest product images from bing search', + 'description': """ + Product images can be searched from the product form using bing image + downloader and it can be set as the product display image. + """, + 'category': 'Productivity', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'depends': ['base', 'product'], + 'external_dependencies': {'python': ['PIL', 'python-resize-image']}, + 'website': 'https://www.cybrosys.com', + 'data': [ + 'views/product_template_views.xml', + ], + 'images': ['static/description/banner.jpg'], + 'license': 'AGPL-3', + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/product_image_suggestion/doc/RELEASE_NOTES.md b/product_image_suggestion/doc/RELEASE_NOTES.md new file mode 100644 index 000000000..5cf0ad934 --- /dev/null +++ b/product_image_suggestion/doc/RELEASE_NOTES.md @@ -0,0 +1,7 @@ +## Module + +#### 05.06.2023 +#### Version 13.0.1.0.0 +#### ADD + +- Initial commit for Product Image Suggestion diff --git a/product_image_suggestion/models/__init__.py b/product_image_suggestion/models/__init__.py new file mode 100644 index 000000000..52dd2512d --- /dev/null +++ b/product_image_suggestion/models/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Rahul CK() +# you can modify it under the terms of the GNU AFFERO GENERAL +# PUBLIC LICENSE (AGPL v3), Version 3. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC +# LICENSE (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +from . import bing +from . import downloader +from . import product_image_suggestion +from . import product_template diff --git a/product_image_suggestion/models/bing.py b/product_image_suggestion/models/bing.py new file mode 100644 index 000000000..7e4e22eed --- /dev/null +++ b/product_image_suggestion/models/bing.py @@ -0,0 +1,111 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Rahul CK() +# you can modify it under the terms of the GNU AFFERO GENERAL +# PUBLIC LICENSE (AGPL v3), Version 3. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC +# LICENSE (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +import imghdr +import posixpath +import re +import urllib +import urllib.request + + +class Bing: + def __init__(self, query, limit, output_dir, adult, timeout, filter='', verbose=True): + self.download_count = 0 + self.query = query + self.output_dir = output_dir + self.adult = adult + self.filter = filter + self.verbose = verbose + self.seen = set() + + assert type(limit) == int, "limit must be integer" + self.limit = limit + assert type(timeout) == int, "timeout must be integer" + self.timeout = timeout + + self.page_counter = 0 + self.headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.11 (KHTML, like Gecko) ' + 'Chrome/23.0.1271.64 Safari/537.11', + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', + 'Accept-Encoding': 'none', + 'Accept-Language': 'en-US,en;q=0.8', + 'Connection': 'keep-alive'} + + def get_filter(self, shorthand): + if shorthand == "line" or shorthand == "linedrawing": + return "+filterui:photo-linedrawing" + elif shorthand == "photo": + return "+filterui:photo-photo" + elif shorthand == "clipart": + return "+filterui:photo-clipart" + elif shorthand == "gif" or shorthand == "animatedgif": + return "+filterui:photo-animatedgif" + elif shorthand == "transparent": + return "+filterui:photo-transparent" + else: + return "" + + def save_image(self, link, file_path): + request = urllib.request.Request(link, None, self.headers) + image = urllib.request.urlopen(request, timeout=self.timeout).read() + if not imghdr.what(None, image): + raise ValueError('Invalid image, not saving {}\n'.format(link)) + with open(str(file_path), 'wb') as path_string: + path_string.write(image) + + def download_image(self, link): + self.download_count += 1 + try: + path = urllib.parse.urlsplit(link).path + filename = posixpath.basename(path).split('?')[0] + file_type = filename.split(".")[-1] + if file_type.lower() not in ["jpe", "jpeg", "jfif", "exif", "tiff", "gif", "bmp", "png", "webp", "jpg"]: + file_type = "jpg" + + self.save_image(link, self.output_dir.joinpath("Image_{}.{}".format( + str(self.download_count), file_type))) + if self.verbose: + return link + + except Exception: + self.download_count -= 1 + self.seen.remove(link) + + def run(self): + while self.download_count < self.limit: + request_url = 'https://www.bing.com/images/async?q=' + urllib.parse.quote_plus(self.query) \ + + '&first=' + str(self.page_counter) + '&count=' + str(self.limit) \ + + '&adlt=' + self.adult + '&qft=' + ( + '' if self.filter is None else self.get_filter(self.filter)) + request = urllib.request.Request(request_url, None, headers=self.headers) + response = urllib.request.urlopen(request) + html = response.read().decode('utf8') + if html == "": + break + links = re.findall('murl":"(.*?)"', html) + + for link in links: + if self.download_count < self.limit and link not in self.seen: + self.seen.add(link) + self.download_image(link) + + self.page_counter += 1 + return self.seen diff --git a/product_image_suggestion/models/downloader.py b/product_image_suggestion/models/downloader.py new file mode 100644 index 000000000..41f976efd --- /dev/null +++ b/product_image_suggestion/models/downloader.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Rahul CK() +# you can modify it under the terms of the GNU AFFERO GENERAL +# PUBLIC LICENSE (AGPL v3), Version 3. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC +# LICENSE (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +import shutil +import sys +from pathlib import Path + +try: + from bing import Bing +except ImportError: + from .bing import Bing + + +def download(query, limit=100, output_dir='dataset', adult_filter_off=True, + force_replace=False, timeout=60, filter="", verbose=True): + if adult_filter_off: + adult = 'off' + else: + adult = 'on' + + image_dir = Path(output_dir).joinpath(query).absolute() + + if force_replace: + if Path.isdir(image_dir): + shutil.rmtree(image_dir) + + try: + if not Path.is_dir(image_dir): + Path.mkdir(image_dir, parents=True) + + except Exception: + sys.exit(1) + + bing = Bing(query, limit, image_dir, adult, timeout, filter, verbose) + return bing.run() diff --git a/product_image_suggestion/models/product_image_suggestion.py b/product_image_suggestion/models/product_image_suggestion.py new file mode 100644 index 000000000..ea2241cd4 --- /dev/null +++ b/product_image_suggestion/models/product_image_suggestion.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Rahul CK() +# you can modify it under the terms of the GNU AFFERO GENERAL +# PUBLIC LICENSE (AGPL v3), Version 3. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC +# LICENSE (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +from odoo import fields, models + + +class ProductImageSuggestion(models.TransientModel): + """creates new model to store the searched image""" + _name = "product.image.suggestion" + _description = "Attach images and set image as the display image of product" + + image = fields.Binary(string='Image', attachment=True, + help="image field to store the image") + product_tmpl_id = fields.Many2one('product.template', + string='Related Product', + help="product field to store the id of " + "product from which the image is " + "searched") + + def action_set_image(self): + """Set image as product display image when 'Set Image' button is + clicked""" + self.product_tmpl_id.image_1920 = self.image diff --git a/product_image_suggestion/models/product_template.py b/product_image_suggestion/models/product_template.py new file mode 100644 index 000000000..ee8a7c920 --- /dev/null +++ b/product_image_suggestion/models/product_template.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Rahul CK() +# you can modify it under the terms of the GNU AFFERO GENERAL +# PUBLIC LICENSE (AGPL v3), Version 3. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC +# LICENSE (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +import base64 +import logging +import os +import tempfile +import requests +from PIL import Image +from resizeimage import resizeimage +from odoo import api, fields, models, _ +from odoo.exceptions import UserError, Warning +from . import downloader + +_logger = logging.getLogger(__name__) + + +class ProductTemplate(models.Model): + """ + Inherited product template to add new fields to show the downloaded image + and set an image as product image + """ + _inherit = 'product.template' + + search_image_ids = fields.One2many('product.image.suggestion', + 'product_tmpl_id', string='Images', + readonly=True, + help="To show the images downloaded") + search_field = fields.Char(string='Search Text', + help="Type the text to be searched") + image_limit = fields.Integer(string='Limit', default=5, + help="Limit of images to display") + resize_image = fields.Boolean(string='Resize Image', default=True, + help="Resize the image") + + @api.onchange('image_limit') + def _onchange_image_limit(self): + """ + Check if the searched image limit is greater than 10 and a warning + message will be raised. + """ + if self.image_limit > 10: + raise Warning(_('This may slow down image search..!!!')) + + def action_search_image(self): + """Clear search images and add new search""" + for rec in self: + rec.search_image_ids = [[5, 0, 0]] + if rec.image_limit > 10: + _logger.warning("High limit number slow down the image " + "searches") + try: + query_string = rec.search_field.replace(" ", "_").replace(",", + "_") + image_datas = downloader.download(query_string, + limit=rec.image_limit, + output_dir='dataset', + adult_filter_off=False, + timeout=60, verbose=True) + except AttributeError: + raise UserError(_('No internet connection available or ' + 'Something wrong!')) + if image_datas: + for img in image_datas: + temp_name = '' + try: + img_request = requests.get(img.strip()).content + if self.resize_image: + temp_file, temp_name = tempfile.mkstemp(suffix= + '.png') + file = open(temp_name, "wb") + file.write(img_request) + file.close() + img_data = resizeimage.resize_contain( + Image.open(temp_name), [1024, 1024]) + img_data.save(temp_name, img_data.format) + with open(temp_name, "rb") as image_file: + binary_image = base64.b64encode(image_file. + read()) + else: + binary_image = \ + base64.b64encode(bytearray(img_request)) + self.env['product.image.suggestion'].create({ + 'image': binary_image, + 'product_tmpl_id': rec.id + }) + if self.resize_image: + os.remove(temp_name) + except: + _logger.exception(_("failed to display in page")) + continue + else: + raise UserError(_('No image suggestions for this image')) diff --git a/product_image_suggestion/static/description/banner.jpg b/product_image_suggestion/static/description/banner.jpg new file mode 100644 index 000000000..b2e3c3dc2 Binary files /dev/null and b/product_image_suggestion/static/description/banner.jpg differ diff --git a/product_image_suggestion/static/description/cybro_logo.png b/product_image_suggestion/static/description/cybro_logo.png new file mode 100644 index 000000000..bb309114c Binary files /dev/null and b/product_image_suggestion/static/description/cybro_logo.png differ diff --git a/product_image_suggestion/static/description/icon.png b/product_image_suggestion/static/description/icon.png new file mode 100644 index 000000000..8994ffaf6 Binary files /dev/null and b/product_image_suggestion/static/description/icon.png differ diff --git a/product_image_suggestion/static/description/images/Image_1.png b/product_image_suggestion/static/description/images/Image_1.png new file mode 100644 index 000000000..73cdb8610 Binary files /dev/null and b/product_image_suggestion/static/description/images/Image_1.png differ diff --git a/product_image_suggestion/static/description/images/Image_2.png b/product_image_suggestion/static/description/images/Image_2.png new file mode 100644 index 000000000..e166d364b Binary files /dev/null and b/product_image_suggestion/static/description/images/Image_2.png differ diff --git a/product_image_suggestion/static/description/images/Image_3.png b/product_image_suggestion/static/description/images/Image_3.png new file mode 100644 index 000000000..b8c9aa13a Binary files /dev/null and b/product_image_suggestion/static/description/images/Image_3.png differ diff --git a/product_image_suggestion/static/description/images/calculator_in_pos.png b/product_image_suggestion/static/description/images/calculator_in_pos.png new file mode 100644 index 000000000..4c192dc10 Binary files /dev/null and b/product_image_suggestion/static/description/images/calculator_in_pos.png differ diff --git a/product_image_suggestion/static/description/images/checked.png b/product_image_suggestion/static/description/images/checked.png new file mode 100644 index 000000000..578cedb80 Binary files /dev/null and b/product_image_suggestion/static/description/images/checked.png differ diff --git a/product_image_suggestion/static/description/images/custom_gantt_view.png b/product_image_suggestion/static/description/images/custom_gantt_view.png new file mode 100644 index 000000000..edc204b88 Binary files /dev/null and b/product_image_suggestion/static/description/images/custom_gantt_view.png differ diff --git a/product_image_suggestion/static/description/images/cybrosys.png b/product_image_suggestion/static/description/images/cybrosys.png new file mode 100644 index 000000000..d76b5bafb Binary files /dev/null and b/product_image_suggestion/static/description/images/cybrosys.png differ diff --git a/product_image_suggestion/static/description/images/dynamic_partner_fields.png b/product_image_suggestion/static/description/images/dynamic_partner_fields.png new file mode 100644 index 000000000..bb21eb8d8 Binary files /dev/null and b/product_image_suggestion/static/description/images/dynamic_partner_fields.png differ diff --git a/product_image_suggestion/static/description/images/dynamic_product_fields.png b/product_image_suggestion/static/description/images/dynamic_product_fields.png new file mode 100644 index 000000000..f7c406cfc Binary files /dev/null and b/product_image_suggestion/static/description/images/dynamic_product_fields.png differ diff --git a/product_image_suggestion/static/description/images/export_stockinfo_xls.png b/product_image_suggestion/static/description/images/export_stockinfo_xls.png new file mode 100644 index 000000000..a8dade6e9 Binary files /dev/null and b/product_image_suggestion/static/description/images/export_stockinfo_xls.png differ diff --git a/product_image_suggestion/static/description/images/image_suggestion_v13.png b/product_image_suggestion/static/description/images/image_suggestion_v13.png new file mode 100644 index 000000000..45c0610f2 Binary files /dev/null and b/product_image_suggestion/static/description/images/image_suggestion_v13.png differ diff --git a/product_image_suggestion/static/description/images/project_custom_gantt.png b/product_image_suggestion/static/description/images/project_custom_gantt.png new file mode 100644 index 000000000..eba731e73 Binary files /dev/null and b/product_image_suggestion/static/description/images/project_custom_gantt.png differ diff --git a/product_image_suggestion/static/description/index.html b/product_image_suggestion/static/description/index.html new file mode 100644 index 000000000..7a813892b --- /dev/null +++ b/product_image_suggestion/static/description/index.html @@ -0,0 +1,327 @@ +
cybrosys-logo
+
+
+
+

Product Image Suggestion

+

An effective and user-friendly method of suggesting product images via web downloads

+
+

Key Highlights

+
    +
  • A seamless and accurate search of product images from Bing.
  • +
  • Prioritizing the image suggestions via setting the desired search limit.
  • +
  • Easy image editing: Can automatically resize the image to 1024x1204 px.
  • +
+
+
+
+
+
+
+
+ +
+
+ +

Overview

+
+

+ This module allows you to search for product images from the bing web browser and suggestions will be shown in the product form. +

+
+ +

Product Image Suggestion

+
+
    +
  • + In the product form a new page 'Image Suggestion' is created. +
  • +
  • + Provide the product name to be searched in the search box and limit of images to display. +
  • +
  • + On click on the search icon, system will search for the image from the Bing browser. +
  • + +
  • + The downloaded images will be shown in the product form. +
  • + +
  • + Images will be converted to 1024x1024 px when 'resize image' is enabled. +
  • + +
  • + Image can be set as product image when 'Set Image' is clicked. +
  • +
+
+ +
+
+

Screenshots

+
+
+
+ +
+
+
+
+ + +
+
    +
+
+
+
+
+
+
+

Suggested Products

+
+ +
+
+

Our Service

+
+ +
+
+
+

Our Industries

+
+ +
+
+
+ +
+
+

Trading

+

Easily procure and sell your products.

+
+
+
+
+ +
+
+

Manufacturing

+

Plan, track and schedule your operations.

+
+
+
+
+ +
+
+

Restaurant

+

Run your bar or restaurant methodical.

+
+
+
+
+ +
+
+

POS

+

Easy configuring and convivial selling.

+
+
+
+
+ +
+
+

E-commerce & Website

+

Mobile friendly, awe-inspiring product pages.

+
+
+
+
+ +
+
+

Hotel Management

+

An all-inclusive hotel management application.

+
+
+
+
+ +
+
+

Education

+

A Collaborative platform for educational management.

+
+
+
+
+ +
+
+

Service Management

+

Keep track of services and invoice accordingly.

+
+
+
+
+
+ +
+
+
+

Need Any Help?

+
+

If you have anything to share with us based on your use of this module, please let us know. We are ready to offer our support.

+
+

Email us

+

odoo@cybrosys.com

+
+
+

Contact Us

+ www.cybrosys.com +
+
+
+
+
+
+
+
+
+ +
+ + + + + + + +
+
+
+ \ No newline at end of file diff --git a/product_image_suggestion/views/product_template_views.xml b/product_image_suggestion/views/product_template_views.xml new file mode 100644 index 000000000..9e29d6087 --- /dev/null +++ b/product_image_suggestion/views/product_template_views.xml @@ -0,0 +1,62 @@ + + + + + + product.template.view.form.inherit.product.image.suggestion + + product.template + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +