Skip to content

Commit f012b0a

Browse files
committed
[ADD] pos_donation
Allow to generate donation tax receipt from donation encoded via point of sale.
1 parent a018ab4 commit f012b0a

16 files changed

Lines changed: 800 additions & 0 deletions

File tree

pos_donation/README.rst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
============
2+
POS Donation
3+
============
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:1713b6df7104e011ddce866123a3db0e673ac9c2dbfb2fae5c4739824e3e7543
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github
20+
:target: https://github.com/OCA/pos/tree/16.0/pos_donation
21+
:alt: OCA/pos
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_donation
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
When a donation product is sold in the POS, this module creates a
32+
donation related to the POS Order in draft state. This donation can be
33+
validated in order to generate a tax receipt for this donation.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Bug Tracker
41+
===========
42+
43+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/issues>`_.
44+
In case of trouble, please check there if your issue has already been reported.
45+
If you spotted it first, help us to smash it by providing a detailed and welcomed
46+
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_donation%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
47+
48+
Do not contact contributors directly about support or help with technical issues.
49+
50+
Credits
51+
=======
52+
53+
Authors
54+
~~~~~~~
55+
56+
* Coop IT Easy SC
57+
58+
Contributors
59+
~~~~~~~~~~~~
60+
61+
* `Coop IT Easy SC <https://coopiteasy.be>`_:
62+
63+
* Rémy Taymans
64+
65+
Maintainers
66+
~~~~~~~~~~~
67+
68+
This module is maintained by the OCA.
69+
70+
.. image:: https://odoo-community.org/logo.png
71+
:alt: Odoo Community Association
72+
:target: https://odoo-community.org
73+
74+
OCA, or the Odoo Community Association, is a nonprofit organization whose
75+
mission is to support the collaborative development of Odoo features and
76+
promote its widespread use.
77+
78+
.. |maintainer-remytms| image:: https://github.com/remytms.png?size=40px
79+
:target: https://github.com/remytms
80+
:alt: remytms
81+
82+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
83+
84+
|maintainer-remytms|
85+
86+
This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/16.0/pos_donation>`_ project on GitHub.
87+
88+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

pos_donation/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
from . import models

pos_donation/__manifest__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
{
6+
"name": "POS Donation",
7+
"summary": "Generate donation for donation sold in POS.",
8+
"version": "16.0.1.0.0",
9+
"category": "POS",
10+
"website": "https://github.com/OCA/pos",
11+
"author": "Coop IT Easy SC, Odoo Community Association (OCA)",
12+
"maintainers": ["remytms"],
13+
"license": "AGPL-3",
14+
"depends": [
15+
"donation",
16+
"point_of_sale",
17+
],
18+
"data": [
19+
"views/donation_views.xml",
20+
"views/product_template_views.xml",
21+
],
22+
"demo": [
23+
"demo/donation.xml",
24+
],
25+
}

pos_donation/demo/donation.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="product_product_donation_pos" model="product.product">
4+
<field name="name">POS Donation</field>
5+
<field name="default_code">POS-DON</field>
6+
<field name="categ_id" ref="product.product_category_5" />
7+
<field name="sale_ok" eval="True" />
8+
<field name="tax_receipt_ok" eval="True" />
9+
<field name="list_price">0</field>
10+
<field name="detailed_type">donation_in_pos</field>
11+
<field name="taxes_id" eval="False" />
12+
<field
13+
name="description"
14+
>This donation item that can be sold in POS and is eligible for a tax receipt.</field>
15+
</record>
16+
</odoo>

pos_donation/models/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
from . import donation
5+
from . import donation_line
6+
from . import product_template
7+
from . import pos_order

pos_donation/models/donation.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import _, fields, models
6+
7+
8+
class DonationDonation(models.Model):
9+
_inherit = "donation.donation"
10+
11+
pos_order_id = fields.Many2one(
12+
string="POS Order",
13+
comodel_name="pos.order",
14+
)
15+
16+
def action_view_pos_order_id(self):
17+
return {
18+
"type": "ir.actions.act_window",
19+
"name": _("POS Order"),
20+
"res_model": "pos.order",
21+
"view_mode": "tree,form",
22+
"domain": [("id", "in", self.pos_order_id.ids)],
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import models
6+
7+
8+
class DonationLine(models.Model):
9+
_inherit = "donation.line"
10+
11+
def _compute_in_kind(self):
12+
"""Donation in POS should be considered as donation in-kind.
13+
These donation should not generate account move,
14+
because account move has already been generated by the POS.
15+
"""
16+
res = super()._compute_in_kind()
17+
for line in self:
18+
# If line is not already considered a an in-kind donation,
19+
# then we must check if it’s a pos_donation
20+
if not line.in_kind:
21+
line.in_kind = line.product_id.detailed_type == "donation_in_pos"
22+
return res

pos_donation/models/pos_order.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
import logging
6+
7+
from odoo import Command, models
8+
from odoo.exceptions import UserError
9+
10+
_logger = logging.getLogger(__name__)
11+
12+
13+
class PosOrder(models.Model):
14+
_inherit = "pos.order"
15+
16+
def _get_donation_vals(self):
17+
# ensure_one because used in an ensure_one method
18+
self.ensure_one()
19+
donations = self.lines.filtered(lambda rec: rec.product_id.is_donation)
20+
payment_mode_id = donations.product_id.default_payment_mode_id
21+
tax_receipt_option = donations.product_id.default_tax_receipt_option
22+
company_id = donations.product_id.company_id
23+
vals = None
24+
if donations:
25+
vals = {
26+
"pos_order_id": self.id,
27+
"partner_id": self.partner_id.id,
28+
"donation_date": self.date_order,
29+
"payment_mode_id": payment_mode_id[0].id if payment_mode_id else False,
30+
"company_id": company_id[0].id if company_id else False,
31+
"payment_ref": self.pos_reference,
32+
"tax_receipt_option": tax_receipt_option,
33+
"line_ids": [],
34+
}
35+
for line in donations:
36+
vals["line_ids"].append(
37+
Command.create(
38+
{
39+
"product_id": line.product_id.id,
40+
"quantity": line.qty,
41+
"unit_price": line.price_unit,
42+
}
43+
)
44+
)
45+
return vals
46+
47+
def action_pos_order_paid(self):
48+
# ensure_one !
49+
res = super().action_pos_order_paid()
50+
donation_vals = self._get_donation_vals()
51+
if donation_vals:
52+
donation = self.env["donation.donation"].create(donation_vals)
53+
try:
54+
donation.validate()
55+
except UserError:
56+
_logger.warning(
57+
"Cannot validate donation {donation} based on pos.order {pos_order}".format(
58+
donation=donation, pos_order=self
59+
)
60+
)
61+
return res
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2025 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import _, fields, models
6+
7+
8+
class ProductTemplate(models.Model):
9+
_inherit = "product.template"
10+
11+
detailed_type = fields.Selection(
12+
selection_add=[
13+
("donation_in_pos", "Donation in POS"),
14+
],
15+
ondelete={
16+
"donation_in_pos": "set consu",
17+
},
18+
)
19+
default_payment_mode_id = fields.Many2one(
20+
"account.payment.mode",
21+
domain="[('company_id', '=', company_id), ('donation', '=', True)]",
22+
tracking=True,
23+
default=lambda self: self.env.user.context_donation_payment_mode_id,
24+
)
25+
default_tax_receipt_option = fields.Selection(
26+
[
27+
("none", "None"),
28+
("each", "For Each Donation"),
29+
("annual", "Annual Tax Receipt"),
30+
],
31+
tracking=True,
32+
)
33+
34+
_sql_constraints = [
35+
(
36+
"check_company_id_for_donation_in_pos",
37+
"""CHECK (
38+
(detailed_type='donation_in_pos' AND company_id IS NOT NULL)
39+
OR detailed_type!='donation_in_pos'
40+
)""",
41+
_(
42+
"Product for donation in pos must belong to a company "
43+
"in ordrer to set default payment mode."
44+
),
45+
)
46+
]
47+
48+
def _detailed_type_mapping(self):
49+
res = super()._detailed_type_mapping()
50+
res.update(
51+
{
52+
"donation_in_pos": "consu",
53+
}
54+
)
55+
return res
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `Coop IT Easy SC <https://coopiteasy.be>`_:
2+
3+
* Rémy Taymans

0 commit comments

Comments
 (0)