[IMP] sale_automatic_workflow_reserve_sale_stock: black, isort, prettier

This commit is contained in:
CarlosRoca13
2021-08-16 09:32:28 +02:00
parent b239d93c0c
commit afd8173ecf
11 changed files with 104 additions and 95 deletions

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

View File

@@ -1,19 +1,13 @@
# -*- coding: utf-8 -*-
# © 2016 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com>
# 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,
}

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import sale_workflow_process

View File

@@ -1,66 +1,72 @@
# -*- coding: utf-8 -*-
# © 2016 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com>
# 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)

View File

@@ -1,24 +1,25 @@
# -*- coding: utf-8 -*-
# © 2016 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com>
# 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"
)

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_flow

View File

@@ -1,24 +1,23 @@
# -*- coding: utf-8 -*-
# © 2016 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com>
# 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)

View File

@@ -1,21 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- © 2016 Hugo Santos <hugo.santos@factorlibre.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>
<record id="sale_workflow_process_view_form" model="ir.ui.view">
<field name="name">sale_automatic_workflow_reserve_sale_stock.sale_workflow_process.view_form</field>
<field name="model">sale.workflow.process</field>
<field name="inherit_id"
ref="sale_automatic_workflow.sale_workflow_process_view_form"/>
<field name="arch" type="xml">
<field name="warning" position="before">
<field name="stock_reservation"/>
<field name="stock_reservation_validity"/>
<field name="stock_reservation_location_id"/>
<field name="stock_reservation_location_dest_id"/>
<data>
<record id="sale_workflow_process_view_form" model="ir.ui.view">
<field
name="name"
>sale_automatic_workflow_reserve_sale_stock.sale_workflow_process.view_form</field>
<field name="model">sale.workflow.process</field>
<field
name="inherit_id"
ref="sale_automatic_workflow.sale_workflow_process_view_form"
/>
<field name="arch" type="xml">
<field name="warning" position="before">
<field name="stock_reservation" />
<field name="stock_reservation_validity" />
<field name="stock_reservation_location_id" />
<field name="stock_reservation_location_dest_id" />
</field>
</field>
</field>
</record>
</data>
</openerp>
</record>
</data>
</openerp>

View File

@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

View File

@@ -0,0 +1 @@
../../../sale_automatic_workflow_reserve_sale_stock

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)