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][MIG][12.0] stock_orderpoint_route #785

Merged
merged 4 commits into from
Apr 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/stock_orderpoint_route/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,
)
82 changes: 82 additions & 0 deletions stock_orderpoint_route/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
======================
Stock Orderpoint Route
======================

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

.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-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/11.0/stock_orderpoint_route
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-11-0/stock-logistics-warehouse-11-0-stock_orderpoint_route
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/153/11.0
:alt: Try me on Runbot

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

This module allows to restrict a specific route to be used in the
reordering rules. This route will be used instead of the default determined by
default.

**Table of contents**

.. contents::
:local:

Usage
=====

Go to the reordering rule and change the route. Only the routes applicable
for this location or locations above it can be selected.

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 <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_orderpoint_route%0Aversion:%2011.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
~~~~~~~

* Eficent

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

* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Lois Rilo <lois.rilo@eficent.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/11.0/stock_orderpoint_route>`_ 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_orderpoint_route/__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_orderpoint_route/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock Orderpoint Route",
"summary": "Allows to force a route to be used when procuring from "
"orderpoints",
"version": "12.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/stock-logistics-warehouse",
"author": "Eficent, "
"Camptocamp, "
"Odoo Community Association (OCA)",
"category": "Warehouse",
"depends": [
"stock",
],
"data": [
"views/stock_warehouse_orderpoint_views.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions stock_orderpoint_route/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_warehouse_orderpoint
58 changes: 58 additions & 0 deletions stock_orderpoint_route/models/stock_warehouse_orderpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models


class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'

route_ids = fields.Many2many(
'stock.location.route', string='Allowed routes',
compute='_compute_route_ids',
)
route_id = fields.Many2one('stock.location.route', string='Route',
domain="[('id', 'in', route_ids)]",
ondelete='restrict')

@api.depends('product_id', 'warehouse_id',
'warehouse_id.route_ids', 'location_id')
def _compute_route_ids(self):
route_obj = self.env['stock.location.route']
for wh in self.mapped('warehouse_id'):
wh_routes = wh.route_ids
for record in self.filtered(lambda r: r.warehouse_id == wh):
routes = route_obj.browse()
if record.product_id:
routes += record.product_id.mapped(
'route_ids'
) | record.product_id.mapped(
'categ_id'
).mapped('total_route_ids')
if record.warehouse_id:
routes |= wh_routes
parents = record.get_parents()
record.route_ids = routes.filtered(
lambda route: any(
p.location_id in parents
for p in route.rule_ids.filtered(
lambda rule: rule.action in ('pull', 'pull_push')
).mapped('location_src_id')
)
)

def get_parents(self):
location = self.location_id
result = location
while location.location_id:
location = location.location_id
result |= location
return result

def _prepare_procurement_values(self, product_qty, date=False,
group=False):
res = super()._prepare_procurement_values(
product_qty, date=date, group=group
)
res['route_ids'] = self.route_id
return res
3 changes: 3 additions & 0 deletions stock_orderpoint_route/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
3 changes: 3 additions & 0 deletions stock_orderpoint_route/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows to restrict a specific route to be used in the
reordering rules. This route will be used instead of the default determined by
default.
2 changes: 2 additions & 0 deletions stock_orderpoint_route/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Go to the reordering rule and change the route. Only the routes applicable
for this location or locations above it can be selected.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.