Newer
Older
# © 2021 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, fields, models
from odoo.exceptions import UserError
_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
def send_mail_adhesion(self):
"""
Send mail adhésion to coop
:return:
"""
self.ensure_one()
template_id = self.env.ref("cgscop_adhesion.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_template_id": template_id.id,
"default_subtype_id": self.env.ref(
"cgscop_adhesion_alfodoo.mail_message_subtype_adhesion"
).id,
"default_composition_mode": "comment",
"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, type_process):
domain = [
("coop_type_id", "=", self.cooperative_form_id.id),
("is_compulsory", "=", True),
("type_process", "=", type_process),
return self.env["scop.adhesion.file"].search(domain)
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
def scop_check_docs(self, type_process, error_type=""):
"""
Return error message for mandatory documents
:param str type_process: scop.adhesion.file type_process
:param str error_type: scop.adhesion.file type_process
"""
errors = str()
compulsory_docs = self.get_compulsory_docs(type_process)
loaded_docs = self.compulsory_doc_cmis_query()
errors_complete_docs = self.check_compulsory_docs(
compulsory_docs, loaded_docs)
if errors_complete_docs:
errors_str = str()
for error in errors_complete_docs:
errors_str += "<li>" + error + "</li>"
errors += (
"<hr/><strong>Documents manquants :</strong><ul>" + errors_str + "</ul>"
)
# Si des erreurs remplir les logs avec la liste des documents manquants
if errors:
local_tz = timezone("Europe/Paris")
utc_tz = timezone("UTC")
log_date = utc_tz.localize(
fields.Datetime.now()).astimezone(local_tz).strftime("%d/%m/%Y %-H:%M")
self.list_logs = "<strong>%s</strong> %s %s" % (
log_date, error_type, errors
)
else:
self.list_logs = False
def check_compulsory_docs(self, compulsory_docs, loaded_docs):
"""
Override function to check docs with cmis query
:param obj compulsory_docs: scop.adhesion.file object
:param list loaded_docs: cmis query response
@returns list: list of missing mandatory documents
"""
errors = list()
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"))
return errors
# ------------------------------------------------------
# Override parent
# ------------------------------------------------------
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")._render_qweb_pdf(
self.invoice_adhesion_id.id
)[0]
invoice_name = "Facture d'Adhésion"
self.push_alfresco_file(
file=invoice_file,
"cm:title": invoice_name,
"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
"cgscop_adhesion.cgscop_adhesion_report"
)._render_qweb_pdf(self.id)[0]
courrier_name = "Courrier d'Adhésion"
self.push_alfresco_file(
file=report_adhesion,
"cm:title": courrier_name,
"cmis:objectTypeId": "D:crm:document",
"cmis:secondaryObjectTypeIds": [
"P:crm:organisme",
"P:cm:titled",
],
"crm:type": "CAD",
"crm:contexte": "STD",
"crm:annee": str(fields.Datetime.now().year),
},
)
def scop_suivi_adhesion(self):
"""
Inherit parent to check documents
"""
# vérification des documents obligatoires
self.scop_check_docs("project", "Impossible de créer la coopérative")
return super(ScopAlfrescoAdhesionPartner, self).scop_suivi_adhesion()
def scop_sumbit_cg(self):
"""
Inherit parent to check documents
"""
res = super(ScopAlfrescoAdhesionPartner, self).scop_sumbit_cg()
# vérification des documents obligatoires
self.scop_check_docs(
"adhesion", "Impossible de transmettre le dossier d'adhésion"
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# ------------------------------------------------------
# Alfresco method
# ------------------------------------------------------
def compulsory_doc_cmis_query(self):
self.ensure_one()
backend = self.env["cmis.backend"].search([])
backend.ensure_one()
cmis_client = backend.get_cmis_client()
query = (
"""
SELECT * FROM crm:document as d
JOIN crm:organisme as o ON d.cmis:objectId = o.cmis:objectId
WHERE o.crm:id = '%s'"""
% self.id
)
try:
doc = cmis_client.getDefaultRepository().query(query)
result = doc.getResults()
return result
except Exception as e:
raise UserError(
_(
"Impossible de vérifier les documents d'adhésion"
" dans Alfresco : %s"
)
% e
)