Skip to content
Extraits de code Groupes Projets
Valider be5731aa rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[add] load_contribution function

parent e1155034
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# © 2021 Le Filament (<http://www.le-filament.com>) # © 2021 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models, api, registry from odoo import models, api
from odoo.exceptions import UserError
import logging
_logger = logging.getLogger(__name__)
class ScopBordereau(models.Model): class ScopBordereau(models.Model):
_name = 'scop.bordereau' _name = 'scop.bordereau'
_inherit = ['scop.bordereau', 'cgscop.alfresco'] _inherit = ['scop.bordereau', 'cgscop.alfresco']
is_loaded_alfresco = fields.Boolean("Bordereau chargé sur Aldresco", default=False)
# ------------------------------------------------------
# Onchange function
# ------------------------------------------------------
@api.onchange('state')
def _onchange_state(self):
if self.state == 'new':
self.is_loaded_alfresco = False
# ------------------------------------------------------ # ------------------------------------------------------
# Override parent # Commmon function
# ------------------------------------------------------ # ------------------------------------------------------
def validate_bordereau(self): def upload_contribution_file(self):
bdx = super(ScopBordereau, self).validate_bordereau()
try: try:
name = "Appel de Cotisation " + str(self.year) + " - " + self.name name = "Appel de Cotisation " + str(self.year) + " - " + self.name
if self.version > 1: if self.version > 1:
name += "-" + str(self.version) + ".pdf" name += "-" + str(self.version) + ".pdf"
else:
name += ".pdf"
print(name)
report_bdx = self.env.ref( report_bdx = self.env.ref(
'cgscop_cotisation_cg.cgscop_bordereau_report').render_qweb_pdf(self.id)[0] 'cgscop_cotisation_cg.cgscop_bordereau_report').render_qweb_pdf(self.id)[0]
self.push_alfresco_file( node_ref = self.push_alfresco_file(
file=report_bdx, file=report_bdx,
name=name, name=name,
folder=self.partner_id.partner_cmis_folder, folder=self.partner_id.partner_cmis_folder,
metadata={ metadata={
'cm:title': name,
'cmis:objectTypeId': 'D:crm:document', 'cmis:objectTypeId': 'D:crm:document',
'cmis:secondaryObjectTypeIds': [ 'cmis:secondaryObjectTypeIds': [
'P:crm:organisme'], 'P:crm:organisme', 'P:cm:titled'],
'crm:type': 'BCC', 'crm:type': 'APC',
'crm:contexte': 'STD', 'crm:contexte': 'COT',
'crm:annee': str(self.year) 'crm:annee': str(self.year)
}) })
except Exception as e: except Exception as e:
raise e raise e
return node_ref
# ------------------------------------------------------
# Override parent
# ------------------------------------------------------
def validate_bordereau(self):
try:
bdx = super(ScopBordereau, self).validate_bordereau()
self.upload_contribution_file()
except Exception as e:
raise e
return bdx return bdx
# ------------------------------------------------------
# To Delete after upload
# ------------------------------------------------------
def load_contribution(self, states=[], year=None):
domain = []
params = ''
if states:
domain.append(('state', 'in', states))
params += ' | ' + ','.join(states)
if year:
domain.append(('year', '=', year))
params += ' | ' + str(year)
bdx_ids = self.search(domain)
# batch queue creation
batch_name = "Chargement PDF cotisations " + params
batch = self.env['queue.job.batch'].get_new_batch(batch_name)
for bdx in bdx_ids:
bdx.with_context(job_batch=batch).with_delay().upload_contribution_file()
batch.enqueue()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter