diff --git a/stock_warehouse_calendar/__init__.py b/stock_warehouse_calendar/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_warehouse_calendar/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_warehouse_calendar/__manifest__.py b/stock_warehouse_calendar/__manifest__.py new file mode 100644 index 000000000..5b31625f2 --- /dev/null +++ b/stock_warehouse_calendar/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Stock Warehouse Calendar", + "summary": "Adds a calendar to the Warehouse", + "version": "11.0.1.0.0", + "license": "AGPL-3", + "website": "https://github.com/stock-logistics-warehouse", + "author": "Eficent, " + "Odoo Community Association (OCA)", + "category": "Warehouse Management", + "depends": [ + "stock", + "resource" + ], + "data": [ + "views/stock_warehouse_views.xml", + ], + "installable": True, + 'development_status': 'Beta', + 'maintainers': ['jbeficent'], +} diff --git a/stock_warehouse_calendar/models/__init__.py b/stock_warehouse_calendar/models/__init__.py new file mode 100644 index 000000000..e41660708 --- /dev/null +++ b/stock_warehouse_calendar/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_warehouse +from . import procurement_rule diff --git a/stock_warehouse_calendar/models/procurement_rule.py b/stock_warehouse_calendar/models/procurement_rule.py new file mode 100644 index 000000000..ebe166203 --- /dev/null +++ b/stock_warehouse_calendar/models/procurement_rule.py @@ -0,0 +1,24 @@ +# Copyright 2018 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models +from datetime import datetime + + +class ProcurementRule(models.Model): + _inherit = 'procurement.rule' + + def _get_stock_move_values(self, product_id, product_qty, product_uom, + location_id, name, origin, values, group_id): + res = super(ProcurementRule, self)._get_stock_move_values( + product_id, product_qty, product_uom, + location_id, name, origin, values, group_id) + dt_planned = fields.Datetime.from_string(values['date_planned']) + warehouse = self.propagate_warehouse_id or self.warehouse_id + if warehouse.calendar_id and self.delay: + date_expected = warehouse.calendar_id.plan_days( + -1 * self.delay - 1, dt_planned) + if date_expected > datetime.now(): + res['date'] = date_expected + res['date_expected'] = date_expected + return res diff --git a/stock_warehouse_calendar/models/stock_warehouse.py b/stock_warehouse_calendar/models/stock_warehouse.py new file mode 100644 index 000000000..9cfb899be --- /dev/null +++ b/stock_warehouse_calendar/models/stock_warehouse.py @@ -0,0 +1,11 @@ +# Copyright 2018 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class StockWarehouse(models.Model): + _inherit = 'stock.warehouse' + + calendar_id = fields.Many2one('resource.calendar', + 'Working Hours') diff --git a/stock_warehouse_calendar/readme/CONFIGURE.rst b/stock_warehouse_calendar/readme/CONFIGURE.rst new file mode 100644 index 000000000..b77834e5b --- /dev/null +++ b/stock_warehouse_calendar/readme/CONFIGURE.rst @@ -0,0 +1,14 @@ +* Go to *Settings* and activate the developer mode. + +* Go to *Settings > Technical > Resource > Working Time* and define your + resource calendar. + +* Go to *Inventory > Configuration > Warehouse Management > Warehouses* + and assign the Resource Calendar. + +* Go to *Inventory > Configuration > Settings* and in *Warehouse* mark + 'Multi-Step Routes option'. + +* Go to *Inventory > Configuration > Warehouse Management > Routes* and + set up the proper delays in the procurement rules where 'action' + is 'Move From Another Location'. diff --git a/stock_warehouse_calendar/readme/CONTRIBUTORS.rst b/stock_warehouse_calendar/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..d72a49b94 --- /dev/null +++ b/stock_warehouse_calendar/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Jordi Ballester (EFICENT) . \ No newline at end of file diff --git a/stock_warehouse_calendar/readme/DESCRIPTION.rst b/stock_warehouse_calendar/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ac46ffca3 --- /dev/null +++ b/stock_warehouse_calendar/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +This module adds a Calendar to the Warehouse. This calendar can then used as +the basis of the proper computation of start/end dates based on lead times in +this and other modules. + +In this module, the calendar considered in the computation of start date of +stock moves and pickings created from procurements, where the lead time +is used. diff --git a/stock_warehouse_calendar/readme/ROADMAP.rst b/stock_warehouse_calendar/readme/ROADMAP.rst new file mode 100644 index 000000000..e69de29bb diff --git a/stock_warehouse_calendar/readme/USAGE.rst b/stock_warehouse_calendar/readme/USAGE.rst new file mode 100644 index 000000000..f71e1f60c --- /dev/null +++ b/stock_warehouse_calendar/readme/USAGE.rst @@ -0,0 +1,6 @@ +When a picking is created out of a procurement evaluation (from an +orderpoint, MTO,...) the calendar is considered in the computation of the +expected date of the picking and moves. For example, if it takes 1 day to +execute a stock transfer from another warehouse and it is Monday, the picking +to resupply will be created with expected start date on the previous Friday, +if the warehouse operates under a Mo-Fri working calendar. diff --git a/stock_warehouse_calendar/static/description/icon.png b/stock_warehouse_calendar/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_warehouse_calendar/static/description/icon.png differ diff --git a/stock_warehouse_calendar/tests/__init__.py b/stock_warehouse_calendar/tests/__init__.py new file mode 100644 index 000000000..faa5afbf1 --- /dev/null +++ b/stock_warehouse_calendar/tests/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import test_stock_warehouse_calendar diff --git a/stock_warehouse_calendar/tests/test_stock_warehouse_calendar.py b/stock_warehouse_calendar/tests/test_stock_warehouse_calendar.py new file mode 100644 index 000000000..3335abdf7 --- /dev/null +++ b/stock_warehouse_calendar/tests/test_stock_warehouse_calendar.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestStockWarehouseCalendar(TransactionCase): + + def setUp(self): + super(TestStockWarehouseCalendar, self).setUp() + self.move_obj = self.env['stock.move'] + self.company = self.env.ref('base.main_company') + self.warehouse = self.env.ref('stock.warehouse0') + self.customer_loc = self.env.ref('stock.stock_location_customers') + self.company_partner = self.env.ref('base.main_partner') + self.calendar = self.env.ref('resource.resource_calendar_std') + self.warehouse.calendar_id = self.calendar + self.warehouse_2 = self.env['stock.warehouse'].create({ + 'code': 'WH-T', + 'name': 'Warehouse Test', + 'calendar_id': self.calendar.id, + }) + + self.product = self.env['product.product'].create({ + 'name': 'test product', + 'default_code': 'PRD', + 'type': 'product', + }) + + route_vals = { + 'name': 'WH2 -> WH', + } + self.transfer_route = self.env['stock.location.route'].create( + route_vals) + rule_vals = { + 'location_id': self.warehouse.lot_stock_id.id, + 'location_src_id': self.warehouse_2.lot_stock_id.id, + 'action': 'move', + 'warehouse_id': self.warehouse.id, + 'propagate_warehouse_id': self.warehouse_2.id, + 'picking_type_id': self.env.ref('stock.picking_type_internal').id, + 'name': 'WH2->WH', + 'route_id': self.transfer_route.id, + 'delay': 1, + } + self.transfer_rule = self.env['procurement.rule'].create(rule_vals) + self.product.route_ids = [(6, 0, self.transfer_route.ids)] + + def test_procurement_with_calendar(self): + values = { + 'date_planned': '2097-01-07 09:00:00', # Monday + 'warehouse_id': self.warehouse, + 'company_id': self.company, + 'rule_id': self.transfer_rule, + } + self.env['procurement.group'].run( + self.product, 100, + self.product.uom_id, + self.warehouse.lot_stock_id, 'Test', + 'Test', values) + move = self.env['stock.move'].search( + [('product_id', '=', self.product.id)], limit=1) + date_expected = fields.Datetime.from_string(move.date_expected).date() + # Friday 4th Jan 2017 + friday = fields.Datetime.from_string('2097-01-04 09:00:00').date() + + self.assertEquals(date_expected, friday) diff --git a/stock_warehouse_calendar/views/stock_warehouse_views.xml b/stock_warehouse_calendar/views/stock_warehouse_views.xml new file mode 100644 index 000000000..4d66eebff --- /dev/null +++ b/stock_warehouse_calendar/views/stock_warehouse_views.xml @@ -0,0 +1,16 @@ + + + + + + stock.warehouse + stock.warehouse + + + + + + + +