-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
195 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
===================== | ||
Push Rule Monkeypatch | ||
===================== | ||
|
||
This module will monkey patch methods that related to push mechanism so those | ||
methods will be extandable | ||
|
||
|
||
|
||
Installation | ||
============ | ||
|
||
To install this module, you need to: | ||
|
||
1. Clone the branch 8.0 of the repository https://github.com/open-synergy/opnsynid-stock-logistics-workflow | ||
2. Add the path to this repository in your configuration (addons-path) | ||
3. Update the module list | ||
4. Go to menu *Setting -> Modules -> Local Modules* | ||
5. Search For *Push Rule Monkeypatch* | ||
6. Install the module | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/open-synergy/opnsynid-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 smashing it by providing a detailed | ||
and welcomed feedback. | ||
|
||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Andhitia Rama <andhitia.r@gmail.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://opensynergy-indonesia.com/logo.png | ||
:alt: OpenSynergy Indonesia | ||
:target: https://opensynergy-indonesia.com | ||
|
||
This module is maintained by the OpenSynergy Indonesia. |
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,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
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,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Push Rule Monkeypatch", | ||
"version": "8.0.1.0.0", | ||
"category": "Stock Management", | ||
"website": "https://opensynergy-indonesia.com", | ||
"author": "OpenSynergy Indonesia", | ||
"license": "AGPL-3", | ||
"installable": True, | ||
"depends": [ | ||
"stock", | ||
], | ||
"data": [ | ||
], | ||
} |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import stock_move_monkeypatch | ||
from . import stock_move |
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,89 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import models, api | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
@api.multi | ||
def _check_push_allowed(self): | ||
self.ensure_one() | ||
result = False | ||
domain = self._prepare_allowed_domain() | ||
obj_move = self.env["stock.move"] | ||
if obj_move.search_count(domain) == 1: | ||
result = True | ||
return result | ||
|
||
@api.multi | ||
def _prepare_allowed_domain(self): | ||
self.ensure_one() | ||
domain = [ | ||
("id", "=", self.id), | ||
("move_dest_id", "=", False), | ||
("origin_returned_move_id", "=", False), | ||
] | ||
return domain | ||
|
||
@api.multi | ||
def _prepare_init_domain(self): | ||
self.ensure_one() | ||
domain = [ | ||
("location_from_id", "=", self.location_dest_id.id), | ||
] | ||
return domain | ||
|
||
@api.multi | ||
def _find_push_rule(self): | ||
obj_rule = self.env["stock.location.path"] | ||
domain = self._prepare_init_domain() | ||
product_routes = self._find_product_related_push_rule_route() | ||
if product_routes[0]: | ||
domain += product_routes[1] | ||
sequence = product_routes[2] | ||
else: | ||
wh_routes = self._find_wh_related_push_rule_route() | ||
if wh_routes[0]: | ||
domain += wh_routes[1] | ||
sequence = wh_routes[2] | ||
else: | ||
domain += [("route_id", "=", False)] | ||
sequence = "sequence" | ||
rules = obj_rule.search( | ||
domain, order=sequence) | ||
if len(rules) > 0: | ||
rule = rules[0] | ||
else: | ||
rule = False | ||
return rule | ||
|
||
@api.multi | ||
def _find_product_related_push_rule_route(self): | ||
self.ensure_one() | ||
flag = False | ||
domain = [] | ||
sequence = "" | ||
routes = self.product_id.route_ids + \ | ||
self.product_id.categ_id.total_route_ids | ||
if len(routes) > 0: | ||
flag = True | ||
domain = [("route_id", "in", routes.ids)] | ||
return [flag, domain, sequence] | ||
|
||
@api.multi | ||
def _find_wh_related_push_rule_route(self): | ||
self.ensure_one() | ||
flag = False | ||
domain = [] | ||
sequence = "" | ||
if self.warehouse_id: | ||
routes = self.warehouse_id.route_ids | ||
elif self.picking_type_id and self.picking_type_id.warehouse_id: | ||
routes = self.picking_type_id.warehouse_id.route_ids | ||
if len(routes) > 0: | ||
flag = True | ||
domain = [("route_id", "in", routes.ids)] | ||
return [flag, domain, sequence] |
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,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import models, api | ||
from openerp.addons.stock import stock_move | ||
|
||
|
||
@api.model | ||
def _push_apply(self, moves): | ||
obj_push = self.env["stock.location.path"] | ||
for move in moves: | ||
if move._check_push_allowed(): | ||
rules = move._find_push_rule() | ||
if rules: | ||
obj_push._apply(rules[0], move) | ||
|
||
return True | ||
|
||
|
||
class StockMoveMonkeypatch(models.TransientModel): | ||
_name = "stock.move.monkeypatch" | ||
_description = "Stock Move Monkeypatch" | ||
|
||
def _register_hook(self, cr): | ||
stock_move._push_apply = _push_apply | ||
return super(StockMoveMonkeypatch, self)._register_hook(cr) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.