You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.3 KiB

  1. # © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models, _
  4. class MassObject(models.Model):
  5. _name = "mass.object"
  6. _description = "Mass Editing Object"
  7. name = fields.Char('Name', required=True, index=1)
  8. model_id = fields.Many2one('ir.model', 'Model', required=True,
  9. ondelete="cascade",
  10. help="Model is used for Selecting Fields. "
  11. "This is editable until Sidebar menu "
  12. "is not created.")
  13. field_ids = fields.Many2many('ir.model.fields', 'mass_field_rel',
  14. 'mass_id', 'field_id', 'Fields')
  15. ref_ir_act_window_id = fields.Many2one('ir.actions.act_window',
  16. 'Sidebar action',
  17. readonly=True,
  18. help="Sidebar action to make this "
  19. "template available on "
  20. "records of the related "
  21. "document model.")
  22. model_list = fields.Char('Model List')
  23. _sql_constraints = [
  24. ('name_uniq', 'unique (name)', 'Name must be unique!'),
  25. ]
  26. @api.onchange('model_id')
  27. def _onchange_model_id(self):
  28. self.field_ids = [(6, 0, [])]
  29. model_list = []
  30. if self.model_id:
  31. model_obj = self.env['ir.model']
  32. model_list = [self.model_id.id]
  33. active_model_obj = self.env[self.model_id.model]
  34. if active_model_obj._inherits:
  35. keys = list(active_model_obj._inherits.keys())
  36. inherits_model_list = model_obj.search([('model', 'in', keys)])
  37. model_list.extend((inherits_model_list and
  38. inherits_model_list.ids or []))
  39. self.model_list = model_list
  40. @api.multi
  41. def create_action(self):
  42. self.ensure_one()
  43. vals = {}
  44. action_obj = self.env['ir.actions.act_window']
  45. src_obj = self.model_id.model
  46. button_name = _('Mass Editing (%s)') % self.name
  47. vals['ref_ir_act_window_id'] = action_obj.create({
  48. 'name': button_name,
  49. 'type': 'ir.actions.act_window',
  50. 'res_model': 'mass.editing.wizard',
  51. 'src_model': src_obj,
  52. 'view_type': 'form',
  53. 'context': "{'mass_editing_object' : %d}" % (self.id),
  54. 'view_mode': 'form, tree',
  55. 'target': 'new',
  56. 'binding_model_id': self.model_id.id,
  57. 'binding_type': 'action',
  58. 'multi': True,
  59. }).id
  60. self.write(vals)
  61. return True
  62. @api.multi
  63. def unlink_action(self):
  64. self.mapped('ref_ir_act_window_id').unlink()
  65. return True
  66. @api.multi
  67. def unlink(self):
  68. self.unlink_action()
  69. return super(MassObject, self).unlink()
  70. @api.returns('self', lambda value: value.id)
  71. def copy(self, default=None):
  72. if default is None:
  73. default = {}
  74. default.update({'name': _("%s (copy)" % self.name), 'field_ids': []})
  75. return super(MassObject, self).copy(default)