diff --git a/mrp_warehouse_calendar/__manifest__.py b/mrp_warehouse_calendar/__manifest__.py index 23b084084..5e50377ff 100644 --- a/mrp_warehouse_calendar/__manifest__.py +++ b/mrp_warehouse_calendar/__manifest__.py @@ -7,14 +7,10 @@ "version": "12.0.1.0.1", "license": "LGPL-3", "website": "https://github.com/stock-logistics-warehouse", - "author": "Eficent, " - "Odoo Community Association (OCA)", + "author": "Eficent, " "Odoo Community Association (OCA)", "category": "Manufacturing", - "depends": [ - "mrp", - "stock_warehouse_calendar", - ], + "depends": ["mrp", "stock_warehouse_calendar"], "installable": True, - 'development_status': 'Beta', - 'maintainers': ['jbeficent'], + "development_status": "Beta", + "maintainers": ["jbeficent"], } diff --git a/mrp_warehouse_calendar/models/mrp_production.py b/mrp_warehouse_calendar/models/mrp_production.py index 373bd8c75..3f4a062ce 100644 --- a/mrp_warehouse_calendar/models/mrp_production.py +++ b/mrp_warehouse_calendar/models/mrp_production.py @@ -5,15 +5,16 @@ from odoo import api, models 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): dt_planned = self.date_planned_start warehouse = self.picking_type_id.warehouse_id if warehouse.calendar_id and self.product_id.produce_delay: 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 @api.multi @@ -23,6 +24,7 @@ class MrpProduction(models.Model): warehouse = mo.picking_type_id.warehouse_id if warehouse.calendar_id and mo.product_id.produce_delay: 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 return mo diff --git a/mrp_warehouse_calendar/models/stock_rule.py b/mrp_warehouse_calendar/models/stock_rule.py index a493b6784..e83990d89 100644 --- a/mrp_warehouse_calendar/models/stock_rule.py +++ b/mrp_warehouse_calendar/models/stock_rule.py @@ -5,22 +5,19 @@ from odoo import fields, models class StockRule(models.Model): - _inherit = 'stock.rule' + _inherit = "stock.rule" def _get_date_planned(self, product_id, values): - date_planned = super(StockRule, self)._get_date_planned( - product_id, values) - picking_type = self.picking_type_id or \ - values['warehouse_id'].manu_type_id + date_planned = super(StockRule, self)._get_date_planned(product_id, values) + 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. # So no work intervals are found in planned date. - dt_planned = fields.Datetime.to_datetime( - values['date_planned']).replace(hour=0) + dt_planned = fields.Datetime.to_datetime(values["date_planned"]).replace(hour=0) warehouse = picking_type.warehouse_id if warehouse.calendar_id and product_id.produce_delay: - lead_days = values['company_id'].manufacturing_lead + \ - product_id.produce_delay - date_expected = warehouse.calendar_id.plan_days( - -1 * lead_days, dt_planned) + lead_days = ( + values["company_id"].manufacturing_lead + product_id.produce_delay + ) + date_expected = warehouse.calendar_id.plan_days(-1 * lead_days, dt_planned) date_planned = date_expected return date_planned diff --git a/mrp_warehouse_calendar/readme/CONTRIBUTORS.rst b/mrp_warehouse_calendar/readme/CONTRIBUTORS.rst index d72a49b94..76e7fbe3e 100644 --- a/mrp_warehouse_calendar/readme/CONTRIBUTORS.rst +++ b/mrp_warehouse_calendar/readme/CONTRIBUTORS.rst @@ -1 +1 @@ -* Jordi Ballester (EFICENT) . \ No newline at end of file +* Jordi Ballester (EFICENT) . diff --git a/mrp_warehouse_calendar/tests/test_mrp_warehouse_calendar.py b/mrp_warehouse_calendar/tests/test_mrp_warehouse_calendar.py index 5df2b6975..470f724ea 100644 --- a/mrp_warehouse_calendar/tests/test_mrp_warehouse_calendar.py +++ b/mrp_warehouse_calendar/tests/test_mrp_warehouse_calendar.py @@ -5,68 +5,69 @@ from odoo.tests.common import TransactionCase class TestMrpWarehouseCalendar(TransactionCase): - def setUp(self): super(TestMrpWarehouseCalendar, 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.manufacture_route = self.env.ref( - 'mrp.route_warehouse0_manufacture') + 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.manufacture_route = self.env.ref("mrp.route_warehouse0_manufacture") self.warehouse.calendar_id = self.calendar.id - self.warehouse_2 = self.env['stock.warehouse'].create({ - 'code': 'WH-T', - 'name': 'Warehouse Test', - 'calendar_id': self.calendar.id, - }) + 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', - 'produce_delay': 1, - }) - self.product_2 = self.env['product.product'].create({ - 'name': 'test product 2', - 'default_code': 'PRD 2', - 'type': 'product', - }) - self.bom = self.env['mrp.bom'].create({ - 'product_id': self.product.id, - 'product_tmpl_id': self.product.product_tmpl_id.id, - 'product_uom_id': self.product.uom_id.id, - 'product_qty': 1.0, - 'type': 'normal', - }) - self.env['mrp.bom.line'].create({ - 'bom_id': self.bom.id, - 'product_id': self.product_2.id, - 'product_qty': 2, - }) + self.product = self.env["product.product"].create( + { + "name": "test product", + "default_code": "PRD", + "type": "product", + "produce_delay": 1, + } + ) + self.product_2 = self.env["product.product"].create( + {"name": "test product 2", "default_code": "PRD 2", "type": "product"} + ) + self.bom = self.env["mrp.bom"].create( + { + "product_id": self.product.id, + "product_tmpl_id": self.product.product_tmpl_id.id, + "product_uom_id": self.product.uom_id.id, + "product_qty": 1.0, + "type": "normal", + } + ) + self.env["mrp.bom.line"].create( + {"bom_id": self.bom.id, "product_id": self.product_2.id, "product_qty": 2} + ) self.product.route_ids = [(6, 0, self.manufacture_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.manufacture_route, + "date_planned": "2097-01-07 09:00:00", # Monday + "warehouse_id": self.warehouse, + "company_id": self.company, + "rule_id": self.manufacture_route, } - self.env['procurement.group'].run( - self.product, 100, + self.env["procurement.group"].run( + self.product, + 100, self.product.uom_id, - self.warehouse.lot_stock_id, 'Test', - 'Test', values) - mo = self.env['mrp.production'].search( - [('product_id', '=', self.product.id)], limit=1) + self.warehouse.lot_stock_id, + "Test", + "Test", + 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) # 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) @@ -74,34 +75,42 @@ class TestMrpWarehouseCalendar(TransactionCase): """Test procuring at the beginning of the day, with no work intervals before.""" values = { - 'date_planned': '2097-01-07 01:00:00', # Monday - 'warehouse_id': self.warehouse, - 'company_id': self.company, - 'rule_id': self.manufacture_route, + "date_planned": "2097-01-07 01:00:00", # Monday + "warehouse_id": self.warehouse, + "company_id": self.company, + "rule_id": self.manufacture_route, } - self.env['procurement.group'].run( - self.product, 100, + self.env["procurement.group"].run( + self.product, + 100, self.product.uom_id, - self.warehouse.lot_stock_id, 'Test 2', - 'Test 2', values) - mo = self.env['mrp.production'].search( - [('product_id', '=', self.product.id)], limit=1) + self.warehouse.lot_stock_id, + "Test 2", + "Test 2", + 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) # 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) def test_onchange_date_planned(self): - mo = self.env['mrp.production'].new({ - 'product_id': self.product.id, - 'bom_id': self.bom.id, - 'product_qty': 1, - 'picking_type_id': - self.env['mrp.production']._get_default_picking_type() - }) - mo.date_planned_start = '2097-01-04 09:00:00' + mo = self.env["mrp.production"].new( + { + "product_id": self.product.id, + "bom_id": self.bom.id, + "product_qty": 1, + "picking_type_id": self.env[ + "mrp.production" + ]._get_default_picking_type(), + } + ) + mo.date_planned_start = "2097-01-04 09:00:00" mo.onchange_date_planned() 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)