Skip to content
Snippets Groups Projects
add_file_wizard.py 2.27 KiB
Newer Older
  • Learn to ignore specific revisions
  • # © 2019 Le Filament (<http://www.le-filament.com>)
    # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
    
    
    Benjamin's avatar
    Benjamin committed
    import mimetypes
    
    
    from odoo import api, fields, models
    
    Benjamin's avatar
    Benjamin committed
    from odoo.tools.mimetypes import guess_mimetype
    
    
    
    class AddFileWizard(models.TransientModel):
    
    Benjamin's avatar
    Benjamin committed
        """ Wizard d'ajout de fichier dans la GED
    
        Récupère automatiquement depuis Alfresco les valeurs de periode,
        type et validité ainsi que l'organisme associé
        """
    
        _name = 'add.file.wizard'
        _inherit = 'connector.alfresco'
        _description = "Ajout de fichier dans Alfresco"
    
        # Default functions
        def _get_selection(self, value):
            file_type = self.alfresco_list_type()[value]
            select_type = []
            for type in file_type:
                select_type.append(
                    (type, type))
            return select_type
    
        @api.model
        def _get_type(self):
            return self._get_selection('type')
    
        @api.model
        def _get_periode(self):
            return self._get_selection('periode')
    
        @api.model
        def _get_validite(self):
            return self._get_selection('validite')
    
        @api.model
        def _default_partner_id(self):
            return self.env.context.get('active_id')
    
        type = fields.Selection(selection=_get_type, string='Type')
        periode = fields.Selection(selection=_get_periode, string='Période')
        validite = fields.Selection(selection=_get_validite, string='Validité')
        file = fields.Binary('Fichier')
        filename = fields.Char('Nom')
        partner_id = fields.Many2one(
            comodel_name='res.partner',
            string='Organisme',
            default=_default_partner_id,)
    
        @api.multi
        def add_file(self):
    
    Benjamin's avatar
    Benjamin committed
            """ Ajoute un fichier sur la GED Alfresco
    
            @return: fonction get_partner_files() de res.partner
            """
    
    Benjamin's avatar
    Benjamin committed
            content_type = mimetypes.guess_type(self.filename)
            if content_type[0]:
                content_type = content_type[0]
            else:
                content_type = guess_mimetype(self.file)
    
            self.alfresco_upload(
                raisonSociale=self.partner_id.name,
                type=self.type,
                periode=self.periode,
                validite=self.validite,
                filename=self.filename,
    
    Benjamin's avatar
    Benjamin committed
                mimetype=content_type,
    
                doc=self.file.decode('utf-8'))
    
    
    Benjamin's avatar
    Benjamin committed
            return self.partner_id.get_partner_files()