diff --git a/import_product_image/README.rst b/import_product_image/README.rst new file mode 100644 index 000000000..9eabed50e --- /dev/null +++ b/import_product_image/README.rst @@ -0,0 +1,51 @@ +Import Product Image v10 +======================== + +This Cybrosys's module allows you to import images for a product/product variant from a +CSV file using URL and file path. You can also create a new product from the wizard +if it does not exist in the system. + +Installation +============ +- www.odoo.com/documentation/10.0/setup/install.html +- Install our custom addon + +Features +======== + +* Import Product Image From CSV File(Url/ File Path). + +Technical Notes +=============== + +Used Libraries: + +* urllib2 +* requests +* urllib2 +* base64 + +License +======= +GNU LESSER GENERAL PUBLIC LICENSE, Version 3 (LGPLv3) +(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. + +Credits +======= +* Cybrosys Techno Solutions + +Author +------ + +Developer: Saritha @ cybrosys, saritha@cybrosys.in + +Maintainer +---------- + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit https://www.cybrosys.com. diff --git a/import_product_image/__init__.py b/import_product_image/__init__.py new file mode 100644 index 000000000..9206ddbc4 --- /dev/null +++ b/import_product_image/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +################################################################################### +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author: Saritha Sahadevan () +# +# This program is free software: you can modify +# it under the terms of the GNU Affero General Public License (AGPL) as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# 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 for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### +from . import models diff --git a/import_product_image/__manifest__.py b/import_product_image/__manifest__.py new file mode 100644 index 000000000..7e4eeb5a8 --- /dev/null +++ b/import_product_image/__manifest__.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +################################################################################### +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author: Saritha Sahadevan () +# +# This program is free software: you can modify +# it under the terms of the GNU Affero General Public License (AGPL) as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# 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 for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### +{ + 'name': "Import Product Image", + 'version': '10.0.1.0.0', + 'summary': """Import Product Image from CSV File""", + 'description': """Import Product Image from CSV File(Web URL/File Path)""", + 'author': "Cybrosys Techno Solutions", + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'website': "https://www.cybrosys.com", + 'category': 'Sales', + 'version': '10.0.1.0.0', + 'depends': ['sale'], + 'data': ['views/import_product_image_view.xml'], + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'auto_install': False, +} diff --git a/import_product_image/models/__init__.py b/import_product_image/models/__init__.py new file mode 100644 index 000000000..0764e94d1 --- /dev/null +++ b/import_product_image/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import import_image diff --git a/import_product_image/models/import_image.py b/import_product_image/models/import_image.py new file mode 100644 index 000000000..478d4ad50 --- /dev/null +++ b/import_product_image/models/import_image.py @@ -0,0 +1,99 @@ +# -*- coding: utf-8 -*- +################################################################################### +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author: Saritha Sahadevan () +# +# This program is free software: you can modify +# it under the terms of the GNU Affero General Public License (AGPL) as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# 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 for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### +import csv +import urllib2 +import base64 +import StringIO +import sys +from odoo import models, fields, api +from odoo.exceptions import Warning + + +class ProductImageImportWizard(models.TransientModel): + _name = 'import.product_image' + + product_model = fields.Selection([('1', 'Product Template'), ('2', 'Product Variants')], string="Product Model") + pdt_operation = fields.Selection([('1', 'Product Creation'), ('2', 'Product Updation')], string="Product Operation") + file = fields.Binary('File to import', required=True) + + @api.multi + def import_file(self): + file = StringIO.StringIO(base64.decodestring(self.file)) + reader = csv.reader(file, delimiter=',') + csv.field_size_limit(sys.maxsize) + skip_header = True + for row in reader: + if skip_header: + skip_header = False + continue + product = row[0] + image_path = row[1] + if "http://" in image_path or "https://" in image_path: + try: + link = urllib2.urlopen(image_path).read() + image_base64 = base64.encodestring(link) + if self.product_model == '1': + product_obj = self.env['product.template'] + else: + product_obj = self.env['product.product'] + product_id = product_obj.search([('name', '=', product)]) + + vals = { + 'image_medium': image_base64, + 'name': product, + } + if self.pdt_operation == '1': + if not product_id: + product_obj.create(vals) + else: + product_id.write(vals) + elif self.pdt_operation == '2' and product_id: + product_id.write(vals) + elif not product_id and self.pdt_operation == '2': + raise Warning("Could not find the product '%s'" % product) + except: + raise Warning("Please provide correct URL for product '%s' or check your image size.!" % product) + else: + try: + with open(image_path, 'rb') as image: + image_base64 = image.read().encode("base64") + if self.product_model == '1': + product_obj = self.env['product.template'] + else: + product_obj = self.env['product.product'] + product_id = product_obj.search([('name', '=', product)]) + vals = { + 'image_medium': image_base64, + 'name': product, + } + if self.pdt_operation == '1': + if not product_id: + product_obj.create(vals) + else: + product_id.write(vals) + elif self.pdt_operation == '2' and product_id: + product_id.write(vals) + elif not product_id and self.pdt_operation == '2': + raise Warning("Could not find the product '%s'" % product) + except IOError: + raise Warning("Could not find the image '%s' - please make sure it is accessible to this script" % product) + diff --git a/import_product_image/static/description/banner.jpg b/import_product_image/static/description/banner.jpg new file mode 100644 index 000000000..f474c18cd Binary files /dev/null and b/import_product_image/static/description/banner.jpg differ diff --git a/import_product_image/static/description/csv_file.png b/import_product_image/static/description/csv_file.png new file mode 100644 index 000000000..127b08e6f Binary files /dev/null and b/import_product_image/static/description/csv_file.png differ diff --git a/import_product_image/static/description/cybro_logo.png b/import_product_image/static/description/cybro_logo.png new file mode 100644 index 000000000..bb309114c Binary files /dev/null and b/import_product_image/static/description/cybro_logo.png differ diff --git a/import_product_image/static/description/icon.png b/import_product_image/static/description/icon.png new file mode 100644 index 000000000..7b3763019 Binary files /dev/null and b/import_product_image/static/description/icon.png differ diff --git a/import_product_image/static/description/import_image.png b/import_product_image/static/description/import_image.png new file mode 100644 index 000000000..eee4b8d6d Binary files /dev/null and b/import_product_image/static/description/import_image.png differ diff --git a/import_product_image/static/description/index.html b/import_product_image/static/description/index.html new file mode 100644 index 000000000..6f4a09760 --- /dev/null +++ b/import_product_image/static/description/index.html @@ -0,0 +1,103 @@ +
+
+

Import Product Image

+

+

Cybrosys Technologies

+
+
+
+ Import Product Image From CSV File(Url/ File Path).
+
+
+
+ +
+
+
+

Overview

+

+ This module allows you to import images for a product/product variant from a + CSV file using URL and file path. You can also create a new product from the wizard + if it does not exist in the system. +

+
+
+
+ +
+
+
+

+

Import Multiple Image Through CSV File

+

+

+
+
+ +
+ This is a sample CSV file to import product image +
+
+
+ +
+
+
+

+

Import Image From Url Or File path

+

+

+
+ Here you have the option to create a new product or to modify existing products +
+ +
+
+
+
+ +
+
+
+

+

Warning Message for unsupported image address

+

+

+
+ In case of video data url.
+ In case of unsupported file format.
+ In case of image size is too large.
+
+
+
+ +
+
+
+
+ +
+

Need Any Help?

+ +
diff --git a/import_product_image/static/description/warning.png b/import_product_image/static/description/warning.png new file mode 100644 index 000000000..0fe08f4af Binary files /dev/null and b/import_product_image/static/description/warning.png differ diff --git a/import_product_image/views/import_product_image_view.xml b/import_product_image/views/import_product_image_view.xml new file mode 100644 index 000000000..f1fdfe95c --- /dev/null +++ b/import_product_image/views/import_product_image_view.xml @@ -0,0 +1,39 @@ + + + + + product.import.image.form + import.product_image + form + +
+ + + + + + + + + +
+
+
+
+
+ + + Import Product Image + ir.actions.act_window + import.product_image + form + form + new + + + +
+
\ No newline at end of file