Skip to content

Commit

Permalink
shopfloor: allow option to not display vendor packagings
Browse files Browse the repository at this point in the history
  • Loading branch information
JuMiSanAr committed Feb 20, 2024
1 parent c114af4 commit 889aa78
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
30 changes: 27 additions & 3 deletions shopfloor/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ def _lot_parser(self):

@ensure_model("stock.move.line")
def move_line(self, record, with_picking=False, **kw):
record = record.with_context(location=record.location_id.id)
display_vendor_packagings = kw.get("display_vendor_packagings")
record = record.with_context(
location=record.location_id.id,
display_vendor_packagings=display_vendor_packagings,
)
parser = self._move_line_parser
if with_picking:
parser += [("picking_id:picking", self._picking_parser)]
Expand Down Expand Up @@ -234,7 +238,11 @@ def _move_line_parser(self):

@ensure_model("stock.move")
def move(self, record, **kw):
record = record.with_context(location=record.location_id.id)
display_vendor_packagings = kw.get("display_vendor_packagings")
record = record.with_context(
location=record.location_id.id,
display_vendor_packagings=display_vendor_packagings,
)
parser = self._move_parser
return self._jsonify(record, parser)

Expand All @@ -256,6 +264,10 @@ def _move_parser(self):

@ensure_model("stock.package_level")
def package_level(self, record, **kw):
display_vendor_packagings = kw.get("display_vendor_packagings")
record = record.with_context(
display_vendor_packagings=display_vendor_packagings
)
return self._jsonify(record, self._package_level_parser)

def package_levels(self, records, **kw):
Expand Down Expand Up @@ -291,6 +303,10 @@ def _package_level_parser(self):

@ensure_model("product.product")
def product(self, record, **kw):
display_vendor_packagings = kw.get("display_vendor_packagings")
record = record.with_context(
display_vendor_packagings=display_vendor_packagings
)
return self._jsonify(record, self._product_parser, **kw)

def products(self, record, **kw):
Expand All @@ -310,8 +326,16 @@ def _product_parser(self):
]

def _product_packaging(self, rec, field):
display_vendor_packagings = rec.env.context["display_vendor_packagings"]
packagings = rec.packaging_ids
if display_vendor_packagings:
packagings = packagings.filtered(lambda x: x.qty)
else:
packagings = packagings.filtered(
lambda x: x.qty and not x.packaging_type_id.is_vendor_packaging
)
return self._jsonify(
rec.packaging_ids.filtered(lambda x: x.qty),
packagings,
self._packaging_parser,
multi=True,
)
Expand Down
20 changes: 20 additions & 0 deletions shopfloor/models/shopfloor_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
to scan a destination package.
"""

DISPLAY_VENDOR_PACKAGINGS_HELP = """
When enabled, the user will be able to see the vendor packagings
in the frontend, e.g. in the qty picker.
"""


class ShopfloorMenu(models.Model):
_inherit = "shopfloor.menu"
Expand Down Expand Up @@ -226,6 +231,14 @@ class ShopfloorMenu(models.Model):
allow_alternative_destination_package_is_possible = fields.Boolean(
compute="_compute_allow_alternative_destination_package_is_possible"
)
display_vendor_packagings = fields.Boolean(
string="Display vendor packagings",
default=False,
help=DISPLAY_VENDOR_PACKAGINGS_HELP,
)
display_vendor_packagings_is_possible = fields.Boolean(
compute="_compute_display_vendor_packagings_is_possible",
)

@api.onchange("unload_package_at_destination")
def _onchange_unload_package_at_destination(self):
Expand Down Expand Up @@ -455,3 +468,10 @@ def _compute_allow_alternative_destination_package_is_possible(self):
menu.allow_alternative_destination_package_is_possible = (
menu.scenario_id.has_option("allow_alternative_destination_package")
)

@api.depends("scenario_id")
def _compute_display_vendor_packagings_is_possible(self):
for menu in self:
menu.display_vendor_packagings_is_possible = menu.scenario_id.has_option(
"display_vendor_packagings"
)
7 changes: 7 additions & 0 deletions shopfloor/views/shopfloor_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@
/>
<field name="allow_alternative_destination_package" />
</group>
<group
name="display_vendor_packagings"
attrs="{'invisible': [('display_vendor_packagings_is_possible', '=', False)]}"
>
<field name="display_vendor_packagings_is_possible" invisible="1" />
<field name="display_vendor_packagings" />
</group>
</group>
</field>
</record>
Expand Down

0 comments on commit 889aa78

Please sign in to comment.