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

[15.0][FW] [14.0][IMP] product_pricelist_direct_print: allow export product images #1865

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions product_pricelist_direct_print/report/product_pricelist_xlsx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Copyright 2021 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
from io import BytesIO

from PIL import Image

from odoo import _, fields, models


Expand Down Expand Up @@ -67,6 +73,9 @@
sheet.write(5, next_col, _("Sale Price"), header_format)
next_col += 1
sheet.write(5, next_col, _("List Price"), header_format)
if book.show_product_images:
next_col += 1
sheet.write(5, next_col, _("Image"), header_format)

Check warning on line 78 in product_pricelist_direct_print/report/product_pricelist_xlsx.py

View check run for this annotation

Codecov / codecov/patch

product_pricelist_direct_print/report/product_pricelist_xlsx.py#L77-L78

Added lines #L77 - L78 were not covered by tests
return sheet

def _add_extra_header(self, sheet, book, next_col, header_format):
Expand Down Expand Up @@ -119,6 +128,28 @@
product.with_context(pricelist=pricelist.id, date=print_date).price,
decimal_bold_format,
)
if book.show_product_images:
sheet.set_row(row, 50)
next_col += 1

Check warning on line 133 in product_pricelist_direct_print/report/product_pricelist_xlsx.py

View check run for this annotation

Codecov / codecov/patch

product_pricelist_direct_print/report/product_pricelist_xlsx.py#L132-L133

Added lines #L132 - L133 were not covered by tests
if product.image_128:
# We have to check if the field contains a valid image for XlsxWriter
try:
image = BytesIO(base64.decodebytes(product.image_128))
Image.open(image)
except Exception:
break
sheet.insert_image(

Check warning on line 141 in product_pricelist_direct_print/report/product_pricelist_xlsx.py

View check run for this annotation

Codecov / codecov/patch

product_pricelist_direct_print/report/product_pricelist_xlsx.py#L136-L141

Added lines #L136 - L141 were not covered by tests
row,
next_col,
"product_{}.png".format(product.default_code),
{
"image_data": image,
"x_scale": 0.5,
"y_scale": 0.5,
"object_position": 2,
"x_offset": 40,
},
)
row += 1
if book.summary:
sheet.write(row, 0, _("Summary:"), bold_format)
Expand Down
11 changes: 11 additions & 0 deletions product_pricelist_direct_print/views/report_product_pricelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<th t-if="pricelist" class="text-right">
<strong>List Price</strong>
</th>
<th t-if="o.show_product_images" class="text-right">
<strong>Image</strong>
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -95,6 +98,14 @@
t-field="product.with_context(pricelist=pricelist.id, date=o.date or None).price"
/>
</td>
<td t-if="o.show_product_images" class="text-right">
<img
t-if="product.image_128"
t-att-src="image_data_uri(product.image_128)"
alt="Img"
style="max-height: 80px;"
/>
</td>
</tr>
</t>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ProductPricelistPrint(models.TransientModel):
string="Selling date threshold",
help="Filter only the products ordered since this date",
)
show_product_images = fields.Boolean(string="Show product images")

@api.depends("partner_ids")
def _compute_partner_count(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<group>
<field name="breakage_per_category" />
<field name="show_internal_category" />
<field name="show_product_images" />
</group>
</page>
</notebook>
Expand Down
Loading