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_picking_type_routing_operation - alpha version #639

Closed
wants to merge 21 commits into from
Closed
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_picking_type_routing_operation/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_picking_type_routing_operation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
==================
Stock Picking Zone
==================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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%2Fstock--logistics--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_picking_zone
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/153/12.0
:alt: Try me on Runbot

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

Route explains the steps you want to produce whereas the “picking zone” defines
how operations are grouped according to their final source and destination
location.

This allows for example:

* To parallelize picking operations in two main zone of a warehouse, splitting
them in two different picking type
* To define pre-picking (wave) in some sub-zones, then roundtrip picking of the
sub-zone waves

**Table of contents**

.. contents::
:local:

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

In Inventory Settings, you must have:

* Storage Locations
* Multi-Warehouses
* Multi-Step Routes

Create an operation type and activate the "Is Zone" checkbox.
The default destination location will be the destination location
of the new operation inserted when a move has a source location which
is a child of the type's source location.

Known issues / Roadmap
======================

The concept of "zone" is duplicated with the zones introduced by
"stock_location_zone" in
https://github.com/OCA/stock-logistics-warehouse/pull/653
They will be merged in the same concept. Note that considering the
alpha version of this module, no data migration will be done.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/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.

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

Credits
=======

Authors
~~~~~~~

* Camptocamp

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

* Joël Grand-Guillaume <joel.grandguillaume@camptocamp.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>

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/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_picking_zone>`_ 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_picking_type_routing_operation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions stock_picking_type_routing_operation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2019 Camptocamp (https://www.camptocamp.com)
{
'name': "Stock Picking Zone",
'summary': "Add extra routing operations for special locations",
'author': 'Camptocamp, Odoo Community Association (OCA)',
'website': "https://github.com/OCA/stock-logistics-warehouse",
'category': 'Warehouse Management',
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'stock',
],
'demo': [
'demo/stock_location_demo.xml',
'demo/stock_picking_type_demo.xml',
],
'data': [
'views/stock_location.xml',
],
'installable': True,
'development_status': 'Alpha',
}
26 changes: 26 additions & 0 deletions stock_picking_type_routing_operation/demo/stock_location_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<record id="stock_location_highbay_demo" model="stock.location">
<field name="name">Highbay</field>
<field name="location_id" ref="stock.stock_location_stock"/>
</record>
<record id="stock_location_highbay_a_demo" model="stock.location">
<field name="name">Bay A</field>
<field name="location_id" ref="stock_location_highbay_demo"/>
</record>
<record id="stock_location_highbay_a_1_demo" model="stock.location">
<field name="name">Bin 1</field>
<field name="location_id" ref="stock_location_highbay_a_demo"/>
</record>
<record id="stock_location_highbay_demo_1_2" model="stock.location">
<field name="name">Bin 2</field>
<field name="location_id" ref="stock_location_highbay_a_demo"/>
</record>

<record id="stock_location_handover_demo" model="stock.location">
<field name="name">Handover</field>
<field name="location_id" ref="stock.stock_location_stock"/>
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<record id="sequence_stock_picking_type_highbay_to_handover_demo" model="ir.sequence">
<field name="name">Highbay → Handover</field>
<field name="code">stock.hb.ho</field>
<field name="prefix">HBHO/</field>
<field name="padding">5</field>
<field name="number_next">1</field>
<field name="number_increment">1</field>
</record>

<record model="stock.picking.type" id="stock_picking_type_highbay_to_handover_demo">
<field name="name">Highbay → Handover</field>
<field name="code">internal</field>
<field name="use_create_lots" eval="False"/>
<field name="use_existing_lots" eval="True"/>
<field name="default_location_src_id" ref="stock_location_highbay_demo"/>
<field name="default_location_dest_id" ref="stock_location_handover_demo"/>
<field name="sequence_id" ref="sequence_stock_picking_type_highbay_to_handover_demo"/>
</record>

<record id="sequence_stock_picking_type_handover_to_highbay_demo" model="ir.sequence">
<field name="name">Handover → Highbay</field>
<field name="code">stock.ho.hb</field>
<field name="prefix">HOHB/</field>
<field name="padding">5</field>
<field name="number_next">1</field>
<field name="number_increment">1</field>
</record>

<record model="stock.picking.type" id="stock_picking_type_handover_to_highbay_demo">
<field name="name">Handover → Highbay</field>
<field name="code">internal</field>
<field name="use_create_lots" eval="False"/>
<field name="use_existing_lots" eval="True"/>
<field name="default_location_src_id" ref="stock_location_handover_demo"/>
<field name="default_location_dest_id" ref="stock_location_highbay_demo"/>
<field name="sequence_id" ref="sequence_stock_picking_type_handover_to_highbay_demo"/>
</record>

<record id="stock_location_highbay_demo" model="stock.location">
<field name="src_routing_picking_type_id" ref="stock_picking_type_highbay_to_handover_demo"/>
<field name="dest_routing_picking_type_id" ref="stock_picking_type_handover_to_highbay_demo"/>
</record>

</odoo>
4 changes: 4 additions & 0 deletions stock_picking_type_routing_operation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import stock_location
from . import stock_move
from . import stock_picking_type
from . import stock_quant
93 changes: 93 additions & 0 deletions stock_picking_type_routing_operation/models/stock_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api, models, fields, _
from odoo.exceptions import ValidationError


class StockLocation(models.Model):
_inherit = 'stock.location'

src_routing_picking_type_id = fields.Many2one(
'stock.picking.type',
string='Source Routing Operation',
help="Change destination of the move line according to the"
" default destination of the picking type after reservation"
" occurs, when the source of the move is in this location"
" (including sub-locations). A new chained move will be created "
" to reach the original destination.",
)
dest_routing_picking_type_id = fields.Many2one(
'stock.picking.type',
string='Destination Routing Operation',
help="Change source of the move line according to the"
" default source of the picking type after reservation"
" occurs, when the destination of the move is in this location"
" (including sub-locations). A new chained move will be created "
" to reach the original source.",
)

@api.constrains('src_routing_picking_type_id')
def _check_src_routing_picking_type_id(self):
for location in self:
picking_type = location.src_routing_picking_type_id
if not picking_type:
continue
if picking_type.default_location_src_id != location:
raise ValidationError(_(
'A picking type for source routing operations cannot have'
' a different default source location than the location it'
' is used on.'
))

@api.constrains('dest_routing_picking_type_id')
def _check_dest_routing_picking_type_id(self):
for location in self:
picking_type = location.dest_routing_picking_type_id
if not picking_type:
continue
if picking_type.default_location_dest_id != location:
raise ValidationError(_(
'A picking type for destination routing operations '
'cannot have a different default destination location'
' than the location it is used on.'
))

@api.multi
def _find_picking_type_for_routing(self, routing_type):
if routing_type not in ('src', 'dest'):
raise ValueError(
"routing_type must be one of ('src', 'dest')"
)
self.ensure_one()
# First select all the parent locations and the matching
# picking types. In a second step, the picking type matching the
# closest location
# is searched in memory. This is to avoid doing an SQL query
# for each location in the tree.
tree = self.search(
[('id', 'parent_of', self.id)],
# the recordset will be ordered bottom location to top location
order='parent_path desc'
)
if routing_type == 'src':
routing_fieldname = 'src_routing_location_ids'
default_location_fieldname = 'default_location_src_id'
else: # dest
routing_fieldname = 'dest_routing_location_ids'
default_location_fieldname = 'default_location_dest_id'
domain = [
(routing_fieldname, '!=', False),
(default_location_fieldname, 'in', tree.ids)
]
picking_types = self.env['stock.picking.type'].search(domain)
# the first location is the current move line's source location,
# then we climb up the tree of locations
for location in tree:
match = picking_types.filtered(
lambda p: p[default_location_fieldname] == location
)
if match:
# we can only have one match as we have a unique
# constraint on is_zone + source (or dest) location
return match
return self.env['stock.picking.type']
Loading