acción de servidor para crear mandatos bancarios en lote
This commit is contained in:
parent
65818b0155
commit
42da5ed3db
4 changed files with 105 additions and 0 deletions
31
account_banking_mandate_batch/README.md
Normal file
31
account_banking_mandate_batch/README.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Account Banking Mandate Batch Create
|
||||
|
||||
Adds a contextual server action **Create SEPA mandates** to the Contacts
|
||||
(`res.partner`) list and form views.
|
||||
|
||||
## Usage
|
||||
|
||||
1. Go to *Contacts* (or *Accounting → Customers*), switch to list view.
|
||||
2. Filter the partners you want (e.g. your members: `is_client = True`).
|
||||
3. Select them (tick the header checkbox to select all).
|
||||
4. *Actions → Create SEPA mandates*.
|
||||
|
||||
For each selected partner the action:
|
||||
|
||||
- takes the partner's first bank account (`bank_ids[:1]`),
|
||||
- creates a recurrent SEPA Core mandate (`format=sepa`, `type=recurrent`,
|
||||
`scheme=CORE`) with today's signature date,
|
||||
- validates it (state → *valid*).
|
||||
|
||||
Partners with no bank account, or that already have a draft/valid mandate,
|
||||
are skipped. A notification reports created / skipped counts.
|
||||
|
||||
> **Legal note:** only create mandates for members who have actually
|
||||
> authorised the direct debit. Adjust the signature date in
|
||||
> `data/server_action.xml` if you need the real authorisation date.
|
||||
|
||||
## Requirements
|
||||
|
||||
Depends on `account_banking_sepa_direct_debit` (OCA `bank-payment`), which
|
||||
pulls in `account_banking_mandate`, `account_payment_order` and
|
||||
`account_payment_mode`.
|
||||
0
account_banking_mandate_batch/__init__.py
Normal file
0
account_banking_mandate_batch/__init__.py
Normal file
14
account_banking_mandate_batch/__manifest__.py
Normal file
14
account_banking_mandate_batch/__manifest__.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "Account Banking Mandate Batch Create",
|
||||
"summary": "Adds a contextual action on contacts to create and validate "
|
||||
"SEPA direct debit mandates in bulk for the selected partners.",
|
||||
"version": "18.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Criptomart",
|
||||
"depends": ["account_banking_sepa_direct_debit"],
|
||||
"data": [
|
||||
"data/server_action.xml",
|
||||
],
|
||||
}
|
||||
60
account_banking_mandate_batch/data/server_action.xml
Normal file
60
account_banking_mandate_batch/data/server_action.xml
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="action_create_sepa_mandates" model="ir.actions.server">
|
||||
<field name="name">Create SEPA mandates</field>
|
||||
<field name="model_id" ref="base.model_res_partner" />
|
||||
<field name="binding_model_id" ref="base.model_res_partner" />
|
||||
<field name="binding_view_types">list,form</field>
|
||||
<field name="state">code</field>
|
||||
<field name="code"><![CDATA[
|
||||
# Bulk-create and validate recurrent SEPA Core mandates for the selected
|
||||
# partners. Filter the contacts list (e.g. is_client = True), select all,
|
||||
# then run this action. One mandate per partner; partners that already have
|
||||
# a draft/valid mandate or no bank account are skipped.
|
||||
Mandate = env["account.banking.mandate"]
|
||||
today = datetime.date.today()
|
||||
|
||||
created = 0
|
||||
no_bank = 0
|
||||
already = 0
|
||||
|
||||
for partner in records:
|
||||
bank = partner.bank_ids[:1]
|
||||
if not bank:
|
||||
no_bank += 1
|
||||
continue
|
||||
if Mandate.search_count([
|
||||
("partner_id", "=", partner.id),
|
||||
("state", "in", ("draft", "valid")),
|
||||
]):
|
||||
already += 1
|
||||
continue
|
||||
mandate = Mandate.create({
|
||||
"partner_bank_id": bank.id,
|
||||
"format": "sepa",
|
||||
"type": "recurrent",
|
||||
"scheme": "CORE",
|
||||
"signature_date": today,
|
||||
})
|
||||
mandate.validate()
|
||||
created += 1
|
||||
|
||||
message = (
|
||||
"SEPA mandates created: %s\n"
|
||||
"Already had a mandate: %s\n"
|
||||
"Skipped (no bank account): %s"
|
||||
) % (created, already, no_bank)
|
||||
|
||||
action = {
|
||||
"type": "ir.actions.client",
|
||||
"tag": "display_notification",
|
||||
"params": {
|
||||
"title": "SEPA mandates",
|
||||
"message": message,
|
||||
"type": "success" if created else "warning",
|
||||
"sticky": False,
|
||||
},
|
||||
}
|
||||
]]></field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue