diff --git a/__manifest__.py b/__manifest__.py index 7f5f3e0cdd90377505116283eaf04a99deb2182a..4da91e7b79fbc2c5b3044c425e394d93272f328d 100755 --- a/__manifest__.py +++ b/__manifest__.py @@ -25,5 +25,7 @@ "wizard/scop_bordereau_update_confirm_view.xml", "wizard/scop_bordereau_validate_confirm_view.xml", "report/report_scop_bordereau.xml", + "report/report_scop_bordereau_payments.xml", + "report/report_scop_bordereau_refund.xml", ] } diff --git a/models/scop_bordereau_cg.py b/models/scop_bordereau_cg.py index e86da6ce20d6d37fcf334e6e53befd70ed610020..1c1edd37d36360b3025e52a3aae7e769d35433ea 100644 --- a/models/scop_bordereau_cg.py +++ b/models/scop_bordereau_cg.py @@ -411,9 +411,12 @@ class Bordereau(models.Model): """ MoveLine = self.env['account.move.line'] for bordereau in self: - inv_ids = bordereau.invoice_ids.ids + inv_ids = bordereau.invoice_ids + if bordereau.is_regul: + inv_ids = inv_ids.filtered( + lambda i: i.type == 'out_invoice') move_lines = MoveLine.search([ - ('invoice_id', 'in', inv_ids), + ('invoice_id', 'in', inv_ids.ids), ('account_id.internal_type', '=', 'receivable')], order='date_maturity', ) @@ -441,36 +444,24 @@ class Bordereau(models.Model): MoveLine = self.env['account.move.line'] for bordereau in self: inv_ids = bordereau.invoice_ids.ids - move_lines = MoveLine.search([ - ('invoice_id', 'in', inv_ids), + schedule_plan = MoveLine.read_group( + [('invoice_id', 'in', inv_ids), ('account_id.internal_type', '=', 'receivable')], - order='date_maturity', + fields=['date_maturity', 'credit', 'debit', 'amount_residual'], + groupby=['date_maturity:day'], + orderby='date_maturity', + lazy=False ) - schedule = list(dict.fromkeys(move_lines.mapped('date_maturity'))) - schedule.sort() - schedule_plan = [] - total_amount = 0 - total_paid = 0 - for date in schedule: - amount = 0 - amount_paid = 0 - for item in move_lines: - if item.date_maturity == date: - amount += item.debit - item.credit - if item.full_reconcile_id.reconciled_line_ids: - aml_payment = item.full_reconcile_id.reconciled_line_ids - move_lines - amount_paid += sum(aml_payment.mapped('credit')) - sum(aml_payment.mapped('debit')) - total_amount += amount - total_paid += amount_paid - schedule_plan.append({ - 'date': date.strftime('%d/%m/%Y'), - 'amount': amount, - 'amount_paid': amount_paid, - }) + total_amount = sum(list(map( + lambda l: l.get('debit'), schedule_plan))) + total_residual = sum(list(map( + lambda l: l.get('amount_residual'), schedule_plan))) + total_paid = total_amount - total_residual return { 'plan': schedule_plan, 'total_amount': total_amount, - 'total_paid': total_paid + 'total_paid': total_paid, + 'total_residual': total_residual } def get_contribution_type(self): @@ -478,13 +469,35 @@ class Bordereau(models.Model): Get contribution by type :return: dict type_contribution and amount """ + domain = [('id', 'in', self.invoice_ids.ids)] + if self.is_regul: + domain.append(('type', '=', 'out_invoice')) + return self.invoice_ids.read_group( + domain, + ['type_contribution_id', 'amount_total_signed'], + ['type_contribution_id']) + + def get_contribution_type_refund(self): + """ + Get contribution by type for refund + :return: dict type_contribution and amount + """ return self.invoice_ids.read_group( - [('id', 'in', self.invoice_ids.ids)], + [('id', 'in', self.invoice_ids.ids), ('type', '=', 'out_refund')], ['type_contribution_id', 'amount_total_signed'], ['type_contribution_id']) - # return self.invoice_ids.mapped(lambda c: { - # 'type_contribution': c.type_contribution_id.name, - # 'amount': c.amount_total_signed}) + + def get_move_reconciled(self, payment): + """ + Check if payment is reconciled + :param payment: account.payment object + :return: True or payment_id + """ + rec = True + for aml in payment.move_line_ids.filtered(lambda x: x.account_id.reconcile): + if not aml.reconciled: + rec = payment.id + return rec # Email def get_recipients(self): diff --git a/report/report_scop_bordereau.xml b/report/report_scop_bordereau.xml index d1eef71f299f85bb2ce267a96c253cbcbd99f5cc..617333522d0aaeb6cf86de0074e8601b25188703 100644 --- a/report/report_scop_bordereau.xml +++ b/report/report_scop_bordereau.xml @@ -35,14 +35,6 @@ <t t-if="o.partner_id.cedex"> <span t-field="o.partner_id.cedex"/></t> </div> </div> - <t t-if="o.is_regul"> - <div class="row"> - <div class="col-12" style="test-align: justify;"> - Une régularisation du bordereau initial a été effectuée pour le motif suivant : <span t-field="o.comment_regul"/><br/> - Date de régularisation : <span t-field="o.date_regul"/> - </div> - </div> - </t> <div class="row mb16"> <div class="col-12" style="font-style: italic; test-align: justify;"> Les cotisations sont calculées annuellement en début d’année sur la base du dernier exercice connu. Le versement se fait par quart tous les trimestres. Merci de retourner ce bordereau à la CG Scop avec le règlement correspondant @@ -72,7 +64,13 @@ <strong>Total cotisation annuelle <t t-esc="str(o.year)"/>*</strong> </td> <td class="text-right" style="border: none; background: inherit; color: inherit;"> - <strong></strong><span t-field="o.amount_total_cotiz" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></td> + <t t-if="o.is_regul"> + <strong><span t-esc="sum(o.invoice_ids.filtered(lambda i: i.type == 'out_invoice').mapped('amount_total_signed'))" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></strong> + </t> + <t t-else=""> + <strong><span t-field="o.amount_total_cotiz" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></strong> + </t> + </td> </tr> </table> </p> @@ -159,44 +157,6 @@ </t> </template> - <template id="report_bordereau_document_with_payments" inherit_id="cgscop_cotisation_cg.report_bordereau_document" primary="True"> - <xpath expr="//p[@id='schedule_table']" position="replace"> - <p id="schedule_table_with_payments"> - <t t-set="schedule_line" t-value="o.get_bordereau_move_line_with_payments()" /> - <table class="table table-sm table-striped" style="border: none;"> - <tr> - <th>Date d'échéance</th> - <th class="text-right">Montant appelé</th> - <th class="text-right">Montant réglé</th> - </tr> - <tr t-foreach="schedule_line.get('plan')" t-as="line" style="border-bottom: 1px solid #ccc;"> - <td style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('date')"/></td> - <td class="text-right" style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('amount')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></td> - <td class="text-right" style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('amount_paid')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></td> - </tr> - </table> - <table class="table table-sm table-striped" style="border: none;"> - <tr> - <th>Total appelé</th> - <th class="text-right">Total réglé</th> - <th class="text-right">Montant dû</th> - </tr> - <tr style="border-bottom: 1px solid #ccc;"> - <td style="border: none; background: inherit; color: inherit;"> - <t t-esc="schedule_line.get('total_amount')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/> - </td> - <td class="text-right" style="border: none; background: inherit; color: inherit;"> - <t t-esc="schedule_line.get('total_paid')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/> - </td> - <td class="text-right" style="border: none; background: inherit; color: inherit;"> - <t t-esc="schedule_line.get('total_amount') - schedule_line.get('total_paid')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/> - </td> - </tr> - </table> - </p> - </xpath> - </template> - <template id="report_bordereau"> <t t-call="web.html_container"> <t t-set="docs" t-value="docs.with_context(lang='fr')"/> @@ -206,15 +166,6 @@ </t> </template> - <template id="report_bordereau_with_payments"> - <t t-call="web.html_container"> - <t t-set="docs" t-value="docs.with_context(lang='fr')"/> - <t t-foreach="docs" t-as="o"> - <t t-call="cgscop_cotisation_cg.report_bordereau_document_with_payments" t-lang="fr"/> - </t> - </t> - </template> - <!-- QWeb Reports --> <report id="cgscop_bordereau_report" @@ -224,14 +175,6 @@ name="cgscop_cotisation_cg.report_bordereau" file="cgscop_cotisation_cg.report_bordereau" /> - <report - id="cgscop_bordereau_report_with_payments" - model="scop.bordereau" - string="Bordereau de Cotisation CG avec paiement" - report_type="qweb-pdf" - name="cgscop_cotisation_cg.report_bordereau_with_payments" - file="cgscop_cotisation_cg.report_bordereau_with_payments" - /> </data> </odoo> diff --git a/report/report_scop_bordereau_payments.xml b/report/report_scop_bordereau_payments.xml new file mode 100644 index 0000000000000000000000000000000000000000..10dc05fe088853881a16a781eecf2d7d373aa6a5 --- /dev/null +++ b/report/report_scop_bordereau_payments.xml @@ -0,0 +1,138 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + + <template id="report_bordereau_document_with_payments"> + <t t-call="web.external_layout"> + <t t-set="o" t-value="o.with_context(lang='fr')" /> + <div class="page" style="font-size: 14px;"> + <div class="row"> + <div class="col-12 text-center"> + <h2 style="color: #E5074D;"> + Etat des paiements de cotisation <span t-esc="str(o.year)"/> + </h2> + </div> + </div> + <div class="row"> + <div class="col-12"> + <p> + N° adhérent : <t t-esc="str(o.partner_id.member_number_int)"/><br/> + Union régionale : <span t-field="o.partner_ur_id.name"/><br/> + N° Bordereau : <span t-field="o.name"/><t t-if="o.is_regul">-<span t-field="o.version"/></t> + </p> + </div> + </div> + <div class="row"> + <div class="col-6 offset-6 mt16 mb32"> + <span t-field="o.partner_id.name" style="text-transform: uppercase; font-weight: 600;"/><br/> + <span t-field="o.partner_id.street" /><br/> + <t t-if="o.partner_id.street2"><span t-field="o.partner_id.street2"/><br/></t> + <t t-if="o.partner_id.street3"><span t-field="o.partner_id.street3"/><br/></t> + <span t-field="o.partner_id.zip" /> <span t-field="o.partner_id.city" style="text-transform: uppercase;"/> + <t t-if="o.partner_id.cedex"> <span t-field="o.partner_id.cedex"/></t> + </div> + </div> + <div class="row"> + <div class="col-6" style="border: 1px solid #aaa;"> + <div></div> + <h5 class="mt8" style="font-weight: 600;">Cotisations annuelles</h5> + <p style="font-style: italic; font-size: 13px;"> + <t t-if="o.year_liasse_retenue">Calcul basé sur la liasse fiscale <span t-esc="str(o.year_liasse_retenue)" /><br/></t> + Assiette base <span t-field="o.type_assiette_retenu" /> : <span t-field="o.montant_assiette" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" />. + </p> + <p> + <t t-set="amount_line" t-value="o.get_contribution_type()" /> + <table class="table table-sm" style="border: none;"> + <tr t-foreach="amount_line" t-as="line" style="border-bottom: 1px solid #ccc;"> + <td style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('type_contribution_id')[1]"/></td> + <td class="text-right" style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('amount_total_signed')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></td> + </tr> + </table> + </p> + <p> + <table class="table table-sm" style="border: none;"> + <tr style="border: none"> + <td style="border: none; background: inherit; color: inherit;"> + <strong>Total cotisation annuelle <t t-esc="str(o.year)"/>*</strong> + </td> + <td class="text-right" style="border: none; background: inherit; color: inherit;"> + <strong></strong><span t-field="o.amount_total_cotiz" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></td> + </tr> + </table> + </p> + + <h5 style="font-weight: 600;">Échéancier</h5> + + <p id="schedule_table_with_payments"> + <t t-set="schedule_line" t-value="o.get_bordereau_move_line_with_payments()" /> + <table class="table table-sm table-striped" style="border: none;"> + <tr> + <th>Date d'échéance</th> + <th class="text-right">Montant appelé</th> + <th class="text-right">Montant réglé</th> + </tr> + <tr t-foreach="schedule_line.get('plan')" t-as="line" style="border-bottom: 1px solid #ccc;"> + <td style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('date_maturity:day')"/></td> + <td class="text-right" style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('debit')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></td> + <td class="text-right" style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('debit') - line.get('amount_residual')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></td> + </tr> + </table> + <table class="table table-sm table-striped" style="border: none;"> + <tr> + <th>Total appelé</th> + <th class="text-right">Total réglé</th> + <th class="text-right">Montant dû</th> + </tr> + <tr style="border-bottom: 1px solid #ccc;"> + <td style="border: none; background: inherit; color: inherit;"> + <t t-esc="schedule_line.get('total_amount')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/> + </td> + <td class="text-right" style="border: none; background: inherit; color: inherit;"> + <t t-esc="schedule_line.get('total_paid')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/> + </td> + <td class="text-right" style="border: none; background: inherit; color: inherit;"> + <t t-esc="schedule_line.get('total_residual')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/> + </td> + </tr> + </table> + </p> + <p style="font-size: 13px;"> + <em>IBAN: FR76 4255 9100 0008 0024 8837 710 - BIC : CCOPFRPPXXX</em> + </p> + </div> + + <div class="col-6" style="margin-top: 220px;"> + <div style="border: 1px solid #aaa; padding: 15px;"> + CG Scop <br/> + 30, rue des Epinettes <br/> + 75017 PARIS + </div> + </div> + </div> + + </div> + </t> + </template> + + + <template id="report_bordereau_with_payments"> + <t t-call="web.html_container"> + <t t-set="docs" t-value="docs.with_context(lang='fr')"/> + <t t-foreach="docs" t-as="o"> + <t t-call="cgscop_cotisation_cg.report_bordereau_document_with_payments" t-lang="fr"/> + </t> + </t> + </template> + + <!-- QWeb Reports --> + <report + id="cgscop_bordereau_report_with_payments" + model="scop.bordereau" + string="Etat des paiements" + report_type="qweb-pdf" + name="cgscop_cotisation_cg.report_bordereau_with_payments" + file="cgscop_cotisation_cg.report_bordereau_with_payments" + /> + + </data> +</odoo> diff --git a/report/report_scop_bordereau_refund.xml b/report/report_scop_bordereau_refund.xml new file mode 100644 index 0000000000000000000000000000000000000000..104ab30e424ee7185999a53e5c393c6dd4cfe516 --- /dev/null +++ b/report/report_scop_bordereau_refund.xml @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + + <template id="report_bordereau_document_refund"> + <t t-call="web.external_layout"> + <t t-set="o" t-value="o.with_context(lang='fr')" /> + <div class="page" style="font-size: 14px;"> + <div class="row"> + <div class="col-12 text-center"> + <h2 style="color: #E5074D;"> + Avoir sur Appel de cotisation <span t-esc="str(o.year)"/> + </h2> + </div> + </div> + <div class="row"> + <div class="col-12"> + <p> + Paris, le <span t-esc="o.date_regul" t-options="{'widget': 'date', 'format': 'd MMMM YYYY'}"/> + </p> + <p> + N° adhérent : <t t-esc="str(o.partner_id.member_number_int)"/><br/> + Union régionale : <span t-field="o.partner_ur_id.name"/><br/> + N° Bordereau : <span t-field="o.name"/><t t-if="o.is_regul">-<span t-field="o.version"/></t> + </p> + </div> + </div> + <div class="row"> + <div class="col-6 offset-6 mt16 mb32"> + <span t-field="o.partner_id.name" style="text-transform: uppercase; font-weight: 600;"/><br/> + <span t-field="o.partner_id.street" /><br/> + <t t-if="o.partner_id.street2"><span t-field="o.partner_id.street2"/><br/></t> + <t t-if="o.partner_id.street3"><span t-field="o.partner_id.street3"/><br/></t> + <span t-field="o.partner_id.zip" /> <span t-field="o.partner_id.city" style="text-transform: uppercase;"/> + <t t-if="o.partner_id.cedex"> <span t-field="o.partner_id.cedex"/></t> + </div> + </div> + <div class="row"> + <div class="col-6" style="border: 1px solid #aaa;"> + <div></div> + <h5 class="mt8" style="font-weight: 600;">Cotisations annuelles</h5> +<!-- <p style="font-style: italic; font-size: 13px;">--> +<!-- <t t-if="o.year_liasse_retenue">Calcul basé sur la liasse fiscale <span t-esc="str(o.year_liasse_retenue)" /><br/></t>--> +<!-- Assiette base <span t-field="o.type_assiette_retenu" /> : <span t-field="o.montant_assiette" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" />.--> +<!-- </p>--> + <p> + <t t-set="amount_line" t-value="o.get_contribution_type_refund()" /> + <table class="table table-sm" style="border: none;"> + <tr t-foreach="amount_line" t-as="line" style="border-bottom: 1px solid #ccc;"> + <td style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('type_contribution_id')[1]"/></td> + <td class="text-right" style="border: none; background: inherit; color: inherit;"><t t-esc="line.get('amount_total_signed')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/></td> + </tr> + </table> + </p> + <p> + <table class="table table-sm" style="border: none;"> + <tr style="border: none"> + <td style="border: none; background: inherit; color: inherit;"> + <strong>Total avoir cotisation annuelle <t t-esc="str(o.year)"/></strong> + </td> + <td class="text-right" style="border: none; background: inherit; color: inherit;"> + <strong></strong><span t-esc="sum(list(map(lambda l: l.get('amount_total_signed'), amount_line)))" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}"/> + </td> + </tr> + </table> + </p> + + + </div> + + <div class="col-6" style="margin-top: 220px;"> + <div style="border: 1px solid #aaa; padding: 15px;"> + CG Scop <br/> + 30, rue des Epinettes <br/> + 75017 PARIS + </div> + </div> + </div> + </div> + </t> + </template> + + <template id="report_bordereau_refund"> + <t t-call="web.html_container"> + <t t-set="docs" t-value="docs.with_context(lang='fr')"/> + <t t-foreach="docs" t-as="o"> + <t t-call="cgscop_cotisation_cg.report_bordereau_document_refund" t-lang="fr"/> + </t> + </t> + </template> + + + <!-- QWeb Reports --> + <report + id="cgscop_bordereau_report_refund" + model="scop.bordereau" + string="Avoir de Cotisation CG" + report_type="qweb-pdf" + name="cgscop_cotisation_cg.report_bordereau_refund" + file="cgscop_cotisation_cg.report_bordereau_refund" + groups="cgscop_partner.group_cg_administrator" + /> + + </data> +</odoo>