Skip to content

Commit

Permalink
Merge pull request #1526 from CompassionCH/devel
Browse files Browse the repository at this point in the history
2022.09 (2)
  • Loading branch information
ecino authored May 23, 2022
2 parents 0ecf0f2 + 17672b8 commit 8cb8f59
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 73 deletions.
4 changes: 2 additions & 2 deletions partner_communication_switzerland/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ def generate_tax_receipts(self):
("partner_id.tax_certificate", "!=", "no"),
]
)
config = self.env.ref("partner_communication_switzerland." "tax_receipt_config")
config = self.env.ref("partner_communication_switzerland.tax_receipt_config")
existing_comm = self.env["partner.communication.job"].search(
[
("config_id", "=", config.id),
("state", "in", ["pending", "done", "call"]),
("date", ">", end_date),
]
)
partners = invoice_lines.mapped("partner_id") - existing_comm.mapped(
partners = invoice_lines.mapped("partner_id.commercial_partner_id") - existing_comm.mapped(
"partner_id"
)
total = len(partners)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ def send_communication(self, config_name):
def form_completion_callback(self):
self.ensure_one()
if datetime.now() >= (
self.zoom_session_id.date_send_link or self.zoom_session_id.date_start):
self.zoom_session_id.date_send_link or self.zoom_session_id.date_start) and self.state != "declined":
return self.send_communication(ZoomCommunication.LINK)
return self.send_communication(ZoomCommunication.REGISTRATION)
3 changes: 1 addition & 2 deletions partner_compassion/models/advocate_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def _compute_thank_you_quote(self):
"image_data": details.partner_id.with_context(bin_size=False)
.image.decode("utf-8"),
"text": details.quote.strip() or "",
"attribution": _("Quote from %s %s"
% (firstname, lastname))
"attribution": _("Quote from %s %s") % (firstname, lastname)
if details.quote.strip()
else "",
}
Expand Down
134 changes: 79 additions & 55 deletions partner_compassion/models/partner_compassion.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,25 +369,9 @@ def _compute_prim_sec_segments(self):
##########################################################################
@api.model
def create(self, vals):
"""
Lookup for duplicate partners and notify.
"""
email = vals.get("email")
if email:
vals["email"] = email.strip()
duplicate = self.search(
[
"|",
"&",
("email", "=", vals.get("email")),
("email", "!=", False),
"&",
"&",
("firstname", "ilike", vals.get("firstname")),
("lastname", "ilike", vals.get("lastname")),
("zip", "=", vals.get("zip")),
]
)
duplicate_domain = self._check_duplicates_domain(vals, skip_props_check=True)
duplicate = self.search(duplicate_domain)

duplicate_ids = [(4, itm.id) for itm in duplicate]
vals.update({"partner_duplicate_ids": duplicate_ids})
vals["ref"] = self.env["ir.sequence"].get("partner.ref")
Expand Down Expand Up @@ -517,47 +501,87 @@ def _check_qorder(self, word):
raise
return True

def _check_duplicates_domain(self, vals=None, skip_props_check=False):
"""
Generates a search domain to find duplicates for this partner based on various filters
:param dict vals: a dictionnary containing values used by the filters, inferred from self if not provided
:param bool skip_props_checks: whether you want to skip verifying that each variable's filter are set, thus running them all anyway
"""
if not vals:
vals = {
"email": self.email,
"firstname": self.firstname,
"lastname": self.lastname,
"zip": self.zip,
"street": self.street,
}

# define set of checks for duplicates and required fields
checks = [
# Email check
(vals.get('email'), [
'&',
('email', '=', vals.get('email')),
('email', '!=', False)
]),
# zip and name check
(vals.get('firstname') and vals.get('lastname') and vals.get('zip'), [
"&",
"&",
("firstname", "ilike", vals.get('firstname')),
("lastname", "ilike", vals.get('lastname')),
("zip", "=", vals.get('zip')),
]),
# name and address check
(vals.get('lastname') and vals.get('street') and vals.get('zip'), [
"&",
"&",
("lastname", "ilike", vals.get('lastname')),
("zip", "=", vals.get('zip')),
("street", "ilike", vals.get('street'))
])
]

# This step builds a domain query based on the checks that
# passed, prepending the list with a "|" operator for all item
# once its size is > 1
search_filters = []
for check in checks:
if skip_props_check or check[0]:
if len(search_filters) > 0:
search_filters.insert(0, "|")
search_filters.extend(check[1])
return search_filters

##########################################################################
# ONCHANGE METHODS #
##########################################################################
@api.onchange("lastname", "firstname", "zip", "email")
def _onchange_partner(self):
if (
(self.lastname and self.firstname and self.zip) or self.email
) and self.contact_type != "attached":
partner_duplicates = self.search(
[
("id", "!=", self._origin.id),
"|",
"&",
("email", "=", self.email),
("email", "!=", False),
"&",
"&",
("firstname", "ilike", self.firstname),
("lastname", "ilike", self.lastname),
("zip", "=", self.zip),
]
)
if partner_duplicates:
self.partner_duplicate_ids = partner_duplicates
# Commit the found duplicates
with api.Environment.manage():
with registry(self.env.cr.dbname).cursor() as new_cr:
new_env = api.Environment(new_cr, self.env.uid, {})
self._origin.with_env(new_env).write(
{"partner_duplicate_ids": [(6, 0, partner_duplicates.ids)]}
)
return {
"warning": {
"title": _("Possible existing partners found"),
"message": _(
"The partner you want to add may "
'already exist. Please use the "'
'Check duplicates" button to review it.'
),
},
}
duplicates_domain = self._check_duplicates_domain(skip_props_check=False)
if self.contact_type == "attached" or not duplicates_domain:
return

partner_duplicates = self.search([("id", "!=", self._origin.id)] + duplicates_domain)
if partner_duplicates:
self.partner_duplicate_ids = partner_duplicates
# Commit the found duplicates
with api.Environment.manage():
with registry(self.env.cr.dbname).cursor() as new_cr:
new_env = api.Environment(new_cr, self.env.uid, {})
self._origin.with_env(new_env).write(
{"partner_duplicate_ids": [(6, 0, partner_duplicates.ids)]}
)
return {
"warning": {
"title": _("Possible existing partners found"),
"message": _(
"The partner you want to add may "
'already exist. Please use the "'
'Check duplicates" button to review it.'
),
},
}

##########################################################################
# PUBLIC METHODS #
Expand Down
8 changes: 3 additions & 5 deletions website_event_compassion/controllers/events_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ def down_payment_validate(self, invoice_id=None, **post):
"""
failure_template = "website_event_compassion.donation_failure"
error_intro = _(
"Thank you for your efforts in the Compassion trip registration " "process."
"Thank you for your efforts in the Compassion trip registration process."
)
try:
invoice = request.env["account.invoice"].browse(int(invoice_id))
invoice = request.env["account.invoice"].browse(int(invoice_id)).sudo()
invoice.exists().ensure_one()
tx = invoice.get_portal_last_transaction()
except ValueError:
Expand Down Expand Up @@ -329,9 +329,7 @@ def down_payment_validate(self, invoice_id=None, **post):
"the departure. Until then, don't hesitate to contact us if "
"you have any question."
)
return super().compassion_payment_validate(
tx, template, failure_template, **post
)
return request.render(template, post)

def get_donation_success_template(self, event):
"""
Expand Down
4 changes: 2 additions & 2 deletions website_event_compassion/controllers/group_visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def group_visit_payment(self, reg_uid, **kwargs):

def get_payment_form(self, reg_uid, form_model, **kwargs):
kwargs["form_model_key"] = form_model
values = self._get_group_visit_page_values(reg_uid, "account.invoice", **kwargs)
values = self._get_group_visit_page_values(reg_uid, "cms.form.event.group.visit.payment", **kwargs)
if not isinstance(values, dict):
# values can be a redirect in case of error
return values
Expand Down Expand Up @@ -221,7 +221,7 @@ def _get_group_visit_page_values(self, reg_uid, form_model=None, **kwargs):
:param kwargs: calling args
:return: dict of values for template rendering
"""
registration = request.env["event.registration"].search(
registration = request.env["event.registration"].sudo().search(
[("uuid", "=", reg_uid)]
)
if not registration:
Expand Down
7 changes: 6 additions & 1 deletion website_event_compassion/forms/agreement_step2_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def form_widgets(self):
res["form_id"] = "cms_form_compassion.form.widget.hidden"
return res

def form_init(self, request, main_object=None, **kw):
if main_object:
main_object = main_object.sudo()
return super().form_init(request, main_object, **kw)

def form_cancel_url(self, main_object=None):
"""URL to redirect to after click on "cancel" button."""
main_object = main_object or self.main_object
Expand Down Expand Up @@ -266,7 +271,7 @@ def _form_validate_passport_expiration_date(self, value, **req_values):
valid = True
old = False
try:
date = datetime.strptime(value, "%d.%m.%Y")
date = fields.Datetime.from_string(value)
limit_date = (
self.main_object.compassion_event_id.end_date
+ relativedelta(months=6)
Expand Down
4 changes: 4 additions & 0 deletions website_event_compassion/forms/group_visit_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ def generate_invoice(self):
}
)
return group_visit_invoice

def _form_create(self, values):
# Do nothing here
return True
2 changes: 1 addition & 1 deletion website_event_compassion/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def modify_open_invoice(self, vals):
self.action_invoice_cancel()
self.action_invoice_draft()
self.write(vals)
for invoice in self.filtered(lambda i: i.partner_id.state == "active"):
for invoice in self:
invoice.action_invoice_open()
return True

Expand Down
7 changes: 3 additions & 4 deletions website_event_compassion/models/partner_communication_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ def get_trip_payment_attachment(self):
"communication": event_name,
}
report_name = "report_compassion.bvr_fund"
report = self.env.ref("report_compassion.report_bvr_fund")
pdf_data = base64.b64encode(
self.env["report"]
.with_context(must_skip_send_to_printer=True)
.render_qweb_pdf(registration.partner_id.ids, report_name,
data=report_vals)
report.with_context(must_skip_send_to_printer=True)
.render_qweb_pdf(registration.partner_id.ids, data=report_vals)[0]
)
return {event_name + ".pdf": [report_name, pdf_data]}

0 comments on commit 8cb8f59

Please sign in to comment.