Exemplo n.º 1
0
class User(models.Model):
    _name = "base.user"

    name = fields.Char(required=True, max_length=255)
    email = fields.Char(unique=True)
    password = fields.Char(exclude=True,
                           required=True,
                           setter="generate_password")
    group_ids = fields.Many2many("base.group",
                                 relation="base.user.group.rel",
                                 field_a="user_oid",
                                 field_b="group_oid")

    def say_my_name(self):
        for rec in self:
            print("Hi, my name is {}!".format(rec.name))
        return

    def say_our_names(self):
        names = [rec.name for rec in self]
        print("Hi, we're {}".format(", ".join(names)))
        return

    def check_password(self, plain_password):
        self.ensure_one()
        return check_password_hash(self.password, plain_password)

    def generate_password(self, plain_password):
        return generate_password_hash(plain_password)
Exemplo n.º 2
0
class tModel(models.Model):
    _name = "test.load.model"

    name = fields.Char()
    age = fields.Integer()
    boolean = fields.Boolean()
    manytoone_id = fields.Many2one("test.load.comodel")
    onetomany_ids = fields.One2many("test.load.comodel", "inverse_id")
    manytomany_ids = fields.Many2many(
        "test.load.comodel", relation="test.load.comodel.rel", field_a="a_oid", field_b="b_oid")
Exemplo n.º 3
0
class tModel(Model):
    _name = "TestModel"

    char_max_req = fields.Char(max_length=10, required=True)
    char_with_default = fields.Char(default="Default")
    integer = fields.Integer()
    selection = fields.Selection(choices=["a", "b", "c"])
    m2o = fields.Many2one("TestCoModel")
    m2m = fields.Many2many("TestTagModel",
                           relation="test.model.tag.rel",
                           field_a="a_oid",
                           field_b="b_oid")
    boolean = fields.Boolean()
    date_time = fields.DateTime()
Exemplo n.º 4
0
class DocumentLevelSecurityRule(models.Model):
    _name = "base.dls"

    name = fields.Char(required=True)
    model = fields.Char(required=True)
    query = fields.Char(required=True)
    group_ids = fields.Many2many("base.group",
                                 relation="base.group.dls.rel",
                                 field_a="dls_oid",
                                 field_b="group_oid")
    on_read = fields.Boolean(required=True, default=True)
    on_write = fields.Boolean(requried=True, default=True)
    on_create = fields.Boolean(required=True, default=True)
    on_unlink = fields.Boolean(required=True, default=True)
Exemplo n.º 5
0
class tModel(models.Model):
    _name = "test.models.model"

    name = fields.Char()
    country = fields.Char(default="Argentina")
    age = fields.Integer()
    boolean = fields.Boolean()
    cascade_id = fields.Many2one("test.models.comodel", ondelete="CASCADE")
    restrict_id = fields.Many2one("test.models.comodel", ondelete="RESTRICT")
    setnull_id = fields.Many2one("test.models.comodel", ondelete="SET NULL")
    onetomany_ids = fields.One2many("test.models.comodel", "inverse_id")
    manytomany_ids = fields.Many2many("test.models.comodel",
                                      relation="test.model.comodel.rel",
                                      field_a="a_oid",
                                      field_b="b_oid")
Exemplo n.º 6
0
class Group(models.Model):
    _name = "base.group"

    name = fields.Char(required=True, max_length=255)
    acl_ids = fields.One2many("base.acl", inversed_by="group_id")
    dls_ids = fields.Many2many("base.dls", relation="base.group.dls.rel", field_a="group_oid", field_b="dls_oid")