def model(self):

        T = current.T
        configure = self.configure
        define_table = self.define_table
        add_components = self.add_components

        s3 = current.response.s3
        crud_strings = s3.crud_strings

        UNKNOWN_OPT = current.messages.UNKNOWN_OPT

        db = current.db

        # ---------------------------------------------------------------------
        # Kits
        #
        tablename = "budget_kit"
        define_table(tablename,
                     Field("code", length=128, notnull=True, unique=True,
                           label = T("Code"),
                           #requires = [IS_NOT_EMPTY(),
                           #            IS_NOT_ONE_OF(db, "%s.code" % tablename),
                           #            ],
                           ),
                     Field("description",
                           label = T("Description"),
                           ),
                     Field("total_unit_cost", "double",
                           default = 0.0,
                           label = T("Total Unit Cost"),
                           writable = False,
                           ),
                     Field("total_monthly_cost", "double",
                           default = 0.0,
                           label = T("Total Monthly Cost"),
                           writable = False,
                           ),
                     Field("total_minute_cost", "double",
                           default = 0.0,
                           label = T("Total Cost per Minute"),
                           writable = False,
                           ),
                     Field("total_megabyte_cost", "double",
                           default = 0.0,
                           label = T("Total Cost per Megabyte"),
                           writable = False,
                           ),
                     s3_comments(),
                     *s3_meta_fields())

        # CRUD Strings
        ADD_KIT = T("Create Kit")
        crud_strings[tablename] = Storage(
            label_create = ADD_KIT,
            title_display = T("Kit Details"),
            title_list = T("Kits"),
            title_update = T("Edit Kit"),
            label_list_button = T("List Kits"),
            label_delete_button = T("Delete Kit"),
            msg_record_created = T("Kit added"),
            msg_record_modified = T("Kit updated"),
            msg_record_deleted = T("Kit deleted"),
            msg_list_empty = T("No Kits currently registered"),
        )

        # Represent
        budget_kit_represent = S3Represent(lookup=tablename, fields=["code"])

        # Reusable Field
        budget_kit_id = S3ReusableField("kit_id", "reference %s" % tablename,
            ondelete = "RESTRICT",
            label = T("Kit"),
            represent = budget_kit_represent,
            requires = IS_ONE_OF(db, "budget_kit.id",
                                 budget_kit_represent,
                                 ),
            comment = S3PopupLink(
                c = "budget",
                f = "kit",
                label = ADD_KIT,
                title = T("Kit"),
                tooltip = T("You can create a new kit by clicking link '%s'.") % ADD_KIT
                ),
            )

        # Configuration
        configure(tablename,
                  onaccept = self.budget_kit_onaccept,
                  )

        # Components
        add_components(tablename,
                       # Items
                       budget_item = {"link": "budget_kit_item",
                                      "joinby": "kit_id",
                                      "key": "item_id",
                                      "actuate": "link",
                                      },
                       )

        # ---------------------------------------------------------------------
        # Items
        #
        budget_cost_type_opts = {1: T("One-time"),
                                 2: T("Recurring"),
                                }

        budget_category_type_opts = {1: T("Consumable"),
                                     2: T("Satellite"),
                                     3: "HF",
                                     4: "VHF",
                                     5: T("Telephony"),
                                     6: "WLAN",
                                     7: T("Network"),
                                     8: T("Generator"),
                                     9: T("Electrical"),
                                     10: T("Vehicle"),
                                     11: "GPS",
                                     12: T("Tools"),
                                     13: "IT",
                                     14: "ICT",
                                     15: "TC",
                                     16: T("Stationery"),
                                     17: T("Relief"),
                                     18: T("Miscellaneous"),
                                     19: T("Running Cost"),
                                     }

        tablename = "budget_item"
        define_table(tablename,
                     Field("category_type", "integer", notnull=True,
                           #default = 1,
                           label = T("Category"),
                           represent = lambda opt: \
                                       budget_category_type_opts.get(opt, UNKNOWN_OPT),
                           requires = IS_IN_SET(budget_category_type_opts, zero=None),
                           ),
                     Field("code", length=128, notnull=True, unique=True,
                           label = T("Code"),
                           #requires = [IS_NOT_EMPTY(),
                           #            IS_NOT_ONE_OF(db, "%s.code" % tablename),
                           #            ],
                           ),
                     Field("description", notnull=True,
                           label = T("Description"),
                           requires = IS_NOT_EMPTY(),
                           ),
                     Field("cost_type", "integer", notnull=True,
                           #default = 1,
                           label = T("Cost Type"),
                           represent = lambda opt: \
                                       budget_cost_type_opts.get(opt, UNKNOWN_OPT),
                           requires = IS_IN_SET(budget_cost_type_opts,
                                                zero=None),
                           ),
                     Field("unit_cost", "double",
                           default = 0.00,
                           label = T("Unit Cost"),
                           ),
                     Field("monthly_cost", "double",
                           default = 0.00,
                           label = T("Monthly Cost"),
                           ),
                     Field("minute_cost", "double",
                           default = 0.00,
                           label = T("Cost per Minute"),
                           ),
                     Field("megabyte_cost", "double",
                           default = 0.00,
                           label = T("Cost per Megabyte"),
                           ),
                     s3_comments(),
                     *s3_meta_fields())

        # CRUD Strings
        ADD_ITEM = T("Create Item")
        crud_strings[tablename] = Storage(
            label_create = ADD_ITEM,
            title_display = T("Item Details"),
            title_list = T("Items"),
            title_update = T("Edit Item"),
            label_list_button = T("List Items"),
            label_delete_button = T("Delete Item"),
            label_search_button = T("Search Items"),
            msg_record_created = T("Item added"),
            msg_record_modified = T("Item updated"),
            msg_record_deleted = T("Item deleted"),
            msg_list_empty = T("No Items currently registered"),
        )

        # Represent
        budget_item_represent = S3Represent(lookup=tablename,
                                            fields=["description"])

        # Reusable Field
        budget_item_id = S3ReusableField("item_id", "reference %s" % tablename,
            label = T("Item"),
            ondelete = "RESTRICT",
            represent = budget_item_represent,
            requires = IS_ONE_OF(db, "budget_item.id",
                                 budget_item_represent,
                                 ),
            comment = S3PopupLink(
                c = "budget",
                f = "item",
                label = ADD_ITEM,
                title = T("Item"),
                tooltip = T("You can create a new item by clicking link '%s'.") % ADD_ITEM
                ),
            )

        # Configuration
        configure(tablename,
                  main = "code",
                  extra = "description",
                  onaccept = self.budget_item_onaccept,
                  orderby = "budget_item.category_type",
                  )

        # ---------------------------------------------------------------------
        # Kit<>Item Many2Many
        #
        tablename = "budget_kit_item"
        define_table(tablename,
                     budget_kit_id(),
                     budget_item_id(),
                     Field("quantity", "integer", notnull=True,
                           default = 1,
                           label = T("Quantity"),
                           requires = IS_NOT_EMPTY(),
                           ),
                     *s3_meta_fields())

        configure(tablename,
                  onaccept = self.budget_kit_item_onaccept,
                  ondelete = self.budget_kit_item_ondelete,
                  )

        # ---------------------------------------------------------------------
        # Pass names back to global scope (s3.*)
        #
        return dict(budget_kit_id = budget_kit_id,
                    budget_item_id = budget_item_id,
                    )

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3db/budget.py/S3BudgetKitModel.model/original