Skip to content

Commit

Permalink
Merge pull request #1274 from CompassionCH/devel
Browse files Browse the repository at this point in the history
Devel to prod
  • Loading branch information
ecino committed Jan 24, 2020
2 parents 8d7a06a + 6856676 commit 5b43fe4
Show file tree
Hide file tree
Showing 37 changed files with 752 additions and 183 deletions.
26 changes: 24 additions & 2 deletions cms_form_compassion/models/cms_form.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from odoo import models
from odoo import models, _
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
import logging
import traceback
Expand All @@ -9,9 +9,30 @@
_logger = logging.getLogger(__name__)


def _form_validate_date_fields(value, **req_values):
try:
if value:
datetime.strptime(value, '%d.%m.%Y')
except ValueError:
return "date", _('Dates should follow the format "dd.mm.yyyy"')
return 0, 0


class CMSForm(models.AbstractModel):
_inherit = 'cms.form'

#######################################################################
# Field validation #
#######################################################################

_form_validators = {
'date': _form_validate_date_fields
}

#######################################################################
# Errors logging #
#######################################################################

def form_process(self, **kw):
"""Catch, log and propagate the error thrown during the form processing"""
try:
Expand Down Expand Up @@ -69,11 +90,12 @@ def truncate_strings(params, length=50):
'line': "",
'func': "",
'context_data': json.dumps({
# Addition data for debugging
# Additional data for debugging
'form_name': self._name,
'error_count': err_count,
'error_message': str(err),
'error_type': err_class,
'user_id': self.env.uid,
'user_input': user_input,
}, skipkeys=True, indent=4, ensure_ascii=True, sort_keys=True),
}
Expand Down
1 change: 1 addition & 0 deletions cms_form_compassion/models/match_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def match_create(self, partner_obj, infos, options=None):
"""Create a new partner from a selection of the given infos."""
create_infos = self.match_process_create_infos(infos, options)
create_infos.setdefault('lang', self.env.lang)
create_infos.setdefault('tz', 'Europe/Zurich')
return partner_obj.create(create_infos)

@api.model
Expand Down
203 changes: 108 additions & 95 deletions crm_compassion/models/interaction_resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,106 +58,119 @@ def populate_resume(self, partner_id):
:param partner_id: the partner
:return: True
"""
self.search([('partner_id', '=', partner_id)]).unlink()
original_partner = self.env['res.partner'].browse(partner_id)
email_address = original_partner.email
partners_with_same_email_ids = self.env['res.partner'].search([
('email', '!=', False),
('email', '=', email_address)
]).ids

self.search([('partner_id', 'in', partners_with_same_email_ids)]).unlink()
self.env.cr.execute("""
SELECT
'Paper' as communication_type,
pcj.sent_date as communication_date,
COALESCE(p.contact_id, pcj.partner_id) AS partner_id,
NULL AS email,
COALESCE(c.name, pcj.subject) AS subject,
REGEXP_REPLACE(pcj.body_html, '<img[^>]*>', '') AS body,
'out' AS direction,
0 as phone_id,
0 as email_id,
0 as message_id,
pcj.id as paper_id,
NULL as tracking_status
FROM "partner_communication_job" as pcj
JOIN res_partner p ON pcj.partner_id = p.id
FULL OUTER JOIN partner_communication_config c
ON pcj.config_id = c.id
AND c.name != 'Default communication'
WHERE pcj.state = 'done'
AND pcj.send_mode = 'physical'
AND (p.contact_id = %s OR p.id = %s)
-- phonecalls
UNION (
SELECT
'Phone' as communication_type,
crmpc.date as communication_date,
COALESCE(p.contact_id, p.id) AS partner_id,
NULL AS email,
crmpc.name as subject,
crmpc.name as body,
CASE crmpc.direction
WHEN 'inbound' THEN 'in' ELSE 'out'
END
AS direction,
crmpc.id as phone_id,
0 as email_id,
0 as message_id,
0 as paper_id,
NULL as tracking_status
FROM "crm_phonecall" as crmpc
JOIN res_partner p ON crmpc.partner_id = p.id
WHERE (p.contact_id = %s OR p.id = %s)
)
-- outgoing e-mails
UNION (
SELECT
'Email' as communication_type,
m.date as communication_date,
COALESCE(p.contact_id, p.id) AS partner_id,
mt.recipient_address as email,
COALESCE(config.name, m.subject) as subject,
REGEXP_REPLACE(m.body, '<img[^>]*>', '') AS body,
'out' AS direction,
0 as phone_id,
mail.id as email_id,
0 as message_id,
job.id as paper_id,
COALESCE(mt.state, 'error') as tracking_status
FROM "mail_mail" as mail
JOIN mail_message m ON mail.mail_message_id = m.id
JOIN mail_mail_res_partner_rel rel
ON rel.mail_mail_id = mail.id
FULL OUTER JOIN mail_tracking_email mt ON mail.id = mt.mail_id
JOIN res_partner p ON rel.res_partner_id = p.id
FULL OUTER JOIN partner_communication_job job
ON job.email_id = mail.id
FULL OUTER JOIN partner_communication_config config
ON job.config_id = config.id
AND config.name != 'Default communication'
WHERE mail.state = ANY (ARRAY ['sent', 'received'])
AND (p.contact_id = %s OR p.id = %s)
)
-- incoming messages from partners
UNION (
SELECT
'Email' as communication_type,
m.date as communication_date,
COALESCE(p.contact_id, p.id) AS partner_id,
m.email_from as email,
m.subject as subject,
REGEXP_REPLACE(m.body, '<img[^>]*>', '') AS body,
'in' AS direction,
0 as phone_id,
0 as email_id,
m.id as message_id,
0 as paper_id,
NULL as tracking_status
FROM "mail_message" as m
JOIN res_partner p ON m.author_id = p.id
WHERE m.subject IS NOT NULL
AND m.message_type = 'email'
AND (p.contact_id = %s OR p.id = %s)
)
""", [partner_id] * 8)
SELECT
'Paper' as communication_type,
pcj.sent_date as communication_date,
COALESCE(p.contact_id, pcj.partner_id) AS partner_id,
NULL AS email,
COALESCE(c.name, pcj.subject) AS subject,
REGEXP_REPLACE(pcj.body_html, '<img[^>]*>', '') AS body,
'out' AS direction,
0 as phone_id,
0 as email_id,
0 as message_id,
pcj.id as paper_id,
NULL as tracking_status
FROM "partner_communication_job" as pcj
JOIN res_partner p ON pcj.partner_id = p.id
FULL OUTER JOIN partner_communication_config c
ON pcj.config_id = c.id
AND c.name != 'Default communication'
WHERE pcj.state = 'done'
AND pcj.send_mode = 'physical'
AND (p.contact_id = %s OR p.id = %s)
-- phonecalls
UNION (
SELECT
'Phone' as communication_type,
crmpc.date as communication_date,
COALESCE(p.contact_id, p.id) AS partner_id,
NULL AS email,
crmpc.name as subject,
crmpc.name as body,
CASE crmpc.direction
WHEN 'inbound' THEN 'in' ELSE 'out'
END
AS direction,
crmpc.id as phone_id,
0 as email_id,
0 as message_id,
0 as paper_id,
NULL as tracking_status
FROM "crm_phonecall" as crmpc
JOIN res_partner p ON crmpc.partner_id = p.id
WHERE (p.contact_id = %s OR p.id = %s)
)
-- outgoing e-mails
UNION (
SELECT
'Email' as communication_type,
m.date as communication_date,
COALESCE(p.contact_id, p.id) AS partner_id,
mt.recipient_address as email,
COALESCE(config.name, m.subject) as subject,
REGEXP_REPLACE(m.body, '<img[^>]*>', '') AS body,
'out' AS direction,
0 as phone_id,
mail.id as email_id,
0 as message_id,
job.id as paper_id,
COALESCE(mt.state, 'error') as tracking_status
FROM "mail_mail" as mail
JOIN mail_message m ON mail.mail_message_id = m.id
JOIN mail_mail_res_partner_rel rel
ON rel.mail_mail_id = mail.id
FULL OUTER JOIN mail_tracking_email mt ON mail.id = mt.mail_id
JOIN res_partner p ON rel.res_partner_id = p.id
FULL OUTER JOIN partner_communication_job job
ON job.email_id = mail.id
FULL OUTER JOIN partner_communication_config config
ON job.config_id = config.id
AND config.name != 'Default communication'
WHERE mail.state = ANY (ARRAY ['sent', 'received'])
AND (p.contact_id = ANY(%s) OR p.id = ANY(%s))
)
-- incoming messages from partners
UNION (
SELECT
'Email' as communication_type,
m.date as communication_date,
COALESCE(p.contact_id, p.id) AS partner_id,
m.email_from as email,
m.subject as subject,
REGEXP_REPLACE(m.body, '<img[^>]*>', '') AS body,
'in' AS direction,
0 as phone_id,
0 as email_id,
m.id as message_id,
0 as paper_id,
NULL as tracking_status
FROM "mail_message" as m
JOIN res_partner p ON m.author_id = p.id
WHERE m.subject IS NOT NULL
AND m.message_type = 'email'
AND (p.contact_id = ANY(%s) OR p.id = ANY(%s))
)
""", (partner_id, partner_id, partner_id, partner_id,
partners_with_same_email_ids,
partners_with_same_email_ids,
partners_with_same_email_ids,
partners_with_same_email_ids))

for row in self.env.cr.dictfetchall():
# ensure that "Example <ex@exmaple.com>" is correctly printed
row['email'] = html_sanitize(row['email'])
self.create(row)

return True

def open_object(self):
Expand Down
6 changes: 5 additions & 1 deletion crm_compassion/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ def open_interaction(self):
"""
self.ensure_one()
self.env['interaction.resume'].populate_resume(self.id)
partners_with_same_email_ids = self.env['res.partner'].search([
('email', '!=', False),
('email', '=', self.email)
]).ids
return {
'name': _('Interaction resume'),
'type': 'ir.actions.act_window',
'res_model': 'interaction.resume',
'view_type': 'form',
'view_mode': 'tree,form',
'domain': [('partner_id', '=', self.id)],
'domain': [('partner_id', 'in', self.ids + partners_with_same_email_ids)],
'target': 'current',
}

Expand Down
2 changes: 1 addition & 1 deletion crm_request/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def action_reply(self):
}

def _get_partner_alias(self, partner, email):
if partner.email != email:
if email and partner.email != email:
for partner_alias in partner.other_contact_ids:
if partner_alias.email == email:
return partner_alias
Expand Down
2 changes: 1 addition & 1 deletion firebase_connector/models/firebase_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ def send_message(self, message_title, message_body, data=None):
"Firebase ID: %s" % firebase_id)
firebase_id.unlink()
else:
raise ex
raise
return True
1 change: 1 addition & 0 deletions mobile_app_connector/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'views/firebase_notification.xml',
'views/communication_job.xml',
'views/communication_config.xml',
'views/res_partner.xml'
],
'demo': [
],
Expand Down
5 changes: 3 additions & 2 deletions mobile_app_connector/controllers/json_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, *args):
}
self.context = dict(self.session.context)
else:
raise error
raise

def _json_response(self, result=None, error=None):
odoo_result = super(MobileAppJsonRequest, self)._json_response(
Expand Down Expand Up @@ -88,4 +88,5 @@ def _handle_exception(self, exception):
'http_status': code,
'message': str(exception)
})
raise exception
# RE-Raise last error, without compromising the StackTrace
raise
4 changes: 2 additions & 2 deletions mobile_app_connector/data/tile_type_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Make a donation]]></field>
<field name="code">LE1</field>
<field name="view_order">1</field>
<field name="default_model_id" ref="model_recurring_contract"/>
<field name="default_records_filter">lambda c: c.correspondent_id == c.env.user.partner_id</field>
<field name="default_records_filter"></field>
<field name="default_title">${ctx['objects'].sudo().child_id.preferred_name}</field>
<field name="default_body"><![CDATA[% set sponsorship = ctx['objects'].sudo()
% set letters = sponsorship.sponsor_letter_ids
Expand Down Expand Up @@ -255,7 +255,7 @@ You never wrote to your sponsored child.
<field name="code">LE_T2</field>
<field name="view_order">5</field>
<field name="default_model_id" ref="model_correspondence"/>
<field name="default_records_filter">lambda c: c.direction == 'Supporter To Beneficiary' and c.letter_image</field>
<field name="default_records_filter">lambda c: c.direction == 'Supporter To Beneficiary' and (c.letter_image or not c.store_letter_image)</field>
<field name="default_title">${ctx['objects'].sudo().child_id.preferred_name}</field>
<field name="default_body">You wrote a letter on ${ctx['objects'].get_date('scanned_date')}</field>
<field name="default_action_text">Read again</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MobileCorrespondenceMapping(OnrampMapping):
'Supportergroup': None,
'supporterId': ('sponsorship_id.partner_id.id', 'res.partner'),
'pathextension': 'letter_format',
'base64string': 'letter_image'
'base64string': 'b64image'
}


Expand Down
16 changes: 11 additions & 5 deletions mobile_app_connector/models/app_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ def mobile_get_message(self, partner_id, **pagination):
return self._public_hub(**pagination)

partner = self.env['res.partner'].browse(partner_id)
# TODO For now we only display the contracts for which the sponsor
# is correspondent (to avoid viewing letters when he doesn't write)
sponsorships = (partner.contracts_correspondant +
partner.contracts_fully_managed).filtered('is_active')
unpaid = partner.contracts_fully_managed.filtered(

if partner.app_displayed_sponsorships == "all":
sponsorships = partner.sponsorship_ids
unpaid = partner.contracts_fully_managed + partner.contracts_paid
else:
sponsorships = partner.contracts_correspondant + \
partner.contracts_fully_managed
unpaid = partner.contracts_fully_managed

sponsorships = sponsorships.filtered('is_active')
unpaid = unpaid.filtered(
lambda c: not c.is_active and not c.parent_id and
(c.state in ['waiting', 'draft']))
children = sponsorships.mapped('child_id')
Expand Down
3 changes: 1 addition & 2 deletions mobile_app_connector/models/app_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ def render_tile(self, tile_data=None):
self.env.ref(module % 'tile_type_child') +\
self.env.ref(module % 'tile_type_community')
if tile.subtype_id.type_id not in no_render and \
tile.subtype_id != self.env.ref(
module % 'tile_subtype_pr1'):
tile.subtype_id != self.env.ref(module % 'tile_subtype_pr1'):
res.append(tile_json)
return res

Expand Down

0 comments on commit 5b43fe4

Please sign in to comment.