-
-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by jgrandguillaume
- Loading branch information
Showing
15 changed files
with
662 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
} |
4 changes: 4 additions & 0 deletions
4
stock_move_location_dest_constraint_base/data/stock_location.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
26 changes: 26 additions & 0 deletions
26
stock_move_location_dest_constraint_base/models/product_strategy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
stock_move_location_dest_constraint_base/models/stock_location.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
stock_move_location_dest_constraint_base/models/stock_move.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
6
stock_move_location_dest_constraint_base/readme/CONFIGURE.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
1 change: 1 addition & 0 deletions
1
stock_move_location_dest_constraint_base/readme/CONTRIBUTORS.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Akim Juillerat <[email protected]> |
4 changes: 4 additions & 0 deletions
4
stock_move_location_dest_constraint_base/readme/DESCRIPTION.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.