Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0] add new addon to allow to display the category image if the product does not have one #572

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/shopinvader_category_image_for_product/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
57 changes: 57 additions & 0 deletions shopinvader_category_image_for_product/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
======================================
Shopinvader category image for product
======================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github
:target: https://github.com/shopinvader/odoo-shopinvader/tree/10.0/shopinvader_cart_expiry
:alt: shopinvader/odoo-shopinvader

|badge1| |badge2| |badge3|

This ShopInvader submodule give the possibility to display the category image for products with no image.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/shopinvader/odoo-shopinvader/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/shopinvader/odoo-shopinvader/issues/new?body=module:%shopinvader_category_image_for_product%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Cédric PIGEON <[email protected]>

Maintainers
~~~~~~~~~~~

This module is part of the `shopinvader/odoo-shopinvader <https://github.com/shopinvader/odoo-shopinvader/tree/10.0/shopinvader_category_image_for_product>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions shopinvader_category_image_for_product/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
21 changes: 21 additions & 0 deletions shopinvader_category_image_for_product/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Shopinvader category image for product",
"summary": "Shopinvader Display category image for product",
"version": "10.0.1.0.0",
"category": "e-commerce",
"author": "ACSONE SA/NV",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"license": "AGPL-3",
"installable": True,
"depends": [
"shopinvader",
"shopinvader_search_engine",
"shopinvader_image",
],
"data": ["data/ir_export.xml"],
"demo": [],
}
9 changes: 9 additions & 0 deletions shopinvader_category_image_for_product/data/ir_export.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="ir_exp_shopinvader_variant_image_category" model="ir.exports.line">
<field name="name">image_categories</field>
<field name="export_id" ref="shopinvader.ir_exp_shopinvader_variant"/>
</record>
</odoo>
1 change: 1 addition & 0 deletions shopinvader_category_image_for_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import shopinvader_variant
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
from odoo.fields import first


class ShopinvaderVariant(models.Model):
_name = "shopinvader.variant"
_inherit = ["shopinvader.variant"]

image_categories = fields.Serialized(compute="_compute_image_categories")

@api.model
def _get_category_by_backend(self, record):
return record.shopinvader_categ_ids.filtered(
lambda c, v=record: c.record_id == v.categ_id
and c.index_id.backend_id == v.index_id.backend_id
and c.images
)

@api.multi
@api.depends(
"shopinvader_categ_ids",
"shopinvader_categ_ids.index_id",
"shopinvader_categ_ids.index_id.backend_id",
"shopinvader_categ_ids.images",
)
def _compute_image_categories(self):
"""
Compute function for image_categories field.
This field should contains the value of images field into the first
category found (with same backend)
:return:
"""
for record in self:
category = self._get_category_by_backend(record)
record.image_categories = first(category).images or []
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Cédric PIGEON <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This addon allows to display the category image when a product has no images.