Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions donation/models/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _compute_country_id(self):
partner_id = fields.Many2one(
"res.partner",
string="Donor",
required=True,
required=False, # now only required on confirmation
index=True,
states={"done": [("readonly", True)]},
tracking=True,
Expand Down Expand Up @@ -253,15 +253,16 @@ def _compute_country_id(self):
)
]

@api.model
def create(self, vals):
if "company_id" in vals:
self = self.with_company(vals["company_id"])
if vals.get("number", _("New")) == _("New"):
vals["number"] = self.env["ir.sequence"].next_by_code(
"donation.donation", sequence_date=vals.get("donation_date")
) or _("New")
return super().create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if "company_id" in vals:
self = self.with_company(vals["company_id"])
if vals.get("number", _("New")) == _("New"):
vals["number"] = self.env["ir.sequence"].next_by_code(
"donation.donation", sequence_date=vals.get("donation_date")
) or _("New")
return super().create(vals_list)

def _prepare_each_tax_receipt(self):
self.ensure_one()
Expand Down Expand Up @@ -395,6 +396,8 @@ def validate(self):
"donation.group_donation_check_total"
)
for donation in self:
if not donation.partner_id:
raise UserError(_("Donor is not set on donation %s.") % donation.number)
if donation.donation_date > fields.Date.context_today(self):
raise UserError(
_(
Expand Down
6 changes: 5 additions & 1 deletion donation/views/donation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@
<field name="model">donation.donation</field>
<field name="arch" type="xml">
<search string="Search Donations">
<field name="number" />
<field
name="number"
string="Number or Donor"
filter_domain="['|', ('number', 'ilike', self), ('partner_id', 'ilike', self)]"
/>
<field name="partner_id" />
<separator />
<filter
Expand Down
92 changes: 92 additions & 0 deletions donation_api/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
========
Donation
========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9411adca8bbdcade1c4d70e5e297cfa4fb04b789e54f9343f8cb153bca414d7e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdonation-lightgray.png?logo=github
:target: https://github.com/OCA/donation/tree/14.0/donation_api
:alt: OCA/donation
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/donation-14-0/donation-14-0-donation_api
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/donation&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module provides a REST API to create new stays. Useful if you have
a web form on your website and you want it to create a new draft stay
upon validation.

**Table of contents**

.. contents::
:local:

Installation
============

This module depends on the OCA module **fastapi** from
`rest-framework <https://github.com/OCA/rest-framework>`__.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/donation/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
`feedback <https://github.com/OCA/donation/issues/new?body=module:%20donation_api%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Akretion

Contributors
------------

- Alexis de Lattre <alexis.delattre@akretion.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-alexis-via| image:: https://github.com/alexis-via.png?size=40px
:target: https://github.com/alexis-via
:alt: alexis-via

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-alexis-via|

This module is part of the `OCA/donation <https://github.com/OCA/donation/tree/14.0/donation_api>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions donation_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import models
from . import schemas
from . import routers
from . import wizards
24 changes: 24 additions & 0 deletions donation_api/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2025 Akretion France (https://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Donation",
"version": "14.0.1.0.0",
"category": "Donation",
"license": "AGPL-3",
"summary": "API for donation module",
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"website": "https://github.com/OCA/donation",
"depends": ["donation", "fastapi", "partner_match_or_create"],
"external_dependencies": {"python": ["fastapi", "pydantic<2"]},
"data": [
"data/res_users.xml",
# "security/ir.model.access.csv",
"wizards/res_config_settings_view.xml",
"views/donation_donation.xml",
# "data/mail_template.xml",
],
"installable": True,
}
68 changes: 68 additions & 0 deletions donation_api/data/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2025 Akretion France (https://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo noupdate="0">


<record id="stay_controller_notify" model="mail.template">
<field name="name">Stay: Notify stay creation/update/cancel from web form</field>
<field name="model_id" ref="stay.model_stay_stay" />
<field name="email_from">${object.company_id.email}</field>
<field
name="partner_to"
>${object.group_id and object.group_id.notify_user_ids and str(object.group_id.notify_user_ids.partner_id.ids)[1:-1] or (object.company_id.stay_notify_user_ids and str(object.company_id.stay_notify_user_ids.partner_id.ids)[1:-1])}</field>
<field name="reply_to">${object.controller_email}</field>
<field name="auto_delete" eval="False" />
<field
name="subject"
>Stay ${ctx.get('action_description')}: ${object.partner_name} ${format_date(object.arrival_date)} → ${format_date(object.departure_date)} x ${object.guest_qty}</field>
<field name="lang">${object.company_id.partner_id.lang}</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p
style="margin: 0px; padding: 0px; font-size: 13px;"
>Stay ${object.name} has been ${ctx.get('action_description')} via the web form:</p>
<ul>
<li>Guest: ${object.partner_name}</li>
<li>Guest Qty: ${object.guest_qty}</li>
<li
>Arrival: ${format_date(object.arrival_date)} ${dict(object.fields_get('arrival_time', 'selection')['arrival_time']['selection'])[object.arrival_time]}</li>
% if object.arrival_note:
<li>Arrival Note: ${object.arrival_note}</li>
% endif
<li
>Departure: ${format_date(object.departure_date)} ${dict(object.fields_get('departure_time', 'selection')['departure_time']['selection'])[object.departure_time]}</li>
% if object.departure_note:
<li>Departure Note: ${object.departure_note}</li>
% endif
% if object.group_id:
<li>Group: ${object.group_id.display_name}</li>
% endif
% if object.controller_email:
<li>E-mail: ${object.controller_email}</li>
% endif
% if object.controller_phone:
<li>Phone: ${object.controller_phone}</li>
% endif
% if object.controller_mobile:
<li>Mobile: ${object.controller_mobile}</li>
% endif
% if object.controller_message:
<li>Guest message: ${object.controller_message}</li>
% endif
% if object.controller_notes:
<li>Other information: ${object.controller_notes}</li>
% endif
% if object.controller_country_id:
<li>Country: ${object.controller_country_id.name}</li>
% endif
</ul>
</div>
</field>
</record>


</odoo>
19 changes: 19 additions & 0 deletions donation_api/data/res_users.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2025 Akretion France (https://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo noupdate="1">

<record id="donation_api_user" model="res.users" context="{'no_reset_password': True}">
<field name="name">Donation API User</field>
<field name="login">donation_api_user</field>
<field name="email">donation_api_user@example.org</field>
<field
name="groups_id"
eval="[(6, 0, [ref('base.group_user'), ref('donation.group_donation_user'), ref('fastapi.group_fastapi_endpoint_runner')])]"
/>
</record>

</odoo>
2 changes: 2 additions & 0 deletions donation_api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import fastapi_endpoint
from . import donation_donation
Loading
Loading