Skip to content

Commit

Permalink
Add shopfloor_vendor_packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
JuMiSanAr committed Feb 21, 2024
1 parent d385bef commit 7d0d44b
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 56 deletions.
6 changes: 6 additions & 0 deletions setup/shopfloor_vendor_packaging/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,
)
30 changes: 3 additions & 27 deletions shopfloor/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,7 @@ def _lot_parser(self):

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

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

Expand All @@ -264,10 +256,6 @@ 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 @@ -303,10 +291,6 @@ 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 @@ -326,16 +310,8 @@ 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(
packagings,
rec.packaging_ids.filtered(lambda x: x.qty),
self._packaging_parser,
multi=True,
)
Expand Down
20 changes: 0 additions & 20 deletions shopfloor/models/shopfloor_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@
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 @@ -231,14 +226,6 @@ 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 @@ -468,10 +455,3 @@ 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: 0 additions & 7 deletions shopfloor/views/shopfloor_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@
/>
<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
4 changes: 2 additions & 2 deletions shopfloor_reception/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "Shopfloor Reception",
"summary": "Reception scenario for shopfloor",
"version": "14.0.2.6.1",
"version": "14.0.2.7.0",
"development_status": "Beta",
"category": "Inventory",
"website": "https://github.com/OCA/wms",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["mmequignon", "JuMiSanAr"],
"license": "AGPL-3",
"installable": True,
"depends": ["shopfloor"],
"depends": ["shopfloor", "shopfloor_vendor_packaging"],
"data": [
"data/shopfloor_scenario_data.xml",
],
Expand Down
2 changes: 2 additions & 0 deletions shopfloor_vendor_packaging/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import actions
19 changes: 19 additions & 0 deletions shopfloor_vendor_packaging/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Camptocamp SA (http://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Shopfloor Vendor Packaging",
"summary": "Manage shopfloor behavior for vendor packaging",
"version": "14.0.1.0.0",
"development_status": "Alpha",
"category": "Inventory",
"website": "https://github.com/OCA/wms",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"data": [
"views/shopfloor_menu.xml",
],
"depends": ["shopfloor", "product_packaging_type_vendor"],
"auto-install": True,
}
56 changes: 56 additions & 0 deletions shopfloor_vendor_packaging/actions/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2024 Camptocamp SA (http://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.addons.component.core import Component
from odoo.addons.shopfloor_base.utils import ensure_model


class DataAction(Component):
_inherit = "shopfloor.data.action"

@ensure_model("stock.move.line")
def move_line(self, record, with_picking=False, **kw):
display_vendor_packagings = kw.get("display_vendor_packagings")
record = record.with_context(
display_vendor_packagings=display_vendor_packagings,
)
return super().move_line(record, with_picking, **kw)

@ensure_model("stock.move")
def move(self, record, **kw):
display_vendor_packagings = kw.get("display_vendor_packagings")
record = record.with_context(
display_vendor_packagings=display_vendor_packagings,
)
return super().move(record, **kw)

@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 super().package_level(record, **kw)

@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 super().product(record, **kw)

def _product_packaging(self, rec, field):
display_vendor_packagings = rec.env.context.get("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(
packagings,
self._packaging_parser,
multi=True,
)
29 changes: 29 additions & 0 deletions shopfloor_vendor_packaging/models/shopfloor_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 Camptocamp SA (http://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models

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"

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.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"
)
1 change: 1 addition & 0 deletions shopfloor_vendor_packaging/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Juan Miguel Sánchez Arce <[email protected]>
2 changes: 2 additions & 0 deletions shopfloor_vendor_packaging/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When installed, this module adds a new option in shopfloor
to prevent vendor packagings from being displayed in the frontend.
18 changes: 18 additions & 0 deletions shopfloor_vendor_packaging/views/shopfloor_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="shopfloor_menu_form_view" model="ir.ui.view">
<field name="model">shopfloor.menu</field>
<field name="inherit_id" ref="shopfloor.shopfloor_menu_form_view" />
<field name="arch" type="xml">
<group name="options" position="inside">
<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>
</odoo>

0 comments on commit 7d0d44b

Please sign in to comment.