|
1 | 1 | # Copyright 2020 Camptocamp SA |
2 | 2 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) |
3 | 3 |
|
4 | | -from odoo.tests.common import Form, TransactionCase |
| 4 | +from odoo.addons.product_packaging_level_salable.tests.common import Common |
5 | 5 |
|
6 | 6 | TU_PRODUCT_QTY = 20 |
7 | 7 | PL_PRODUCT_QTY = TU_PRODUCT_QTY * 30 |
8 | 8 |
|
9 | 9 |
|
10 | | -class Common(TransactionCase): |
11 | | - at_install = False |
12 | | - post_install = True |
13 | | - |
| 10 | +class SellOnlyByPackagingCommon(Common): |
14 | 11 | @classmethod |
15 | 12 | def setUpClass(cls): |
16 | | - super(Common, cls).setUpClass() |
17 | | - cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) |
| 13 | + super().setUpClass() |
18 | 14 | cls.env.user.groups_id += cls.env.ref("product.group_stock_packaging") |
19 | | - cls.setUpClassPartner() |
20 | | - cls.setUpClassProduct() |
21 | | - cls.setUpClassPackagingType() |
22 | | - cls.setUpClassPackaging() |
23 | | - cls.setUpClassSaleOrder() |
24 | | - cls.setUpClassConfig() |
25 | | - |
26 | | - @classmethod |
27 | | - def setUpClassConfig(cls): |
28 | | - cls.precision = cls.env["decimal.precision"].precision_get("Product Price") |
29 | | - |
30 | | - @classmethod |
31 | | - def setUpClassPartner(cls): |
32 | | - cls.partner = cls.env.ref("base.res_partner_12") |
33 | | - |
34 | | - @classmethod |
35 | | - def setUpClassProduct(cls): |
36 | | - cls.product = cls.env.ref("product.product_product_9") |
37 | | - |
38 | | - @classmethod |
39 | | - def setUpClassPackagingType(cls): |
40 | | - cls.packaging_level_tu = cls.env["product.packaging.level"].create( |
41 | | - {"name": "Transport Unit", "code": "TU", "sequence": 1} |
42 | | - ) |
43 | | - cls.packaging_level_pl = cls.env["product.packaging.level"].create( |
44 | | - {"name": "Pallet", "code": "PL", "sequence": 2} |
45 | | - ) |
46 | | - cls.packaging_level_cannot_be_sold = cls.env["product.packaging.level"].create( |
47 | | - { |
48 | | - "name": "Can not be sold", |
49 | | - "code": "CNBS", |
50 | | - "sequence": 30, |
51 | | - "can_be_sold": False, |
52 | | - } |
53 | | - ) |
54 | | - |
55 | | - @classmethod |
56 | | - def setUpClassPackaging(cls): |
57 | | - cls.packaging_tu = cls.env["product.packaging"].create( |
58 | | - { |
59 | | - "name": "PACKAGING TU", |
60 | | - "product_id": cls.product.id, |
61 | | - "packaging_level_id": cls.packaging_level_tu.id, |
62 | | - "qty": TU_PRODUCT_QTY, |
63 | | - } |
64 | | - ) |
65 | | - cls.packaging_pl = cls.env["product.packaging"].create( |
66 | | - { |
67 | | - "name": "PACKAGING PL", |
68 | | - "product_id": cls.product.id, |
69 | | - "packaging_level_id": cls.packaging_level_pl.id, |
70 | | - "qty": PL_PRODUCT_QTY, |
71 | | - } |
72 | | - ) |
73 | | - cls.packaging_cannot_be_sold = cls.env["product.packaging"].create( |
74 | | - { |
75 | | - "name": "Test packaging cannot be sold", |
76 | | - "product_id": cls.product.id, |
77 | | - "qty": 10.0, |
78 | | - "packaging_level_id": cls.packaging_level_cannot_be_sold.id, |
79 | | - } |
80 | | - ) |
81 | | - cls.sellable_packagings = cls.packaging_tu | cls.packaging_pl |
82 | | - |
83 | | - @classmethod |
84 | | - def setUpClassSaleOrder(cls): |
85 | | - cls.so_model = cls.env["sale.order"] |
86 | | - sale_form = Form(cls.so_model) |
87 | | - sale_form.partner_id = cls.partner |
88 | | - with sale_form.order_line.new() as line: |
89 | | - line.product_id = cls.product |
90 | | - line.product_uom = cls.product.uom_id |
91 | | - cls.order = sale_form.save() |
92 | | - cls.order_line = cls.order.order_line |
0 commit comments