|
| 1 | +# Copyright 2018 Akretion (http://www.akretion.com). |
| 2 | +# @author Benoît GUILLOT <benoit.guillot@akretion.com> |
| 3 | +# Copyright 2018 Camptocamp |
| 4 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
| 5 | + |
| 6 | +from odoo.tests import Form, SavepointCase |
| 7 | + |
| 8 | + |
| 9 | +class TestSaleProductionState(SavepointCase): |
| 10 | + @classmethod |
| 11 | + def setUpClass(cls): |
| 12 | + super().setUpClass() |
| 13 | + route_manufacture_1 = cls.env.ref("mrp.route_warehouse0_manufacture") |
| 14 | + route_manufacture_2 = cls.env.ref("stock.route_warehouse0_mto") |
| 15 | + route_manufacture_2.active = True |
| 16 | + cls.product_1 = cls.env["product.product"].create( |
| 17 | + { |
| 18 | + "name": "Test sale production state product 1", |
| 19 | + "type": "product", |
| 20 | + "route_ids": [ |
| 21 | + (4, route_manufacture_1.id), |
| 22 | + (4, route_manufacture_2.id), |
| 23 | + ], |
| 24 | + } |
| 25 | + ) |
| 26 | + cls.product = cls.env["product.product"].create( |
| 27 | + { |
| 28 | + "name": "Test sale production state product", |
| 29 | + "type": "product", |
| 30 | + } |
| 31 | + ) |
| 32 | + cls.bom_1 = cls.env["mrp.bom"].create( |
| 33 | + { |
| 34 | + "product_tmpl_id": cls.product_1.product_tmpl_id.id, |
| 35 | + } |
| 36 | + ) |
| 37 | + cls.env["mrp.bom.line"].create( |
| 38 | + {"bom_id": cls.bom_1.id, "product_id": cls.product.id, "product_qty": 1} |
| 39 | + ) |
| 40 | + cls.product_2 = cls.env["product.product"].create( |
| 41 | + { |
| 42 | + "name": "Test sale production state product 2", |
| 43 | + "type": "product", |
| 44 | + "route_ids": [ |
| 45 | + (4, route_manufacture_1.id), |
| 46 | + (4, route_manufacture_2.id), |
| 47 | + ], |
| 48 | + } |
| 49 | + ) |
| 50 | + cls.bom_2 = cls.env["mrp.bom"].create( |
| 51 | + { |
| 52 | + "product_tmpl_id": cls.product_2.product_tmpl_id.id, |
| 53 | + } |
| 54 | + ) |
| 55 | + cls.env["mrp.bom.line"].create( |
| 56 | + {"bom_id": cls.bom_2.id, "product_id": cls.product.id, "product_qty": 1} |
| 57 | + ) |
| 58 | + cls.partner = cls.env["res.partner"].create({"name": "Test client"}) |
| 59 | + cls.order = cls.env["sale.order"].create( |
| 60 | + { |
| 61 | + "partner_id": cls.partner.id, |
| 62 | + "client_order_ref": "SO1", |
| 63 | + "order_line": [ |
| 64 | + ( |
| 65 | + 0, |
| 66 | + 0, |
| 67 | + { |
| 68 | + "product_id": cls.product_1.id, |
| 69 | + "product_uom_qty": 1, |
| 70 | + "price_unit": 1, |
| 71 | + }, |
| 72 | + ), |
| 73 | + ( |
| 74 | + 0, |
| 75 | + 0, |
| 76 | + { |
| 77 | + "product_id": cls.product_2.id, |
| 78 | + "product_uom_qty": 1, |
| 79 | + "price_unit": 1, |
| 80 | + }, |
| 81 | + ), |
| 82 | + ], |
| 83 | + } |
| 84 | + ) |
| 85 | + |
| 86 | + def test_no_production(self): |
| 87 | + self.assertEqual(self.order.order_line[0].production_state, "no") |
| 88 | + self.assertEqual(self.order.production_state, "no") |
| 89 | + |
| 90 | + def test_unprocessed_production(self): |
| 91 | + self.order.action_confirm() |
| 92 | + self.assertEqual(self.order.order_line[0].production_state, "unprocessed") |
| 93 | + self.assertEqual(self.order.production_state, "unprocessed") |
| 94 | + self.assertTrue(self.order.order_line[0].production_ids) |
| 95 | + |
| 96 | + def test_partially(self): |
| 97 | + self.order.action_confirm() |
| 98 | + mrp = self.order.order_line[0].production_ids |
| 99 | + mrp.action_confirm() |
| 100 | + mo_form = Form(mrp) |
| 101 | + mo_form.qty_producing = 1 |
| 102 | + mrp = mo_form.save() |
| 103 | + mrp.button_mark_done() |
| 104 | + self.assertEqual(self.order.order_line[0].production_state, "done") |
| 105 | + self.assertEqual(self.order.production_state, "partially") |
| 106 | + |
| 107 | + def test_production_done(self): |
| 108 | + self.order.action_confirm() |
| 109 | + for line in self.order.order_line: |
| 110 | + mrp = line.production_ids |
| 111 | + mrp.action_confirm() |
| 112 | + mo_form = Form(mrp) |
| 113 | + mo_form.qty_producing = 1 |
| 114 | + mrp = mo_form.save() |
| 115 | + mrp.button_mark_done() |
| 116 | + self.assertEqual(self.order.production_state, "done") |
0 commit comments