|
| 1 | +# Copyright 2023 Camptocamp SA |
| 2 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) |
| 3 | + |
| 4 | +from odoo.tests.common import Form, SavepointCase |
| 5 | + |
| 6 | + |
| 7 | +class TestMTOVariantCommon(SavepointCase): |
| 8 | + at_install = False |
| 9 | + post_install = True |
| 10 | + |
| 11 | + @classmethod |
| 12 | + def setUpClass(cls): |
| 13 | + super().setUpClass() |
| 14 | + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) |
| 15 | + cls.setUpClassProduct() |
| 16 | + |
| 17 | + |
| 18 | + @classmethod |
| 19 | + def setUpClassProduct(cls): |
| 20 | + cls.color = cls.env['product.attribute'].create({'name': 'Color'}) |
| 21 | + value_model = cls.env['product.attribute.value'] |
| 22 | + cls.values = value_model.create( |
| 23 | + [ |
| 24 | + {'name': 'red', 'attribute_id': cls.color.id}, |
| 25 | + {'name': 'blue', 'attribute_id': cls.color.id}, |
| 26 | + {'name': 'black', 'attribute_id': cls.color.id}, |
| 27 | + {'name': 'green', 'attribute_id': cls.color.id}, |
| 28 | + ] |
| 29 | + ) |
| 30 | + cls.value_red = cls.values.filtered(lambda v: v.name == "red") |
| 31 | + cls.value_blue = cls.values.filtered(lambda v: v.name == "blue") |
| 32 | + cls.value_black = cls.values.filtered(lambda v: v.name == "black") |
| 33 | + cls.value_green = cls.values.filtered(lambda v: v.name == "green") |
| 34 | + cls.template_pen = cls.env["product.template"].create( |
| 35 | + { |
| 36 | + "name": "pen", |
| 37 | + 'attribute_line_ids': [ |
| 38 | + (0, 0, { |
| 39 | + 'attribute_id': cls.color.id, |
| 40 | + 'value_ids': [(6, 0, cls.values.ids)], |
| 41 | + }) |
| 42 | + ] |
| 43 | + } |
| 44 | + ) |
| 45 | + cls.variants_pen = cls.template_pen.product_variant_ids |
| 46 | + cls.black_pen = cls.variants_pen.filtered(lambda v: v.product_template_attribute_value_ids.name == "black") |
| 47 | + cls.green_pen = cls.variants_pen.filtered(lambda v: v.product_template_attribute_value_ids.name == "green") |
| 48 | + cls.red_pen = cls.variants_pen.filtered(lambda v: v.product_template_attribute_value_ids.name == "red") |
| 49 | + cls.blue_pen = cls.variants_pen.filtered(lambda v: v.product_template_attribute_value_ids.name == "blue") |
| 50 | + cls.mto_route = cls.env.ref("stock.route_warehouse0_mto") |
| 51 | + cls.mto_route.active = True |
| 52 | + |
| 53 | + def add_route(self, template, route): |
| 54 | + if not route: |
| 55 | + route = self.mto_route |
| 56 | + with Form(template) as record: |
| 57 | + record.route_ids.add(route) |
| 58 | + |
| 59 | + def remove_route(self, template, route): |
| 60 | + if not route: |
| 61 | + route = self.mto_route |
| 62 | + with Form(template) as record: |
| 63 | + record.route_ids.remove(id=route.id) |
| 64 | + |
| 65 | + @classmethod |
| 66 | + def toggle_is_mto(self, records): |
| 67 | + for record in records: |
| 68 | + record.is_mto = not record.is_mto |
| 69 | + |
| 70 | + def assertVariantsMTO(self, records): |
| 71 | + records.invalidate_cache(["is_mto"]) |
| 72 | + self.assertTrue(all([record.is_mto for record in records])) |
| 73 | + |
| 74 | + def assertVariantsNotMTO(self, records): |
| 75 | + records.invalidate_cache(["is_mto"]) |
| 76 | + self.assertFalse(any([record.is_mto for record in records])) |
0 commit comments