models.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models
  4. class SomeObj(models.Model):
  5. _name = 'test_access_right.some_obj'
  6. _description = 'Object For Test Access Right'
  7. val = fields.Integer()
  8. categ_id = fields.Many2one('test_access_right.obj_categ')
  9. company_id = fields.Many2one('res.company')
  10. forbidden = fields.Integer(
  11. groups='test_access_rights.test_group,!base.group_no_one,base.group_user,!base.group_public',
  12. default=5
  13. )
  14. forbidden2 = fields.Integer(groups='test_access_rights.test_group')
  15. forbidden3 = fields.Integer(groups=fields.NO_ACCESS)
  16. class Container(models.Model):
  17. _name = 'test_access_right.container'
  18. _description = 'Test Access Right Container'
  19. some_ids = fields.Many2many('test_access_right.some_obj', 'test_access_right_rel', 'container_id', 'some_id')
  20. class Parent(models.Model):
  21. _name = 'test_access_right.parent'
  22. _description = 'Object for testing related access rights'
  23. _inherits = {'test_access_right.some_obj': 'obj_id'}
  24. obj_id = fields.Many2one('test_access_right.some_obj', required=True, ondelete='restrict')
  25. class Child(models.Model):
  26. _name = 'test_access_right.child'
  27. _description = 'Object for testing company ir rule'
  28. parent_id = fields.Many2one('test_access_right.some_obj')
  29. class ObjCateg(models.Model):
  30. _name = 'test_access_right.obj_categ'
  31. _description = "Context dependent searchable model"
  32. name = fields.Char(required=True)
  33. def search(self, args, **kwargs):
  34. if self.env.context.get('only_media'):
  35. args += [('name', '=', 'Media')]
  36. return super(ObjCateg, self).search(args, **kwargs)
  37. class FakeTicket(models.Model):
  38. """We want to simulate a record that would typically be accessed by a portal user,
  39. with a relational field to records that could not be accessed by a portal user.
  40. """
  41. _name = 'test_access_right.ticket'
  42. _description = 'Fake ticket For Test Access Right'
  43. name = fields.Char()
  44. message_partner_ids = fields.Many2many(comodel_name='res.partner')
  45. class ResPartner(models.Model):
  46. """User inherits partner, so we are implicitly adding these fields to User
  47. This essentially reproduces the (sad) situation introduced by account.
  48. """
  49. _name = 'res.partner'
  50. _inherit = 'res.partner'
  51. currency_id = fields.Many2one('res.currency', compute='_get_company_currency', readonly=True)
  52. monetary = fields.Monetary() # implicitly depends on currency_id as currency_field
  53. def _get_company_currency(self):
  54. for partner in self:
  55. partner.currency_id = partner.sudo().company_id.currency_id