Skip to content
Extraits de code Groupes Projets
Valider 74da02de rédigé par jordan's avatar jordan
Parcourir les fichiers

[update] report invoice and contribution deal with multi-modules (cg, riga, idf)

parent 13e37eb4
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"installable": True, "installable": True,
"depends": [ "depends": [
"cgscop_partner", "cgscop_partner",
"cgscop_cotisation",
"multi_company_menu", "multi_company_menu",
], ],
"data": [ "data": [
......
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import account_invoice_all from . import account_invoice_all
from . import scop_contribution_report
# © 2022 Le Filament (<http://www.le-filament.com>) # © 2022 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # 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): class ScopAccountInvoiceIDFReport(models.Model):
_inherit = "account.invoice.all" _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 += """ select_str += """
UNION ALL ( UNION ALL (
SELECT SELECT
id,
null as invoice_id, null as invoice_id,
writing_date as date_invoice, writing_date as date_invoice,
writing_date as date_due, writing_date as date_due,
...@@ -36,3 +38,35 @@ class ScopAccountInvoiceIDFReport(models.Model): ...@@ -36,3 +38,35 @@ class ScopAccountInvoiceIDFReport(models.Model):
) )
""" """
return select_str 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()
# © 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()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter