Skip to content

Commit

Permalink
[ADD] stock_restrict_lot_update
Browse files Browse the repository at this point in the history
  • Loading branch information
aleuffre committed Dec 6, 2023
1 parent 6161534 commit 93fdf40
Show file tree
Hide file tree
Showing 18 changed files with 865 additions and 0 deletions.
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,
)
102 changes: 102 additions & 0 deletions stock_restrict_lot_update/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
=========================
Stock Restrict Lot Domain
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e21b532422c60da9426546cdbe6019ef571622c6e46c2565934671d778b7531f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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:

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:
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
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

* 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/UPDATE.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

0 comments on commit 93fdf40

Please sign in to comment.