mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
11.0 - add stock_warehouse_calendar
This commit is contained in:
committed by
Lois Rilo
parent
7d3106e48d
commit
a3d9fade2a
1
stock_warehouse_calendar/__init__.py
Normal file
1
stock_warehouse_calendar/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
23
stock_warehouse_calendar/__manifest__.py
Normal file
23
stock_warehouse_calendar/__manifest__.py
Normal 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'],
|
||||||
|
}
|
||||||
2
stock_warehouse_calendar/models/__init__.py
Normal file
2
stock_warehouse_calendar/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import stock_warehouse
|
||||||
|
from . import procurement_rule
|
||||||
24
stock_warehouse_calendar/models/procurement_rule.py
Normal file
24
stock_warehouse_calendar/models/procurement_rule.py
Normal 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
|
||||||
11
stock_warehouse_calendar/models/stock_warehouse.py
Normal file
11
stock_warehouse_calendar/models/stock_warehouse.py
Normal 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')
|
||||||
14
stock_warehouse_calendar/readme/CONFIGURE.rst
Normal file
14
stock_warehouse_calendar/readme/CONFIGURE.rst
Normal 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'.
|
||||||
1
stock_warehouse_calendar/readme/CONTRIBUTORS.rst
Normal file
1
stock_warehouse_calendar/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* Jordi Ballester (EFICENT) <jordi.ballester@eficent.com>.
|
||||||
7
stock_warehouse_calendar/readme/DESCRIPTION.rst
Normal file
7
stock_warehouse_calendar/readme/DESCRIPTION.rst
Normal 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.
|
||||||
0
stock_warehouse_calendar/readme/ROADMAP.rst
Normal file
0
stock_warehouse_calendar/readme/ROADMAP.rst
Normal file
6
stock_warehouse_calendar/readme/USAGE.rst
Normal file
6
stock_warehouse_calendar/readme/USAGE.rst
Normal 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.
|
||||||
BIN
stock_warehouse_calendar/static/description/icon.png
Normal file
BIN
stock_warehouse_calendar/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
2
stock_warehouse_calendar/tests/__init__.py
Normal file
2
stock_warehouse_calendar/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from . import test_stock_warehouse_calendar
|
||||||
@@ -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)
|
||||||
16
stock_warehouse_calendar/views/stock_warehouse_views.xml
Normal file
16
stock_warehouse_calendar/views/stock_warehouse_views.xml
Normal 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>
|
||||||
Reference in New Issue
Block a user