paso a pos.sessions más natural, los apuntes están ahí.

This commit is contained in:
GitHub Copilot 2026-06-26 19:57:07 +02:00
parent 62e0e8a92c
commit 80f24bcc46
2 changed files with 42 additions and 36 deletions

View file

@ -1,27 +1,32 @@
# POS Account Payment Order SEPA
Adds a contextual action **"Collect by SEPA direct debit"** on the POS orders
list/form (Point of Sale → Orders).
Adds a contextual action **"Collect by SEPA direct debit"** on the POS
sessions list/form (Point of Sale → Sessions).
## Purpose
When a POS order is paid with a *"Customer Account"* payment method
(`split_transactions = True`), Odoo does not register a real collection: it
leaves the amount as an **open receivable** for the customer inside the
session's journal entry. This module lets you collect those receivables in
bulk through a **SEPA direct debit payment order** (debit order), without
(`split_transactions = True`) and is **not invoiced**, Odoo does not register a
real collection nor a per-order accounting move: the amount lands as an **open
receivable** for the customer inside the **session's** single journal entry
(`pos.session.move_id`). This module lets you collect those receivables in bulk
through a **SEPA direct debit payment order** (debit order), without
re-invoicing the already-issued (simplified) tickets.
> The action runs on **sessions** (not orders) precisely because the receivable
> lives in the session move, not in the order. Selecting the sessions of the
> affected period collects every open "Customer Account" line in them.
## Usage
1. Make sure the affected customers have a **valid SEPA mandate** (see
`account_banking_mandate_batch`).
2. Go to **Point of Sale → Orders**, filter the orders paid on account, select
them and run **Action → Collect by SEPA direct debit**.
2. Go to **Point of Sale → Sessions**, filter the sessions of the period,
select them and run **Action → Collect by SEPA direct debit**.
3. The action creates the **payment lines** inside a draft inbound SEPA
payment order, grouped by payment mode. Orders without an open receivable,
without a partner, already queued, or whose partner has no valid mandate are
**skipped and reported**.
payment order, grouped by payment mode. Receivable lines without a partner,
already queued, or whose partner has no valid mandate are **skipped and
reported**. Already-collected lines (reconciled) are ignored.
4. Open **Invoicing → Customers → Payment Orders**, confirm it and **generate
the SEPA file (pain.008)**.

View file

@ -2,37 +2,38 @@
<odoo>
<record id="action_pos_collect_sepa" model="ir.actions.server">
<field name="name">Collect by SEPA direct debit</field>
<field name="model_id" ref="point_of_sale.model_pos_order" />
<field name="binding_model_id" ref="point_of_sale.model_pos_order" />
<field name="model_id" ref="point_of_sale.model_pos_session" />
<field name="binding_model_id" ref="point_of_sale.model_pos_session" />
<field name="binding_view_types">list,form</field>
<field name="state">code</field>
<field name="code"><![CDATA[
# Collect the still-open "Customer Account" receivables generated by the
# selected POS orders through a SEPA direct debit payment order (debit
# order). For each order we take the receivable journal item of its session
# move, keep the unreconciled ones whose partner has a valid SEPA mandate,
# and create the payment lines inside a single draft inbound payment order.
# The SEPA XML (pain.008) is generated afterwards from that order by the user.
# Collect the still-open "Customer Account" receivables of the selected POS
# sessions through a SEPA direct debit payment order (debit order).
#
# Orders are skipped (and reported) when: no accounting move yet, no open
# Unfactured POS orders do not get their own accounting move: the receivable
# generated by a "Customer Account" payment method (split_transactions) lands
# in the SINGLE journal entry of the session (session.move_id). So we read the
# open receivable lines from that move, keep the ones whose partner has a valid
# SEPA mandate, and create the payment lines inside a draft inbound payment
# order. The SEPA file (pain.008) is generated afterwards from that order.
#
# Lines are skipped (and reported) when: the session has no move yet, no open
# receivable line, no partner, the line is already in a payment order, or the
# partner has no valid SEPA mandate. Refunds/credit lines are ignored.
# partner has no valid SEPA mandate.
Mode = env["account.payment.mode"]
Order = env["account.payment.order"]
Mandate = env["account.banking.mandate"]
PaymentLine = env["account.payment.line"]
# --- Resolve the inbound SEPA payment mode (partner mode, with fallback) ---
def sepa_mode_for(partner):
mode = partner.customer_payment_mode_id
if (
def is_sepa_inbound(mode):
return bool(
mode
and mode.payment_order_ok
and mode.payment_method_id.code == "sepa_direct_debit"
and mode.payment_method_id.payment_type == "inbound"
):
return mode
return False
)
fallback_mode = Mode.search(
[
@ -43,12 +44,12 @@ fallback_mode = Mode.search(
limit=1,
)
# --- Classify the selected orders ---
# --- Collect open receivable lines from the selected sessions' moves ---
lines_by_mode = {}
skipped = {"no_move": 0, "no_line": 0, "no_partner": 0, "already": 0, "no_mandate": 0, "no_mode": 0}
for order in records:
move = order.account_move
for session in records:
move = session.move_id
if not move:
skipped["no_move"] += 1
continue
@ -65,7 +66,7 @@ for order in records:
if not partner:
skipped["no_partner"] += 1
continue
if env["account.payment.line"].search_count(
if PaymentLine.search_count(
[("move_line_id", "=", line.id), ("order_id.state", "!=", "cancel")]
):
skipped["already"] += 1
@ -75,7 +76,8 @@ for order in records:
):
skipped["no_mandate"] += 1
continue
mode = sepa_mode_for(partner) or fallback_mode
partner_mode = partner.customer_payment_mode_id
mode = partner_mode if is_sepa_inbound(partner_mode) else fallback_mode
if not mode:
skipped["no_mode"] += 1
continue
@ -86,7 +88,6 @@ for order in records:
created_lines = 0
order_names = []
for mode_id, move_lines in lines_by_mode.items():
mode = Mode.browse(mode_id)
payment_order = Order.search(
[("payment_mode_id", "=", mode_id), ("state", "=", "draft")], limit=1
)
@ -101,9 +102,9 @@ message = (
"Payment lines created: %(created)s\n"
"Payment order(s): %(orders)s\n\n"
"Skipped:\n"
" no accounting move: %(no_move)s\n"
" no open receivable line: %(no_line)s\n"
" no partner: %(no_partner)s\n"
" session without accounting move: %(no_move)s\n"
" session without open receivable line: %(no_line)s\n"
" line without partner: %(no_partner)s\n"
" already in a payment order: %(already)s\n"
" no valid SEPA mandate: %(no_mandate)s\n"
" no SEPA payment mode: %(no_mode)s"