Skip to content

Commit

Permalink
[ADD][8.0] stock_push_rule_extend
Browse files Browse the repository at this point in the history
  • Loading branch information
andhit-r committed Apr 8, 2017
1 parent ec46880 commit 3dfc5b4
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 0 deletions.
51 changes: 51 additions & 0 deletions stock_push_rule_extend/README.rst
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.
5 changes: 5 additions & 0 deletions stock_push_rule_extend/__init__.py
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
17 changes: 17 additions & 0 deletions stock_push_rule_extend/__openerp__.py
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": [
],
}
6 changes: 6 additions & 0 deletions stock_push_rule_extend/models/__init__.py
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
89 changes: 89 additions & 0 deletions stock_push_rule_extend/models/stock_move.py
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]
27 changes: 27 additions & 0 deletions stock_push_rule_extend/models/stock_move_monkeypatch.py
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.

0 comments on commit 3dfc5b4

Please sign in to comment.