diff --git a/__manifest__.py b/__manifest__.py
index 2dc5e4a2a1eee070489c02b372b4b678916401a6..6f9b93b3b7d432091beb569b2edeb08f7c4dbad6 100644
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -9,6 +9,7 @@
"installable": True,
"depends": [
"cgscop_partner",
+ "cgscop_cotisation",
"multi_company_menu",
],
"data": [
diff --git a/report/__init__.py b/report/__init__.py
index 8c22d988445f27931957c835d2c9de28eed45521..cf825a9ca3cbdccc94e7818788d5dc2a74ab1847 100755
--- a/report/__init__.py
+++ b/report/__init__.py
@@ -2,3 +2,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import account_invoice_all
+from . import scop_contribution_report
diff --git a/report/account_invoice_all.py b/report/account_invoice_all.py
index 27aa6ca5eda574a6e12a504cef371eb2b893c8ce..f025fb73b38de0cd98b46228e9b67a225ed2dae9 100644
--- a/report/account_invoice_all.py
+++ b/report/account_invoice_all.py
@@ -1,18 +1,20 @@
# © 2022 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-from odoo import models
+from odoo import models, api
class ScopAccountInvoiceIDFReport(models.Model):
_inherit = "account.invoice.all"
- def _select(self):
- select_str = super(ScopAccountInvoiceIDFReport, self)._select()
+ # ------------------------------------------------------
+ # Query
+ # ------------------------------------------------------
+ def _subquery(self):
+ select_str = super(ScopAccountInvoiceIDFReport, self)._subquery()
select_str += """
UNION ALL (
SELECT
- id,
null as invoice_id,
writing_date as date_invoice,
writing_date as date_due,
@@ -36,3 +38,35 @@ class ScopAccountInvoiceIDFReport(models.Model):
)
"""
return select_str
+
+ # ------------------------------------------------------
+ # Computed fields
+ # ------------------------------------------------------
+ @api.multi
+ def _compute_lines(self):
+ for inv in self:
+ ur_idf_id = self.env.ref('cgscop_partner.riga_14231')
+ if not inv.invoice_id and inv.partner_id.ur_id == ur_idf_id:
+ invoice_idf_id = self.env['scop.invoice.idf'].sudo().search([
+ ('partner_id', '=', inv.partner_id.id),
+ ('writing_date', '=', inv.date_invoice),
+ ('acc_doc', '=', inv.number),
+ ('type', '=', 'inv'),
+ ])
+ if len(invoice_idf_id) == 1:
+ inv.lines = "<table class='table table-hover table-striped table-sm'>" \
+ "<thead class='thead-light'><tr><th>Description</th><th>Quantité</th><th>P.U</th>" \
+ "<th>Total HT</th><th>Total TTC</th></tr></thead><tbody>" + \
+ ''.join(
+ invoice_idf_id.mapped(
+ lambda l: ("<tr><td>" + l.name.replace(
+ '\n', '<br/>') + "</td>" +
+ "<td></td>" +
+ "<td>" + str(
+ l.debit) + "</td>" +
+ "<td>" + str(
+ l.debit) + "</td>" +
+ "<td>" + str(
+ l.debit) + "</td></tr>"))) + "</tbody></table>"
+ if not inv.lines:
+ super(ScopAccountInvoiceIDFReport, inv)._compute_lines()
diff --git a/report/scop_contribution_report.py b/report/scop_contribution_report.py
new file mode 100644
index 0000000000000000000000000000000000000000..4075c0e547defa08639a436fd2ab914d30eb83c8
--- /dev/null
+++ b/report/scop_contribution_report.py
@@ -0,0 +1,61 @@
+# © 2022 Le Filament (<http://www.le-filament.com>)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from odoo import models, fields
+
+
+class ScopContributionReport(models.Model):
+ _inherit = "scop.contribution.report"
+
+ source = fields.Selection(
+ selection_add=[
+ ('idf', 'IDF')])
+
+ # ------------------------------------------------------
+ # Query
+ # ------------------------------------------------------
+ def _subquery(self):
+ contribution_ur_id = self.env.ref('cgscop_partner.riga_14399').id
+ query = super(ScopContributionReport, self)._subquery()
+ query += """
+ UNION ALL (
+ SELECT
+ 'idf' as source,
+ year,
+ %s as type_contribution_id,
+ partner_id,
+ debit AS amount_called,
+ debit - amount_residual AS amount_paid,
+ amount_residual AS amount_due
+ FROM
+ scop_cotisation_idf
+ WHERE
+ type = 'inv'
+ )
+ """ % contribution_ur_id
+ return query
+
+ # ------------------------------------------------------
+ # Business functions
+ # ------------------------------------------------------
+ def _get_payment(self):
+ self.ensure_one()
+ if self.source == 'idf':
+ payment_ids = self.env['scop.cotisation.idf'].sudo().search([
+ ('year', '=', self.year),
+ ('partner_id', '=', self.partner_id.id),
+ ('type', '!=', 'inv'),
+ ])
+ if payment_ids:
+ payments = payment_ids.mapped(lambda p: {
+ 'date': p.writing_date,
+ 'name': p.name,
+ 'ref': p.piece,
+ 'credit': p.credit,
+ })
+ payments_html = self._get_html_table(payments)
+ else:
+ payments_html = "<p>Il n'y a pas de paiements associés à cette cotisation</p>"
+ return payments_html
+ else:
+ return super(ScopContributionReport, self)._get_payment()