from odoo import fields, models


class UploadAttachmentWizard(models.TransientModel):
    _name = 'upload.attachment.wizard'
    _description = 'Upload Attachment Wizard'

    picking_id = fields.Many2one('stock.picking', required=True)
    attachment = fields.Binary('Attachment', required=True)
    filename = fields.Char('File Name')

    def action_upload(self):
        if self.attachment:
            self.env['ir.attachment'].create({
                'name': self.filename,
                'res_model': 'stock.picking',
                'res_id': self.picking_id.id,
                'type': 'binary',
                'datas': self.attachment,
            })
