From fae5880e1b98ffe4bb3293363a02bc2b35433daf Mon Sep 17 00:00:00 2001 From: hveficent Date: Thu, 1 Aug 2019 10:25:47 +0200 Subject: [PATCH] [12.0][IMP] stock_request: * Add readme autogenerated * Add some hooks * Improve test inheritance (reduce testing time) * Don't allow qty <= 0 * SR expected_date = order expected_date if SRO --- stock_request/README.rst | 89 ++-- stock_request/__manifest__.py | 2 +- stock_request/models/stock_request.py | 24 +- .../models/stock_request_abstract.py | 7 + stock_request/models/stock_request_order.py | 2 +- stock_request/readme/CONFIGURE.rst | 17 + stock_request/readme/CONTRIBUTORS.rst | 10 + stock_request/readme/DESCRIPTION.rst | 2 + stock_request/readme/USAGE.rst | 16 + stock_request/static/description/index.html | 467 ++++++++++++++++++ stock_request/tests/test_stock_request.py | 6 + 11 files changed, 605 insertions(+), 37 deletions(-) create mode 100644 stock_request/readme/CONFIGURE.rst create mode 100644 stock_request/readme/CONTRIBUTORS.rst create mode 100644 stock_request/readme/DESCRIPTION.rst create mode 100644 stock_request/readme/USAGE.rst create mode 100644 stock_request/static/description/index.html diff --git a/stock_request/README.rst b/stock_request/README.rst index 69ff494bc..6dd8533cf 100644 --- a/stock_request/README.rst +++ b/stock_request/README.rst @@ -1,40 +1,64 @@ -.. 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 - ============= Stock Request ============= +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/12.0/stock_request + :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-12-0/stock-logistics-warehouse-12-0-stock_request + :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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + This module was written to allow users to request products that are frequently stocked by the company, to be transferred to their chosen location. +**Table of contents** + +.. contents:: + :local: Configuration ============= +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 --------------------------- +## 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 ------------------------------ +## Group Stock Request / Manager * Can fully manage all Stock Requests - Usage ===== -Creation --------- +## Creation + * Go to 'Stock Requests / Stock Requests' and create a new Request. * Indicate a product, quantity and location. * Press 'Confirm'. @@ -45,30 +69,31 @@ 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 ------- +## 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 -`_. 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. +Bugs are tracked on `GitHub 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 +~~~~~~~ + +* Eficent + Contributors ------------- +~~~~~~~~~~~~ * Jordi Ballester (EFICENT) . * Enric Tobella @@ -76,18 +101,24 @@ Contributors * Lois Rilo * Raul Martin * Serpent Consulting Services Pvt. Ltd. +* `Open Source Integrators `_ -Maintainer ----------- + * Maxime Chambreuil + * Steve Campbell + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. 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. +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_request/__manifest__.py b/stock_request/__manifest__.py index 3ddf524e8..5cfa5353e 100644 --- a/stock_request/__manifest__.py +++ b/stock_request/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Stock Request", "summary": "Internal request for stock", - "version": "12.0.1.0.3", + "version": "12.0.1.0.4", "license": "LGPL-3", "website": "https://github.com/stock-logistics-warehouse", "author": "Eficent, " diff --git a/stock_request/models/stock_request.py b/stock_request/models/stock_request.py index ab20be058..77f2be79c 100644 --- a/stock_request/models/stock_request.py +++ b/stock_request/models/stock_request.py @@ -22,6 +22,17 @@ class StockRequest(models.Model): def _get_default_requested_by(self): return self.env['res.users'].browse(self.env.uid) + @staticmethod + def _get_expected_date(): + return fields.Datetime.now() + + def _get_default_expected_date(self): + if self.order_id: + res = self.order_id.expected_date + else: + res = self._get_expected_date() + return res + name = fields.Char( states={'draft': [('readonly', False)]} ) @@ -35,8 +46,8 @@ class StockRequest(models.Model): default=lambda s: s._get_default_requested_by(), ) expected_date = fields.Datetime( - 'Expected Date', default=fields.Datetime.now, index=True, - required=True, readonly=True, + 'Expected Date', default=lambda s: s._get_default_expected_date(), + index=True, required=True, readonly=True, states={'draft': [('readonly', False)]}, help="Date when you expect to receive the goods.", ) @@ -244,6 +255,10 @@ class StockRequest(models.Model): 'stock_request_id': self.id, } + def _skip_procurement(self): + return self.state != 'draft' or \ + self.product_id.type not in ('consu', 'product') + @api.multi def _action_launch_procurement_rule(self): """ @@ -257,10 +272,7 @@ class StockRequest(models.Model): 'Product Unit of Measure') errors = [] for request in self: - if ( - request.state != 'draft' or - request.product_id.type not in ('consu', 'product') - ): + if request._skip_procurement(): continue qty = 0.0 for move in request.move_ids.filtered( diff --git a/stock_request/models/stock_request_abstract.py b/stock_request/models/stock_request_abstract.py index 3631071fa..b4568d470 100644 --- a/stock_request/models/stock_request_abstract.py +++ b/stock_request/models/stock_request_abstract.py @@ -158,6 +158,13 @@ class StockRequest(models.AbstractModel): 'same category than the default unit ' 'of measure of the product')) + @api.constrains('product_qty') + def _check_qty(self): + for rec in self: + if rec.product_qty <= 0: + raise ValueError(_('Stock Request product quantity has to be' + ' strictly positive.')) + @api.onchange('warehouse_id') def onchange_warehouse_id(self): """ Finds location id for changed warehouse. """ diff --git a/stock_request/models/stock_request_order.py b/stock_request/models/stock_request_order.py index 3e00ad3c4..84e425825 100644 --- a/stock_request/models/stock_request_order.py +++ b/stock_request/models/stock_request_order.py @@ -301,7 +301,7 @@ class StockRequestOrder(models.Model): stock_request_ids=[(0, 0, dict( product_id=product.id, product_uom_id=product.uom_id.id, - product_uom_qty=0.0, + product_uom_qty=1.0, expected_date=expected, )) for product in products] )) diff --git a/stock_request/readme/CONFIGURE.rst b/stock_request/readme/CONFIGURE.rst new file mode 100644 index 000000000..4cbc55ffe --- /dev/null +++ b/stock_request/readme/CONFIGURE.rst @@ -0,0 +1,17 @@ +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 diff --git a/stock_request/readme/CONTRIBUTORS.rst b/stock_request/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..67adc0edc --- /dev/null +++ b/stock_request/readme/CONTRIBUTORS.rst @@ -0,0 +1,10 @@ +* Jordi Ballester (EFICENT) . +* Enric Tobella +* Atte Isopuro +* Lois Rilo +* Raul Martin +* Serpent Consulting Services Pvt. Ltd. +* `Open Source Integrators `_ + + * Maxime Chambreuil + * Steve Campbell diff --git a/stock_request/readme/DESCRIPTION.rst b/stock_request/readme/DESCRIPTION.rst new file mode 100644 index 000000000..e797cff95 --- /dev/null +++ b/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. diff --git a/stock_request/readme/USAGE.rst b/stock_request/readme/USAGE.rst new file mode 100644 index 000000000..3d65e7a61 --- /dev/null +++ b/stock_request/readme/USAGE.rst @@ -0,0 +1,16 @@ +## 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. diff --git a/stock_request/static/description/index.html b/stock_request/static/description/index.html new file mode 100644 index 000000000..c151d5aec --- /dev/null +++ b/stock_request/static/description/index.html @@ -0,0 +1,467 @@ + + + + + + +Stock Request + + + +
+

Stock Request

+ + +

Beta License: LGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

This module was written to allow users to request products that are +frequently stocked by the company, to be transferred to their chosen location.

+

Table of contents

+ +
+

Configuration

+

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
  • +
+
+
+

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.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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

+
    +
  • Eficent
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_request/tests/test_stock_request.py b/stock_request/tests/test_stock_request.py index 255b6d8d1..c1047355a 100644 --- a/stock_request/tests/test_stock_request.py +++ b/stock_request/tests/test_stock_request.py @@ -125,6 +125,12 @@ class TestStockRequest(common.TransactionCase): **vals )) + +class TestStockRequestBase(TestStockRequest): + + def setUp(self): + super(TestStockRequestBase, self).setUp() + def test_defaults(self): vals = { 'product_id': self.product.id,