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

[WMS][12.0] Add stock_move_location_dest_constraint_base - alpha version #696

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
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ account-analytic
product-attribute
server-ux
web
stock-logistics-warehouse https://github.com/grindtildeath/stock-logistics-warehouse 12.0_add_stock_putaway_rule
94 changes: 94 additions & 0 deletions stock_move_location_dest_constraint_base/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
=========================================
Stock Move Location Dest Constraints Base
=========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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%2Fcrm-lightgray.png?logo=github
:target: https://github.com/OCA/crm/tree/12.0/stock_move_location_dest_constraint_base
:alt: OCA/crm
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/crm-12-0/crm-12-0-stock_move_location_dest_constraint_base
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/111/12.0
:alt: Try me on Runbot

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

This module provides a base mechanism to constrain the selection of destination
location on stock move lines.
It also adds a checkbox 'Bypass constraints' on stock location to deactivate
the checks implemented by installed modules.

**Table of contents**

.. contents::
:local:

Configuration
=============

When installing the module, all the existing stock location will be set to
bypass constraints.
Therefore the user must manually activate the constraints on existing
locations.
However, any location created after the module installation will have the
constraints activated as the flag will not be set to True automatically.

Usage
=====

To define new constraints on stock location, function
`check_move_dest_constraint` on `stock.location` must be overriden to throw a
ValidationError if the location is not allowed for selected product or stock
move line.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/crm/issues/new?body=module:%20stock_move_location_dest_constraint_base%0Aversion:%2012.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
~~~~~~~

* Camptocamp

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

* Akim Juillerat <[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.

This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/12.0/stock_move_location_dest_constraint_base>`_ 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_move_location_dest_constraint_base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions stock_move_location_dest_constraint_base/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
{
"name": "Stock Move Location Dest Constraints Base",
"summary": "Base module to constrain dest location on stock move line",
"version": "12.0.1.0.0",
"development_status": "Alpha",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"stock_putaway_rule",
],
"data": [
"data/stock_location.xml",
"views/stock_location.xml",
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<function model="stock.location" name="_set_bypass_on_existing_locations" />
</odoo>
3 changes: 3 additions & 0 deletions stock_move_location_dest_constraint_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_strategy
from . import stock_location
from . import stock_move
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models
from odoo.exceptions import ValidationError


class StockPutawayRule(models.Model):
_inherit = 'stock.putaway.rule'

def filtered(self, func):
"""Filter putaway strats according to installed constraints"""
putaway_rules = super().filtered(func)
if self.env.context.get('_filter_on_constraints'):
product_id = self.env.context.get('_constraint_product')
product = self.env['product.product'].browse(product_id)
filtered_putaways = self.browse()
for put in putaway_rules:
try:
put.location_out_id.check_move_dest_constraint(
product=product
)
except ValidationError:
continue
filtered_putaways |= put
putaway_rules = filtered_putaways
return putaway_rules
28 changes: 28 additions & 0 deletions stock_move_location_dest_constraint_base/models/stock_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api, models, fields


class StockLocation(models.Model):

_inherit = 'stock.location'

bypass_constraints = fields.Boolean()

def check_move_dest_constraint(self, line=None, product=None):
"""Raise Validation error if not allowed"""
self.ensure_one()
return True

@api.model
def _set_bypass_on_existing_locations(self):
"""Set bypass_constrains on all the existing locations"""
existing_locations = self.search([])
existing_locations.write({'bypass_constraints': True})

def get_putaway_strategy(self, product):
"""Activate constraint when looking for putaway rules"""
self = self.with_context(
_filter_on_constraints=True, _constraint_product=product.id
)
return super().get_putaway_strategy(product)
16 changes: 16 additions & 0 deletions stock_move_location_dest_constraint_base/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api, models


class StockMoveLine(models.Model):

_inherit = 'stock.move.line'

@api.constrains('location_dest_id')
def _check_location_dest_id(self):
"""Check if destination location is allowed"""
for line in self:
if line.location_dest_id.bypass_constraints:
continue
line.location_dest_id.check_move_dest_constraint(line=line)
6 changes: 6 additions & 0 deletions stock_move_location_dest_constraint_base/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
When installing the module, all the existing stock location will be set to
bypass constraints.
Therefore the user must manually activate the constraints on existing
locations.
However, any location created after the module installation will have the
constraints activated as the flag will not be set to True automatically.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Akim Juillerat <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module provides a base mechanism to constrain the selection of destination
location on stock move lines.
It also adds a checkbox 'Bypass constraints' on stock location to deactivate
the checks implemented by installed modules.
4 changes: 4 additions & 0 deletions stock_move_location_dest_constraint_base/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To define new constraints on stock location, function
`check_move_dest_constraint` on `stock.location` must be overriden to throw a
ValidationError if the location is not allowed for selected product or stock
move line.
Loading