paso a pos.sessions más natural, los apuntes están ahí.
This commit is contained in:
parent
62e0e8a92c
commit
80f24bcc46
2 changed files with 42 additions and 36 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue