From e759e02ff3664da0279c652c3287f92432cc906d Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 22 Mar 2022 10:48:05 +0000 Subject: [PATCH] [FIX] mrp: mrp document not displayed on product Steps to reproduce the issue: - create product P - create a Engineering Change ders ECO in PLM app - attach documents to ECO and apply changements Bug: - go to the product, try to open uploaded documents. they are not found This bug happened since odoo/odoo@114b71f opw:2762448 closes odoo/odoo#87176 X-original-commit: 779a0df6732db51af652d6c282490187d11244a1 Signed-off-by: Simon Goffin Co-authored-by: mart-e --- addons/mrp/models/mrp_document.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/mrp/models/mrp_document.py b/addons/mrp/models/mrp_document.py index f49602d84ed..c9323620756 100644 --- a/addons/mrp/models/mrp_document.py +++ b/addons/mrp/models/mrp_document.py @@ -15,6 +15,14 @@ class MrpDocument(models.Model): } _order = "priority desc, id desc" + def copy(self, default=None): + ir_default = default + if ir_default: + ir_fields = list(self.env['ir.attachment']._fields) + ir_default = {field : default[field] for field in default.keys() if field in ir_fields} + new_attach = self.ir_attachment_id.copy(ir_default) + return super().copy(dict(default, ir_attachment_id=new_attach.id)) + ir_attachment_id = fields.Many2one('ir.attachment', string='Related attachment', required=True, ondelete='cascade') active = fields.Boolean('Active', default=True) priority = fields.Selection([