11.0 - add stock_warehouse_calendar

This commit is contained in:
Jordi Ballester Alomar
2018-06-28 19:02:11 +02:00
committed by Lois Rilo
parent 7d3106e48d
commit a3d9fade2a
14 changed files with 175 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -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'],
}

View File

@@ -0,0 +1,2 @@
from . import stock_warehouse
from . import procurement_rule

View File

@@ -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

View File

@@ -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')

View File

@@ -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'.

View File

@@ -0,0 +1 @@
* Jordi Ballester (EFICENT) <jordi.ballester@eficent.com>.

View File

@@ -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.

View File

@@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import test_stock_warehouse_calendar

View File

@@ -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)

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Eficent
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_warehouse" model="ir.ui.view">
<field name="name">stock.warehouse</field>
<field name="model">stock.warehouse</field>
<field name="inherit_id" ref="stock.view_warehouse"/>
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="calendar_id" options="{'no_create': True}"/>
</field>
</field>
</record>
</odoo>