Skip to content

Commit

Permalink
[IMP] stock_request: Add group to bypass submission (OCA#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
max3903 committed Jul 9, 2019
1 parent b16eee6 commit 473661a
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 124 deletions.
104 changes: 16 additions & 88 deletions stock_request/README.rst
@@ -1,93 +1,21 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
**This file is going to be generated by oca-gen-addon-readme.**

=============
Stock Request
=============
*Manual changes will be overwritten.*

This module was written to allow users to request products that are
frequently stocked by the company, to be transferred to their chosen location.
Please provide content in the ``readme`` directory:

* **DESCRIPTION.rst** (required)
* INSTALL.rst (optional)
* CONFIGURE.rst (optional)
* **USAGE.rst** (optional, highly recommended)
* DEVELOP.rst (optional)
* ROADMAP.rst (optional)
* HISTORY.rst (optional, recommended)
* **CONTRIBUTORS.rst** (optional, highly recommended)
* CREDITS.rst (optional)

Configuration
=============
Content of this README will also be drawn from the addon manifest,
from keys such as name, authors, maintainers, development_status,
and license.

Users should be assigned to the groups 'Stock Request / User' or 'Stock
Request / Manager'.

Group Stock Request / User
--------------------------

* Can see her/his own Stock Requests, and others that she/he's been granted
permission to follow.

* Can create/update only her/his Stock Requests.

Group Stock Request / Manager
-----------------------------

* Can fully manage all Stock Requests


Usage
=====

Creation
--------
* Go to 'Stock Requests / Stock Requests' and create a new Request.
* Indicate a product, quantity and location.
* Press 'Confirm'.

Upon confirmation the request will be evaluated using the procurement rules
for the selected location.

In case that transfers are created, the user will be able to access to them
from the button 'Transfers' available in the Stock Request.

Cancel
------
When the user cancels a Stock Request, the related pending stock moves will be
also cancelled.


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/153/12.0


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 smash it by providing detailed and welcomed feedback.

Credits
=======

Contributors
------------

* Jordi Ballester (EFICENT) <jordi.ballester@eficent.com>.
* Enric Tobella <etobella@creublanca.es>
* Atte Isopuro <atte.isopuro@avoin.systems>
* Lois Rilo <lois.rilo@eficent.com>
* Raul Martin <raul.martin@braintec-group.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
A good, one sentence summary in the manifest is also highly recommended.
6 changes: 5 additions & 1 deletion stock_request/__manifest__.py
Expand Up @@ -4,7 +4,7 @@
{
"name": "Stock Request",
"summary": "Internal request for stock",
"version": "12.0.1.0.0",
"version": "12.0.2.0.0",
"license": "LGPL-3",
"website": "https://github.com/stock-logistics-warehouse",
"author": "Eficent, "
Expand All @@ -27,4 +27,8 @@
"data/stock_request_sequence_data.xml",
],
"installable": True,
"development_status": "Stable",
"maintainers": [
"jbeficent",
]
}
18 changes: 18 additions & 0 deletions stock_request/migrations/12.0.2.0.0/post-migration.py
@@ -0,0 +1,18 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api
from odoo import SUPERUSER_ID


def migrate(cr, version):
if not version:
return

env = api.Environment(cr, SUPERUSER_ID, {})
settings = env['res.config.settings'].\
search([('group_bypass_submit_request', '=', True)])
if not settings:
settings = env['res.config.settings'].create({
'group_bypass_submit_request': True,
})
settings.execute()
3 changes: 3 additions & 0 deletions stock_request/models/res_config_settings.py
Expand Up @@ -10,6 +10,9 @@ class ResConfigSettings(models.TransientModel):
group_stock_request_order = fields.Boolean(
implied_group='stock_request.group_stock_request_order')

group_bypass_submit_request = fields.Boolean(
implied_group='stock_request.group_bypass_submit_request')

module_stock_request_purchase = fields.Boolean(
string='Stock Requests for Purchases')

Expand Down
35 changes: 31 additions & 4 deletions stock_request/models/stock_request.py
Expand Up @@ -8,6 +8,7 @@

REQUEST_STATES = [
('draft', 'Draft'),
('submitted', 'Submitted'),
('open', 'In progress'),
('done', 'Done'),
('cancel', 'Cancelled')]
Expand Down Expand Up @@ -79,7 +80,8 @@ def _get_default_requested_by(self):
states={'draft': [('readonly', False)]}, readonly=True
)
location_id = fields.Many2one(
states={'draft': [('readonly', False)]}, readonly=True
states={'draft': [('readonly', False)]}, readonly=True,
domain=[('usage', 'in', ['internal', 'transit', 'customer'])],
)
product_id = fields.Many2one(
states={'draft': [('readonly', False)]}, readonly=True
Expand All @@ -97,14 +99,29 @@ def _get_default_requested_by(self):
states={'draft': [('readonly', False)]}, readonly=True
)
route_id = fields.Many2one(
states={'draft': [('readonly', False)]}, readonly=True
states={'draft': [('readonly', False)],
'submitted': [('readonly', False)]}, readonly=True
)
direction = fields.Selection([('outbound', 'Outbound'),
('inbound', 'Inbound')],
string='Direction',
states={'draft': [('readonly', False)]},
readonly=True)

_sql_constraints = [
('name_uniq', 'unique(name, company_id)',
'Stock Request name must be unique'),
]

@api.onchange('direction')
def _onchange_location_id(self):
if self.direction == 'outbound':
# Partner Locations/Customers
self.location_id = self.env.ref('stock.stock_location_customers')
else:
# Otherwise the Stock Location of the Warehouse
self.location_id = self.warehouse_id.lot_stock_id.id

@api.depends('allocation_ids')
def _compute_move_ids(self):
for request in self:
Expand Down Expand Up @@ -195,7 +212,17 @@ def _action_confirm(self):

@api.multi
def action_confirm(self):
self._action_confirm()
# Check if user allowed to skip Submit stage
if self.env.user.\
has_group('stock_request.group_bypass_submit_request'):
self._action_confirm()
return True
else:
# Move one state
if self.state == 'draft':
self.state = 'submitted'
else:
self._action_confirm()
return True

def action_draft(self):
Expand Down Expand Up @@ -257,7 +284,7 @@ def _action_launch_procurement_rule(self):
errors = []
for request in self:
if (
request.state != 'draft' or
request.state not in ('draft', 'submitted') or
request.product_id.type not in ('consu', 'product')
):
continue
Expand Down
37 changes: 33 additions & 4 deletions stock_request/models/stock_request_order.py
Expand Up @@ -6,6 +6,7 @@

REQUEST_STATES = [
('draft', 'Draft'),
('submitted', 'Submitted'),
('open', 'In progress'),
('done', 'Done'),
('cancel', 'Cancelled')]
Expand Down Expand Up @@ -50,7 +51,7 @@ def _get_default_requested_by(self):
states={'draft': [('readonly', False)]})
location_id = fields.Many2one(
'stock.location', 'Location', readonly=True,
domain=[('usage', 'in', ['internal', 'transit'])],
domain=[('usage', 'in', ['internal', 'transit', 'customer'])],
ondelete="cascade", required=True,
states={'draft': [('readonly', False)]},
)
Expand Down Expand Up @@ -111,6 +112,12 @@ def _get_default_requested_by(self):
'Stock Request name must be unique'),
]

direction = fields.Selection([('outbound', 'Outbound'),
('inbound', 'Inbound')],
string='Direction',
states={'draft': [('readonly', False)]},
readonly=True)

@api.depends('stock_request_ids.allocation_ids')
def _compute_picking_ids(self):
for record in self:
Expand Down Expand Up @@ -139,6 +146,16 @@ def onchange_expected_date(self):
def onchange_picking_policy(self):
self.change_childs()

@api.onchange('direction')
def _onchange_location_id(self):
if self.direction == 'outbound':
# Partner Locations/Customers
self.location_id = self.env.ref('stock.stock_location_customers')
else:
# Otherwise the Stock Location of the Warehouse
self.location_id = self.warehouse_id.lot_stock_id.id
self.change_childs()

@api.onchange('location_id')
def onchange_location_id(self):
if self.location_id:
Expand Down Expand Up @@ -189,6 +206,7 @@ def change_childs(self):
if not self._context.get('no_change_childs', False):
for line in self.stock_request_ids:
line.warehouse_id = self.warehouse_id
line.direction = self.direction
line.location_id = self.location_id
line.company_id = self.company_id
line.picking_policy = self.picking_policy
Expand All @@ -198,9 +216,20 @@ def change_childs(self):

@api.multi
def action_confirm(self):
for line in self.stock_request_ids:
line.action_confirm()
self.state = 'open'
# Check if user allowed to skip Submit stage
if self.env.user.\
has_group('stock_request.group_bypass_submit_request'):
for line in self.stock_request_ids:
line.action_confirm()
self.state = 'open'
else:
# Move one state
for line in self.stock_request_ids:
line.action_confirm()
if self.state == 'draft':
self.state = 'submitted'
else:
self.state = 'open'
return True

def action_draft(self):
Expand Down
19 changes: 19 additions & 0 deletions stock_request/readme/CONFIGURE.rst
@@ -0,0 +1,19 @@
To configure this module:

* Go to Stock Requests > Settings

Users should be assigned to the groups 'Stock Request / User' or 'Stock
Request / Manager'.

Group Stock Request / User
--------------------------

* Can see her/his own Stock Requests, and others that she/he's been granted
permission to follow.

* Can create/update only her/his Stock Requests.

Group Stock Request / Manager
-----------------------------

* Can fully manage all Stock Requests
8 changes: 8 additions & 0 deletions stock_request/readme/CONTRIBUTORS.rst
@@ -0,0 +1,8 @@
* Jordi Ballester (EFICENT) <jordi.ballester@eficent.com>.
* Enric Tobella <etobella@creublanca.es>
* Atte Isopuro <atte.isopuro@avoin.systems>
* Lois Rilo <lois.rilo@eficent.com>
* Raul Martin <raul.martin@braintec-group.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Steve Campbell <scampbell@opensourceintegrators.com>
2 changes: 2 additions & 0 deletions stock_request/readme/CREDITS.rst
@@ -0,0 +1,2 @@
* Eficent <https://www.eficent.com>
* Open Source Integrators <https://www.opensourceintegrators.com>
2 changes: 2 additions & 0 deletions stock_request/readme/DESCRIPTION.rst
@@ -0,0 +1,2 @@
This module was written to allow users to request products that are
frequently stocked by the company, to be transferred to their chosen location.
18 changes: 18 additions & 0 deletions stock_request/readme/USAGE.rst
@@ -0,0 +1,18 @@
Creation
--------

* Go to 'Stock Requests / Stock Requests' and create a new Request.
* Indicate a product, quantity and location.
* Press 'Confirm'.

Upon confirmation the request will be evaluated using the procurement rules
for the selected location.

In case that transfers are created, the user will be able to access to them
from the button 'Transfers' available in the Stock Request.

Cancel
------

When the user cancels a Stock Request, the related pending stock moves will be
also cancelled.
2 changes: 1 addition & 1 deletion stock_request/security/ir.model.access.csv
Expand Up @@ -4,7 +4,7 @@ access_stock_request_manager,stock request manager,model_stock_request,group_sto
access_stock_request_stock_user,stock.request stock user,model_stock_request,stock.group_stock_user,1,0,0,0
access_stock_request_allocation_user,stock request allocation user,model_stock_request_allocation,group_stock_request_user,1,1,1,1
access_stock_request_allocation_manager,stock request allocation manager,model_stock_request_allocation,group_stock_request_manager,1,1,1,1
access_stock_request_allocation_stock_user,stock.request.allocation stock user,model_stock_request_allocation,stock.group_stock_user,1,0,0,0
access_stock_request_allocation_stock_user,stock.request.allocation stock user,model_stock_request_allocation,base.group_user,1,0,0,0
access_stock_location_user,stock.location.user,stock.model_stock_location,group_stock_request_user,1,0,0,0
access_stock_location_request_manager,stock.location request manager,stock.model_stock_location,group_stock_request_manager,1,0,0,0
access_stock_rule_request_manager,stock_rule_request_manager,stock.model_stock_rule,group_stock_request_manager,1,0,0,0
Expand Down

0 comments on commit 473661a

Please sign in to comment.