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.

64 lines
2.1 KiB

  1. # Copyright 2019 Coop IT Easy SCRL fs
  2. # Houssine BAKKALI <houssine@coopiteasy.be>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from datetime import date
  5. from odoo import api, fields, models, _
  6. from odoo.exceptions import UserError
  7. class LoanIssueLine(models.Model):
  8. _inherit = "loan.issue.line"
  9. awaiting_move_id = fields.Many2one(
  10. "account.move",
  11. string="Awaiting payment account move"
  12. )
  13. @api.multi
  14. def get_loan_move_line(self, move_id):
  15. self.ensure_one()
  16. move_line = {
  17. "partner_id": self.partner_id.id,
  18. "date_maturity": date.today(),
  19. "move_id": move_id,
  20. }
  21. return move_line
  22. @api.multi
  23. def create_waiting_payment_moves(self):
  24. move_obj = self.env["account.move"]
  25. move_line_obj = self.env["account.move.line"]
  26. for line in self:
  27. company = line.company_id
  28. move_vals = {
  29. "ref": line.reference,
  30. "date": date.today(),
  31. "journal_id": company.awaiting_loan_payment_journal.id,
  32. }
  33. move = move_obj.create(move_vals)
  34. loan_vals = line.get_loan_move_line(move.id)
  35. loaner_vals = line.get_loan_move_line(move.id)
  36. loan_vals["account_id"] = company.debt_long_term_account.id
  37. loan_vals["credit"] = line.amount
  38. loaner_vals["account_id"] = company.awaiting_loan_payment_account.id
  39. loaner_vals["debit"] = line.amount
  40. move_line_obj.create([loan_vals, loaner_vals])
  41. line.awaiting_move_id = move
  42. @api.multi
  43. def action_request_payment(self):
  44. self.create_waiting_payment_moves()
  45. super(LoanIssueLine, self).action_request_payment()
  46. @api.multi
  47. def action_paid(self):
  48. paid_by = self.env.context.get("paid_by_bank_statement")
  49. if paid_by:
  50. super(LoanIssueLine, self).action_paid()
  51. else:
  52. raise UserError(_("The payment must be registered"
  53. " by bank statement"))