[IMP] mrp_warehouse_calendar: black, isort

This commit is contained in:
Lois Rilo
2019-12-17 12:09:20 +01:00
committed by davidborromeo
parent 962dac2c07
commit f8c6e5f7c6
5 changed files with 96 additions and 92 deletions

View File

@@ -7,14 +7,10 @@
"version": "12.0.1.0.1", "version": "12.0.1.0.1",
"license": "LGPL-3", "license": "LGPL-3",
"website": "https://github.com/stock-logistics-warehouse", "website": "https://github.com/stock-logistics-warehouse",
"author": "Eficent, " "author": "Eficent, " "Odoo Community Association (OCA)",
"Odoo Community Association (OCA)",
"category": "Manufacturing", "category": "Manufacturing",
"depends": [ "depends": ["mrp", "stock_warehouse_calendar"],
"mrp",
"stock_warehouse_calendar",
],
"installable": True, "installable": True,
'development_status': 'Beta', "development_status": "Beta",
'maintainers': ['jbeficent'], "maintainers": ["jbeficent"],
} }

View File

@@ -5,15 +5,16 @@ from odoo import api, models
class MrpProduction(models.Model): class MrpProduction(models.Model):
_inherit = 'mrp.production' _inherit = "mrp.production"
@api.onchange('date_planned_start', 'product_id') @api.onchange("date_planned_start", "product_id")
def onchange_date_planned(self): def onchange_date_planned(self):
dt_planned = self.date_planned_start dt_planned = self.date_planned_start
warehouse = self.picking_type_id.warehouse_id warehouse = self.picking_type_id.warehouse_id
if warehouse.calendar_id and self.product_id.produce_delay: if warehouse.calendar_id and self.product_id.produce_delay:
date_expected_finished = warehouse.calendar_id.plan_days( date_expected_finished = warehouse.calendar_id.plan_days(
+1 * self.product_id.produce_delay + 1, dt_planned) +1 * self.product_id.produce_delay + 1, dt_planned
)
self.date_planned_finished = date_expected_finished self.date_planned_finished = date_expected_finished
@api.multi @api.multi
@@ -23,6 +24,7 @@ class MrpProduction(models.Model):
warehouse = mo.picking_type_id.warehouse_id warehouse = mo.picking_type_id.warehouse_id
if warehouse.calendar_id and mo.product_id.produce_delay: if warehouse.calendar_id and mo.product_id.produce_delay:
date_expected = warehouse.calendar_id.plan_days( date_expected = warehouse.calendar_id.plan_days(
+1 * self.product_id.produce_delay + 1, dt_planned) +1 * self.product_id.produce_delay + 1, dt_planned
)
mo.date_planned_finished = date_expected mo.date_planned_finished = date_expected
return mo return mo

View File

@@ -5,22 +5,19 @@ from odoo import fields, models
class StockRule(models.Model): class StockRule(models.Model):
_inherit = 'stock.rule' _inherit = "stock.rule"
def _get_date_planned(self, product_id, values): def _get_date_planned(self, product_id, values):
date_planned = super(StockRule, self)._get_date_planned( date_planned = super(StockRule, self)._get_date_planned(product_id, values)
product_id, values) picking_type = self.picking_type_id or values["warehouse_id"].manu_type_id
picking_type = self.picking_type_id or \
values['warehouse_id'].manu_type_id
# We force the date planned to be at the beginning of the day. # We force the date planned to be at the beginning of the day.
# So no work intervals are found in planned date. # So no work intervals are found in planned date.
dt_planned = fields.Datetime.to_datetime( dt_planned = fields.Datetime.to_datetime(values["date_planned"]).replace(hour=0)
values['date_planned']).replace(hour=0)
warehouse = picking_type.warehouse_id warehouse = picking_type.warehouse_id
if warehouse.calendar_id and product_id.produce_delay: if warehouse.calendar_id and product_id.produce_delay:
lead_days = values['company_id'].manufacturing_lead + \ lead_days = (
product_id.produce_delay values["company_id"].manufacturing_lead + product_id.produce_delay
date_expected = warehouse.calendar_id.plan_days( )
-1 * lead_days, dt_planned) date_expected = warehouse.calendar_id.plan_days(-1 * lead_days, dt_planned)
date_planned = date_expected date_planned = date_expected
return date_planned return date_planned

View File

@@ -5,68 +5,69 @@ from odoo.tests.common import TransactionCase
class TestMrpWarehouseCalendar(TransactionCase): class TestMrpWarehouseCalendar(TransactionCase):
def setUp(self): def setUp(self):
super(TestMrpWarehouseCalendar, self).setUp() super(TestMrpWarehouseCalendar, self).setUp()
self.move_obj = self.env['stock.move'] self.move_obj = self.env["stock.move"]
self.company = self.env.ref('base.main_company') self.company = self.env.ref("base.main_company")
self.warehouse = self.env.ref('stock.warehouse0') self.warehouse = self.env.ref("stock.warehouse0")
self.customer_loc = self.env.ref('stock.stock_location_customers') self.customer_loc = self.env.ref("stock.stock_location_customers")
self.company_partner = self.env.ref('base.main_partner') self.company_partner = self.env.ref("base.main_partner")
self.calendar = self.env.ref('resource.resource_calendar_std') self.calendar = self.env.ref("resource.resource_calendar_std")
self.manufacture_route = self.env.ref( self.manufacture_route = self.env.ref("mrp.route_warehouse0_manufacture")
'mrp.route_warehouse0_manufacture')
self.warehouse.calendar_id = self.calendar.id self.warehouse.calendar_id = self.calendar.id
self.warehouse_2 = self.env['stock.warehouse'].create({ self.warehouse_2 = self.env["stock.warehouse"].create(
'code': 'WH-T', {"code": "WH-T", "name": "Warehouse Test", "calendar_id": self.calendar.id}
'name': 'Warehouse Test', )
'calendar_id': self.calendar.id,
})
self.product = self.env['product.product'].create({ self.product = self.env["product.product"].create(
'name': 'test product', {
'default_code': 'PRD', "name": "test product",
'type': 'product', "default_code": "PRD",
'produce_delay': 1, "type": "product",
}) "produce_delay": 1,
self.product_2 = self.env['product.product'].create({ }
'name': 'test product 2', )
'default_code': 'PRD 2', self.product_2 = self.env["product.product"].create(
'type': 'product', {"name": "test product 2", "default_code": "PRD 2", "type": "product"}
}) )
self.bom = self.env['mrp.bom'].create({ self.bom = self.env["mrp.bom"].create(
'product_id': self.product.id, {
'product_tmpl_id': self.product.product_tmpl_id.id, "product_id": self.product.id,
'product_uom_id': self.product.uom_id.id, "product_tmpl_id": self.product.product_tmpl_id.id,
'product_qty': 1.0, "product_uom_id": self.product.uom_id.id,
'type': 'normal', "product_qty": 1.0,
}) "type": "normal",
self.env['mrp.bom.line'].create({ }
'bom_id': self.bom.id, )
'product_id': self.product_2.id, self.env["mrp.bom.line"].create(
'product_qty': 2, {"bom_id": self.bom.id, "product_id": self.product_2.id, "product_qty": 2}
}) )
self.product.route_ids = [(6, 0, self.manufacture_route.ids)] self.product.route_ids = [(6, 0, self.manufacture_route.ids)]
def test_procurement_with_calendar(self): def test_procurement_with_calendar(self):
values = { values = {
'date_planned': '2097-01-07 09:00:00', # Monday "date_planned": "2097-01-07 09:00:00", # Monday
'warehouse_id': self.warehouse, "warehouse_id": self.warehouse,
'company_id': self.company, "company_id": self.company,
'rule_id': self.manufacture_route, "rule_id": self.manufacture_route,
} }
self.env['procurement.group'].run( self.env["procurement.group"].run(
self.product, 100, self.product,
100,
self.product.uom_id, self.product.uom_id,
self.warehouse.lot_stock_id, 'Test', self.warehouse.lot_stock_id,
'Test', values) "Test",
mo = self.env['mrp.production'].search( "Test",
[('product_id', '=', self.product.id)], limit=1) values,
)
mo = self.env["mrp.production"].search(
[("product_id", "=", self.product.id)], limit=1
)
date_plan_start = fields.Date.to_date(mo.date_planned_start) date_plan_start = fields.Date.to_date(mo.date_planned_start)
# Friday 4th Jan 2097 # Friday 4th Jan 2097
friday = fields.Date.to_date('2097-01-04 09:00:00') friday = fields.Date.to_date("2097-01-04 09:00:00")
self.assertEqual(date_plan_start, friday) self.assertEqual(date_plan_start, friday)
@@ -74,34 +75,42 @@ class TestMrpWarehouseCalendar(TransactionCase):
"""Test procuring at the beginning of the day, with no work intervals """Test procuring at the beginning of the day, with no work intervals
before.""" before."""
values = { values = {
'date_planned': '2097-01-07 01:00:00', # Monday "date_planned": "2097-01-07 01:00:00", # Monday
'warehouse_id': self.warehouse, "warehouse_id": self.warehouse,
'company_id': self.company, "company_id": self.company,
'rule_id': self.manufacture_route, "rule_id": self.manufacture_route,
} }
self.env['procurement.group'].run( self.env["procurement.group"].run(
self.product, 100, self.product,
100,
self.product.uom_id, self.product.uom_id,
self.warehouse.lot_stock_id, 'Test 2', self.warehouse.lot_stock_id,
'Test 2', values) "Test 2",
mo = self.env['mrp.production'].search( "Test 2",
[('product_id', '=', self.product.id)], limit=1) values,
)
mo = self.env["mrp.production"].search(
[("product_id", "=", self.product.id)], limit=1
)
date_plan_start = fields.Date.to_date(mo.date_planned_start) date_plan_start = fields.Date.to_date(mo.date_planned_start)
# Friday 4th Jan 2097 # Friday 4th Jan 2097
friday = fields.Date.to_date('2097-01-04 09:00:00') friday = fields.Date.to_date("2097-01-04 09:00:00")
self.assertEqual(date_plan_start, friday) self.assertEqual(date_plan_start, friday)
def test_onchange_date_planned(self): def test_onchange_date_planned(self):
mo = self.env['mrp.production'].new({ mo = self.env["mrp.production"].new(
'product_id': self.product.id, {
'bom_id': self.bom.id, "product_id": self.product.id,
'product_qty': 1, "bom_id": self.bom.id,
'picking_type_id': "product_qty": 1,
self.env['mrp.production']._get_default_picking_type() "picking_type_id": self.env[
}) "mrp.production"
mo.date_planned_start = '2097-01-04 09:00:00' ]._get_default_picking_type(),
}
)
mo.date_planned_start = "2097-01-04 09:00:00"
mo.onchange_date_planned() mo.onchange_date_planned()
date_plan_finished = fields.Date.to_date(mo.date_planned_finished) date_plan_finished = fields.Date.to_date(mo.date_planned_finished)
monday = fields.Date.to_date('2097-01-07 09:00:00') monday = fields.Date.to_date("2097-01-07 09:00:00")
self.assertEqual(date_plan_finished, monday) self.assertEqual(date_plan_finished, monday)