Skip to content

Commit

Permalink
shopfloor_mobile: add icons to qty picker packagings
Browse files Browse the repository at this point in the history
  • Loading branch information
JuMiSanAr committed Jan 11, 2024
1 parent 7d6cafb commit 5eece6b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
12 changes: 12 additions & 0 deletions shopfloor/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def _packaging_parser(self):
"id",
("packaging_type_id:name", lambda rec, fname: rec.packaging_type_id.name),
("packaging_type_id:code", lambda rec, fname: rec.packaging_type_id.code),
("packaging_type_id:shopfloor_icon", self._packaging_icon_data),
"qty",
]

Expand Down Expand Up @@ -316,6 +317,17 @@ def _product_packaging(self, rec, field):
multi=True,
)

def _packaging_icon_data(self, rec, field):
icon_data = {"alt_text": rec.packaging_type_id.name}
if not rec.packaging_type_id.shopfloor_icon:
return icon_data
icon_data[
"url"
] = "/web/image/product.packaging.type/{}/shopfloor_icon/30x30".format(
rec.packaging_type_id.id
)
return icon_data

def _product_supplier_code(self, rec, field):
supplier_info = fields.first(
rec.seller_ids.filtered(lambda x: x.product_id == rec)
Expand Down
8 changes: 8 additions & 0 deletions shopfloor/actions/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ def packaging(self):
"name": {"type": "string", "nullable": False, "required": True},
"code": {"type": "string", "nullable": True, "required": True},
"qty": {"type": "float", "required": True},
"shopfloor_icon": {
"type": "dict",
"required": False,
"schema": {
"url": {"type": "string", "required": False},
"alt_text": {"type": "string", "required": False},
},
},
}

def delivery_packaging(self):
Expand Down
9 changes: 7 additions & 2 deletions shopfloor/models/product_packaging_type.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
# Copyright 2023 Camptocamp SA (http://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ProductPackagingType(models.Model):
_inherit = "product.packaging.type"

icon = fields.Image()
shopfloor_icon = fields.Binary(
help="Icon to be displayed in the frontend qty picker. "
"Its final size will be a 30x30 image, "
"which means that square-shaped icons will work best."
)
8 changes: 8 additions & 0 deletions shopfloor/tests/test_actions_data_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,17 @@ def _expected_packaging(self, record, **kw):
"code": record.packaging_type_id.code,
"qty": record.qty,
}
data["shopfloor_icon"] = self._expected_packaging_shopfloor_icon(record)
data.update(kw)
return data

def _expected_packaging_shopfloor_icon(self, record):
shopfloor_icon_data = {"alt_text": record.packaging_type_id.name}
shopfloor_icon = record.packaging_type_id.shopfloor_icon
if shopfloor_icon:
shopfloor_icon_data["url"] = shopfloor_icon
return shopfloor_icon_data

def _expected_delivery_packaging(self, record, **kw):
data = {
"id": record.id,
Expand Down
2 changes: 1 addition & 1 deletion shopfloor/views/product_packaging_type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<field name="arch" type="xml">
<field name="name" position="after">
<div>
<field name="icon" widget="image" width="90" />
<field name="shopfloor_icon" widget="image" width="90" />
</div>
</field>
</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,17 @@ export var PackagingQtyPicker = Vue.component("packaging-qty-picker", {
<v-col cols="2" md="2" v-if="!readonly">
<span class="qty-todo">/ {{ qty_todo_by_pkg[pkg.id] }}</span>
</v-col>
<v-col>
<v-col cols="4">
<div :class="qty_by_pkg[pkg.id] > 0 ? 'pkg-name font-weight-bold' : 'pkg-name'"> {{ pkg[pkgNameKey] }}</div>
<div v-if="contained_packaging[pkg.id]" :class="qty_by_pkg[pkg.id] > 0 ? 'pkg-qty font-weight-bold' : 'pkg-qty'">(x{{ contained_packaging[pkg.id].qty }} {{ contained_packaging[pkg.id].pkg.name }})</div>
</v-col>
<v-col cols="2" v-if="_.result(contained_packaging[pkg.id], 'pkg.shopfloor_icon.url', '')">
<img
class="qty-picker-packaging-icon"
:src="_.result(contained_packaging[pkg.id], 'pkg.shopfloor_icon.url', '')"
:alt="_.result(contained_packaging[pkg.id], 'pkg.shopfloor_icon.alt_text', '')"
/>
</v-col>
</v-row>
</v-expansion-panel-content>
</v-expansion-panel>
Expand Down
5 changes: 5 additions & 0 deletions shopfloor_mobile/static/wms/src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ I tested only w/ checkout/select_package for now
top: 5px;
right: 5px;
}

.qty-picker-packaging-icon {
width: 30px;
height: 30px;
}

0 comments on commit 5eece6b

Please sign in to comment.