Newer
Older
# © 2021 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
class ScopAlfrescoAdhesionPartner(models.Model):
_inherit = 'res.partner'
log_missing_docs = fields.Text('Documents manquants')
# ------------------------------------------------------
# Actions
# ------------------------------------------------------
# Email
def get_recipients_adhesion(self):
"""
Get recipients for email adhesion
:return:
"""
recipient_list = list()
if self.director_ids:
for director in self.director_ids:
if director.email:
recipient_list.append(director.id)
if not recipient_list and self.email:
recipient_list.append(self.id)
recipient_ids = self.browse(recipient_list)
res = ','.join(map(lambda x: str(x), recipient_ids.ids))
return res
@api.multi
def send_mail_adhesion(self):
"""
Send mail adhésion to coop
:return:
"""
self.ensure_one()
template_id = self.env.ref(
'cgscop_adhesion_alfodoo.email_template_adhesion')
ir_model_data = self.env['ir.model.data']
try:
compose_form_id = ir_model_data.get_object_reference(
'mail', 'email_compose_message_wizard_form')[1]
except ValueError:
compose_form_id = False
ctx = {
'default_model': 'res.partner',
'default_res_id': self.id,
'default_use_template': True,
'default_subtype_id': self.env.ref(
'cgscop_adhesion_alfodoo.mail_message_subtype_adhesion').id,
'default_composition_mode': 'comment',
}
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form_id, 'form')],
'view_id': compose_form_id,
'target': 'new',
'context': ctx,
}
def check_docs_adhesion(self):
compulsory_docs = self.get_compulsory_docs()
missing_docs = self.check_compulsory_docs()
html = str()
for doc in compulsory_docs:
html += "<input type='checkbox'"
if doc.name not in missing_docs:
html += "checked"
html += "/> " + doc.name + "<br/>"
local_tz = timezone('Europe/Paris')
utc_tz = timezone('UTC')
html += "<hr/>Vérifié le " + '<strong>' + utc_tz.localize(
fields.Datetime.now()).astimezone(local_tz).strftime(
"%d/%m/%Y à %-H:%M") + \
'</strong>'
self.log_missing_docs = html
# ------------------------------------------------------
# Business method
# ------------------------------------------------------
def get_compulsory_docs(self):
return self.env['scop.adhesion.file'].search([
('coop_type_id', '=', self.cooperative_form_id.id),
('is_compulsory', '=', True)
])
# ------------------------------------------------------
# Override parent
# ------------------------------------------------------
@api.multi
def scop_valid_cg_button(self):
"""
Inherit button to send mail
"""
super(ScopAlfrescoAdhesionPartner, self).scop_valid_cg_button()

jordan
committed
Inherit function to push files on Alfresco :
- Facture d'adhésion
- Courrier d'adhésion
res = super(ScopAlfrescoAdhesionPartner, self).scop_valid_cg()
if not self.partner_cmis_folder:
folder_coop = self.create_cmis_folder()
folder_coop = self.partner_cmis_folder
# Create & store Facture d'adhésion
invoice_file = self.env.ref('account.account_invoices'). \

jordan
committed
render_qweb_pdf(self.invoice_adhesion_id.id)[0]
invoice_name = 'Facture d\'Adhésion'
self.push_alfresco_file(
file=invoice_file,
'cmis:objectTypeId': 'D:crm:document',
'cmis:secondaryObjectTypeIds': [
'P:crm:organisme', 'P:cm:titled'],
'crm:type': 'FAD',
'crm:contexte': 'STD',
'crm:annee': str(fields.Datetime.now().year)
})
# Create & store Courrier adhésion
report_adhesion = self.env.ref(
'cgscop_adhesion.cgscop_adhesion_report'). \
render_qweb_pdf(self.id)[0]
courrier_name = 'Courrier d\'Adhésion'
self.push_alfresco_file(
file=report_adhesion,
'cmis:objectTypeId': 'D:crm:document',
'cmis:secondaryObjectTypeIds': [
'P:crm:organisme', 'P:cm:titled'],
'crm:contexte': 'STD',
'crm:annee': str(fields.Datetime.now().year)
})
@api.multi
def check_compulsory_docs(self):
"""
Override function to check docs with cmis query
:return:
"""
errors = list()
compulsory_docs = self.get_compulsory_docs()
loaded_docs = self.env['scop.adhesion.file'].\
compulsory_doc_cmis_query(self)
compulsory_docs_list = compulsory_docs.mapped(lambda d: {'name': d.name, 'metadata': d.type_doc})
loaded_docs_list = list(map(lambda d: d.properties.get('crm:type'), loaded_docs))
for mandatory_doc in compulsory_docs_list:
if mandatory_doc.get('metadata') not in loaded_docs_list:
errors.append(mandatory_doc.get('name'))