addons-cm/pos_attribute_image_lazy/models/pos_session.py

27 lines
1.1 KiB
Python

from odoo import models
class PosSession(models.Model):
_inherit = "pos.session"
def _get_attributes_by_ptal_id(self):
"""Return the attribute values without inlining their image content.
``point_of_sale`` reads the ``image`` field of every
``product.attribute.value`` belonging to a ``no_variant`` attribute and
ships it, base64 encoded, inside the ``load_pos_data`` response --
repeated once per attribute line using that value.
The POS front end never uses those bytes: the only reader is
``point_of_sale.ColorProductAttribute``, which merely tests the field
for truthiness and then renders the swatch from
``/web/image/product.template.attribute.value/<id>/image``.
Reading with ``bin_size`` makes the ORM return the human readable
attachment size (e.g. ``b'827.41 Kb'``) instead of its content, so the
attachment is never loaded into memory. The value stays truthy, which
keeps the swatch rendering identical.
"""
return super(
PosSession, self.with_context(bin_size=True)
)._get_attributes_by_ptal_id()