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

[ADD] stock_restrict_lot_update #1442

Merged
merged 1 commit into from
Dec 7, 2023
Merged
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
6 changes: 6 additions & 0 deletions setup/stock_restrict_lot_update/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,
)
119 changes: 119 additions & 0 deletions stock_restrict_lot_update/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
=========================
Stock Restrict Lot Domain
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6c9687e14e9171010883f69e800f8dfa51bd4511ff93dda7ba8c69d2414b7b40
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_restrict_lot_update
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-14-0/stock-logistics-workflow-14-0-stock_restrict_lot_update
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module builds on `stock_restrict_lot` and exposes the field
`restrict_lot_id` of `stock.move`, allowing the user to update or
even remove the lot restriction if the product does not fall within
a domain.

The domain can be updated in the settings of each individual company.

Any change to `restrict_lot_id` is propagated to linked stock moves,
but only forwards, not backwards.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

In a setup where lot selection is managed both at sale level and warehouse level
(but the final call is made by warehouse flows), there can be the need to select
a different lot than the one set in sale order line. As current sale order lot
selection modules are depending on stock_restrict_lot (which doesn't allow to
select a different lot in picking), this module allows to limit the restriction
to for specific products.

Usage
=====

Go to Settings > Inventory > Enforce lot restrictions

Set a domain for the products for which lot restriction on stock moves should apply (empty domain: all products)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_restrict_lot_update%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ooops404
* PyTech SRL

Contributors
~~~~~~~~~~~~

* Ooops404

* Francesco Foresti [email protected]

* PyTech SRL

* Alessandro Uffreduzzi <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-aleuffre| image:: https://github.com/aleuffre.png?size=40px
:target: https://github.com/aleuffre
:alt: aleuffre
.. |maintainer-renda-dev| image:: https://github.com/renda-dev.png?size=40px
:target: https://github.com/renda-dev
:alt: renda-dev

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-aleuffre| |maintainer-renda-dev|

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/14.0/stock_restrict_lot_update>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions stock_restrict_lot_update/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions stock_restrict_lot_update/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Stock Restrict Lot Domain",
"summary": "Only apply lot restriction on products in a domain",
"version": "14.0.1.0.0",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Ooops404, PyTech SRL, Odoo Community Association (OCA)",
"maintainers": ["aleuffre", "renda-dev"],
"license": "AGPL-3",
"installable": True,
"depends": ["stock_restrict_lot"],
"data": [
"views/stock_picking_views.xml",
"views/res_config_settings_views.xml",
],
}
3 changes: 3 additions & 0 deletions stock_restrict_lot_update/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import res_company
from . import res_config_settings
from . import stock_move
15 changes: 15 additions & 0 deletions stock_restrict_lot_update/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Ooops404
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

enforce_lot_restriction_product_domain = fields.Char(
default="[]",
string="Enforce lot restrictions",
help="Lot restriction of stock movements cannot be changed "
"for products in this domain.\n if empty, lot restrictions "
"cannot be changed for any product.",
)
12 changes: 12 additions & 0 deletions stock_restrict_lot_update/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2023 Ooops404
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

enforce_lot_restriction_product_domain = fields.Char(
related="company_id.enforce_lot_restriction_product_domain",
readonly=False,
)
38 changes: 38 additions & 0 deletions stock_restrict_lot_update/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2023 Ooops404
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo.tools.safe_eval import safe_eval


class StockMove(models.Model):
_inherit = "stock.move"

change_restrict_lot = fields.Boolean(
compute="_compute_change_restrict_lot",
help="If the product is in the domain",
)

@api.depends("product_id", "company_id")
def _compute_change_restrict_lot(self):
for move in self:
product_domain = safe_eval(
move.sudo().company_id.enforce_lot_restriction_product_domain
)
# if product is not in the enforcement domain, user can change the lot
move.change_restrict_lot = not move.product_id.filtered_domain(
product_domain
)

def write(self, vals):
"""
Propagate changes to restrict_lot_id to all
destination moves - recursively.
"""
res = super().write(vals)
if "restrict_lot_id" in vals:
aleuffre marked this conversation as resolved.
Show resolved Hide resolved
related_moves = self.mapped("move_dest_ids")
if related_moves:
related_moves.write({"restrict_lot_id": vals["restrict_lot_id"]})
self._action_assign()
return res
6 changes: 6 additions & 0 deletions stock_restrict_lot_update/readme/CONTEXT.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
In a setup where lot selection is managed both at sale level and warehouse level
(but the final call is made by warehouse flows), there can be the need to select
a different lot than the one set in sale order line. As current sale order lot
selection modules are depending on stock_restrict_lot (which doesn't allow to
select a different lot in picking), this module allows to limit the restriction
to for specific products.
7 changes: 7 additions & 0 deletions stock_restrict_lot_update/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* Ooops404

aleuffre marked this conversation as resolved.
Show resolved Hide resolved
* Francesco Foresti [email protected]

* PyTech SRL

* Alessandro Uffreduzzi <[email protected]>
9 changes: 9 additions & 0 deletions stock_restrict_lot_update/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This module builds on `stock_restrict_lot` and exposes the field
`restrict_lot_id` of `stock.move`, allowing the user to update or
even remove the lot restriction if the product does not fall within
a domain.

The domain can be updated in the settings of each individual company.

Any change to `restrict_lot_id` is propagated to linked stock moves,
but only forwards, not backwards.
3 changes: 3 additions & 0 deletions stock_restrict_lot_update/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Go to Settings > Inventory > Enforce lot restrictions

Set a domain for the products for which lot restriction on stock moves should apply (empty domain: all products)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading