From db446737fdf39ff6af519f768439b727d1794a07 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Thu, 26 Sep 2024 14:08:19 +0200 Subject: [PATCH] T1851 [ADD] partner matching during checkout - This avoids partner duplications when someone is donating through the website --- website_sale_donation/README.rst | 8 +++++ website_sale_donation/__init__.py | 1 + website_sale_donation/__manifest__.py | 3 +- website_sale_donation/controllers/__init__.py | 1 + .../controllers/website_sale.py | 17 ++++++++++ website_sale_donation/readme/HISTORY.md | 3 ++ .../static/description/index.html | 33 +++++++++++++------ 7 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 website_sale_donation/controllers/__init__.py create mode 100644 website_sale_donation/controllers/website_sale.py create mode 100644 website_sale_donation/readme/HISTORY.md diff --git a/website_sale_donation/README.rst b/website_sale_donation/README.rst index bdf2e4c..807e379 100644 --- a/website_sale_donation/README.rst +++ b/website_sale_donation/README.rst @@ -29,6 +29,14 @@ Helper module to manage donations in the e-commerce platform. .. contents:: :local: +Changelog +========= + +14.0.1.1.0 +---------- + +- [ADD] Automatically match partner during checkout. + Bug Tracker =========== diff --git a/website_sale_donation/__init__.py b/website_sale_donation/__init__.py index 31660d6..f4a659e 100644 --- a/website_sale_donation/__init__.py +++ b/website_sale_donation/__init__.py @@ -1,3 +1,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import models +from . import controllers diff --git a/website_sale_donation/__manifest__.py b/website_sale_donation/__manifest__.py index 55f8c4a..16f7494 100644 --- a/website_sale_donation/__manifest__.py +++ b/website_sale_donation/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Website - Sale donation", "summary": "Allows to have a product considered as a donation", - "version": "14.0.1.0.0", + "version": "14.0.1.1.0", "development_status": "Beta", "category": "Website", "website": "https://github.com/CompassionCH/compassion-website", @@ -19,6 +19,7 @@ "website_sale", "mass_mailing", "base_automation", + "partner_auto_match", ], "data": [ "data/base_automation.xml", diff --git a/website_sale_donation/controllers/__init__.py b/website_sale_donation/controllers/__init__.py new file mode 100644 index 0000000..bdae4cc --- /dev/null +++ b/website_sale_donation/controllers/__init__.py @@ -0,0 +1 @@ +from . import website_sale diff --git a/website_sale_donation/controllers/website_sale.py b/website_sale_donation/controllers/website_sale.py new file mode 100644 index 0000000..75d70c5 --- /dev/null +++ b/website_sale_donation/controllers/website_sale.py @@ -0,0 +1,17 @@ +from odoo.http import request + +from odoo.addons.website_sale.controllers.main import WebsiteSale + + +class WebsiteSaleDonation(WebsiteSale): + def _checkout_form_save(self, mode, checkout, all_values): + # Try to match existing partner if possible + if mode[0] == "new": + partner = ( + request.env["res.partner.match"] + .sudo() + .match_values_to_partner(checkout, match_create=False) + ) + if partner: + return partner[:1].id + return super()._checkout_form_save(mode, checkout, all_values) diff --git a/website_sale_donation/readme/HISTORY.md b/website_sale_donation/readme/HISTORY.md new file mode 100644 index 0000000..ec99155 --- /dev/null +++ b/website_sale_donation/readme/HISTORY.md @@ -0,0 +1,3 @@ +## 14.0.1.1.0 + +- [ADD] Automatically match partner during checkout. diff --git a/website_sale_donation/static/description/index.html b/website_sale_donation/static/description/index.html index 7c3300b..de42546 100644 --- a/website_sale_donation/static/description/index.html +++ b/website_sale_donation/static/description/index.html @@ -373,17 +373,30 @@

Website - Sale donation

Table of contents

+
+

Changelog

+
+

14.0.1.1.0

+
    +
  • [ADD] Automatically match partner during checkout.
  • +
+
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -391,21 +404,21 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Compassion Switzerland
-

Maintainers

+

Maintainers

Current maintainer:

ecino

This module is part of the CompassionCH/compassion-website project on GitHub.