mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
add resource calendar to mrp area
This commit is contained in:
committed by
davidborromeo
parent
307d495db3
commit
ccbae558f2
@@ -4,5 +4,6 @@
|
|||||||
<field name="name">WH/Stock</field>
|
<field name="name">WH/Stock</field>
|
||||||
<field name="warehouse_id" ref="stock.warehouse0"/>
|
<field name="warehouse_id" ref="stock.warehouse0"/>
|
||||||
<field name="location_id" ref="stock.stock_location_stock"/>
|
<field name="location_id" ref="stock.stock_location_stock"/>
|
||||||
|
<field name="calendar_id" ref="resource.resource_calendar_std"/>
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -19,3 +19,5 @@ class MrpArea(models.Model):
|
|||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
active = fields.Boolean(default=True)
|
active = fields.Boolean(default=True)
|
||||||
|
calendar_id = fields.Many2one('resource.calendar',
|
||||||
|
'Working Hours')
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# (http://www.eficent.com)
|
# (http://www.eficent.com)
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from odoo.tests.common import SavepointCase
|
from odoo.tests.common import SavepointCase
|
||||||
from odoo import fields
|
from odoo import fields
|
||||||
@@ -37,6 +37,7 @@ class TestMrpMultiLevel(SavepointCase):
|
|||||||
cls.stock_location = cls.wh.lot_stock_id
|
cls.stock_location = cls.wh.lot_stock_id
|
||||||
cls.customer_location = cls.env.ref(
|
cls.customer_location = cls.env.ref(
|
||||||
'stock.stock_location_customers')
|
'stock.stock_location_customers')
|
||||||
|
cls.calendar = cls.env.ref('resource.resource_calendar_std')
|
||||||
|
|
||||||
# Partner:
|
# Partner:
|
||||||
vendor1 = cls.partner_obj.create({'name': 'Vendor 1'})
|
vendor1 = cls.partner_obj.create({'name': 'Vendor 1'})
|
||||||
@@ -53,7 +54,8 @@ class TestMrpMultiLevel(SavepointCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Create test picking:
|
# Create test picking:
|
||||||
date_move = datetime.today() + timedelta(days=7)
|
res = cls.calendar.plan_days(7+1, datetime.today())
|
||||||
|
date_move = res.date()
|
||||||
cls.picking_1 = cls.stock_picking_obj.create({
|
cls.picking_1 = cls.stock_picking_obj.create({
|
||||||
'picking_type_id': cls.env.ref('stock.picking_type_out').id,
|
'picking_type_id': cls.env.ref('stock.picking_type_out').id,
|
||||||
'location_id': cls.stock_location.id,
|
'location_id': cls.stock_location.id,
|
||||||
@@ -83,7 +85,7 @@ class TestMrpMultiLevel(SavepointCase):
|
|||||||
cls.picking_1.action_confirm()
|
cls.picking_1.action_confirm()
|
||||||
|
|
||||||
# Create Test PO:
|
# Create Test PO:
|
||||||
date_po = datetime.today() + timedelta(days=1)
|
date_po = cls.calendar.plan_days(1+1, datetime.today()).date()
|
||||||
cls.po = cls.po_obj.create({
|
cls.po = cls.po_obj.create({
|
||||||
'name': 'Test PO-001',
|
'name': 'Test PO-001',
|
||||||
'partner_id': cls.vendor.id,
|
'partner_id': cls.vendor.id,
|
||||||
@@ -99,7 +101,7 @@ class TestMrpMultiLevel(SavepointCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Create test MO:
|
# Create test MO:
|
||||||
date_mo = datetime.today() + timedelta(days=9)
|
date_mo = cls.calendar.plan_days(9+1, datetime.today()).date()
|
||||||
bom_fp_2 = cls.env.ref('mrp_multi_level.mrp_bom_fp_2')
|
bom_fp_2 = cls.env.ref('mrp_multi_level.mrp_bom_fp_2')
|
||||||
cls.mo = cls.mo_obj.create({
|
cls.mo = cls.mo_obj.create({
|
||||||
'product_id': cls.fp_2.id,
|
'product_id': cls.fp_2.id,
|
||||||
@@ -111,13 +113,20 @@ class TestMrpMultiLevel(SavepointCase):
|
|||||||
|
|
||||||
# Dates (Strings):
|
# Dates (Strings):
|
||||||
today = datetime.today()
|
today = datetime.today()
|
||||||
cls.date_3 = fields.Date.to_string(today + timedelta(days=3))
|
cls.date_3 = fields.Date.to_string(
|
||||||
cls.date_5 = fields.Date.to_string(today + timedelta(days=5))
|
cls.calendar.plan_days(3+1, datetime.today()).date())
|
||||||
cls.date_6 = fields.Date.to_string(today + timedelta(days=6))
|
cls.date_5 = fields.Date.to_string(
|
||||||
cls.date_7 = fields.Date.to_string(today + timedelta(days=7))
|
cls.calendar.plan_days(5+1, datetime.today()).date())
|
||||||
cls.date_8 = fields.Date.to_string(today + timedelta(days=8))
|
cls.date_6 = fields.Date.to_string(
|
||||||
cls.date_9 = fields.Date.to_string(today + timedelta(days=9))
|
cls.calendar.plan_days(6+1, datetime.today()).date())
|
||||||
cls.date_10 = fields.Date.to_string(today + timedelta(days=10))
|
cls.date_7 = fields.Date.to_string(
|
||||||
|
cls.calendar.plan_days(7+1, datetime.today()).date())
|
||||||
|
cls.date_8 = fields.Date.to_string((
|
||||||
|
cls.calendar.plan_days(8+1, datetime.today()).date()))
|
||||||
|
cls.date_9 = fields.Date.to_string((
|
||||||
|
cls.calendar.plan_days(9+1, datetime.today()).date()))
|
||||||
|
cls.date_10 = fields.Date.to_string(
|
||||||
|
cls.calendar.plan_days(10+1, datetime.today()).date())
|
||||||
|
|
||||||
# Create Date Ranges:
|
# Create Date Ranges:
|
||||||
cls.dr_type = cls.env['date.range.type'].create({
|
cls.dr_type = cls.env['date.range.type'].create({
|
||||||
@@ -359,7 +368,7 @@ class TestMrpMultiLevel(SavepointCase):
|
|||||||
self.assertTrue(mos)
|
self.assertTrue(mos)
|
||||||
self.assertEqual(mos.product_qty, 100.0)
|
self.assertEqual(mos.product_qty, 100.0)
|
||||||
datetime_5 = fields.Datetime.to_string(
|
datetime_5 = fields.Datetime.to_string(
|
||||||
date.today() + timedelta(days=5))
|
self.calendar.plan_days(5 + 1, datetime.today()).date())
|
||||||
self.assertEqual(mos.date_planned_start, datetime_5)
|
self.assertEqual(mos.date_planned_start, datetime_5)
|
||||||
|
|
||||||
# TODO: test procure wizard: pos, multiple...
|
# TODO: test procure wizard: pos, multiple...
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="warehouse_id"/>
|
<field name="warehouse_id"/>
|
||||||
<field name="location_id"/>
|
<field name="location_id"/>
|
||||||
|
<field name="calendar_id"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
<group>
|
<group>
|
||||||
<field name="warehouse_id"/>
|
<field name="warehouse_id"/>
|
||||||
<field name="location_id"/>
|
<field name="location_id"/>
|
||||||
|
<field name="calendar_id"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -220,8 +220,15 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
else:
|
else:
|
||||||
mrp_date_supply = mrp_date
|
mrp_date_supply = mrp_date
|
||||||
|
|
||||||
mrp_action_date = mrp_date - timedelta(
|
calendar = mrp_product_id.mrp_area_id.calendar_id
|
||||||
days=mrp_product_id.mrp_lead_time)
|
if calendar and mrp_product_id.mrp_lead_time:
|
||||||
|
date_str = fields.Date.to_string(mrp_date)
|
||||||
|
dt = fields.Datetime.from_string(date_str)
|
||||||
|
res = calendar.plan_days(-1 * mrp_product_id.mrp_lead_time -1, dt)
|
||||||
|
mrp_action_date = res.date()
|
||||||
|
else:
|
||||||
|
mrp_action_date = mrp_date - timedelta(
|
||||||
|
days=mrp_product_id.mrp_lead_time)
|
||||||
|
|
||||||
qty_ordered = 0.00
|
qty_ordered = 0.00
|
||||||
qty_to_order = mrp_qty
|
qty_to_order = mrp_qty
|
||||||
@@ -235,8 +242,7 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
qty_ordered = qty_ordered + qty
|
qty_ordered = qty_ordered + qty
|
||||||
|
|
||||||
if mrp_action == 'mo':
|
if mrp_action == 'mo':
|
||||||
mrp_date_demand = mrp_date - timedelta(
|
mrp_date_demand = mrp_action_date
|
||||||
days=mrp_product_id.mrp_lead_time)
|
|
||||||
if mrp_date_demand < date.today():
|
if mrp_date_demand < date.today():
|
||||||
mrp_date_demand = date.today()
|
mrp_date_demand = date.today()
|
||||||
if not mrp_product_id.product_id.bom_ids:
|
if not mrp_product_id.product_id.bom_ids:
|
||||||
|
|||||||
Reference in New Issue
Block a user