Skip to content

Commit

Permalink
Merge pull request #1438 from CompassionCH/devel
Browse files Browse the repository at this point in the history
Stabilization 1.14 (2)
  • Loading branch information
ecino authored Dec 14, 2021
2 parents 02a2131 + 6e63915 commit bde7cc3
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 25 deletions.
2 changes: 1 addition & 1 deletion child_sync_wp/tools/wp_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def remove_children(self, children):
_logger.info("Remove from Wordpress : " + str(res))
return res
except:
_logger.error("Remove from Wordpress failed.")
_logger.error("Remove from Wordpress failed.", exc_info=True)

return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def _get_test_objects(self, partner):
("partner_id", "=", partner.id),
("invoice_id.invoice_category", "=", "fund")
], limit=4).ids
elif self.model == "account.invoice":
object_ids = self.env["account.invoice"].search([
("partner_id", "=", partner.id)
], limit=4).ids
return object_ids

def _find_partner(self, number_sponsorships, lang, family_case):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<t t-set="custom_css">
.container {
font-family: "millerLight";
font-size: 12pt;
font-size: 10pt;
}
#body {
width: 100%;
Expand Down
16 changes: 7 additions & 9 deletions report_compassion/report/bvr_sponsorship.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@
<!-- Sponsorship Due Template -->
<template id="bvr_due">
<t t-call="web.html_container">
<t t-foreach="docs.mapped('partner_id')" t-as="partner">
<t t-call="report_compassion.report_bvr_due_document" t-lang="partner.lang"/>
<t t-call="web.external_layout">
<t t-set="report_header_style">display: none;</t>
<t t-foreach="docs.mapped('partner_id')" t-as="partner">
<t t-call="report_compassion.report_bvr_due_document" t-lang="partner.lang"/>
</t>
</t>
</t>
</template>
Expand All @@ -145,7 +148,7 @@
<t t-set="sponsorships" t-value="docs.browse(ids)"/>
<t t-set="partner_address" t-value="partner.short_address"/>
<t t-set="bank_account" t-value="partner.env['recurring.contract.group'].get_company_qrr_account()"/>
<t t-set="position" t-value="0"/>
<t t-set="swissqr_position_top" t-value="192"/>
<t t-set="contract_groups" t-value="sponsorships.mapped('group_id')"/>
<t t-set="o" t-value="contract_groups[0]"/>
<t t-set="reference" t-value="o.bvr_reference"/>
Expand All @@ -159,11 +162,6 @@
</t>
</t>
<t t-set="amount" t-value="due"/>
<t t-call="web.external_layout">
<t t-call="report_compassion.style"/>
<t t-set="report_header_style">display: none;</t>
<t t-set="swissqr_position_top" t-value="192"/>
<t t-call="report_compassion.report_compassion_qr_slip"/>
</t>
<t t-call="report_compassion.report_compassion_qr_slip"/>
</template>
</odoo>
16 changes: 10 additions & 6 deletions report_compassion/report/partner_communication.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
}
#logo {
display: inline-block;
margin-top: 6mm;
width: 50mm;
height: 20mm;
}
Expand All @@ -34,16 +33,21 @@
}
#compassion_address {
float: left;
margin-bottom: 5mm;
margin-top: 10mm;
font-size: 8pt;
}
#title {
text-decoration: underline;
margin-bottom: 2mm;
}
#address {
margin-top: 8mm;
}
#letter {
position: absolute;
font-family: "millerLight";
font-size: 10pt;
font-size: <t t-esc="font_size or '10'"/>pt;
color: black;
top: 40mm;
<t t-if="success_story">
margin-left: 11mm;
Expand Down Expand Up @@ -206,7 +210,7 @@
</t>
<div id="letter">
<div id="date" t-if="not print_header">
<span t-raw="partner.date_communication" style="float: left; margin-top: 15mm; min-width: 70mm;"/>
<span t-raw="partner.date_communication" style="float: left; margin-top: 10mm; min-width: 70mm;"/>
</div>
<t t-if="print_header">
<div id="compassion_address">
Expand All @@ -226,7 +230,7 @@
<span> 17-312562-0</span>
</div>
</t>
<div id="address" class="right" t-attf-style="margin-bottom: #{'0' if display_pp or print_header else '10'}mm;">
<div id="address" class="right">
<div id="pp" t-if="display_pp">
<div id="pp-box">
<div>P.P.</div>
Expand All @@ -238,7 +242,7 @@
<hr/>
</div>
<span t-raw="partner.short_address"/>
<div id="date" t-if="print_header" t-attf-style="margin-top: #{ '10' if display_pp else '20' }mm;">
<div id="date" t-if="print_header" t-attf-style="margin-top: #{'10' if display_pp else '15'}mm;">
<span t-raw="partner.date_communication"/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions report_compassion/wizards/print_sponsorship_bvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def default_start(self):
today = date.today()
start = today.replace(day=1, month=1)
# Exception in December, we want to print for next year.
if today.month == 12 and today.day > 10:
if today.month == 12 and today.day >= 15:
start = start.replace(year=today.year + 1)
return start.replace(day=1)

Expand All @@ -63,7 +63,7 @@ def default_stop(self):
today = date.today()
stop = today.replace(day=31, month=12)
# Exception in December, we want to print for next year.
if today.month == 12 and today.day > 10:
if today.month == 12 and today.day >= 15:
stop = stop.replace(year=today.year + 1)
return stop

Expand Down
13 changes: 13 additions & 0 deletions sponsorship_switzerland/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,16 @@ def group_or_split_reconcile(self):
"""Reconcile given invoices with partner open payments.
"""
return self._group_or_split_reconcile()

def action_invoice_open(self):
for invoice in self:
condition = [
("transaction_id", "=", invoice.transaction_id),
("transaction_id", "!=", False),
("state", "in", ["open", "paid"]),
("id", "!=", invoice.id),
]
if self.env[self._name].search_count(condition):
error_msg = _("The Transaction ID `{}` is already used in another validated account invoice !")
raise UserError(error_msg.format(invoice.transaction_id))
return super(AccountInvoice, self).action_invoice_open()
2 changes: 1 addition & 1 deletion sponsorship_switzerland/models/completion_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _generate_invoice(self, stmts_vals, st_line, partner, ref_index):

def _generate_invoice_line(self, invoice_id, product, st_line, partner_id):
inv_line_data = {
"name": product.name,
"name": st_line.get("note") or product.name,
"account_id": product.property_account_income_id.id,
"price_unit": st_line["amount"],
"price_subtotal": st_line["amount"],
Expand Down
71 changes: 70 additions & 1 deletion website_compassion/controllers/my_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
from urllib.request import urlretrieve, urlopen
from math import ceil
from dateutil.relativedelta import relativedelta
import secrets
from passlib.context import CryptContext

from werkzeug.datastructures import Headers
from werkzeug.wrappers import Response

from odoo import fields, _
from odoo.http import request, route
from odoo.http import request, route, local_redirect
from odoo.addons.web.controllers.main import content_disposition
from odoo.addons.cms_form_compassion.controllers.payment_controller import (
PaymentFormController,
Expand Down Expand Up @@ -198,6 +200,73 @@ def _download_image(type, child_id=None, obj_id=None):


class MyAccountController(PaymentFormController):
@route("/my/login/<partner_uuid>/<redirect_page>", type="http", auth="public",
website=True)
def magic_login(self, partner_uuid=None, redirect_page=None, **kwargs):
if not partner_uuid:
return None

res_partner = request.env["res.partner"].sudo()
res_users = request.env["res.users"].sudo()

partner = res_partner.search([["uuid", "=", partner_uuid]], limit=1)
partner = partner.sudo()

redirect_page_request = local_redirect(f"/my/{redirect_page}", kwargs)

if not partner:
# partner does not exist
return redirect_page_request

user = res_users.search([["partner_id", "=", partner.id]], limit=1)

if user and not user.created_with_magic_link:
# user already have an account not created with the magic link
# this will ask him to log in then redirect him on the route asked
return redirect_page_request

if not user:
# don't have a res_user must be created
login = MyAccountController._create_magic_user_from_partner(partner)
else:
# already have a res_user created with a magic link
login = user.login

MyAccountController._reset_password_and_authenticate(login)

return redirect_page_request

@staticmethod
def _reset_password_and_authenticate(login):
# create a random password
password = secrets.token_urlsafe(16)

# reset password
crypt_context = CryptContext(schemes=["pbkdf2_sha512", "plaintext"], deprecated=["plaintext"])
password_encrypted = crypt_context.encrypt(password)
request.env.cr.execute("UPDATE res_users SET password=%s WHERE login=%s;", [password_encrypted, login])
request.env.cr.commit()

# authenticate
request.session.authenticate(request.session.db, login, password)
return True

@staticmethod
def _create_magic_user_from_partner(partner):
res_users = request.env["res.users"].sudo()

values = {
# ensure a login when the partner doesnt have an email
"login": partner.email or "magic_login_" + secrets.token_urlsafe(16),
"partner_id": partner.id,
"created_with_magic_link": True,
}

# create a signup_token and create the account
partner.signup_prepare()
_, login, _ = res_users.signup(values=values, token=partner.signup_token)
return login

@route(["/my", "/my/home", "/my/account"], type="http", auth="user", website=True)
def account(self, redirect=None, **post):
# All this paths needs to be redirected
Expand Down
5 changes: 2 additions & 3 deletions website_compassion/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ msgstr "Spenden"
#. module: website_compassion
#: model_terms:ir.ui.view,arch_db:website_compassion.letter_text_content
msgid "Make sure that any image you upload does not exceed 10Mb."
msgstr "Stell dich sicher, dass jedes Bild 10 MB nicht überschreitet."
msgstr "Bitte stelle sicher, dass dein Bild nicht 10 MB überschreitet."

#. module: website_compassion
#: model_terms:ir.ui.view,arch_db:website_compassion.my_donations_payment_options_multiple
Expand Down Expand Up @@ -1245,8 +1245,7 @@ msgstr ""
msgid ""
"There are many easy-to-use solution to resize an image.<br/> for example"
msgstr ""
"Es gibt viele benutzerfreundliche Lösungen, um die Grösse eines Bildes zu "
"ändern.<br/> Zum Beispiel"
"Du kannst die Grösse des Bildes verkleinern, bspw. über "

#. module: website_compassion
#: model_terms:ir.ui.view,arch_db:website_compassion.letter_actions
Expand Down
4 changes: 3 additions & 1 deletion website_compassion/models/res_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
##############################################################################
import logging

from odoo import models, _
from odoo import models, fields

_logger = logging.getLogger(__name__)


class ResUsers(models.Model):
_inherit = 'res.users'

created_with_magic_link = fields.Boolean(default=False)

def reset_password(self, login):
""" retrieve the user corresponding to login (login or email),
and reset their password
Expand Down
2 changes: 2 additions & 0 deletions wordpress_connector/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ def create_sponsorship_job(self, values, form_data):
:param form_data: wordpress form data
:return: <recurring.contract> record
"""
child = self.env["compassion.child"].browse(values["child_id"])
child.remove_from_wordpress()
sponsorship = self.env["recurring.contract"].create(values)
list_keys = [
"salutation",
Expand Down

0 comments on commit bde7cc3

Please sign in to comment.