def model(self):

        T = current.T
        db = current.db
        configure = self.configure
        define_table = self.define_table
        super_link = self.super_link
        messages = current.messages
        UNKNOWN_OPT = messages.UNKNOWN_OPT

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

        # ---------------------------------------------------------------------
        # Budget Entity (super-entity for resources that can have a budget)
        entity_types = Storage(#event_incident = T("Incident"),
                               #org_organisation = T("Organization"),
                               #org_site = T("Facility"),
                               #pr_group = T("Team"),
                               project_project = T("Project"),
                               )

        tablename = "budget_entity"
        self.super_entity(tablename, "budget_entity_id", entity_types)

        self.add_components(tablename,
                            # Budget Details
                            budget_budget = "budget_entity_id",
                            # Allocations
                            budget_allocation = "budget_entity_id",
                            # Monitoring
                            budget_monitoring = "budget_entity_id",
                            # Staff
                            budget_staff = {"link": "budget_budget_staff",
                                            "joinby": "budget_entity_id",
                                            "key": "staff_id",
                                            "actuate": "link",
                                            },
                            # Bundles
                            budget_bundle = {"link": "budget_budget_bundle",
                                             "joinby": "budget_entity_id",
                                             "key": "bundle_id",
                                             "actuate": "link",
                                             },
                            )

        # ---------------------------------------------------------------------
        # Budgets
        #
        status_opts = {1: T("Draft"),
                       2: T("Approved"),
                       3: T("Rejected"),
                       }

        # Currently only Monthly is supported
        monitoring_opts = {1: messages["NONE"],
                           #2: T("Annually"),
                           3: T("Monthly"),
                           #3: T("Weekly"),
                           #3: T("Daily"),
                           }

        tablename = "budget_budget"
        define_table(tablename,
                     # This is a component, so needs to be a super_link
                     # - can't override field name, ondelete or requires
                     super_link("budget_entity_id", "budget_entity"),
                     Field("name", length=128, notnull=True, unique=True,
                           label = T("Name"),
                           #requires = [IS_NOT_EMPTY(),
                           #            IS_NOT_ONE_OF(db, "%s.name" % tablename),
                           #            ],
                           ),
                     Field("description",
                           label = T("Description"),
                           ),
                     Field("total_onetime_costs", "double",
                           default = 0.0,
                           label = T("Total One-time Costs"),
                           writable = False,
                           ),
                     Field("total_recurring_costs", "double",
                           default = 0.0,
                           label = T("Total Recurring Costs"),
                           writable = False,
                           ),
                     Field("total_budget", "double",
                           default = 0.0,
                           label = T("Total Budget"),
                           ),
                     s3_currency(required = True),
                     Field("monitoring_frequency", "integer",
                           default = 1,
                           label = T("Monitoring Frequency"),
                           represent = lambda opt: \
                            monitoring_opts.get(opt, UNKNOWN_OPT),
                           requires = IS_IN_SET(monitoring_opts),
                           ),
                     Field("status", "integer",
                           default = 1,
                           represent = lambda opt: \
                            status_opts.get(opt, UNKNOWN_OPT),
                           requires = IS_IN_SET(status_opts),
                           ),
                     s3_comments(),
                     *s3_meta_fields()
                     )

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

        # Represent
        #budget_budget_represent = S3Represent(lookup=tablename, show_link=True)

        # Reusable Field
        #budget_budget_id = S3ReusableField("budget_id", "reference %s" % tablename,
        #    label = T("Budget"),
        #    ondelete = "CASCADE",
        #    represent = budget_budget_represent,
        #    requires = IS_ONE_OF(db, "budget_budget.id",
        #                         budget_budget_represent,
        #                         ),
        #    comment = S3PopupLink(
        #        c = "budget",
        #        f = "budget",
        #        label = ADD_BUDGET,
        #        title = T("Budget"),
        #        tooltip = T("You can create a new budget by clicking link '%s'.") % ADD_BUDGET
        #        ),
        #    )

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

        # ---------------------------------------------------------------------
        # Parameters (currently unused)
        #
        # @todo: take into account when calculating totals
        #
        tablename = "budget_parameter"
        define_table(tablename,
                     Field("shipping", "double", notnull=True,
                           default = 15.0,
                           label = T("Shipping cost"),
                           requires = IS_FLOAT_IN_RANGE(0, 100),
                           ),
                     Field("logistics", "double", notnull=True,
                           default = 0.0,
                           label = T("Procurement & Logistics cost"),
                           requires = IS_FLOAT_IN_RANGE(0, 100),
                           ),
                     Field("admin", "double", notnull=True,
                           default = 0.0,
                           label = T("Administrative support cost"),
                           requires = IS_FLOAT_IN_RANGE(0, 100),
                           ),
                     Field("indirect", "double", notnull=True,
                           default = 7.0,
                           label = T("Indirect support cost HQ"),
                           requires = IS_FLOAT_IN_RANGE(0, 100),
                           ),
                     *s3_meta_fields())

        # CRUD Strings
        crud_strings[tablename] = Storage(
            title_update = T("Edit Parameters"),
            title_display = T("Parameters")
        )

        # ---------------------------------------------------------------------
        # Locations
        #
        tablename = "budget_location"
        define_table(tablename,
                     Field("code", length=3, 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("subsistence", "double",
                           default = 0.0,
                           label = T("Subsistence Cost"),
                           # UN terminology:
                           #label = "DSA",
                           ),
                     Field("hazard_pay", "double",
                           default = 0.0,
                           label = T("Hazard Pay"),
                           ),
                     s3_comments(),
                     *s3_meta_fields())

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

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

        # Reusable Field
        budget_location_id = S3ReusableField("location_id", "reference %s" % tablename,
            label = T("Location"),
            ondelete = "CASCADE",
            represent = budget_location_represent,
            requires = IS_ONE_OF(db, "budget_location.id",
                                 budget_location_represent,
                                 ),
            comment = S3PopupLink(
                c = "budget",
                f = "location",
                label = ADD_LOCATION,
                title = T("Location"),
                tooltip = T("You can create a new location by clicking link '%s'.") % ADD_LOCATION
                ),
            )

        # Configuration
        configure(tablename,
                  update_onaccept = self.budget_location_onaccept,
                  )

        # ---------------------------------------------------------------------
        # Staff Types
        #
        tablename = "budget_staff"
        define_table(tablename,
                     Field("name", length=128, notnull=True, unique=True,
                           label = T("Name"),
                           #requires = [IS_NOT_EMPTY(),
                           #            IS_NOT_ONE_OF(db, "%s.name" % tablename),
                           #            ],
                           ),
                     Field("grade", notnull=True,
                           label = T("Grade"),
                           requires = IS_NOT_EMPTY(),
                           ),
                     Field("salary", "integer", notnull=True,
                           label = T("Monthly Salary"),
                           requires = IS_NOT_EMPTY(),
                           ),
                     s3_currency(),
                     Field("travel", "integer",
                           default = 0,
                           label = T("Travel Cost"),
                           ),
                     # Shouldn't be grade-dependent, but purely
                     # location-dependent
                     #Field("subsistence", "double",
                     #      default=0.00,
                     #     ),
                     # Location-dependent
                     #Field("hazard_pay", "double",
                     #      default=0.00,
                     #     ),
                     s3_comments(),
                     *s3_meta_fields())

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

        # Represent
        budget_staff_represent = S3Represent(lookup=tablename,
                                             fields=["name"])

        # Reusable Field
        budget_staff_id = S3ReusableField("staff_id", "reference %s" % tablename,
            label = T("Staff"),
            ondelete = "RESTRICT",
            represent = budget_staff_represent,
            requires = IS_ONE_OF(db, "budget_staff.id",
                                 budget_staff_represent,
                                 ),
            comment = S3PopupLink(
                c = "budget",
                f = "staff",
                label = ADD_STAFF_TYPE,
                title = T("Staff"),
                tooltip = ADD_STAFF_TYPE % T("You can create new staff by clicking link '%s'.")
                ),
            )

        # Configuration
        configure(tablename,
                  update_onaccept = self.budget_staff_onaccept,
                  )

        # ---------------------------------------------------------------------
        # Budget<>Staff Many2Many
        #
        tablename = "budget_budget_staff"
        define_table(tablename,
                     # This is a component, so needs to be a super_link
                     # - can't override field name, ondelete or requires
                     super_link("budget_entity_id", "budget_entity"),
                     budget_location_id(),
                     budget_staff_id(),
                     Field("quantity", "integer", notnull=True,
                           default = 1,
                           label = T("Quantity"),
                           requires = IS_NOT_EMPTY(),
                           ),
                     Field("months", "integer", notnull=True,
                           default = 3,
                           label = T("Months"),
                           requires = IS_NOT_EMPTY(),
                           ),
                     *s3_meta_fields())

        # Configuration
        configure(tablename,
                  onaccept = self.budget_budget_staff_onaccept,
                  ondelete = self.budget_budget_staff_ondelete,
                  )

        # ---------------------------------------------------------------------
        # Pass names back to global scope (s3.*)
        #
        return dict(#budget_budget_id = budget_budget_id,
                    budget_location_id = budget_location_id,
                    budget_staff_id=budget_staff_id,
                    )

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3db/budget.py/S3BudgetModel.model/swapped operands of `%`