Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • lefilament/cgscop/cgscop_cotisation
  • hsilvant/cgscop_cotisation
2 results
Select Git revision
Show changes
Commits on Source (3)
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
], ],
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",
"datas/mail_data.xml",
"views/account_banking_mandate.xml", "views/account_banking_mandate.xml",
"views/account_move.xml", "views/account_move.xml",
"views/account_payment_order.xml", "views/account_payment_order.xml",
......
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<!-- Email d'avis de prélèvement -->
<record id="email_template_payment_order" model="mail.template">
<field name="name">CG SCOP : Prélèvements</field>
<field
name="model_id"
ref="account_payment_order.model_account_payment_order"
/>
<field
name="email_from"
>"Confédération Générale des Scop et Scic" &lt;administratif.cg@scop.coop&gt;</field>
<field
name="reply_to"
>"Confédération Générale des Scop et Scic" &lt;administratif.cg@scop.coop&gt;</field>
<field name="partner_to">${object.get_recipients()}</field>
<field name="subject">CG SCOP : Avis de prélèvement</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
<p>Chère Coopératrice, Cher Coopérateur,</p>
<p>&#160;</p>
<p
>Un prélèvement d'un montant de ${format_amount(object.get_email_values().get("total"), object.company_currency_id)} va être effectué en date du ${object.get_email_values().get("date").strftime('%d/%m/%Y')}.</p>
<p>&#160;</p>
<p
>Nous vous prions d'agréer, Chère Coopératrice, Cher Coopérateur, nos sentiments les meilleurs.</p>
<p>&#160;</p>
<p>L'équipe de la CGScop</p>
</p>
</div>
</field>
<field name="lang">fr_FR</field>
<field name="auto_delete" eval="False" />
</record>
</data>
</odoo>
# Copyright 2020 Le Filament # Copyright 2020 Le Filament
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models from odoo import _, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import UserError, ValidationError
class AccountPaymentOrder(models.Model): class AccountPaymentOrder(models.Model):
...@@ -20,6 +20,9 @@ class AccountPaymentOrder(models.Model): ...@@ -20,6 +20,9 @@ class AccountPaymentOrder(models.Model):
mandate_validity = fields.Boolean( mandate_validity = fields.Boolean(
"Mandats valides", compute="_compute_mandate_validity" "Mandats valides", compute="_compute_mandate_validity"
) )
email_sent = fields.Boolean("Email envoyé aux coopératives", default=False)
email_datetime = fields.Datetime("Date email envoyé aux coopératives")
email_count = fields.Integer(string="Nombre de mails", compute="_compute_emails")
# ------------------------------------------------------ # ------------------------------------------------------
# Compute fields # Compute fields
...@@ -52,6 +55,14 @@ class AccountPaymentOrder(models.Model): ...@@ -52,6 +55,14 @@ class AccountPaymentOrder(models.Model):
else: else:
o.mandate_validity = True o.mandate_validity = True
# Emails
def _compute_emails(self):
for r in self:
email_ids = self.env["mail.mail"].search(
[("mail_message_id", "in", r.message_ids.ids)]
)
r.email_count = len(email_ids)
# ------------------------------------------------------ # ------------------------------------------------------
# Button function # Button function
# ------------------------------------------------------ # ------------------------------------------------------
...@@ -107,6 +118,36 @@ class AccountPaymentOrder(models.Model): ...@@ -107,6 +118,36 @@ class AccountPaymentOrder(models.Model):
"domain": [["id", "in", mandate_ids.ids]], "domain": [["id", "in", mandate_ids.ids]],
} }
def action_send_email(self):
self.ensure_one()
try:
template = self.env.ref("cgscop_cotisation.email_template_payment_order")
except Exception:
raise UserError(
_(
"Aucun modèle d'e-mail n'a été trouvé pour envoyer un "
"e-mail à la DIRECCTE"
)
)
# Get partners
partner_ids = self.payment_line_ids.mapped("partner_id")
for partner in partner_ids:
template.with_context(partner_id=partner.id).send_mail(
self.id,
)
self.email_sent = True
self.email_datetime = fields.Datetime.now()
def action_show_emails(self):
return {
"name": "Etat des mails envoyés",
"type": "ir.actions.act_window",
"view_mode": "tree",
"views": [(False, "tree"), (False, "form")],
"res_model": "mail.mail",
"domain": [("mail_message_id", "in", self.message_ids.ids)],
}
# ------------------------------------------------------ # ------------------------------------------------------
# Common function # Common function
# ------------------------------------------------------ # ------------------------------------------------------
...@@ -130,6 +171,36 @@ class AccountPaymentOrder(models.Model): ...@@ -130,6 +171,36 @@ class AccountPaymentOrder(models.Model):
else: else:
return True return True
# Email
def get_email_values(self):
self.ensure_one()
partner_id = self.env["res.partner"].browse(self.env.context.get("partner_id"))
partner_line_ids = self.payment_line_ids.filtered(
lambda l: l.partner_id == partner_id
)
return {
"total": sum(partner_line_ids.mapped("amount_currency")),
"date": partner_line_ids.mapped("date")[0],
}
def get_recipients(self):
recipients = ",".join(map(lambda x: str(x), self._get_recipient().ids))
return recipients
def _get_recipient(self):
partner_id = self.env["res.partner"].browse(self.env.context.get("partner_id"))
if partner_id:
tag_cotiz_id = self.env.company.tag_cotiz_id
child_ids = partner_id.child_ids.filtered(
lambda child: (tag_cotiz_id in child.category_id) and child.email
)
if partner_id.email:
recipient_ids = partner_id + child_ids
else:
recipient_ids = child_ids
return recipient_ids
# ------------------------------------------------------ # ------------------------------------------------------
# Override Parent # Override Parent
# ------------------------------------------------------ # ------------------------------------------------------
......
# © 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).
import logging
from psycopg2.extensions import AsIs from psycopg2.extensions import AsIs
from odoo import api, fields, models, tools from odoo import api, fields, models, tools
_logger = logging.getLogger(__name__)
class ScopContributionReport(models.Model): class ScopContributionReport(models.Model):
_name = "scop.contribution.report" _name = "scop.contribution.report"
...@@ -146,6 +150,7 @@ class ScopContributionReport(models.Model): ...@@ -146,6 +150,7 @@ class ScopContributionReport(models.Model):
"CREATE or REPLACE VIEW %s as (%s)", "CREATE or REPLACE VIEW %s as (%s)",
(AsIs(self._table), AsIs(self._query())), (AsIs(self._table), AsIs(self._query())),
) )
self._set_ro_table()
# ------------------------------------------------------ # ------------------------------------------------------
# Computed fields # Computed fields
......
...@@ -13,6 +13,26 @@ ...@@ -13,6 +13,26 @@
/> />
<field name="priority">100</field> <field name="priority">100</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<!-- Header and buttons -->
<xpath expr="//button[@name='action_cancel']" position="after">
<button
name="action_send_email"
type="object"
string="Envoyer un email aux coopératives"
class="btn-info"
groups="base.group_system"
attrs="{'invisible': ['|', ('state', 'not in', ('generated', 'uploaded')), ('email_sent', '=', True)]}"
confirm="Valider l'envoi des emails ?"
/>
<button
name="action_send_email"
type="object"
string="Renvoyer un email aux coopératives"
groups="base.group_system"
attrs="{'invisible': ['|', ('state', 'not in', ('generated', 'uploaded')), ('email_sent', '!=', True)]}"
confirm="Valider l'envoi des emails ?"
/>
</xpath>
<xpath expr="//button[@name='action_cancel']" position="attributes"> <xpath expr="//button[@name='action_cancel']" position="attributes">
<attribute <attribute
name="groups" name="groups"
...@@ -32,6 +52,32 @@ ...@@ -32,6 +52,32 @@
name="confirm" name="confirm"
>Confirmer l'annulation de l'ordre de prélèvement ?</attribute> >Confirmer l'annulation de l'ordre de prélèvement ?</attribute>
</xpath> </xpath>
<!-- Sheet -->
<!-- Button box -->
<xpath expr="//div[@name='button_box']" position="inside">
<button
class="oe_stat_button"
name="action_show_emails"
type="object"
icon="fa-envelope-o"
>
<field string="Emails" name="email_count" widget="statinfo" />
</button>
</xpath>
<!-- Alert -->
<xpath expr="//div[hasclass('oe_title')]" position="before">
<field name="email_sent" invisible="1" />
<div
class="alert alert-warning"
role="alert"
attrs="{'invisible': [('email_sent', '!=', True)]}"
>
Un email a été envoyé aux coopératives le
<field name="email_datetime" readonly="1" />
</div>
</xpath>
<!-- Sheet Buttons -->
<xpath expr="//field[@name='bank_line_count']" position="after"> <xpath expr="//field[@name='bank_line_count']" position="after">
<field name="payment_line_amount" /> <field name="payment_line_amount" />
<field name="bank_line_amount" /> <field name="bank_line_amount" />
......