You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.7 KiB

  1. # Copyright 2020 Coop IT Easy SCRL fs
  2. # Robin Keunen <robin@coopiteasy.be>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from odoo import _, api, fields, models
  5. from odoo.exceptions import ValidationError
  6. from ..components.emc_adapters import AccountPaymentAdapter
  7. class AccountPayment(models.Model):
  8. _inherit = "account.payment"
  9. binding_id = fields.One2many(
  10. comodel_name="emc.binding.account.payment",
  11. inverse_name="internal_id",
  12. string="Binding ID",
  13. required=False,
  14. )
  15. @api.multi
  16. def post(self):
  17. res = super(AccountPayment, self).post()
  18. for payment in self:
  19. if any(payment.invoice_ids.mapped("release_capital_request")):
  20. invoice_id = payment.invoice_ids
  21. if len(invoice_id) > 1:
  22. raise ValidationError(
  23. _(
  24. "This version of easy my coop connector "
  25. "can't handle several invoice per"
  26. "payment. Please contact your "
  27. "system administrator"
  28. )
  29. )
  30. backend = self.env["emc.backend"].get_backend()
  31. adapter = AccountPaymentAdapter(backend=backend)
  32. external_id, external_record = adapter.create(payment)
  33. self.env["emc.binding.account.payment"].create(
  34. {
  35. "backend_id": backend.id,
  36. "internal_id": payment.id,
  37. "external_id": external_id,
  38. }
  39. )
  40. return res