Skip to content

Commit

Permalink
Merge pull request #1532 from CompassionCH/devel
Browse files Browse the repository at this point in the history
2021-06-10 Release
  • Loading branch information
ecino authored Jun 10, 2021
2 parents 287cb3d + 028e9bf commit 6585b21
Show file tree
Hide file tree
Showing 34 changed files with 346 additions and 326 deletions.
3 changes: 3 additions & 0 deletions child_compassion/models/compassion_hold.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def create(self, vals):

@api.multi
def write(self, vals):
if "expiration_date" in vals and self.filtered(lambda h: h.expiration_date < datetime.now()):
raise UserError(_("The expiration date as been reach and thus can't be changed."))

res = super().write(vals)
notify_vals = ["primary_owner", "type", "expiration_date"]
notify = reduce(lambda prev, val: prev or val in vals, notify_vals, False)
Expand Down
1 change: 1 addition & 0 deletions child_compassion/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# from . import test_webservice
from . import test_compassion_hold
38 changes: 38 additions & 0 deletions child_compassion/tests/test_compassion_hold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
##############################################################################
#
# Copyright (C) 2021 Compassion CH (http://www.compassion.ch)
# Releasing children from poverty in Jesus' name
# @author: Jonathan Guerne <guernej@compassion.ch>
#
# The licence is in the file __manifest__.py
#
##############################################################################
import mock
from datetime import datetime
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError

from odoo.tests import tagged, TransactionCase

mock_update_hold = (
"odoo.addons.child_compassion.models.compassion_hold" ".CompassionHold.update_hold"
)


@tagged("wip_test")
class TestHold(TransactionCase):

@mock.patch(mock_update_hold)
def test_no_date_change_after_expiration(self, update_hold):
"""
Assert changing the expiration date of an already expired hold
will throw an error
"""

update_hold.return_value = True

test_hold = self.env["compassion.hold"].create({
"expiration_date": datetime.now() - relativedelta(day=1)
})

self.assertRaises(UserError, test_hold.write, {"expiration_date": datetime.now()})
1 change: 1 addition & 0 deletions cms_form_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"views/config_view.xml",
"views/ir_logging.xml",
"data/activity_data.xml",
"data/base_automation_data.xml"
],
"demo": [],
"development_status": "Stable",
Expand Down
14 changes: 14 additions & 0 deletions cms_form_compassion/data/base_automation_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>
<record id="automated_action" model="base.automation">
<field name="name">Cancel Draft Transaction after 10 min</field>
<field name="model_id" ref="model_payment_transaction"/>
<field name="trigger">on_time</field>
<field name="trg_date_range">10</field>
<field name="trg_date_range_type">minutes</field>
<field name="active" eval="False"/>
<field name="filter_domain">[("state", "=", "draft")]</field>
<field name="state">code</field>
<field name="trg_date_id" ref="payment.field_payment_transaction__create_date"></field>
<field name="code">records._set_transaction_cancel()</field>
</record>
</odoo>
4 changes: 2 additions & 2 deletions cms_form_compassion/forms/match_partner_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PartnerMatchform(models.AbstractModel):
lambda self: self.env["res.lang"].sudo().get_installed(),
"Language"
)
partner_birthdate = fields.Date("Birthdate")
partner_birthdate_date = fields.Date("Birthdate")

#######################################################################
# Inject default values in form from main object #
Expand Down Expand Up @@ -85,7 +85,7 @@ def _form_load_partner_country_id(self, fname, field, value, **req_values):
def _form_load_partner_lang(self, fname, field, value, **req_values):
return value or self._load_partner_field(fname, **req_values)

def _form_load_partner_birthdate(self, fname, field, value, **req_values):
def _form_load_partner_birthdate_date(self, fname, field, value, **req_values):
return value or self._load_partner_field(fname, **req_values)

def _load_partner_field(self, fname, **req_values):
Expand Down
2 changes: 2 additions & 0 deletions cms_form_compassion/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
from . import queue_job
from . import match_partner
from . import link_tracker
from . import invoice
from . import payment_transaction
18 changes: 18 additions & 0 deletions cms_form_compassion/models/invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
##############################################################################
#
# Copyright (C) 2021 Compassion CH (http://www.compassion.ch)
# @author: Robin Berguerand <robin.berguerand@gmail.com>
#
# The licence is in the file __manifest__.py
#
##############################################################################
from odoo import models, fields


class AccountInvoice(models.Model):
_inherit = "account.invoice"

auto_cancel_no_transaction = fields.Boolean(
default=False, help='If true, cancel the invoice if the linked payment '
'transaction is cancelled'
)
3 changes: 2 additions & 1 deletion cms_form_compassion/models/match_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _match_get_valid_create_fields(self):
"state_id",
"title",
"lang",
"birthdate",
"birthdate_date",
"church_unlinked",
"church_id",
"function",
Expand All @@ -239,6 +239,7 @@ def _match_get_valid_update_fields(self):
"state_id",
"country_id",
"state_id",
"birthdate_date",
"church_unlinked",
"church_id",
"function",
Expand Down
19 changes: 19 additions & 0 deletions cms_form_compassion/models/payment_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##############################################################################
#
# Copyright (C) 2021 Compassion CH (http://www.compassion.ch)
# @author: Robin Berguerand <robin.berguerand@gmail.com>
#
# The licence is in the file __manifest__.py
#
##############################################################################
from odoo import models, fields


class PaymentTransaction(models.Model):
_inherit = "payment.transaction"

def _set_transaction_cancel(self):
for invoice in self.invoice_ids.filtered('auto_cancel_no_transaction'):
invoice.action_invoice_cancel()
return super()._set_transaction_cancel()

27 changes: 21 additions & 6 deletions firebase_connector/controllers/firebase_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def verify_and_retrieve(registration_id, partner_id=None):
raise Unauthorized()
existing = (
request.env["firebase.registration"]
.sudo()
.search([("registration_id", "=", registration_id)])
.sudo()
.search([("registration_id", "=", registration_id)])
)

assert len(existing) < 2, "Two firebase registration with same id"
Expand All @@ -44,16 +44,31 @@ class RestController(http.Controller):
@http.route(
"/firebase/register", type="http", methods=["PUT"], auth="public", csrf=False
)
def firebase_register(self, registration_id, partner_id=None, **kwargs):
def firebase_register(self, registration_id, partner_id=None, language=None, **kwargs):
existing = verify_and_retrieve(registration_id, partner_id)
if existing:
existing.partner_id = partner_id
else:

languages_map = {
"en": "en_US",
"fr": "fr_CH",
"de": "de_DE",
"it": "it_IT",
}

partner_lang = request.env.user.partner_id.lang if partner_id else False

# get the communication language.
communication_language = partner_lang if partner_lang else languages_map.get(language, False)

existing = (
request.env["firebase.registration"]
.sudo()
.create(
{"registration_id": registration_id, "partner_id": partner_id, })
.sudo()
.create(
{"registration_id": registration_id,
"partner_id": partner_id,
"language": communication_language})
)

return str(existing.id)
Expand Down
13 changes: 12 additions & 1 deletion firebase_connector/models/firebase_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FirebaseNotification(models.Model):
string="Partner read status of the notification",
readonly=True,
)
language = fields.Selection("_get_lang")
res_model = fields.Char()
res_id = fields.Integer()
test_mode = fields.Boolean()
Expand All @@ -77,6 +78,11 @@ class FirebaseNotification(models.Model):
failed_ratio = fields.Integer(compute="_compute_statistics")
opened_ratio = fields.Integer(compute="_compute_statistics")

@api.model
def _get_lang(self):
langs = self.env["res.lang"].search([])
return [(l.code, l.name) for l in langs]

@api.onchange('stage_id')
def onchange_stage_id(self):
for notification in self:
Expand Down Expand Up @@ -142,6 +148,11 @@ def send(self, **kwargs):
[("partner_id", "=", False)]
)

# filter registration based on language
if notif.language:
registration_ids = registration_ids.filtered(
lambda reg: not reg.language or reg.language == notif.language)

kwargs.update({
"notification_id": str(notif.id),
"title": notif.title, "body": notif.body
Expand All @@ -160,7 +171,7 @@ def send(self, **kwargs):
self.env["firebase.notification.partner.read"].create([
{"partner_id": partner.id, "notification_id": notif.id}
for partner in registration_ids[i: i + split].exists()
.mapped("partner_id")
.mapped("partner_id")
])
self.env.cr.commit()
notif.sent = status_ok
Expand Down
1 change: 1 addition & 0 deletions firebase_connector/models/firebase_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class FirebaseRegistration(models.Model):
registration_id = fields.Char("Firebase Registration ID", required=True, index=True)
partner_id = fields.Many2one("res.partner", "Partner", readonly=False)
partner_name = fields.Char(related="partner_id.name", readonly=True)
language = fields.Char()

_sql_constraints = [
(
Expand Down
1 change: 1 addition & 0 deletions firebase_connector/views/firebase_notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<group>
<field name="title" attrs="{'readonly': [('sent', '=', True)]}"/>
<field name="body" attrs="{'readonly': [('sent', '=', True)]}"/>
<field name="language" attrs="{'readonly': [('sent', '=', True)]}"/>
<field name="send_date" attrs="{'readonly': [('sent', '=', True)]}"/>
<field name="send_to_logged_out_devices" attrs="{'readonly': [('sent', '=', True)]}"/>
<field name="test_mode"/>
Expand Down
2 changes: 2 additions & 0 deletions firebase_connector/views/firebase_registration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<group>
<field name="partner_id"/>
<field name="registration_id"/>
<field name="language"/>
<button class="oe_inline oe_stat_button"
string="Send Notification"
type="object"
Expand All @@ -29,6 +30,7 @@
<tree>
<field name="partner_name"/>
<field name="registration_id"/>
<field name="language"/>
</tree>
</field>
</record>
Expand Down
6 changes: 3 additions & 3 deletions gift_compassion/views/gift_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
<field name="sponsorship_id"
options="{'colors':{'draft':'blue', 'waiting':'green', 'cancelled':'grey', 'terminated':'grey', 'mandate':'red'}, 'field_color':'state'}"
attrs="{'required': [('gift_type', '!=', 'Project Gift')]}"/>
<field name="partner_id" domain="[('global_id', '!=', False)]"/>
<field name="child_id"/>
<field name="project_id"/>
<field name="partner_id" domain="[('global_id', '!=', False)]" class="oe_read_only"/>
<field name="child_id" class="oe_read_only"/>
<field name="project_id" class="oe_read_only"/>
</group>
<group>
<field name="gift_type"/>
Expand Down
3 changes: 1 addition & 2 deletions hr_attendance_management/wizards/hr_create_period_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def create_period(self):
# Add one day to end_date as the logic
# uses an exclusive superior bound
str(
datetime.datetime.strptime(record.end_date, "%Y-%m-%d").date()
+ datetime.timedelta(days=1)
record.end_date + datetime.timedelta(days=1)
),
0,
previous_period_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RegistrationController(Controller, WizardFormControllerMixin):
def registration(self, model_id=None, **kw):
"""Handle a wizard route.
"""
request.session["should_save"] = True
return self.make_response("cms.form.res.users", model_id=model_id, **kw)

@http.route("/registration/confirm", type="http", auth="public", website=True,
Expand Down
2 changes: 1 addition & 1 deletion mobile_app_connector/data/template_mail_user_not_found.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="name">Template user not found - Send by Email</field>
<field name="email_to">info@compassion.ch</field>
<field name="subject">Account Setup: User Not Found</field>
<field name="body_html"><![CDATA[Hello,<br/><br/>Please set my mobile app account with the following email address: "%(email_address)"<br/><br/>Yours sincerely]]></field>
<field name="body_html"><![CDATA[Hello,<br/><br/>Please set %(app_type) account with the following email address: "%(email_address)"<br/><br/>Yours sincerely]]></field>
</record>
</data>
</odoo>
14 changes: 11 additions & 3 deletions mobile_app_connector/forms/registration_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def form_widgets(self):
res.update(
{
"gtc_accept": "cms_form_compassion.form.widget.terms",
"partner_birthdate": "cms.form.widget.date.ch",
"partner_birthdate_date": "cms.form.widget.date.ch",
"source": "cms_form_compassion.form.widget.hidden"
}
)
Expand Down Expand Up @@ -263,7 +263,7 @@ def _form_fieldsets(self):
"partner_zip",
"partner_city",
"partner_country_id",
"partner_birthdate",
"partner_birthdate_date",
"gtc_accept",
"source"
],
Expand Down Expand Up @@ -389,6 +389,7 @@ def form_before_create_or_update(self, values, extra_values):
_("This email is already linked to an account.")
)
# partner is not sponsoring a child (but answered yes (form))
values["source"] = extra_values.get("source")
if not partner or len(partner) > 1:
email_template = self.env.ref(
"mobile_app_connector.email_template_user_not_found"
Expand All @@ -399,6 +400,14 @@ def form_before_create_or_update(self, values, extra_values):
body = email_template.body_html.replace(
"%(email_address)", partner_email
)
if values["source"] == "myaccount":
body = body.replace(
"%(app_type)", "mycompassion"
)
else:
body = body.replace(
"%(app_type)", "my mobile app"
)
href_link = self._add_mailto(link_text, to, subject, body)
raise ValidationError(
_(
Expand All @@ -413,7 +422,6 @@ def form_before_create_or_update(self, values, extra_values):
values["email"] = partner_email
values["partner_id"] = partner.id
# Push source to values for using it in creation
values["source"] = extra_values.get("source")

def _form_create(self, values):
""" Here we create the user using the portal wizard or
Expand Down
1 change: 1 addition & 0 deletions mobile_app_connector/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def mobile_post_invoice(self, json_data, **parameters):
"origin": wrapper.source,
"type": "out_invoice",
"date_invoice": fields.Date.today(),
"auto_cancel_no_transaction": True,
}
)

Expand Down
8 changes: 4 additions & 4 deletions mobile_app_connector/models/firebase_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def mobile_register(self, json_data, **params):

firebase_id = params["firebaseId"]
operation = params["operation"]
partner_id = params.get("supId", None)
if partner_id == "":
partner_id = None
partner_id = params.get("supId") or None
language = params.get("language") or None

_logger.debug(
operation
+ "ing a Firebase ID from partner id: "
Expand All @@ -137,7 +137,7 @@ def mobile_register(self, json_data, **params):

if operation == "Insert":
response = Firebase().firebase_register(
registration_id=firebase_id, partner_id=partner_id,
registration_id=firebase_id, partner_id=partner_id,language=language
)
elif operation == "Delete":
response = Firebase().firebase_unregister(
Expand Down
Loading

0 comments on commit 6585b21

Please sign in to comment.