Skip to content
Extraits de code Groupes Projets
Valider 8e7af0b9 rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[update] compute is_loss & review query

parent ed6739ed
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -21,7 +21,7 @@ class ScopContributionReport(models.Model): ...@@ -21,7 +21,7 @@ class ScopContributionReport(models.Model):
amount_called = fields.Float('Montant Appelé') amount_called = fields.Float('Montant Appelé')
amount_paid = fields.Float('Montant Payé') amount_paid = fields.Float('Montant Payé')
amount_due = fields.Float('Montant Restant') amount_due = fields.Float('Montant Restant')
is_loss = fields.Boolean('Exonération/Perte') is_loss = fields.Boolean('Exonération/Perte', compute="_compute_is_loss")
payments = fields.Html('Paiements', compute="_compute_payments") payments = fields.Html('Paiements', compute="_compute_payments")
_depends = { _depends = {
...@@ -43,8 +43,7 @@ class ScopContributionReport(models.Model): ...@@ -43,8 +43,7 @@ class ScopContributionReport(models.Model):
i.partner_id, i.partner_id,
SUM(i.amount_total_signed) AS amount_called, SUM(i.amount_total_signed) AS amount_called,
SUM(i.amount_total_signed - i.residual_company_signed) AS amount_paid, SUM(i.amount_total_signed - i.residual_company_signed) AS amount_paid,
SUM(i.residual_company_signed) AS amount_due, SUM(i.residual_company_signed) AS amount_due
(CASE WHEN max(refund.id) IS NOT NULL THEN true ELSE FALSE END) AS is_loss
""" """
return select_str return select_str
...@@ -52,16 +51,13 @@ class ScopContributionReport(models.Model): ...@@ -52,16 +51,13 @@ class ScopContributionReport(models.Model):
from_str = """ from_str = """
FROM FROM
account_invoice i account_invoice i
LEFT JOIN
account_invoice refund ON refund.refund_invoice_id = i.id
""" """
return from_str return from_str
def _where_invoice(self): def _where_invoice(self):
where_str = """ where_str = """
WHERE WHERE
i.type = 'out_invoice' AND i.state in ('open', 'paid', 'in_payment') AND
i.state in ('open', 'paid') AND
i.is_contribution = true i.is_contribution = true
""" """
return where_str return where_str
...@@ -96,8 +92,7 @@ class ScopContributionReport(models.Model): ...@@ -96,8 +92,7 @@ class ScopContributionReport(models.Model):
c.partner_id, c.partner_id,
SUM(c.amount_called) AS amount_called, SUM(c.amount_called) AS amount_called,
SUM(c.amount_paid) AS amount_paid, SUM(c.amount_paid) AS amount_paid,
SUM(c.amount_due) AS amount_due, SUM(c.amount_due) AS amount_due
BOOL_OR(c.is_loss) AS is_loss
FROM ( FROM (
""" """
return select_str return select_str
...@@ -131,6 +126,11 @@ class ScopContributionReport(models.Model): ...@@ -131,6 +126,11 @@ class ScopContributionReport(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Computed fields # Computed fields
# ------------------------------------------------------ # ------------------------------------------------------
@api.multi
def _compute_is_loss(self):
for contribution in self:
contribution.is_loss = contribution._get_is_loss()
@api.multi @api.multi
def _compute_name(self): def _compute_name(self):
for contribution in self: for contribution in self:
...@@ -146,13 +146,26 @@ class ScopContributionReport(models.Model): ...@@ -146,13 +146,26 @@ class ScopContributionReport(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Business functions # Business functions
# ------------------------------------------------------ # ------------------------------------------------------
def _get_is_loss(self):
invoice_ids = self.env['account.invoice'].search([
('year', '=', int(self.year)),
('partner_id', '=', self.partner_id.id),
('type_contribution_id', '=', self.type_contribution_id.id),
])
refund_ids = invoice_ids.filtered(lambda i: i.type == 'out_refund')
if refund_ids:
return True
else:
return False
def _get_payment(self): def _get_payment(self):
self.ensure_one() self.ensure_one()
invoice_ids = self.env['account.invoice'].search([ invoice_ids = self.env['account.invoice'].search([
('year', '=', int(self.year)), ('year', '=', int(self.year)),
('partner_id', '=', self.partner_id.id), ('partner_id', '=', self.partner_id.id),
('type_contribution_id', '=', self.type_contribution_id.id), ('type_contribution_id', '=', self.type_contribution_id.id),
('type', '=', 'out_invoice') ('type', '=', 'out_invoice'),
('bordereau_id.state', 'not in', ('cancel',))
]) ])
payment_ids = invoice_ids.mapped('payment_move_line_ids') payment_ids = invoice_ids.mapped('payment_move_line_ids')
if payment_ids: if payment_ids:
...@@ -161,6 +174,13 @@ class ScopContributionReport(models.Model): ...@@ -161,6 +174,13 @@ class ScopContributionReport(models.Model):
'name': p.name, 'name': p.name,
'ref': p.ref, 'ref': p.ref,
'credit': p.credit, 'credit': p.credit,
'class': ''
} if not p.invoice_id else {
'date': p.date,
'name': p.name,
'ref': 'Avoir',
'credit': p.credit,
'class': 'text-danger'
}) })
payments_html = self._get_html_table(payments) payments_html = self._get_html_table(payments)
else: else:
...@@ -185,13 +205,14 @@ class ScopContributionReport(models.Model): ...@@ -185,13 +205,14 @@ class ScopContributionReport(models.Model):
content_html = "" content_html = ""
for payment in payments: for payment in payments:
content_html += """ content_html += """
<tr> <tr class='%s'>
<td>%s</td> <td>%s</td>
<td>%s</td> <td>%s</td>
<td>%s</td> <td>%s</td>
<td class='text-right'>%.2f €</td> <td class='text-right'>%.2f €</td>
</tr> </tr>
""" % (payment.get('date', '').strftime('%d/%m/%Y'), """ % (payment.get('class', ''),
payment.get('date', '').strftime('%d/%m/%Y'),
payment.get('name', ''), payment.get('ref', ''), payment.get('name', ''), payment.get('ref', ''),
payment.get('credit', 0.0),) payment.get('credit', 0.0),)
......
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