Skip to content

Commit

Permalink
[IMP] donation: finish migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaime Arroyo committed Jul 21, 2020
1 parent b028e84 commit 54c9346
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 72 deletions.
66 changes: 52 additions & 14 deletions donation/README.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

========
Donation
========

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/12.0/donation
:alt: OCA/donation
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/donation-12-0/donation-12-0-donation
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/180/12.0
:alt: Try me on Runbot

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

This module handles donations, including in-kind donations. When you validate a donation,
it will create the corresponding accounting entries.


**Table of contents**

.. contents::
:local:

Configuration
=============

Expand All @@ -18,6 +43,7 @@ To configure this module, you need to:
* activate the option *Donation Payment Method* on some bank/cash account journals
* if you wish to have a control amount on the donation, add the users to the group *Check Total on supplier invoices*


Usage
=====

Expand All @@ -29,37 +55,49 @@ To have some statistics about the donations, go to the menu Reporting > Donation
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/180/11.0


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 smashing it by providing a detailed and welcomed feedback.
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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/donation/issues/new?body=module:%20donation%0Aversion:%2012.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
~~~~~~~

* Barroux Abbey
* Akretion

Contributors
------------
~~~~~~~~~~~~

* Brother Bernard <informatique - at - barroux.org>
* Brother Irénée (Barroux Abbey)
* Alexis de Lattre <[email protected]>
* Serpent Consulting Services Pvt. Ltd. <[email protected]>
* Nikul Chaudhary <[email protected]>

Maintainer
----------

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

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

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
This module is part of the `OCA/donation <https://github.com/OCA/donation/tree/12.0/donation>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
30 changes: 21 additions & 9 deletions donation/models/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class DonationDonation(models.Model):
def _compute_total(self):
for donation in self:
total = tax_receipt_total = 0.0
donation_currency = donation.currency_id
for line in donation.line_ids:
line_total = line.quantity * line.unit_price
total += line_total
Expand All @@ -31,10 +30,18 @@ def _compute_total(self):
donation_currency =\
donation.currency_id.with_context(date=donation.donation_date)
company_currency = donation.company_currency_id
total_company_currency = donation_currency.compute(
total, company_currency)
tax_receipt_total_cc = donation_currency.compute(
tax_receipt_total, company_currency)
total_company_currency = donation_currency._convert(
total,
company_currency,
donation.company_id,
donation.donation_date
)
tax_receipt_total_cc = donation_currency._convert(
tax_receipt_total,
company_currency,
donation.company_id,
donation.donation_date
)
donation.amount_total_company_currency = total_company_currency
donation.tax_receipt_total = tax_receipt_total_cc

Expand Down Expand Up @@ -349,7 +356,7 @@ def validate(self):
raise UserError(_(
'The date of the donation of %s should be today '
'or in the past, not in the future!')
% donation.partner_id.name)
% donation.partner_id.name)
if not donation.line_ids:
raise UserError(_(
"Cannot validate the donation of %s because it doesn't "
Expand Down Expand Up @@ -521,8 +528,12 @@ def _compute_amount(self):
line.amount = amount
donation_currency = line.donation_id.currency_id.with_context(
date=line.donation_id.donation_date)
amount_company_currency = donation_currency.compute(
amount, line.donation_id.company_id.currency_id)
amount_company_currency = donation_currency._convert(
amount,
line.donation_id.company_id.currency_id,
line.donation_id.company_id,
line.donation_id.donation_date
)
tax_receipt_amount_cc = 0.0
if line.product_id.tax_receipt_ok:
tax_receipt_amount_cc = amount_company_currency
Expand All @@ -544,7 +555,8 @@ def _compute_amount(self):
'res.currency',
related='donation_id.company_id.currency_id',
readonly=True,
compute_sudo=True
compute_sudo=True,
string="Company Currency"
)
product_id = fields.Many2one(
'product.product',
Expand Down
2 changes: 1 addition & 1 deletion donation/models/donation_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def name_get(self):
'Start Date',
default=fields.Date.context_today
)
note = fields.Text('Notes')
note = fields.Text('Notes', oldname='nota')
1 change: 0 additions & 1 deletion donation/post_install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Akretion (Alexis de Lattre <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand Down
35 changes: 19 additions & 16 deletions donation/report/donation_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from odoo import tools
from odoo import models, fields
from psycopg2 import sql


class DonationReport(models.Model):
Expand Down Expand Up @@ -66,7 +67,7 @@ class DonationReport(models.Model):
)

def _select(self):
select = """
return sql.SQL("""
SELECT min(l.id) AS id,
d.donation_date AS donation_date,
l.product_id AS product_id,
Expand All @@ -80,26 +81,23 @@ def _select(self):
d.company_currency_id AS company_currency_id,
sum(l.amount_company_currency) AS amount_company_currency,
sum(l.tax_receipt_amount) AS tax_receipt_amount
"""
return select
""")

def _from(self):
from_sql = """
return sql.SQL("""
donation_line l
LEFT JOIN donation_donation d ON (d.id=l.donation_id)
LEFT JOIN product_product pp ON (l.product_id=pp.id)
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
"""
return from_sql
""")

def _where(self):
where = """
return sql.SQL("""
WHERE d.state='done'
"""
return where
""")

def _group_by(self):
group_by = """
return sql.SQL("""
GROUP BY l.product_id,
l.in_kind,
l.tax_receipt_ok,
Expand All @@ -110,12 +108,17 @@ def _group_by(self):
d.campaign_id,
d.company_id,
d.company_currency_id
"""
return group_by
""")

def init(self):
tools.drop_view_if_exists(self._cr, self._table)
sql = "CREATE OR REPLACE VIEW %s AS (%s FROM %s %s %s)" % (
self._table, self._select(), self._from(),
self._where(), self._group_by())
self._cr.execute(sql)
query = sql.SQL(
"CREATE OR REPLACE VIEW {0} AS ({1} FROM {2} {3} {4})"
).format(
sql.Identifier(self._table),
self._select(),
self._from(),
self._where(),
self._group_by(),
) # pylint: disable=sql-injection
self._cr.execute(query)
Binary file modified donation/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

5 comments on commit 54c9346

@alexis-via
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarroyomorales Short question: how did you found/generate this nice logo that has a style very similar to the official odoo application icons ? I need to generate such an icon for another OCA module...

@etobella
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alexis-via we used https://android-material-icon-generator.bitdroid.de/ but it is currently not working anymore 😭
However, you can use the following site that seems to work https://spilymp.github.io/ibo/ but no SVG is generated.

I found the information on https://www.odoo.com/es_ES/forum/ayuda-1/creating-an-app-icon-the-easiest-way-158389

@alexis-via
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etobella Thank you very much for your answer. I'll look into this in details.

@pedrobaeza
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use OCA/maintainer-tools#491 for generating SVG icons.

@alexis-via
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pointer @pedrobaeza I'll test that.

Please sign in to comment.