diff --git a/mrp_auto_assign/models/mrp_production.py b/mrp_auto_assign/models/mrp_production.py index f3f32eca6..c7988e750 100644 --- a/mrp_auto_assign/models/mrp_production.py +++ b/mrp_auto_assign/models/mrp_production.py @@ -6,11 +6,11 @@ from odoo import api, models class MrpProduction(models.Model): - _inherit = 'mrp.production' + _inherit = "mrp.production" @api.model def create(self, values): production = super(MrpProduction, self).create(values) - if production.availability != 'none': + if production.availability != "none": production.action_assign() return production diff --git a/mrp_auto_assign/tests/test_auto_assign.py b/mrp_auto_assign/tests/test_auto_assign.py index 817960489..3dcec3ce2 100644 --- a/mrp_auto_assign/tests/test_auto_assign.py +++ b/mrp_auto_assign/tests/test_auto_assign.py @@ -6,60 +6,75 @@ from odoo.tests.common import TransactionCase class TestMrpAutoAssign(TransactionCase): - def setUp(self, *args, **kwargs): super(TestMrpAutoAssign, self).setUp(*args, **kwargs) - self.production_model = self.env['mrp.production'] - self.bom_model = self.env['mrp.bom'] - self.stock_location_stock = self.env.ref('stock.stock_location_stock') - self.manufacture_route = self.env.ref( - 'mrp.route_warehouse0_manufacture') - self.uom_unit = self.env.ref('uom.product_uom_unit') + self.production_model = self.env["mrp.production"] + self.bom_model = self.env["mrp.bom"] + self.stock_location_stock = self.env.ref("stock.stock_location_stock") + self.manufacture_route = self.env.ref("mrp.route_warehouse0_manufacture") + self.uom_unit = self.env.ref("uom.product_uom_unit") - self.product_manuf = self.env['product.product'].create({ - 'name': 'Manuf', - 'type': 'product', - 'uom_id': self.uom_unit.id, - 'route_ids': [(4, self.manufacture_route.id)] - }) - self.product_raw_material = self.env['product.product'].create({ - 'name': 'Raw Material', - 'type': 'product', - 'uom_id': self.uom_unit.id, - }) + self.product_manuf = self.env["product.product"].create( + { + "name": "Manuf", + "type": "product", + "uom_id": self.uom_unit.id, + "route_ids": [(4, self.manufacture_route.id)], + } + ) + self.product_raw_material = self.env["product.product"].create( + { + "name": "Raw Material", + "type": "product", + "uom_id": self.uom_unit.id, + } + ) - self._update_product_qty(self.product_raw_material, - self.stock_location_stock, 1) + self._update_product_qty( + self.product_raw_material, self.stock_location_stock, 1 + ) - self.bom = self.env['mrp.bom'].create({ - 'product_id': self.product_manuf.id, - 'product_tmpl_id': self.product_manuf.product_tmpl_id.id, - 'bom_line_ids': ([ - (0, 0, { - 'product_id': self.product_raw_material.id, - 'product_qty': 1, - 'product_uom_id': self.uom_unit.id - }), - ]) - }) + self.bom = self.env["mrp.bom"].create( + { + "product_id": self.product_manuf.id, + "product_tmpl_id": self.product_manuf.product_tmpl_id.id, + "bom_line_ids": ( + [ + ( + 0, + 0, + { + "product_id": self.product_raw_material.id, + "product_qty": 1, + "product_uom_id": self.uom_unit.id, + }, + ), + ] + ), + } + ) def _update_product_qty(self, product, location, quantity): """Update Product quantity.""" - product_qty = self.env['stock.change.product.qty'].create({ - 'location_id': location.id, - 'product_id': product.id, - 'new_quantity': quantity, - }) + product_qty = self.env["stock.change.product.qty"].create( + { + "location_id": location.id, + "product_id": product.id, + "new_quantity": quantity, + } + ) product_qty.change_product_qty() return product_qty def test_01_manufacture_auto_assign(self): """Test if Manufacturing order is auto-assigned.""" - production = self.production_model.create({ - 'product_id': self.product_manuf.id, - 'product_qty': 1, - 'product_uom_id': self.uom_unit.id, - 'bom_id': self.bom.id - }) - self.assertEqual(production.availability, 'assigned') + production = self.production_model.create( + { + "product_id": self.product_manuf.id, + "product_qty": 1, + "product_uom_id": self.uom_unit.id, + "bom_id": self.bom.id, + } + ) + self.assertEqual(production.availability, "assigned") diff --git a/setup/mrp_auto_assign/odoo/addons/mrp_auto_assign b/setup/mrp_auto_assign/odoo/addons/mrp_auto_assign new file mode 120000 index 000000000..c5f7605c9 --- /dev/null +++ b/setup/mrp_auto_assign/odoo/addons/mrp_auto_assign @@ -0,0 +1 @@ +../../../../mrp_auto_assign \ No newline at end of file diff --git a/setup/mrp_auto_assign/setup.py b/setup/mrp_auto_assign/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_auto_assign/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)