mrp_document.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 MrpDocument(models.Model):
  5. """ Extension of ir.attachment only used in MRP to handle archivage
  6. and basic versioning.
  7. """
  8. _name = 'mrp.document'
  9. _description = "Production Document"
  10. _inherits = {
  11. 'ir.attachment': 'ir_attachment_id',
  12. }
  13. _order = "priority desc, id desc"
  14. def copy(self, default=None):
  15. ir_default = default
  16. if ir_default:
  17. ir_fields = list(self.env['ir.attachment']._fields)
  18. ir_default = {field : default[field] for field in default.keys() if field in ir_fields}
  19. new_attach = self.ir_attachment_id.with_context(no_document=True).copy(ir_default)
  20. return super().copy(dict(default, ir_attachment_id=new_attach.id))
  21. ir_attachment_id = fields.Many2one('ir.attachment', string='Related attachment', required=True, ondelete='cascade')
  22. active = fields.Boolean('Active', default=True)
  23. priority = fields.Selection([
  24. ('0', 'Normal'),
  25. ('1', 'Low'),
  26. ('2', 'High'),
  27. ('3', 'Very High')], string="Priority") # used to order
  28. def unlink(self):
  29. self.mapped('ir_attachment_id').unlink()
  30. return super(MrpDocument, self).unlink()