def setUpClass(cls):
        super().setUpClass()
        # Load a test model using odoo_test_helper
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import TestDateRangeSearchMixin

        cls.loader.update_registry((TestDateRangeSearchMixin, ))

        cls.env.user.lang = "en_US"
        rtype = cls.env["date.range.type"].create({
            "name": __name__,
            "company_id": False,
            "allow_overlap": False
        })
        cls.env["date.range.generator"].create({
            "date_start": "1943-01-01",
            "name_prefix": "1943-",
            "type_id": rtype.id,
            "duration_count": 3,
            "unit_of_time": str(MONTHLY),
            "count": 4,
        }).action_apply()
        cls.ranges = cls.env["date.range"].search([("type_id", "=", rtype.id)])
        cls.model = cls.env[TestDateRangeSearchMixin._name]
Пример #2
0
    def setUpClass(cls):
        super().setUpClass()

        # Load fake models ->/
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from odoo.addons.connector_search_engine.tests.models import SeBackendFake

        class AgnosticBinding(models.Model):
            # `aaa` to keep it on top when sorting ;)
            _name = "commerce.aaa.test.agnostic.binding"
            _inherit = "se.binding"
            _se_index_lang_agnostic = True

            name = fields.Char()

        cls.AgnosticBinding = AgnosticBinding
        cls.loader.update_registry((SeBackendFake, AgnosticBinding))
        # ->/ Load fake models

        cls.se_backend = (
            cls.env[SeBackendFake._name].create({"name": "Fake SE"}).se_backend_id
        )
        cls.backend = cls.env.ref("commerce.backend_1")
        cls.backend.se_backend_id = cls.se_backend
        cls.prod_export = cls.env.ref("commerce.ir_exp_commerce_variant")
        cls.categ_export = cls.env.ref("commerce.ir_exp_commerce_category")
        cls.ir_model_model = cls.env["ir.model"]
        cls.variant_model = cls.ir_model_model._get("commerce.variant")
        cls.categ_model = cls.ir_model_model._get("commerce.category")
        cls.agnostic_model = cls.ir_model_model._get(cls.AgnosticBinding._name)
        cls.lang_en = cls.backend.lang_ids
        cls.lang_fr = _install_lang_odoo(cls.env, "base.lang_fr")
    def setUpClass(cls):
        super().setUpClass()
        # Load a test model using odoo_test_helper
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import L10nEsAeatTestReport

        cls.loader.update_registry((L10nEsAeatTestReport,))
        cls.AeatReport = cls.env[TEST_MODEL_NAME]
        cls.period_types = {
            "0A": ("2016-01-01", "2016-12-31"),
            "1T": ("2016-01-01", "2016-03-31"),
            "2T": ("2016-04-01", "2016-06-30"),
            "3T": ("2016-07-01", "2016-09-30"),
            "4T": ("2016-10-01", "2016-12-31"),
            "01": ("2016-01-01", "2016-01-31"),
            "02": ("2016-02-01", "2016-02-29"),
            "03": ("2016-03-01", "2016-03-31"),
            "04": ("2016-04-01", "2016-04-30"),
            "05": ("2016-05-01", "2016-05-31"),
            "06": ("2016-06-01", "2016-06-30"),
            "07": ("2016-07-01", "2016-07-31"),
            "08": ("2016-08-01", "2016-08-31"),
            "09": ("2016-09-01", "2016-09-30"),
            "10": ("2016-10-01", "2016-10-31"),
            "11": ("2016-11-01", "2016-11-30"),
            "12": ("2016-12-01", "2016-12-31"),
        }
Пример #4
0
    def _setup_search_engine(cls):
        # Load fake models ->/
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from odoo.addons.connector_search_engine.tests.models import SeBackendFake

        cls.loader.update_registry((SeBackendFake,))
        # ->/ Load fake models
        cls.se_backend = (
            cls.env[SeBackendFake._name].create({"name": "Fake SE"}).se_backend_id
        )
        cls.search_engine_name = cls.se_backend.search_engine_name
        cls.backend.se_backend_id = cls.se_backend
        cls.env["se.index"].create(
            {
                "backend_id": cls.backend.se_backend_id.id,
                "name": "index-product",
                "lang_id": cls.env.ref("base.lang_en").id,
                "model_id": cls.env.ref("commerce.model_commerce_variant").id,
                "exporter_id": cls.env.ref("commerce.ir_exp_commerce_variant").id,
            }
        )
        cls.env["se.index"].create(
            {
                "backend_id": cls.backend.se_backend_id.id,
                "name": "index-category",
                "lang_id": cls.env.ref("base.lang_en").id,
                "model_id": cls.env.ref("commerce.model_commerce_category").id,
                "exporter_id": cls.env.ref(
                    "commerce.ir_exp_commerce_category"
                ).id,
            }
        )
Пример #5
0
    def setUpClass(cls):
        super(TestSpecModel, cls).setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()

        # import a simpilified equivalend of purchase module
        from .fake_odoo_purchase import (
            PurchaseOrder as FakePurchaseOrder,
            PurchaseOrderLine as FakePurchaseOrderLine,
        )

        cls.loader.update_registry((FakePurchaseOrder, FakePurchaseOrderLine))

        # import generated spec mixins
        from .fake_mixin import PoXsdMixin
        from .spec_poxsd import Item, Items, PurchaseOrder, USAddress

        cls.loader.update_registry(
            (PoXsdMixin, Item, Items, USAddress, PurchaseOrder))

        # inject the mixins into existing Odoo models
        from .spec_purchase import (
            PurchaseOrder as PurchaseOrder2,
            PurchaseOrderLine,
            ResPartner,
        )

        cls.loader.update_registry(
            (ResPartner, PurchaseOrderLine, PurchaseOrder2))
        # the binding lib should be loaded in sys.modules:
        from . import purchase_order_lib  # NOQA
Пример #6
0
    def setUpClass(cls):
        super().setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .multi_step_wizard_test import MultiStepWizardTest

        cls.loader.update_registry((MultiStepWizardTest, ))
Пример #7
0
    def setUpClass(cls):
        super().setUpClass()
        # Load fake models ->/
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import (
            BindingResPartnerFake,
            ResPartnerFake,
            SeAdapterFake,
            SeBackendFake,
        )

        cls.loader.update_registry(
            (BindingResPartnerFake, ResPartnerFake, SeBackendFake)
        )
        cls.binding_model = cls.env[BindingResPartnerFake._name]
        cls.fake_backend_model = cls.env[SeBackendFake._name]
        # ->/ Load fake models

        cls.se_adapter_fake = SeAdapterFake
        cls._load_fixture("ir_exports_test.xml")
        cls.exporter = cls.env.ref("connector_search_engine.ir_exp_partner_test")
        cls.record_id_export_line = cls.env.ref(
            "connector_search_engine.ir_exp_partner_line_test0"
        )
    def setUpClass(cls):
        super(TierTierValidation, cls).setUpClass()

        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from odoo.addons.base_tier_validation.tests.tier_validation_tester import (
            TierValidationTester, )

        cls.loader.update_registry((TierValidationTester, ))
        cls.test_model = cls.env[TierValidationTester._name]

        cls.tester_model = cls.env["ir.model"].search([
            ("model", "=", "tier.validation.tester")
        ])

        # Access record:
        cls.env["ir.model.access"].create({
            "name": "access.tester",
            "model_id": cls.tester_model.id,
            "perm_read": 1,
            "perm_write": 1,
            "perm_create": 1,
            "perm_unlink": 1,
        })

        # Create users:
        group_ids = cls.env.ref("base.group_system").ids
        cls.test_user_1 = cls.env["res.users"].create({
            "name":
            "John",
            "login":
            "******",
            "groups_id": [(6, 0, group_ids)]
        })
        cls.test_user_2 = cls.env["res.users"].create({
            "name": "Mike",
            "login": "******"
        })
        cls.test_user_3 = cls.env["res.users"].create({
            "name": "Mary",
            "login": "******"
        })

        # Create tier definitions:
        cls.tier_def_obj = cls.env["tier.definition"]
        cls.tier_def_obj.create({
            "model_id":
            cls.tester_model.id,
            "review_type":
            "individual",
            "reviewer_id":
            cls.test_user_1.id,
            "definition_domain":
            "[('test_field', '>', 1.0)]",
        })

        cls.test_record = cls.test_model.create({"test_field": 2.5})
Пример #9
0
    def setUpClass(cls):
        super().setUpClass()
        cls.model_id = cls.env.ref("base.model_res_partner").id
        cls.group = cls.env["attribute.group"].create({
            "name": "My Group",
            "model_id": cls.model_id
        })
        vals = {
            "nature": "custom",
            "model_id": cls.model_id,
            "attribute_type": "char",
            "field_description": "Attribute test",
            "name": "x_test",
            "attribute_group_id": cls.group.id,
        }
        cls.attr1 = cls.env["attribute.attribute"].create(vals)

        vals.update({
            "name": "x_test2",
            "field_description": "Attribute test2"
        })
        cls.attr2 = cls.env["attribute.attribute"].create(vals)

        vals = {
            "name":
            "My attribute Set",
            "model_id":
            cls.model_id,
            "attribute_ids": [(4, cls.attr1.id), (4, cls.attr2.id)],
            "attribute_set_completeness_ids": [
                (0, 0, {
                    "field_id": cls.attr1.field_id.id,
                    "completion_rate": 50.0
                }),
                (0, 0, {
                    "field_id": cls.attr2.field_id.id,
                    "completion_rate": 50.0
                }),
            ],
        }
        cls.attr_set = cls.env["attribute.set"].create(vals)

        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        # fmt: off
        from odoo.addons.attribute_set.tests.models import (
            ResPartner,  # pylint: disable=odoo-addons-relative-import
        )

        cls.loader.update_registry([ResPartner])

        from .res_partner_event_listener import (
            ResPartnerEventListener,  # pylint: disable=odoo-addons-relative-import
        )

        # fmt: on
        ResPartnerEventListener._build_component(cls._components_registry)
Пример #10
0
    def setUpClass(cls):
        super().setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()

        # The fake class is imported here !! After the backup_registry
        from .models import FakeDeliveryCarrier

        cls.loader.update_registry((FakeDeliveryCarrier, ))
        cls.real_get_carriers_action_available = roulier.get_carriers_action_available
Пример #11
0
    def setUpClass(cls):
        super(TestBaseRevision, cls).setUpClass()

        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .base_revision_tester import BaseRevisionTester

        cls.loader.update_registry((BaseRevisionTester,))

        cls.revision_model = cls.env[BaseRevisionTester._name]
Пример #12
0
 def setUpClass(cls):
     super().setUpClass()
     cls.loader = FakeModelLoader(cls.env, cls.__module__)
     cls.loader.backup_registry()
     # fmt: off
     from .fake_models import (FakeSourceConsumer, FakeSourceStatic)
     cls.loader.update_registry((FakeSourceConsumer, FakeSourceStatic))
     # fmt: on
     cls.source = cls._create_source()
     cls.consumer = cls._create_consumer()
Пример #13
0
    def setUpClass(cls):
        super(TestMixin, cls).setUpClass()

        # Creating a record before loading a fake model should work
        cls.env["res.partner"].create({"name": "Setup Class Foo"})

        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import ResPartner

        cls.loader.update_registry((ResPartner, ))
Пример #14
0
    def setUpClass(cls):
        super().setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import ModelTest

        cls.loader.update_registry((ModelTest, ))
        path = os.path.dirname(os.path.abspath(__file__))
        with open(os.path.join(path, "static/akretion-logo.png"), "rb") as f:
            data = f.read()
        cls.filesize = len(data)
        cls.filedata = base64.b64encode(data)
        cls.filename = "akretion-logo.png"
Пример #15
0
    def setUpClass(cls):
        super().setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import SecondaryUnitFake

        cls.loader.update_registry((SecondaryUnitFake, ))
        cls.product_uom_kg = cls.env.ref("uom.product_uom_kgm")
        cls.product_uom_unit = cls.env.ref("uom.product_uom_unit")
        cls.product_uom_dozen = cls.env.ref("uom.product_uom_dozen")
        cls.product_template = cls.env["product.template"].create({
            "name":
            "test",
            "uom_id":
            cls.product_uom_kg.id,
            "uom_po_id":
            cls.product_uom_kg.id,
            "secondary_uom_ids": [
                (
                    0,
                    0,
                    {
                        "code": "C5",
                        "name": "box 5",
                        "uom_id": cls.product_uom_unit.id,
                        "factor": 5,
                    },
                ),
                (
                    0,
                    0,
                    {
                        "code": "C10",
                        "name": "box 10",
                        "uom_id": cls.product_uom_unit.id,
                        "factor": 10,
                    },
                ),
            ],
        })
        cls.secondary_unit_box_5 = cls.product_template.secondary_uom_ids[0]
        cls.secondary_unit_box_10 = cls.product_template.secondary_uom_ids[1]
        # Fake model which inherit from
        cls.secondary_unit_fake = cls.env["secondary.unit.fake"].create({
            "name":
            "Secondary unit fake",
            "product_id":
            cls.product_template.product_variant_ids.id,
            "product_uom_id":
            cls.product_uom_unit.id,
        })
    def setUpClass(cls):
        super().setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        cls.addClassCleanup(cls.loader.restore_registry)

        # Must be lazy-imported
        from ._purchase_test_models import PurchaseTest, LineTest

        cls.loader.update_registry((PurchaseTest, LineTest))

        cls.base_exception = cls.env["base.exception"]
        cls.exception_rule = cls.env["exception.rule"]
        if "test_purchase_ids" not in cls.exception_rule._fields:
            field = fields.Many2many("base.exception.test.purchase")
            cls.exception_rule._add_field("test_purchase_ids", field)
        cls.exception_confirm = cls.env["exception.rule.confirm"]
        cls.exception_rule._fields["model"].selection.append(
            ("base.exception.test.purchase", "Purchase Order")
        )

        cls.exception_rule._fields["model"].selection.append(
            ("base.exception.test.purchase.line", "Purchase Order Line")
        )

        cls.exceptionnozip = cls.env["exception.rule"].create(
            {
                "name": "No ZIP code on destination",
                "sequence": 10,
                "model": "base.exception.test.purchase",
                "code": "if not obj.partner_id.zip: failed=True",
            }
        )

        cls.exceptionno_minorder = cls.env["exception.rule"].create(
            {
                "name": "Min order except",
                "sequence": 10,
                "model": "base.exception.test.purchase",
                "code": "if obj.amount_total <= 200.0: failed=True",
            }
        )

        cls.exceptionno_lineqty = cls.env["exception.rule"].create(
            {
                "name": "Qty > 0",
                "sequence": 10,
                "model": "base.exception.test.purchase.line",
                "code": "if obj.qty <= 0: failed=True",
            }
        )
Пример #17
0
    def test_update_and_restore(self):
        loader = FakeModelLoader(self.env, self.__module__)
        loader.backup_registry()
        from .models import ResPartner, ResPartnerExtra

        self.assertNotIn("res.partner.extra", self.env.registry)
        self.assertNotIn("test_char", self.env["res.partner"]._fields)

        loader.update_registry([ResPartner, ResPartnerExtra])
        self.assertIn("res.partner.extra", self.env.registry)
        self.assertIn("test_char", self.env["res.partner"]._fields)

        loader.restore_registry()
        self.assertNotIn("res.partner.extra", self.env.registry)
        self.assertNotIn("test_char", self.env["res.partner"]._fields)
Пример #18
0
    def _setup_records(cls):
        super()._setup_records()
        # Load fake models ->/
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .fake_models import EdiExchangeConsumerTest

        cls.loader.update_registry((EdiExchangeConsumerTest, ))

        cls.group = cls.env["res.groups"].create({"name": "Demo Group"})
        cls.ir_access = cls.env["ir.model.access"].create({
            "name":
            "model access",
            "model_id":
            cls.env.ref("edi_oca.model_edi_exchange_consumer_test").id,
            "group_id":
            cls.group.id,
            "perm_read":
            True,
            "perm_write":
            True,
            "perm_create":
            True,
            "perm_unlink":
            True,
        })
        cls.rule = cls.env["ir.rule"].create({
            "name":
            "Exchange Record rule demo",
            "model_id":
            cls.env.ref("edi_oca.model_edi_exchange_consumer_test").id,
            "domain_force":
            "[('name', '=', 'test')]",
            "groups": [(4, cls.group.id)],
        })
        cls.user = (cls.env["res.users"].with_context(
            no_reset_password=True, mail_notrack=True).create({
                "name":
                "Poor Partner (not integrating one)",
                "email":
                "*****@*****.**",
                "login":
                "******",
                "groups_id": [(6, 0, [cls.env.ref("base.group_user").id])],
            }))
        cls.consumer_record = cls.env["edi.exchange.consumer.test"].create(
            {"name": "test"})
        cls.exchange_type_out.exchange_filename_pattern = "{record.id}"
Пример #19
0
    def setUpClass(cls):
        super(TestAbstractUrl, cls).setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import ResPartner, ResPartnerAddressableFake, UrlBackendFake

        cls.loader.update_registry(
            (UrlBackendFake, ResPartner, ResPartnerAddressableFake)
        )

        cls.lang = cls.env.ref("base.lang_en")
        cls.UrlUrl = cls.env["url.url"]
        cls.ResPartnerAddressable = cls.env["res.partner.addressable.fake"]
        cls.url_backend = cls.env["url.backend.fake"].create({"name": "fake backend"})
        cls.name = "partner name"
        cls.auto_key = "partner-name"
Пример #20
0
    def setUpClass(cls):
        super().setUpClass()
        cls.model_id = cls.env.ref("base.model_res_partner").id
        cls.group = cls.env["attribute.group"].create({
            "name": "My Group",
            "model_id": cls.model_id
        })
        vals = {
            "nature": "custom",
            "model_id": cls.model_id,
            "attribute_type": "char",
            "field_description": "Attribute test",
            "name": "x_test",
            "attribute_group_id": cls.group.id,
        }
        cls.attr1 = cls.env["attribute.attribute"].create(vals)

        vals.update({
            "name": "x_test2",
            "field_description": "Attribute test2"
        })
        cls.attr2 = cls.env["attribute.attribute"].create(vals)

        vals = {
            "name":
            "My attribute Set",
            "model_id":
            cls.model_id,
            "attribute_ids": [(4, cls.attr1.id), (4, cls.attr2.id)],
            "attribute_set_completeness_ids": [
                (0, 0, {
                    "field_id": cls.attr1.field_id.id,
                    "completion_rate": 0.5
                }),
                (0, 0, {
                    "field_id": cls.attr2.field_id.id,
                    "completion_rate": 0.5
                }),
            ],
        }
        cls.attr_set = cls.env["attribute.set"].create(vals)
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from odoo.addons.attribute_set.tests.models import ResPartner

        cls.loader.update_registry((ResPartner, ))
    def setUpClass(cls):
        super().setUpClass()
        # Setup env
        cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
        # Load fake order model
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models.fake_order import FakeOrder

        cls.loader.update_registry((FakeOrder, ))
        cls.fake_order_model = cls.env["ir.model"].search([("model", "=",
                                                            "fake.order")])
        # Email Template
        cls.mail_template = cls.env["mail.template"].create({
            "model_id":
            cls.fake_order_model.id,
            "name":
            "Fake Order: Send by Mail",
            "subject":
            "Fake Order: ${object.partner_id.name}",
            "partner_to":
            "${object.partner_id.id}",
            "body_html":
            "Hello, this is a fake order",
        })
        # Partners
        cls.commercial_partner = cls.env.ref("base.res_partner_4")
        cls.partner_1 = cls.env.ref("base.res_partner_address_13")
        cls.partner_2 = cls.env.ref("base.res_partner_address_14")
        cls.partner_3 = cls.env.ref("base.res_partner_address_24")
        # Autosubscribe rules
        cls.autosubscribe_fake_order = cls.env["mail.autosubscribe"].create(
            {"model_id": cls.fake_order_model.id})
        cls.partner_3.mail_autosubscribe_ids = [
            (4, cls.autosubscribe_fake_order.id)
        ]
        # Empty fake.order
        cls.order = cls.env["fake.order"].create(
            {"partner_id": cls.partner_2.id})
Пример #22
0
    def setUpClass(cls):
        super().setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import BarcodeGeneratorUserFake, BarcodeRuleUserFake

        cls.loader.update_registry((
            BarcodeGeneratorUserFake,
            BarcodeRuleUserFake,
        ))
        cls.barcode_rule_fake = cls.env["barcode.rule"].create({
            "name":
            "User rule",
            "barcode_nomenclature_id":
            cls.env.ref("barcodes.default_barcode_nomenclature").id,
            "type":
            "user",
            "sequence":
            999,
            "encoding":
            "ean13",
            "pattern":
            "20.....{NNNDD}",
            "generate_type":
            "manual",
            "generate_model":
            "res.users",
        })
        cls.user_fake = cls.env["res.users"].create({
            "name":
            "Test user",
            "login":
            "******",
            "barcode_rule_id":
            cls.barcode_rule_fake.id,
            "barcode_base":
            10,
        })
        cls.user_fake.generate_barcode()
Пример #23
0
    def _setup_records(cls):
        super()._setup_records()
        # Load fake models ->/
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .fake_models import EdiExchangeConsumerTest

        cls.loader.update_registry((EdiExchangeConsumerTest,))
        cls.consumer_record = cls.env["edi.exchange.consumer.test"].create(
            {"name": "Test Consumer"}
        )
        cls.exchange_type_out.exchange_filename_pattern = "{record.id}"
        cls.exchange_type_new = cls._create_exchange_type(
            name="Test CSV output",
            code="test_csv_new_output",
            direction="output",
            exchange_file_ext="csv",
            backend_id=False,
            exchange_filename_pattern="{record.ref}-{type.code}-{dt}",
            model_ids=[(4, cls.env["ir.model"]._get_id(cls.consumer_record._name))],
            enable_domain="[]",
            enable_snippet="""result = not   record._has_exchange_record(
            exchange_type.code)""",
        )
        cls.exchange_type_out.write(
            {
                "model_ids": [
                    (
                        4,
                        cls.env["ir.model"]._get_id(cls.consumer_record._name),
                    )
                ],
                "enable_domain": "[]",
                "enable_snippet": """result = not   record._has_exchange_record(
            exchange_type.code, exchange_type.backend_id)""",
            }
        )
        cls.backend_02 = cls.backend.copy()
    def setUpClass(cls):
        super().setUpClass()
        # Load a test model using odoo_test_helper
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import TestDateRangeSearchMixin
        cls.loader.update_registry((TestDateRangeSearchMixin, ))

        cls.env.user.lang = "en_US"
        rtype = cls.env['date.range.type'].create({
            'name': __name__,
            'company_id': False,
            'allow_overlap': False
        })
        cls.env['date.range.generator'].create({
            'date_start': '1943-01-01',
            'name_prefix': '1943-',
            'type_id': rtype.id,
            'duration_count': 3,
            'unit_of_time': MONTHLY,
            'count': 4
        }).action_apply()
        cls.ranges = cls.env['date.range'].search([('type_id', '=', rtype.id)])
        cls.model = cls.env[TestDateRangeSearchMixin._name]
Пример #25
0
    def setUpClass(cls):
        super().setUpClass()
        cls.loader = FakeModelLoader(cls.env, cls.__module__)
        cls.loader.backup_registry()
        from .models import ResPartner

        cls.loader.update_registry((ResPartner, ))

        # Create a new inherited view with the 'attributes' placeholder.
        cls.view = cls.env["ir.ui.view"].create({
            "name":
            "res.partner.form.test",
            "model":
            "res.partner",
            "inherit_id":
            cls.env.ref("base.view_partner_form").id,
            "arch":
            """
                    <xpath expr="//notebook" position="inside">
                        <page name="partner_attributes">
                            <separator name="attributes_placeholder" />
                        </page>
                    </xpath>
                """,
        })
        # Create some attributes
        cls.model_id = cls.env.ref("base.model_res_partner").id
        cls.partner = cls.env.ref("base.res_partner_12")
        cls.set_1 = cls._create_set("Set 1")
        cls.set_2 = cls._create_set("Set 2")
        cls.group_1 = cls._create_group({"name": "Group 1", "sequence": 1})
        cls.group_2 = cls._create_group({"name": "Group 2", "sequence": 2})
        cls.attr_1 = cls._create_attribute({
            "nature":
            "custom",
            "name":
            "x_attr_1",
            "attribute_type":
            "char",
            "sequence":
            1,
            "attribute_group_id":
            cls.group_1.id,
            "attribute_set_ids": [(6, 0, [cls.set_1.id])],
        })
        cls.attr_2 = cls._create_attribute({
            "nature":
            "custom",
            "name":
            "x_attr_2",
            "attribute_type":
            "text",
            "sequence":
            2,
            "attribute_group_id":
            cls.group_1.id,
            "attribute_set_ids": [(6, 0, [cls.set_1.id])],
        })
        cls.attr_3 = cls._create_attribute({
            "nature":
            "custom",
            "name":
            "x_attr_3",
            "attribute_type":
            "boolean",
            "sequence":
            1,
            "attribute_group_id":
            cls.group_2.id,
            "attribute_set_ids": [(6, 0, [cls.set_1.id, cls.set_2.id])],
        })
        cls.attr_4 = cls._create_attribute({
            "nature":
            "custom",
            "name":
            "x_attr_4",
            "attribute_type":
            "date",
            "sequence":
            2,
            "attribute_group_id":
            cls.group_2.id,
            "attribute_set_ids": [(6, 0, [cls.set_1.id, cls.set_2.id])],
        })
        cls.attr_select = cls._create_attribute({
            "nature":
            "custom",
            "name":
            "x_attr_select",
            "attribute_type":
            "select",
            "attribute_group_id":
            cls.group_2.id,
            "attribute_set_ids": [(6, 0, [cls.set_1.id])],
        })
        cls.attr_select_option = cls.env["attribute.option"].create({
            "name":
            "Option 1",
            "attribute_id":
            cls.attr_select.id
        })
        cls.attr_native = cls._create_attribute({
            "nature":
            "native",
            "field_id":
            cls.env.ref("base.field_res_partner__category_id").id,
            "attribute_group_id":
            cls.group_2.id,
            "attribute_set_ids": [(6, 0, [cls.set_1.id, cls.set_2.id])],
        })
        cls.attr_native_readonly = cls._create_attribute({
            "nature":
            "native",
            "field_id":
            cls.env.ref("base.field_res_partner__create_uid").id,
            "attribute_group_id":
            cls.group_2.id,
            "attribute_set_ids": [(6, 0, [cls.set_1.id, cls.set_2.id])],
        })