Browse Source

[ADD] Initial Commit

pull/57/head
Sreejith 7 years ago
parent
commit
c3fe063449
  1. 51
      import_product_image/README.rst
  2. 22
      import_product_image/__init__.py
  3. 39
      import_product_image/__manifest__.py
  4. 3
      import_product_image/models/__init__.py
  5. 99
      import_product_image/models/import_image.py
  6. BIN
      import_product_image/static/description/banner.jpg
  7. BIN
      import_product_image/static/description/csv_file.png
  8. BIN
      import_product_image/static/description/cybro_logo.png
  9. BIN
      import_product_image/static/description/icon.png
  10. BIN
      import_product_image/static/description/import_image.png
  11. 103
      import_product_image/static/description/index.html
  12. BIN
      import_product_image/static/description/warning.png
  13. 39
      import_product_image/views/import_product_image_view.xml

51
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<https://www.cybrosys.com>
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.

22
import_product_image/__init__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
# Author: Saritha Sahadevan (<https://www.cybrosys.com>)
#
# 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 <https://www.gnu.org/licenses/>.
#
###################################################################################
from . import models

39
import_product_image/__manifest__.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
# Author: Saritha Sahadevan (<https://www.cybrosys.com>)
#
# 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 <https://www.gnu.org/licenses/>.
#
###################################################################################
{
'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,
}

3
import_product_image/models/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import import_image

99
import_product_image/models/import_image.py

@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
# Author: Saritha Sahadevan (<https://www.cybrosys.com>)
#
# 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 <https://www.gnu.org/licenses/>.
#
###################################################################################
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)

BIN
import_product_image/static/description/banner.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
import_product_image/static/description/csv_file.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
import_product_image/static/description/cybro_logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
import_product_image/static/description/icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
import_product_image/static/description/import_image.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

103
import_product_image/static/description/index.html

@ -0,0 +1,103 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<h2 class="oe_slogan">Import Product Image</h2>
<h3 class="oe_slogan"></h3>
<h4 class="oe_slogan"><a href="https://www.cybrosys.com">Cybrosys Technologies</a> </h4>
</div>
<div class="oe_row oe_spaced" style="padding-left:65px;">
<div>
<span style="color:green;"> &#9745; </span> Import Product Image From CSV File(Url/ File Path).<br/>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_picture">
<h3 class="oe_slogan">Overview</h3>
<p class="oe_mt32 text-justify" style="text-align: center;">
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.
</p>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<div style="text-align: center">
<p>
<h4>Import Multiple Image Through CSV File</h4>
<p>
</div>
<div style="text-align: center">
<div class="oe_demo oe_picture oe_screenshot">
<img style="border:10px solid white;height:400px;" src="csv_file.png">
</div>
<span>This is a sample CSV file to import product image</span>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div style="text-align: center">
<p>
<h4>Import Image From Url Or File path</h4>
<p>
</div>
<div style="text-align: center">
<span>Here you have the option to create a new product or to modify existing products</span>
<div class="oe_demo oe_picture oe_screenshot">
<img style="border:10px solid white;" src="import_image.png">
</div>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<div style="text-align: center">
<p>
<h4>Warning Message for unsupported image address</h4>
<p>
</div>
<div class="oe_row oe_spaced" style="padding-left:65px;">
<span style="color:green;"> &#9885; </span> In case of video data url.<br/>
<span style="color:green;"> &#9885; </span> In case of unsupported file format.<br/>
<span style="color:green;"> &#9885; </span> In case of image size is too large.<br/>
</div>
<div style="text-align: center">
<div class="oe_demo oe_picture oe_screenshot">
<img style="border:10px solid white;" src="warning.png">
</div>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<h2 class="oe_slogan" style="margin-top:20px;" >Need Any Help?</h2>
<div class="oe_slogan" style="margin-top:10px !important;">
<div>
<a class="btn btn-primary btn-lg mt8"
style="color: #FFFFFF !important;border-radius: 0;" href="https://www.cybrosys.com"><i
class="fa fa-envelope"></i> Email </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="https://www.cybrosys.com/contact/"><i
class="fa fa-phone"></i> Contact Us </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="https://www.cybrosys.com/odoo-customization-and-installation/"><i
class="fa fa-check-square"></i> Request Customization </a>
</div>
<br>
<img src="cybro_logo.png" style="width: 190px; margin-bottom: 20px;" class="center-block">
<div>
<a href="https://twitter.com/cybrosys" target="_blank"><i class="fa fa-2x fa-twitter" style="color:white;background: #00a0d1;width:35px;"></i></a></td>
<a href="https://www.linkedin.com/company/cybrosys-technologies-pvt-ltd" target="_blank"><i class="fa fa-2x fa-linkedin" style="color:white;background: #31a3d6;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://www.facebook.com/cybrosystechnologies" target="_blank"><i class="fa fa-2x fa-facebook" style="color:white;background: #3b5998;width:35px;padding-left: 8px;"></i></a></td>
<a href="https://plus.google.com/106641282743045431892/about" target="_blank"><i class="fa fa-2x fa-google-plus" style="color:white;background: #c53c2c;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://in.pinterest.com/cybrosys" target="_blank"><i class="fa fa-2x fa-pinterest" style="color:white;background: #ac0f18;width:35px;padding-left: 3px;"></i></a></td>
</div>
</div>
</section>

BIN
import_product_image/static/description/warning.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

39
import_product_image/views/import_product_image_view.xml

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="product_import_image_wizard_form_view" model="ir.ui.view">
<field name="name">product.import.image.form</field>
<field name="model">import.product_image</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Products Image Import">
<group>
<group>
<field name="product_model"/>
<field name="file" filename="filename"/>
</group>
<group>
<field name="pdt_operation"/>
</group>
</group>
<footer>
<button class="oe_highlight" string="Import File" name="import_file" type="object"/> or
<button class="oe_link" string="Cancel" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="import_image_action_form" model="ir.actions.act_window">
<field name="name">Import Product Image</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">import.product_image</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem name="Import Product Image" id="menu_import_product_image" parent="sales_team.menu_sales"
action="import_image_action_form" sequence="22"/>
</data>
</odoo>
Loading…
Cancel
Save