Skip to content

Commit fb3ab36

Browse files
Morena Sandroniclaude
authored andcommitted
[FIX] account_payment_pro_receiptbook, account_payment_pro, l10n_ar_payment_bundle: apply upstream fixes from PRs ingadhoc#1055, ingadhoc#1054, ingadhoc#1051, ingadhoc#1049
- account_payment_pro_receiptbook: enforce receiptbook prefix in _get_next_sequence_format (PR ingadhoc#1055): replaces previous _get_last_sequence_domain approach; now detects prefix mismatch after _get_last_sequence() and falls back to direct SQL filtered by correct sequence_prefix, preventing PAY-prefixed orphan sequences from propagating. - account_payment_pro: sync amount when all to_pay lines removed (PR ingadhoc#1054); add _onchange_amount to keep amount in sync with to_pay_amount on line changes (PR ingadhoc#1049). - l10n_ar_payment_bundle: wrap action_post unlink/validation in for-rec loop and filter draft_linked by parent non-draft state to fix batch posting (PR ingadhoc#1051). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 36bf4ba commit fb3ab36

3 files changed

Lines changed: 47 additions & 29 deletions

File tree

account_payment_pro/models/account_payment.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,12 @@ def _compute_to_pay_amount(self):
984984
for rec in self:
985985
rec.to_pay_amount = rec.selected_debt + rec.unreconciled_amount
986986

987+
@api.onchange("to_pay_move_line_ids")
988+
def _onchange_amount(self):
989+
for rec in self.filtered(lambda r: r.company_id.use_payment_pro):
990+
if rec.amount != abs(rec.to_pay_amount):
991+
rec.amount = abs(rec.to_pay_amount)
992+
987993
@api.onchange("to_pay_amount")
988994
def _inverse_to_pay_amount(self):
989995
for rec in self:
@@ -1004,11 +1010,13 @@ def _onchange_to_pay_lines_adjust_amount(self):
10041010
Aplica a todos los tipos de pago (clientes y proveedores).
10051011
"""
10061012
for rec in self:
1007-
if not rec.use_payment_pro or rec.state != "draft":
1013+
if not rec.use_payment_pro or rec.state != "draft" or not rec.currency_id:
10081014
continue
10091015
if not rec.to_pay_move_line_ids:
1016+
if not rec.currency_id.is_zero(rec.amount - abs(rec.to_pay_amount)):
1017+
rec.amount = abs(rec.to_pay_amount)
10101018
continue
1011-
if not rec.payment_difference or not rec.currency_id:
1019+
if not rec.payment_difference:
10121020
continue
10131021
diff_in_a = rec._get_payment_difference_in_currency_a()
10141022
amount = rec.amount + diff_in_a

account_payment_pro_receiptbook/models/account_move.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,13 @@ class AccountMove(models.Model):
99
store=True,
1010
)
1111

12-
def _get_receiptbook_expected_prefix(self):
13-
# Derive the expected sequence_prefix from the receiptbook so we can
14-
# constrain _get_last_sequence_domain to only RE-X (or whatever the
15-
# talonario prefix is) and avoid PAY-prefixed orphan sequences from
16-
# poisoning the prefix subquery that Odoo base adds on top of our WHERE.
17-
self.ensure_one()
18-
if not self.receiptbook_id:
19-
return None
20-
if self.receiptbook_id.document_type_id:
21-
return "%s %s" % (
22-
self.receiptbook_id.document_type_id.doc_code_prefix,
23-
self.receiptbook_id.prefix or "",
24-
)
25-
return self.receiptbook_id.prefix or None
26-
2712
def _get_last_sequence_domain(self, relaxed=False):
2813
self.ensure_one()
2914
is_payment = self.origin_payment_id or self.env.context.get("is_payment")
3015

3116
if self.receiptbook_id and is_payment:
3217
where_string = "WHERE receiptbook_id = %(receiptbook_id)s AND name != '/'"
3318
param = {"receiptbook_id": self.receiptbook_id.id}
34-
expected_prefix = self._get_receiptbook_expected_prefix()
35-
if expected_prefix:
36-
where_string += " AND sequence_prefix = %(sequence_prefix)s"
37-
param["sequence_prefix"] = expected_prefix
3819
return where_string, param
3920
else:
4021
where_string, param = super()._get_last_sequence_domain(relaxed)
@@ -55,10 +36,36 @@ def _get_starting_sequence(self):
5536

5637
def _get_next_sequence_format(self):
5738
if self.receiptbook_id:
39+
starting_sequence = self._get_starting_sequence()
40+
format_string, starting_values = self._get_sequence_format_param(starting_sequence)
41+
expected_prefix = starting_values.get("prefix1", "")
42+
5843
last_sequence = self._get_last_sequence()
59-
new = not last_sequence
60-
if new:
61-
last_sequence = self._get_last_sequence(relaxed=True) or self._get_starting_sequence()
44+
45+
if last_sequence:
46+
_, last_values = self._get_sequence_format_param(last_sequence)
47+
if last_values.get("prefix1") != expected_prefix:
48+
# La última secuencia tiene un formato incorrecto (por error previo).
49+
# Buscamos en la BD la última secuencia válida para este receiptbook
50+
# filtrando directamente por el sequence_prefix correcto.
51+
self.flush_model(["name", "sequence_number", "sequence_prefix"])
52+
self.env.cr.execute(
53+
"""
54+
SELECT name FROM account_move
55+
WHERE receiptbook_id = %s
56+
AND name != '/'
57+
AND sequence_prefix = %s
58+
ORDER BY sequence_number DESC
59+
LIMIT 1
60+
""",
61+
[self.receiptbook_id.id, expected_prefix],
62+
)
63+
row = self.env.cr.fetchone()
64+
last_sequence = row[0] if row else None
65+
66+
if not last_sequence:
67+
starting_values["seq"] = 0
68+
return format_string, starting_values
6269

6370
format_string, format_values = self._get_sequence_format_param(last_sequence)
6471
return format_string, format_values

l10n_ar_payment_bundle/models/account_payment.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,12 @@ def _select_bundle(self, bundles):
227227
return super()._select_bundle(bundles)
228228

229229
def action_post(self):
230-
if self.link_payment_ids and self.payment_method_code != "payment_bundle":
231-
self.link_payment_ids.unlink()
230+
for rec in self:
231+
if rec.link_payment_ids and rec.payment_method_code != "payment_bundle":
232+
rec.link_payment_ids.unlink()
232233

233-
if self.main_payment_id and not self.main_payment_id.name:
234-
raise ValidationError(_("The main payment must have a name before a linked payment can be posted."))
234+
if rec.main_payment_id and not rec.main_payment_id.name:
235+
raise ValidationError(_("The main payment must have a name before a linked payment can be posted."))
235236

236237
self._check_bundle_currency_consistency()
237238

@@ -254,7 +255,9 @@ def action_post(self):
254255
payment.name = f"{self.name} ({next_num})"
255256
next_num += 1
256257

257-
draft_linked = self.link_payment_ids.filtered(lambda x: x.state == "draft")
258+
draft_linked = self.filtered(lambda x: x.state != "draft").link_payment_ids.filtered(
259+
lambda x: x.state == "draft"
260+
)
258261
if draft_linked:
259262
draft_linked.action_post()
260263

0 commit comments

Comments
 (0)