From b239d93c0cce9804ca9824185110551e0c21b371 Mon Sep 17 00:00:00 2001 From: FactorLibre Date: Mon, 16 Aug 2021 09:31:29 +0200 Subject: [PATCH 1/3] [ADD] sale_automatic_workflow_reserve_sale_stock: New module to allow make automatic reserves --- .../__init__.py | 4 ++ .../__openerp__.py | 19 +++++ .../i18n/es.po | 58 +++++++++++++++ .../models/__init__.py | 5 ++ .../models/automatic_workflow_job.py | 71 +++++++++++++++++++ .../models/sale_workflow_process.py | 24 +++++++ .../tests/__init__.py | 4 ++ .../tests/test_flow.py | 36 ++++++++++ .../views/sale_workflow_process_view.xml | 21 ++++++ 9 files changed, 242 insertions(+) create mode 100644 sale_automatic_workflow_reserve_sale_stock/__init__.py create mode 100644 sale_automatic_workflow_reserve_sale_stock/__openerp__.py create mode 100644 sale_automatic_workflow_reserve_sale_stock/i18n/es.po create mode 100644 sale_automatic_workflow_reserve_sale_stock/models/__init__.py create mode 100644 sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py create mode 100644 sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py create mode 100644 sale_automatic_workflow_reserve_sale_stock/tests/__init__.py create mode 100644 sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py create mode 100644 sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml diff --git a/sale_automatic_workflow_reserve_sale_stock/__init__.py b/sale_automatic_workflow_reserve_sale_stock/__init__.py new file mode 100644 index 000000000..d327fe472 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2016 FactorLibre - Hugo Santos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/sale_automatic_workflow_reserve_sale_stock/__openerp__.py b/sale_automatic_workflow_reserve_sale_stock/__openerp__.py new file mode 100644 index 000000000..c3414d579 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2016 FactorLibre - Hugo Santos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'Sale Automatic Workflow: Reserve Sale stock', + 'version': '8.0.0.1.0', + 'category': 'Generic Modules/Others', + 'license': 'AGPL-3', + 'author': "FactorLibre,Odoo Community Association (OCA)", + 'website': 'http://www.factorlibre.com/', + 'depends': [ + 'sale_automatic_workflow', + 'stock_reserve_sale' + ], + 'data': [ + 'views/sale_workflow_process_view.xml' + ], + 'installable': True, +} diff --git a/sale_automatic_workflow_reserve_sale_stock/i18n/es.po b/sale_automatic_workflow_reserve_sale_stock/i18n/es.po new file mode 100644 index 000000000..01271b194 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/i18n/es.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_automatic_workflow_reserve_sale_stock +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-02-01 11:26+0000\n" +"PO-Revision-Date: 2016-02-01 12:28+0100\n" +"Last-Translator: Hugo Santos \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: es_ES\n" +"X-Generator: Poedit 1.5.4\n" + +#. module: sale_automatic_workflow_reserve_sale_stock +#: help:sale.workflow.process,stock_reservation:0 +msgid "Allows to make stock reservations before the confirm the sale quotation" +msgstr "" +"Permite realizar reservas de stock antes de confirmar el presupuesto de " +"venta." + +#. module: sale_automatic_workflow_reserve_sale_stock +#: help:sale.workflow.process,stock_reservation_validity:0 +msgid "" +"Make a stock reservation for this number of days. When this number of days " +"pass the stock reservation is released" +msgstr "" +"Realiza una reserva de stock durante este número de días. Cuando pasan la " +"reserva de stock es liberada" + +#. module: sale_automatic_workflow_reserve_sale_stock +#: model:ir.model,name:sale_automatic_workflow_reserve_sale_stock.model_sale_workflow_process +msgid "Sale Workflow Process" +msgstr "Proceso Workflow Venta" + +#. module: sale_automatic_workflow_reserve_sale_stock +#: field:sale.workflow.process,stock_reservation:0 +msgid "Stock Reservation" +msgstr "Reserva de stock" + +#. module: sale_automatic_workflow_reserve_sale_stock +#: field:sale.workflow.process,stock_reservation_validity:0 +msgid "Stock Reservation Validity (Days)" +msgstr "Validez de reserva de stock (Días)" + +#. module: sale_automatic_workflow_reserve_sale_stock +#: field:sale.workflow.process,stock_reservation_location_dest_id:0 +msgid "Stock reservation Location" +msgstr "Ub. de reserva de stock" + +#. module: sale_automatic_workflow_reserve_sale_stock +#: field:sale.workflow.process,stock_reservation_location_id:0 +msgid "Stock reservation Source Location" +msgstr "Ub. origen de reserva de stock" diff --git a/sale_automatic_workflow_reserve_sale_stock/models/__init__.py b/sale_automatic_workflow_reserve_sale_stock/models/__init__.py new file mode 100644 index 000000000..b97c5892a --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 FactorLibre - Hugo Santos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import sale_workflow_process +from . import automatic_workflow_job diff --git a/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py b/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py new file mode 100644 index 000000000..db7bc70cf --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# © 2016 FactorLibre - Hugo Santos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import logging +from datetime import datetime, timedelta +from openerp import models, api +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT +from openerp.addons.sale_automatic_workflow.automatic_workflow_job import \ + commit + +_logger = logging.getLogger(__name__) + + +class AutomaticWorkflowJob(models.Model): + + _inherit = 'automatic.workflow.job' + + @api.model + def _get_domain_for_stock_reservation(self): + return [('state', '=', 'draft'), + ('is_stock_reservable', '=', True), + ('has_stock_reservation', '=', False), + ('workflow_process_id.validate_order', '=', False), + ('workflow_process_id.stock_reservation', '=', True), + ('workflow_process_id.stock_reservation_validity', '>=', 0)] + + @api.model + def _make_stock_reservation(self): + sale_env = self.env['sale.order'] + sale_stock_reserve_env = self.env['sale.stock.reserve'] + sales = sale_env.search(self._get_domain_for_stock_reservation()) + _logger.debug('Sale Orders for what the stock will be reserved: %s' % + sales) + today = datetime.now() + for sale in sales: + workflow_process = sale.workflow_process_id + plus_days = timedelta( + days=workflow_process.stock_reservation_validity) + min_date_order = (today.date() - plus_days).strftime( + DEFAULT_SERVER_DATE_FORMAT) + # Check reservation date + if sale.date_order <= min_date_order: + continue + ctx = dict(self.env.context) + ctx.update({ + 'active_model': 'sale.order', + 'active_id': sale.id, + 'active_ids': [sale.id] + }) + with commit(self.env.cr): + reservation_vals = {} + if workflow_process.stock_reservation_validity: + reserve_until = today + plus_days + reservation_vals['date_validity'] =\ + reserve_until.strftime(DEFAULT_SERVER_DATE_FORMAT) + if workflow_process.stock_reservation_location_id: + reservation_vals['location_id'] =\ + workflow_process.stock_reservation_location_id.id + if workflow_process.stock_reservation_location_dest_id: + reservation_vals['location_dest_id'] =\ + workflow_process.stock_reservation_location_dest_id.id + sale_stock_reserve = sale_stock_reserve_env.with_context(ctx)\ + .create(reservation_vals) + line_ids = [line.id for line in sale.order_line] + sale_stock_reserve.stock_reserve(line_ids) + + @api.model + def run(self): + res = super(AutomaticWorkflowJob, self).run() + self._make_stock_reservation() + return res diff --git a/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py b/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py new file mode 100644 index 000000000..3d5558fcf --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# © 2016 FactorLibre - Hugo Santos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import models, fields + + +class SaleWorkflowProcess(models.Model): + _inherit = 'sale.workflow.process' + + stock_reservation = fields.Boolean( + 'Stock Reservation', + help='Allows to make stock reservations before the confirm the ' + 'sale quotation') + stock_reservation_validity = fields.Integer( + 'Stock Reservation Validity (Days)', + help='Make a stock reservation for this number of days. ' + 'When this number of days pass the stock reservation is released', + default=5) + stock_reservation_location_id = fields.Many2one( + 'stock.location', + 'Stock reservation Source Location') + stock_reservation_location_dest_id = fields.Many2one( + 'stock.location', + 'Stock reservation Location') diff --git a/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py b/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py new file mode 100644 index 000000000..aa0109602 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2016 FactorLibre - Hugo Santos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import test_flow diff --git a/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py b/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py new file mode 100644 index 000000000..72d2f516e --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# © 2016 FactorLibre - Hugo Santos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp.addons.sale_automatic_workflow.tests.test_flow import \ + TestAutomaticWorkflow + + +class TestAutomaticWorkflowStockReservation(TestAutomaticWorkflow): + + def test_workflow_stock_reservation(self): + workflow = self._create_full_automatic({ + 'name': 'Workflow Automatic Reservation', + 'validate_order': False, + 'invoice_quantity': 'procurement', + 'order_policy': 'picking', + 'stock_reservation': True, + 'stock_reservation_validity': 5 + }) + sale = self._create_sale_order(workflow) + sale.onchange_workflow_process_id() + self.assertEqual(sale.state, 'draft') + self.assertEqual(sale.is_stock_reservable, True) + self.assertEqual(sale.has_stock_reservation, False) + self.progress() + self.assertEqual(sale.has_stock_reservation, True) + + def test_workflow_automatic_no_reservation(self): + workflow = self._create_full_automatic() + sale = self._create_sale_order(workflow) + sale.onchange_workflow_process_id() + self.assertEqual(sale.state, 'draft') + self.assertEqual(sale.is_stock_reservable, True) + self.assertEqual(sale.has_stock_reservation, False) + self.progress() + self.assertEqual(sale.state, 'progress') + self.assertEqual(sale.has_stock_reservation, False) diff --git a/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml b/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml new file mode 100644 index 000000000..5e7c75aee --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml @@ -0,0 +1,21 @@ + + + + + + sale_automatic_workflow_reserve_sale_stock.sale_workflow_process.view_form + sale.workflow.process + + + + + + + + + + + + \ No newline at end of file From afd8173ecf169266da3a2d8f68d7ba01fa211eee Mon Sep 17 00:00:00 2001 From: CarlosRoca13 Date: Mon, 16 Aug 2021 09:32:28 +0200 Subject: [PATCH 2/3] [IMP] sale_automatic_workflow_reserve_sale_stock: black, isort, prettier --- .../__init__.py | 1 - .../__openerp__.py | 24 +++---- .../models/__init__.py | 1 - .../models/automatic_workflow_job.py | 68 ++++++++++--------- .../models/sale_workflow_process.py | 29 ++++---- .../tests/__init__.py | 1 - .../tests/test_flow.py | 29 ++++---- .../views/sale_workflow_process_view.xml | 38 ++++++----- .../odoo_addons/__init__.py | 1 + ...sale_automatic_workflow_reserve_sale_stock | 1 + .../setup.py | 6 ++ 11 files changed, 104 insertions(+), 95 deletions(-) create mode 100644 setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/__init__.py create mode 120000 setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/sale_automatic_workflow_reserve_sale_stock create mode 100644 setup/sale_automatic_workflow_reserve_sale_stock/setup.py diff --git a/sale_automatic_workflow_reserve_sale_stock/__init__.py b/sale_automatic_workflow_reserve_sale_stock/__init__.py index d327fe472..e0f57b4d7 100644 --- a/sale_automatic_workflow_reserve_sale_stock/__init__.py +++ b/sale_automatic_workflow_reserve_sale_stock/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2016 FactorLibre - Hugo Santos # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/sale_automatic_workflow_reserve_sale_stock/__openerp__.py b/sale_automatic_workflow_reserve_sale_stock/__openerp__.py index c3414d579..59a0bd5d0 100644 --- a/sale_automatic_workflow_reserve_sale_stock/__openerp__.py +++ b/sale_automatic_workflow_reserve_sale_stock/__openerp__.py @@ -1,19 +1,13 @@ -# -*- coding: utf-8 -*- # © 2016 FactorLibre - Hugo Santos # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Sale Automatic Workflow: Reserve Sale stock', - 'version': '8.0.0.1.0', - 'category': 'Generic Modules/Others', - 'license': 'AGPL-3', - 'author': "FactorLibre,Odoo Community Association (OCA)", - 'website': 'http://www.factorlibre.com/', - 'depends': [ - 'sale_automatic_workflow', - 'stock_reserve_sale' - ], - 'data': [ - 'views/sale_workflow_process_view.xml' - ], - 'installable': True, + "name": "Sale Automatic Workflow: Reserve Sale stock", + "version": "8.0.0.1.0", + "category": "Generic Modules/Others", + "license": "AGPL-3", + "author": "FactorLibre,Odoo Community Association (OCA)", + "website": "http://www.factorlibre.com/", + "depends": ["sale_automatic_workflow", "stock_reserve_sale"], + "data": ["views/sale_workflow_process_view.xml"], + "installable": True, } diff --git a/sale_automatic_workflow_reserve_sale_stock/models/__init__.py b/sale_automatic_workflow_reserve_sale_stock/models/__init__.py index b97c5892a..9cb68e8b8 100644 --- a/sale_automatic_workflow_reserve_sale_stock/models/__init__.py +++ b/sale_automatic_workflow_reserve_sale_stock/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2016 FactorLibre - Hugo Santos # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import sale_workflow_process diff --git a/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py b/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py index db7bc70cf..d2cbbc42e 100644 --- a/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py +++ b/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py @@ -1,66 +1,72 @@ -# -*- coding: utf-8 -*- # © 2016 FactorLibre - Hugo Santos # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging from datetime import datetime, timedelta -from openerp import models, api + +from openerp import api, models +from openerp.addons.sale_automatic_workflow.automatic_workflow_job import commit from openerp.tools import DEFAULT_SERVER_DATE_FORMAT -from openerp.addons.sale_automatic_workflow.automatic_workflow_job import \ - commit _logger = logging.getLogger(__name__) class AutomaticWorkflowJob(models.Model): - _inherit = 'automatic.workflow.job' + _inherit = "automatic.workflow.job" @api.model def _get_domain_for_stock_reservation(self): - return [('state', '=', 'draft'), - ('is_stock_reservable', '=', True), - ('has_stock_reservation', '=', False), - ('workflow_process_id.validate_order', '=', False), - ('workflow_process_id.stock_reservation', '=', True), - ('workflow_process_id.stock_reservation_validity', '>=', 0)] + return [ + ("state", "=", "draft"), + ("is_stock_reservable", "=", True), + ("has_stock_reservation", "=", False), + ("workflow_process_id.validate_order", "=", False), + ("workflow_process_id.stock_reservation", "=", True), + ("workflow_process_id.stock_reservation_validity", ">=", 0), + ] @api.model def _make_stock_reservation(self): - sale_env = self.env['sale.order'] - sale_stock_reserve_env = self.env['sale.stock.reserve'] + sale_env = self.env["sale.order"] + sale_stock_reserve_env = self.env["sale.stock.reserve"] sales = sale_env.search(self._get_domain_for_stock_reservation()) - _logger.debug('Sale Orders for what the stock will be reserved: %s' % - sales) + _logger.debug("Sale Orders for what the stock will be reserved: %s" % sales) today = datetime.now() for sale in sales: workflow_process = sale.workflow_process_id - plus_days = timedelta( - days=workflow_process.stock_reservation_validity) + plus_days = timedelta(days=workflow_process.stock_reservation_validity) min_date_order = (today.date() - plus_days).strftime( - DEFAULT_SERVER_DATE_FORMAT) + DEFAULT_SERVER_DATE_FORMAT + ) # Check reservation date if sale.date_order <= min_date_order: continue ctx = dict(self.env.context) - ctx.update({ - 'active_model': 'sale.order', - 'active_id': sale.id, - 'active_ids': [sale.id] - }) + ctx.update( + { + "active_model": "sale.order", + "active_id": sale.id, + "active_ids": [sale.id], + } + ) with commit(self.env.cr): reservation_vals = {} if workflow_process.stock_reservation_validity: reserve_until = today + plus_days - reservation_vals['date_validity'] =\ - reserve_until.strftime(DEFAULT_SERVER_DATE_FORMAT) + reservation_vals["date_validity"] = reserve_until.strftime( + DEFAULT_SERVER_DATE_FORMAT + ) if workflow_process.stock_reservation_location_id: - reservation_vals['location_id'] =\ - workflow_process.stock_reservation_location_id.id + reservation_vals[ + "location_id" + ] = workflow_process.stock_reservation_location_id.id if workflow_process.stock_reservation_location_dest_id: - reservation_vals['location_dest_id'] =\ - workflow_process.stock_reservation_location_dest_id.id - sale_stock_reserve = sale_stock_reserve_env.with_context(ctx)\ - .create(reservation_vals) + reservation_vals[ + "location_dest_id" + ] = workflow_process.stock_reservation_location_dest_id.id + sale_stock_reserve = sale_stock_reserve_env.with_context(ctx).create( + reservation_vals + ) line_ids = [line.id for line in sale.order_line] sale_stock_reserve.stock_reserve(line_ids) diff --git a/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py b/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py index 3d5558fcf..9f96824c2 100644 --- a/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py +++ b/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py @@ -1,24 +1,25 @@ -# -*- coding: utf-8 -*- # © 2016 FactorLibre - Hugo Santos # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields +from openerp import fields, models class SaleWorkflowProcess(models.Model): - _inherit = 'sale.workflow.process' + _inherit = "sale.workflow.process" stock_reservation = fields.Boolean( - 'Stock Reservation', - help='Allows to make stock reservations before the confirm the ' - 'sale quotation') + "Stock Reservation", + help="Allows to make stock reservations before the confirm the " + "sale quotation", + ) stock_reservation_validity = fields.Integer( - 'Stock Reservation Validity (Days)', - help='Make a stock reservation for this number of days. ' - 'When this number of days pass the stock reservation is released', - default=5) + "Stock Reservation Validity (Days)", + help="Make a stock reservation for this number of days. " + "When this number of days pass the stock reservation is released", + default=5, + ) stock_reservation_location_id = fields.Many2one( - 'stock.location', - 'Stock reservation Source Location') + "stock.location", "Stock reservation Source Location" + ) stock_reservation_location_dest_id = fields.Many2one( - 'stock.location', - 'Stock reservation Location') + "stock.location", "Stock reservation Location" + ) diff --git a/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py b/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py index aa0109602..74fd8e13e 100644 --- a/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py +++ b/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2016 FactorLibre - Hugo Santos # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import test_flow diff --git a/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py b/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py index 72d2f516e..661d03170 100644 --- a/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py +++ b/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py @@ -1,24 +1,23 @@ -# -*- coding: utf-8 -*- # © 2016 FactorLibre - Hugo Santos # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.addons.sale_automatic_workflow.tests.test_flow import \ - TestAutomaticWorkflow +from openerp.addons.sale_automatic_workflow.tests.test_flow import TestAutomaticWorkflow class TestAutomaticWorkflowStockReservation(TestAutomaticWorkflow): - def test_workflow_stock_reservation(self): - workflow = self._create_full_automatic({ - 'name': 'Workflow Automatic Reservation', - 'validate_order': False, - 'invoice_quantity': 'procurement', - 'order_policy': 'picking', - 'stock_reservation': True, - 'stock_reservation_validity': 5 - }) + workflow = self._create_full_automatic( + { + "name": "Workflow Automatic Reservation", + "validate_order": False, + "invoice_quantity": "procurement", + "order_policy": "picking", + "stock_reservation": True, + "stock_reservation_validity": 5, + } + ) sale = self._create_sale_order(workflow) sale.onchange_workflow_process_id() - self.assertEqual(sale.state, 'draft') + self.assertEqual(sale.state, "draft") self.assertEqual(sale.is_stock_reservable, True) self.assertEqual(sale.has_stock_reservation, False) self.progress() @@ -28,9 +27,9 @@ class TestAutomaticWorkflowStockReservation(TestAutomaticWorkflow): workflow = self._create_full_automatic() sale = self._create_sale_order(workflow) sale.onchange_workflow_process_id() - self.assertEqual(sale.state, 'draft') + self.assertEqual(sale.state, "draft") self.assertEqual(sale.is_stock_reservable, True) self.assertEqual(sale.has_stock_reservation, False) self.progress() - self.assertEqual(sale.state, 'progress') + self.assertEqual(sale.state, "progress") self.assertEqual(sale.has_stock_reservation, False) diff --git a/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml b/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml index 5e7c75aee..6e2ba9a84 100644 --- a/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml +++ b/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml @@ -1,21 +1,25 @@ - + - - - sale_automatic_workflow_reserve_sale_stock.sale_workflow_process.view_form - sale.workflow.process - - - - - - - + + + sale_automatic_workflow_reserve_sale_stock.sale_workflow_process.view_form + sale.workflow.process + + + + + + + + - - - - \ No newline at end of file + + + diff --git a/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/__init__.py b/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/sale_automatic_workflow_reserve_sale_stock b/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/sale_automatic_workflow_reserve_sale_stock new file mode 120000 index 000000000..24bd494c7 --- /dev/null +++ b/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/sale_automatic_workflow_reserve_sale_stock @@ -0,0 +1 @@ +../../../sale_automatic_workflow_reserve_sale_stock \ No newline at end of file diff --git a/setup/sale_automatic_workflow_reserve_sale_stock/setup.py b/setup/sale_automatic_workflow_reserve_sale_stock/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sale_automatic_workflow_reserve_sale_stock/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From befb0f0f213729052cec75b598196d2ec8c687e5 Mon Sep 17 00:00:00 2001 From: CarlosRoca13 Date: Mon, 16 Aug 2021 09:36:02 +0200 Subject: [PATCH 3/3] [MIG] sale_automatic_workflow_reserve_sale_stock: Migration to v13 --- oca_dependencies.txt | 1 + .../README.rst | 104 ++++ .../__init__.py | 2 - .../__manifest__.py | 15 + .../__openerp__.py | 13 - .../i18n/es.po | 73 +-- .../sale_automatic_workflow_stock_reserve.pot | 66 +++ .../models/__init__.py | 4 +- .../models/automatic_workflow_job.py | 44 +- .../models/sale_workflow_process.py | 17 +- .../readme/CONFIGURE.rst | 4 + .../readme/CONTRIBUTORS.rst | 5 + .../readme/DESCRIPTION.rst | 1 + .../readme/USAGE.rst | 6 + .../static/description/index.html | 452 ++++++++++++++++++ .../tests/__init__.py | 4 +- ..._sale_automatic_workflow_stock_reserve.py} | 35 +- .../views/sale_workflow_process_view.xml | 24 +- ...sale_automatic_workflow_reserve_sale_stock | 1 + .../odoo_addons/__init__.py | 1 - ...sale_automatic_workflow_reserve_sale_stock | 1 - 21 files changed, 760 insertions(+), 113 deletions(-) create mode 100644 sale_automatic_workflow_reserve_sale_stock/README.rst create mode 100644 sale_automatic_workflow_reserve_sale_stock/__manifest__.py delete mode 100644 sale_automatic_workflow_reserve_sale_stock/__openerp__.py create mode 100644 sale_automatic_workflow_reserve_sale_stock/i18n/sale_automatic_workflow_stock_reserve.pot create mode 100644 sale_automatic_workflow_reserve_sale_stock/readme/CONFIGURE.rst create mode 100644 sale_automatic_workflow_reserve_sale_stock/readme/CONTRIBUTORS.rst create mode 100644 sale_automatic_workflow_reserve_sale_stock/readme/DESCRIPTION.rst create mode 100644 sale_automatic_workflow_reserve_sale_stock/readme/USAGE.rst create mode 100644 sale_automatic_workflow_reserve_sale_stock/static/description/index.html rename sale_automatic_workflow_reserve_sale_stock/tests/{test_flow.py => test_sale_automatic_workflow_stock_reserve.py} (52%) create mode 120000 setup/sale_automatic_workflow_reserve_sale_stock/odoo/addons/sale_automatic_workflow_reserve_sale_stock delete mode 100644 setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/__init__.py delete mode 120000 setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/sale_automatic_workflow_reserve_sale_stock diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 731715c8d..46e37b47e 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,6 +1,7 @@ account-analytic connector product-attribute +sale-workflow server-env server-ux web diff --git a/sale_automatic_workflow_reserve_sale_stock/README.rst b/sale_automatic_workflow_reserve_sale_stock/README.rst new file mode 100644 index 000000000..0467e8c70 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/README.rst @@ -0,0 +1,104 @@ +=========================================== +Sale Automatic Workflow: Reserve Sale stock +=========================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/13.0/sale_automatic_workflow_stock_reserve + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-13-0/sale-workflow-13-0-sale_automatic_workflow_stock_reserve + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/167/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends Automatic Workflows to allow make Automatic Reserves at Sale Orders. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +#. Go to *Sales > Configuration > Automatic Workflow*. +#. Create or select one. +#. Make sure that **Validate Order** is not selected and **Stock Reservation** is selected. +#. Save changes. + +Usage +===== + +#. Create a new Quotation. +#. Fill the lines with some **Storable products**. +#. Go to *Automation Information*. +#. Set the **Automatic Workflow** created previously. +#. Save the Quotation. +#. Wait since the cron is executed. + +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 +~~~~~~~ + +* FactorLibre +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* Hugo Santos + +* `Tecnativa `_: + + * Carlos Roca + +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. + +.. |maintainer-CarlosRoca13| image:: https://github.com/CarlosRoca13.png?size=40px + :target: https://github.com/CarlosRoca13 + :alt: CarlosRoca13 + +Current `maintainer `__: + +|maintainer-CarlosRoca13| + +This module is part of the `OCA/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_automatic_workflow_reserve_sale_stock/__init__.py b/sale_automatic_workflow_reserve_sale_stock/__init__.py index e0f57b4d7..0650744f6 100644 --- a/sale_automatic_workflow_reserve_sale_stock/__init__.py +++ b/sale_automatic_workflow_reserve_sale_stock/__init__.py @@ -1,3 +1 @@ -# © 2016 FactorLibre - Hugo Santos -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/sale_automatic_workflow_reserve_sale_stock/__manifest__.py b/sale_automatic_workflow_reserve_sale_stock/__manifest__.py new file mode 100644 index 000000000..f5b31b515 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2016 FactorLibre - Hugo Santos +# Copyright 2021 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Automatic Workflow: Reserve Sale stock", + "version": "13.0.1.0.0", + "category": "Sales Management", + "license": "AGPL-3", + "author": "FactorLibre, Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-workflow", + "depends": ["sale_automatic_workflow", "stock_reserve_sale"], + "data": ["views/sale_workflow_process_view.xml"], + "maintainers": ["CarlosRoca13"], + "installable": True, +} diff --git a/sale_automatic_workflow_reserve_sale_stock/__openerp__.py b/sale_automatic_workflow_reserve_sale_stock/__openerp__.py deleted file mode 100644 index 59a0bd5d0..000000000 --- a/sale_automatic_workflow_reserve_sale_stock/__openerp__.py +++ /dev/null @@ -1,13 +0,0 @@ -# © 2016 FactorLibre - Hugo Santos -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -{ - "name": "Sale Automatic Workflow: Reserve Sale stock", - "version": "8.0.0.1.0", - "category": "Generic Modules/Others", - "license": "AGPL-3", - "author": "FactorLibre,Odoo Community Association (OCA)", - "website": "http://www.factorlibre.com/", - "depends": ["sale_automatic_workflow", "stock_reserve_sale"], - "data": ["views/sale_workflow_process_view.xml"], - "installable": True, -} diff --git a/sale_automatic_workflow_reserve_sale_stock/i18n/es.po b/sale_automatic_workflow_reserve_sale_stock/i18n/es.po index 01271b194..4dbd0a029 100644 --- a/sale_automatic_workflow_reserve_sale_stock/i18n/es.po +++ b/sale_automatic_workflow_reserve_sale_stock/i18n/es.po @@ -1,58 +1,71 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * sale_automatic_workflow_reserve_sale_stock +# * sale_automatic_workflow_stock_reserve # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-02-01 11:26+0000\n" -"PO-Revision-Date: 2016-02-01 12:28+0100\n" -"Last-Translator: Hugo Santos \n" +"POT-Creation-Date: 2021-08-06 10:28+0000\n" +"PO-Revision-Date: 2021-08-06 12:36+0200\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Language: es_ES\n" -"X-Generator: Poedit 1.5.4\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.4.3\n" +"Last-Translator: \n" +"Language: es\n" -#. module: sale_automatic_workflow_reserve_sale_stock -#: help:sale.workflow.process,stock_reservation:0 +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,help:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation msgid "Allows to make stock reservations before the confirm the sale quotation" -msgstr "" -"Permite realizar reservas de stock antes de confirmar el presupuesto de " -"venta." +msgstr "Permite hacer reservas de stock antes de confirmar el presupuesto" -#. module: sale_automatic_workflow_reserve_sale_stock -#: help:sale.workflow.process,stock_reservation_validity:0 +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,help:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation_validity msgid "" "Make a stock reservation for this number of days. When this number of days " "pass the stock reservation is released" msgstr "" -"Realiza una reserva de stock durante este número de días. Cuando pasan la " -"reserva de stock es liberada" +"Realiza una reserva de stock para esta cantidad de días. Cuando este número " +"de días se supera la reserva va a ser liberada" -#. module: sale_automatic_workflow_reserve_sale_stock -#: model:ir.model,name:sale_automatic_workflow_reserve_sale_stock.model_sale_workflow_process +#. module: sale_automatic_workflow_stock_reserve +#: model_terms:ir.ui.view,arch_db:sale_automatic_workflow_stock_reserve.sale_workflow_process_view_form +msgid "Reserve Options" +msgstr "Opciones de reserva" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model,name:sale_automatic_workflow_stock_reserve.model_sale_workflow_process msgid "Sale Workflow Process" -msgstr "Proceso Workflow Venta" +msgstr "Proceso del flujo de venta" -#. module: sale_automatic_workflow_reserve_sale_stock -#: field:sale.workflow.process,stock_reservation:0 +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model,name:sale_automatic_workflow_stock_reserve.model_automatic_workflow_job +msgid "" +"Scheduler that will play automatically the validation of invoices, " +"pickings..." +msgstr "" +"Planificar que va a ser ejecutada automáticamente la validaciín de facturas, " +"movimientos de stock..." + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,field_description:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation msgid "Stock Reservation" msgstr "Reserva de stock" -#. module: sale_automatic_workflow_reserve_sale_stock -#: field:sale.workflow.process,stock_reservation_validity:0 +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,field_description:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation_validity msgid "Stock Reservation Validity (Days)" -msgstr "Validez de reserva de stock (Días)" +msgstr "Validez de la reserva de stock (días)" -#. module: sale_automatic_workflow_reserve_sale_stock -#: field:sale.workflow.process,stock_reservation_location_dest_id:0 +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,field_description:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation_location_dest_id msgid "Stock reservation Location" -msgstr "Ub. de reserva de stock" +msgstr "Localización de la reserva" -#. module: sale_automatic_workflow_reserve_sale_stock -#: field:sale.workflow.process,stock_reservation_location_id:0 +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,field_description:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation_location_id msgid "Stock reservation Source Location" -msgstr "Ub. origen de reserva de stock" +msgstr "Localización inicial de la reserva" diff --git a/sale_automatic_workflow_reserve_sale_stock/i18n/sale_automatic_workflow_stock_reserve.pot b/sale_automatic_workflow_reserve_sale_stock/i18n/sale_automatic_workflow_stock_reserve.pot new file mode 100644 index 000000000..09813c5c7 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/i18n/sale_automatic_workflow_stock_reserve.pot @@ -0,0 +1,66 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_automatic_workflow_stock_reserve +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-08-06 10:28+0000\n" +"PO-Revision-Date: 2021-08-06 10:28+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,help:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation +msgid "" +"Allows to make stock reservations before the confirm the sale quotation" +msgstr "" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,help:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation_validity +msgid "" +"Make a stock reservation for this number of days. When this number of days " +"pass the stock reservation is released" +msgstr "" + +#. module: sale_automatic_workflow_stock_reserve +#: model_terms:ir.ui.view,arch_db:sale_automatic_workflow_stock_reserve.sale_workflow_process_view_form +msgid "Reserve Options" +msgstr "" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model,name:sale_automatic_workflow_stock_reserve.model_sale_workflow_process +msgid "Sale Workflow Process" +msgstr "" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model,name:sale_automatic_workflow_stock_reserve.model_automatic_workflow_job +msgid "" +"Scheduler that will play automatically the validation of invoices, " +"pickings..." +msgstr "" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,field_description:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation +msgid "Stock Reservation" +msgstr "" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,field_description:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation_validity +msgid "Stock Reservation Validity (Days)" +msgstr "" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,field_description:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation_location_dest_id +msgid "Stock reservation Location" +msgstr "" + +#. module: sale_automatic_workflow_stock_reserve +#: model:ir.model.fields,field_description:sale_automatic_workflow_stock_reserve.field_sale_workflow_process__stock_reservation_location_id +msgid "Stock reservation Source Location" +msgstr "" diff --git a/sale_automatic_workflow_reserve_sale_stock/models/__init__.py b/sale_automatic_workflow_reserve_sale_stock/models/__init__.py index 9cb68e8b8..fdcba65b2 100644 --- a/sale_automatic_workflow_reserve_sale_stock/models/__init__.py +++ b/sale_automatic_workflow_reserve_sale_stock/models/__init__.py @@ -1,4 +1,2 @@ -# © 2016 FactorLibre - Hugo Santos -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import sale_workflow_process from . import automatic_workflow_job +from . import sale_workflow_process diff --git a/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py b/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py index d2cbbc42e..4a45e9939 100644 --- a/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py +++ b/sale_automatic_workflow_reserve_sale_stock/models/automatic_workflow_job.py @@ -1,17 +1,17 @@ -# © 2016 FactorLibre - Hugo Santos -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2016 FactorLibre - Hugo Santos +# Copyright 2021 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import logging from datetime import datetime, timedelta -from openerp import api, models -from openerp.addons.sale_automatic_workflow.automatic_workflow_job import commit -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT +from odoo import api, models + +from odoo.addons.sale_automatic_workflow.models.automatic_workflow_job import savepoint _logger = logging.getLogger(__name__) class AutomaticWorkflowJob(models.Model): - _inherit = "automatic.workflow.job" @api.model @@ -27,18 +27,18 @@ class AutomaticWorkflowJob(models.Model): @api.model def _make_stock_reservation(self): - sale_env = self.env["sale.order"] - sale_stock_reserve_env = self.env["sale.stock.reserve"] - sales = sale_env.search(self._get_domain_for_stock_reservation()) - _logger.debug("Sale Orders for what the stock will be reserved: %s" % sales) + sales = self.env["sale.order"].search(self._get_domain_for_stock_reservation()) + _logger.debug("Sales orders for which stock will be reserved: %s" % sales) today = datetime.now() for sale in sales: workflow_process = sale.workflow_process_id + # Check that the date_order is set at least at n days + # declared at workflow_process. Doing this, we are sure + # that the reservation.validity_date will be at least + # at today. If this wasn't like that, the cron of stock_reserve + # will release this reservation. plus_days = timedelta(days=workflow_process.stock_reservation_validity) - min_date_order = (today.date() - plus_days).strftime( - DEFAULT_SERVER_DATE_FORMAT - ) - # Check reservation date + min_date_order = today - plus_days if sale.date_order <= min_date_order: continue ctx = dict(self.env.context) @@ -46,16 +46,14 @@ class AutomaticWorkflowJob(models.Model): { "active_model": "sale.order", "active_id": sale.id, - "active_ids": [sale.id], + "active_ids": sale.ids, } ) - with commit(self.env.cr): + with savepoint(self.env.cr): reservation_vals = {} if workflow_process.stock_reservation_validity: reserve_until = today + plus_days - reservation_vals["date_validity"] = reserve_until.strftime( - DEFAULT_SERVER_DATE_FORMAT - ) + reservation_vals["date_validity"] = reserve_until if workflow_process.stock_reservation_location_id: reservation_vals[ "location_id" @@ -64,14 +62,16 @@ class AutomaticWorkflowJob(models.Model): reservation_vals[ "location_dest_id" ] = workflow_process.stock_reservation_location_dest_id.id - sale_stock_reserve = sale_stock_reserve_env.with_context(ctx).create( - reservation_vals + sale_stock_reserve = ( + self.env["sale.stock.reserve"] + .with_context(ctx) + .create(reservation_vals) ) line_ids = [line.id for line in sale.order_line] sale_stock_reserve.stock_reserve(line_ids) @api.model def run(self): - res = super(AutomaticWorkflowJob, self).run() + res = super().run() self._make_stock_reservation() return res diff --git a/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py b/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py index 9f96824c2..d68fc6a60 100644 --- a/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py +++ b/sale_automatic_workflow_reserve_sale_stock/models/sale_workflow_process.py @@ -1,25 +1,24 @@ -# © 2016 FactorLibre - Hugo Santos -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import fields, models +# Copyright 2016 FactorLibre - Hugo Santos +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models class SaleWorkflowProcess(models.Model): _inherit = "sale.workflow.process" stock_reservation = fields.Boolean( - "Stock Reservation", - help="Allows to make stock reservations before the confirm the " - "sale quotation", + string="Stock Reservation", + help="Allows to make stock reservations before the confirm the sale quotation", ) stock_reservation_validity = fields.Integer( - "Stock Reservation Validity (Days)", + string="Stock Reservation Validity (Days)", help="Make a stock reservation for this number of days. " "When this number of days pass the stock reservation is released", default=5, ) stock_reservation_location_id = fields.Many2one( - "stock.location", "Stock reservation Source Location" + comodel_name="stock.location", string="Stock reservation Source Location" ) stock_reservation_location_dest_id = fields.Many2one( - "stock.location", "Stock reservation Location" + comodel_name="stock.location", string="Stock reservation Location" ) diff --git a/sale_automatic_workflow_reserve_sale_stock/readme/CONFIGURE.rst b/sale_automatic_workflow_reserve_sale_stock/readme/CONFIGURE.rst new file mode 100644 index 000000000..2fee1d698 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +#. Go to *Sales > Configuration > Automatic Workflow*. +#. Create or select one. +#. Make sure that **Validate Order** is not selected and **Stock Reservation** is selected. +#. Save changes. diff --git a/sale_automatic_workflow_reserve_sale_stock/readme/CONTRIBUTORS.rst b/sale_automatic_workflow_reserve_sale_stock/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..46003ad8d --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Hugo Santos + +* `Tecnativa `_: + + * Carlos Roca diff --git a/sale_automatic_workflow_reserve_sale_stock/readme/DESCRIPTION.rst b/sale_automatic_workflow_reserve_sale_stock/readme/DESCRIPTION.rst new file mode 100644 index 000000000..35a341cc3 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module extends Automatic Workflows to allow make Automatic Reserves at Sale Orders. diff --git a/sale_automatic_workflow_reserve_sale_stock/readme/USAGE.rst b/sale_automatic_workflow_reserve_sale_stock/readme/USAGE.rst new file mode 100644 index 000000000..a1626b16b --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/readme/USAGE.rst @@ -0,0 +1,6 @@ +#. Create a new Quotation. +#. Fill the lines with some **Storable products**. +#. Go to *Automation Information*. +#. Set the **Automatic Workflow** created previously. +#. Save the Quotation. +#. Wait since the cron is executed. diff --git a/sale_automatic_workflow_reserve_sale_stock/static/description/index.html b/sale_automatic_workflow_reserve_sale_stock/static/description/index.html new file mode 100644 index 000000000..d06fb37c2 --- /dev/null +++ b/sale_automatic_workflow_reserve_sale_stock/static/description/index.html @@ -0,0 +1,452 @@ + + + + + + +Sale Automatic Workflow: Reserve Sale stock + + + +
+

Sale Automatic Workflow: Reserve Sale stock

+ + +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runbot

+

This module extends Automatic Workflows to allow make Automatic Reserves at Sale Orders.

+

Table of contents

+ +
+

Configuration

+
    +
  1. Go to Sales > Configuration > Automatic Workflow.
  2. +
  3. Create or select one.
  4. +
  5. Make sure that Validate Order is not selected and Stock Reservation is selected.
  6. +
  7. Save changes.
  8. +
+
+
+

Usage

+
    +
  1. Create a new Quotation.
  2. +
  3. Fill the lines with some Storable products.
  4. +
  5. Go to Automation Information.
  6. +
  7. Set the Automatic Workflow created previously.
  8. +
  9. Save the Quotation.
  10. +
  11. Wait since the cron is executed.
  12. +
+
+
+

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

+
    +
  • FactorLibre
  • +
  • Tecnativa
  • +
+
+
+

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.

+

Current maintainer:

+

CarlosRoca13

+

This module is part of the OCA/sale-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py b/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py index 74fd8e13e..162e41c3a 100644 --- a/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py +++ b/sale_automatic_workflow_reserve_sale_stock/tests/__init__.py @@ -1,3 +1 @@ -# © 2016 FactorLibre - Hugo Santos -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import test_flow +from . import test_sale_automatic_workflow_stock_reserve diff --git a/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py b/sale_automatic_workflow_reserve_sale_stock/tests/test_sale_automatic_workflow_stock_reserve.py similarity index 52% rename from sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py rename to sale_automatic_workflow_reserve_sale_stock/tests/test_sale_automatic_workflow_stock_reserve.py index 661d03170..72624528e 100644 --- a/sale_automatic_workflow_reserve_sale_stock/tests/test_flow.py +++ b/sale_automatic_workflow_reserve_sale_stock/tests/test_sale_automatic_workflow_stock_reserve.py @@ -1,35 +1,38 @@ -# © 2016 FactorLibre - Hugo Santos -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.addons.sale_automatic_workflow.tests.test_flow import TestAutomaticWorkflow +# Copyright 2016 FactorLibre - Hugo Santos +# Copyright 2021 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.addons.sale_automatic_workflow.tests.common import ( + TestAutomaticWorkflowMixin, + TestCommon, +) -class TestAutomaticWorkflowStockReservation(TestAutomaticWorkflow): +class TestAutomaticWorkflowStockReservation(TestAutomaticWorkflowMixin, TestCommon): def test_workflow_stock_reservation(self): - workflow = self._create_full_automatic( - { + workflow = self.create_full_automatic( + override={ "name": "Workflow Automatic Reservation", "validate_order": False, - "invoice_quantity": "procurement", - "order_policy": "picking", + "create_invoice": False, "stock_reservation": True, "stock_reservation_validity": 5, } ) - sale = self._create_sale_order(workflow) - sale.onchange_workflow_process_id() + sale = self.create_sale_order(workflow) + sale._onchange_workflow_process_id() self.assertEqual(sale.state, "draft") self.assertEqual(sale.is_stock_reservable, True) self.assertEqual(sale.has_stock_reservation, False) - self.progress() + self.run_job() self.assertEqual(sale.has_stock_reservation, True) def test_workflow_automatic_no_reservation(self): - workflow = self._create_full_automatic() - sale = self._create_sale_order(workflow) - sale.onchange_workflow_process_id() + workflow = self.create_full_automatic() + sale = self.create_sale_order(workflow) + sale._onchange_workflow_process_id() self.assertEqual(sale.state, "draft") self.assertEqual(sale.is_stock_reservable, True) self.assertEqual(sale.has_stock_reservation, False) - self.progress() - self.assertEqual(sale.state, "progress") + self.run_job() + self.assertEqual(sale.state, "sale") self.assertEqual(sale.has_stock_reservation, False) diff --git a/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml b/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml index 6e2ba9a84..aec6bfbd4 100644 --- a/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml +++ b/sale_automatic_workflow_reserve_sale_stock/views/sale_workflow_process_view.xml @@ -1,25 +1,23 @@ - - + - sale_automatic_workflow_reserve_sale_stock.sale_workflow_process.view_form + sale.workflow.process.stock.reserve sale.workflow.process - - - - - - + + + + + + + + - + diff --git a/setup/sale_automatic_workflow_reserve_sale_stock/odoo/addons/sale_automatic_workflow_reserve_sale_stock b/setup/sale_automatic_workflow_reserve_sale_stock/odoo/addons/sale_automatic_workflow_reserve_sale_stock new file mode 120000 index 000000000..46dafff27 --- /dev/null +++ b/setup/sale_automatic_workflow_reserve_sale_stock/odoo/addons/sale_automatic_workflow_reserve_sale_stock @@ -0,0 +1 @@ +../../../../sale_automatic_workflow_reserve_sale_stock \ No newline at end of file diff --git a/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/__init__.py b/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/__init__.py deleted file mode 100644 index de40ea7ca..000000000 --- a/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/sale_automatic_workflow_reserve_sale_stock b/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/sale_automatic_workflow_reserve_sale_stock deleted file mode 120000 index 24bd494c7..000000000 --- a/setup/sale_automatic_workflow_reserve_sale_stock/odoo_addons/sale_automatic_workflow_reserve_sale_stock +++ /dev/null @@ -1 +0,0 @@ -../../../sale_automatic_workflow_reserve_sale_stock \ No newline at end of file