Coverage for ingadhoc-account-payment / account_payment_pro / models / account_move_line.py: 47%
44 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 19:54 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 19:54 +0000
1from odoo import _, api, fields, models
2from odoo.exceptions import UserError
5class AccountMoveLine(models.Model):
6 _inherit = "account.move.line"
8 payment_matched_amount = fields.Monetary(
9 compute="_compute_payment_matched_amount",
10 currency_field="company_currency_id",
11 )
13 @api.depends_context("matched_payment_ids")
14 def _compute_payment_matched_amount(self):
15 """
16 Reciviendo un matched_payment_id por contexto, decimos en ese payment, cuanto se pago para la lína en cuestión.
17 """
18 matched_payment_ids = self.env.context.get("matched_payment_ids")
20 if not matched_payment_ids:
21 self.payment_matched_amount = 0.0
22 return False
23 payments = self.env["account.payment"].search([("id", "in", matched_payment_ids)])
24 payment_lines = payments.move_id.mapped("line_ids").filtered(
25 lambda x: x.account_type in ["asset_receivable", "liability_payable"]
26 )
27 for rec in self:
28 debit_move_amount = sum(
29 payment_lines.mapped("matched_debit_ids").filtered(lambda x: x.debit_move_id == rec).mapped("amount")
30 )
31 credit_move_amount = sum(
32 payment_lines.mapped("matched_credit_ids").filtered(lambda x: x.credit_move_id == rec).mapped("amount")
33 )
34 rec.payment_matched_amount = debit_move_amount - credit_move_amount
36 def action_register_payment(self, ctx=None):
37 to_pay_partners = self.mapped("move_id.commercial_partner_id") or self.mapped("partner_id")
38 company_pay_pro = len(self.mapped("company_id").ids) == 1 and self.mapped("company_id").use_payment_pro
39 payment_pro = self.env.context.get("force_payment_pro")
40 # si force_payment_pro se pasa como False estamos forzando no usar payment pro, vamos a metodo original
41 # usamos payment pro si lo pasamos forzado (Caso pay and new donde todavia no tenemos company) o si estoy
42 # pagando deuda de una sola cia y tiene payment pro
43 # y si ademas estoy pagando solo deuda de un partner
44 if payment_pro is not False and ((payment_pro or company_pay_pro) and len(to_pay_partners) <= 1): 44 ↛ 96line 44 didn't jump to line 96 because the condition on line 44 was always true
45 to_pay_move_lines = self.filtered(
46 lambda r: not r.reconciled and r.account_id.account_type in ["asset_receivable", "liability_payable"]
47 )
48 if not to_pay_move_lines: 48 ↛ 49line 48 didn't jump to line 49 because the condition on line 48 was never true
49 partner_type = self.env.context.get("default_partner_type")
50 to_pay_partner_id = self.env.context.get("default_partner_id")
51 company_id = self.env.context.get("default_company_id")
52 if not partner_type or not to_pay_partner_id:
53 raise UserError(_("Nothing to be paid on selected entries"))
54 else:
55 to_pay_partner_id = to_pay_partners.id
56 partner_type = (
57 "customer" if to_pay_move_lines[0].account_id.account_type == "asset_receivable" else "supplier"
58 )
59 company_id = self.company_id.id
60 to_pay_amount = sum(line.amount_residual for line in to_pay_move_lines)
61 if to_pay_amount > 0: 61 ↛ 63line 61 didn't jump to line 63 because the condition on line 61 was always true
62 payment_type = "inbound"
63 elif to_pay_amount < 0:
64 payment_type = "outbound"
65 else:
66 payment_type = "inbound" if partner_type == "customer" else "outbound"
67 create_and_new = True if self.env.context.get("create_and_new") else False
68 context = {
69 "active_model": "account.move.line",
70 "active_ids": self.ids,
71 "default_payment_type": payment_type,
72 "default_partner_type": partner_type,
73 "default_partner_id": to_pay_partner_id,
74 "default_amount": abs(to_pay_amount),
75 "default_to_pay_move_line_ids": to_pay_move_lines.ids,
76 # We set this because if became from other view and in the context has 'create=False'
77 # you can't crate payment lines (for ej: subscription)
78 "create": True,
79 "create_and_new": create_and_new,
80 "default_company_id": company_id,
81 }
82 if self.env.context.get("default_l10n_ar_fiscal_position_id") is not None: 82 ↛ 83line 82 didn't jump to line 83 because the condition on line 82 was never true
83 context["default_l10n_ar_fiscal_position_id"] = self.env.context.get(
84 "default_l10n_ar_fiscal_position_id"
85 )
86 return {
87 "name": _("Register Payment"),
88 "res_model": "account.payment",
89 "view_mode": "form",
90 "views": [[False, "form"]],
91 "context": context,
92 "target": "current",
93 "type": "ir.actions.act_window",
94 }
95 else:
96 return super().action_register_payment(ctx=ctx)