|
| 1 | +from odoo.fields import Command |
| 2 | +from odoo.tests.common import TransactionCase |
| 3 | + |
| 4 | + |
| 5 | +class TestCpqSaleMrpCommon(TransactionCase): |
| 6 | + @classmethod |
| 7 | + def setUpClass(cls): |
| 8 | + super().setUpClass() |
| 9 | + |
| 10 | + cls.env.company.anglo_saxon_accounting = True |
| 11 | + |
| 12 | + cls.categ_real_time = cls.env["product.category"].create( |
| 13 | + { |
| 14 | + "name": "CPQ Real Time", |
| 15 | + "property_valuation": "real_time", |
| 16 | + } |
| 17 | + ) |
| 18 | + |
| 19 | + cls.uom_meter = cls.env.ref("uom.product_uom_meter") |
| 20 | + |
| 21 | + cls.uom_unit = cls.env.ref("uom.product_uom_unit") |
| 22 | + |
| 23 | + cls.attr_cable_length = cls.env["product.attribute"].create( |
| 24 | + {"name": "Cable Length"} |
| 25 | + ) |
| 26 | + cls.attr_val_custom_length = cls.env["product.attribute.value"].create( |
| 27 | + { |
| 28 | + "name": "Custom Length", |
| 29 | + "attribute_id": cls.attr_cable_length.id, |
| 30 | + "is_custom": True, |
| 31 | + "cpq_custom_type": "float", |
| 32 | + } |
| 33 | + ) |
| 34 | + |
| 35 | + cls.attr_cable_color = cls.env["product.attribute"].create( |
| 36 | + {"name": "Cable Color"} |
| 37 | + ) |
| 38 | + cls.attr_val_black = cls.env["product.attribute.value"].create( |
| 39 | + { |
| 40 | + "name": "Black", |
| 41 | + "attribute_id": cls.attr_cable_color.id, |
| 42 | + } |
| 43 | + ) |
| 44 | + cls.attr_val_grey = cls.env["product.attribute.value"].create( |
| 45 | + { |
| 46 | + "name": "Grey", |
| 47 | + "attribute_id": cls.attr_cable_color.id, |
| 48 | + } |
| 49 | + ) |
| 50 | + |
| 51 | + cls.bulk_cable = cls.env["product.product"].create( |
| 52 | + { |
| 53 | + "name": "Bulk Cat6 Cable", |
| 54 | + "is_storable": True, |
| 55 | + "standard_price": 2.0, |
| 56 | + "uom_id": cls.uom_meter.id, |
| 57 | + "categ_id": cls.categ_real_time.id, |
| 58 | + } |
| 59 | + ) |
| 60 | + cls.rj45 = cls.env["product.product"].create( |
| 61 | + { |
| 62 | + "name": "RJ45 Connector", |
| 63 | + "is_storable": True, |
| 64 | + "standard_price": 0.0, |
| 65 | + "uom_id": cls.uom_unit.id, |
| 66 | + "categ_id": cls.categ_real_time.id, |
| 67 | + } |
| 68 | + ) |
| 69 | + cls.boot = cls.env["product.product"].create( |
| 70 | + { |
| 71 | + "name": "Strain Relief Boot", |
| 72 | + "is_storable": True, |
| 73 | + "standard_price": 10.0, |
| 74 | + "uom_id": cls.uom_unit.id, |
| 75 | + "categ_id": cls.categ_real_time.id, |
| 76 | + } |
| 77 | + ) |
| 78 | + cls.tie = cls.env["product.product"].create( |
| 79 | + { |
| 80 | + "name": "Velcro Tie", |
| 81 | + "is_storable": True, |
| 82 | + "standard_price": 5.0, |
| 83 | + "uom_id": cls.uom_unit.id, |
| 84 | + "categ_id": cls.categ_real_time.id, |
| 85 | + } |
| 86 | + ) |
| 87 | + |
| 88 | + # The CPQ kit |
| 89 | + cls.cable_kit_tmpl = cls.env["product.template"].create( |
| 90 | + { |
| 91 | + "name": "Configured Cable Loom Kit", |
| 92 | + "cpq_ok": True, |
| 93 | + "is_storable": True, |
| 94 | + "categ_id": cls.categ_real_time.id, |
| 95 | + "uom_id": cls.uom_unit.id, |
| 96 | + "attribute_line_ids": [ |
| 97 | + Command.create( |
| 98 | + { |
| 99 | + "attribute_id": cls.attr_cable_length.id, |
| 100 | + "value_ids": [Command.set([cls.attr_val_custom_length.id])], |
| 101 | + } |
| 102 | + ), |
| 103 | + Command.create( |
| 104 | + { |
| 105 | + "attribute_id": cls.attr_cable_color.id, |
| 106 | + "value_ids": [ |
| 107 | + Command.set( |
| 108 | + [cls.attr_val_black.id, cls.attr_val_grey.id] |
| 109 | + ) |
| 110 | + ], |
| 111 | + } |
| 112 | + ), |
| 113 | + ], |
| 114 | + } |
| 115 | + ) |
| 116 | + |
| 117 | + # Resolve PTAVs for the kit template. |
| 118 | + cls.ptav_custom_length = cls.env["product.template.attribute.value"].search( |
| 119 | + [ |
| 120 | + ("product_tmpl_id", "=", cls.cable_kit_tmpl.id), |
| 121 | + ( |
| 122 | + "product_attribute_value_id", |
| 123 | + "=", |
| 124 | + cls.attr_val_custom_length.id, |
| 125 | + ), |
| 126 | + ], |
| 127 | + limit=1, |
| 128 | + ) |
| 129 | + cls.ptav_black = cls.env["product.template.attribute.value"].search( |
| 130 | + [ |
| 131 | + ("product_tmpl_id", "=", cls.cable_kit_tmpl.id), |
| 132 | + ("product_attribute_value_id", "=", cls.attr_val_black.id), |
| 133 | + ], |
| 134 | + limit=1, |
| 135 | + ) |
| 136 | + |
| 137 | + cls.cable_kit_dyn_bom = cls.env["cpq.dynamic.bom"].create( |
| 138 | + { |
| 139 | + "code": "TEST CABLE KIT DYN", |
| 140 | + "type": "phantom", |
| 141 | + "product_tmpl_id": cls.cable_kit_tmpl.id, |
| 142 | + "product_uom_id": cls.cable_kit_tmpl.uom_id.id, |
| 143 | + "product_qty": 1.0, |
| 144 | + "bom_line_ids": [ |
| 145 | + Command.create( |
| 146 | + { |
| 147 | + "component_type": "variant", |
| 148 | + "component_product_id": cls.bulk_cable.id, |
| 149 | + "quantity_type": "ptav_custom_id", |
| 150 | + "quantity_ptav_custom_id": cls.ptav_custom_length.id, |
| 151 | + "condition_type": "always", |
| 152 | + "uom_id": cls.uom_meter.id, |
| 153 | + } |
| 154 | + ), |
| 155 | + Command.create( |
| 156 | + { |
| 157 | + "component_type": "variant", |
| 158 | + "component_product_id": cls.rj45.id, |
| 159 | + "quantity_type": "fixed", |
| 160 | + "quantity_fixed": 2.0, |
| 161 | + "condition_type": "always", |
| 162 | + "uom_id": cls.uom_unit.id, |
| 163 | + } |
| 164 | + ), |
| 165 | + Command.create( |
| 166 | + { |
| 167 | + "component_type": "variant", |
| 168 | + "component_product_id": cls.boot.id, |
| 169 | + "quantity_type": "fixed", |
| 170 | + "quantity_fixed": 2.0, |
| 171 | + "condition_type": "always", |
| 172 | + "uom_id": cls.uom_unit.id, |
| 173 | + } |
| 174 | + ), |
| 175 | + Command.create( |
| 176 | + { |
| 177 | + "component_type": "variant", |
| 178 | + "component_product_id": cls.tie.id, |
| 179 | + "quantity_type": "fixed", |
| 180 | + "quantity_fixed": 2.0, |
| 181 | + "condition_type": "always", |
| 182 | + "uom_id": cls.uom_unit.id, |
| 183 | + } |
| 184 | + ), |
| 185 | + ], |
| 186 | + } |
| 187 | + ) |
| 188 | + |
| 189 | + cls.partner = cls.env["res.partner"].create({"name": "CPQ Test Customer"}) |
0 commit comments