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.

90 lines
2.7 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.model
  23. def create_move(self, line, date, journal):
  24. return self.env["account.move"].create({
  25. "ref": line.reference,
  26. "date": date.today(),
  27. "journal_id": journal.id,
  28. })
  29. @api.multi
  30. def create_waiting_payment_move(self):
  31. move_line_obj = self.env["account.move.line"]
  32. for line in self:
  33. company = line.company_id
  34. move = self.create_move(
  35. line,
  36. date.today(),
  37. company.awaiting_loan_payment_journal.id,
  38. )
  39. loan_vals = line.get_loan_move_line(move.id)
  40. loaner_vals = line.get_loan_move_line(move.id)
  41. loan_vals["account_id"] = company.debt_long_term_account.id
  42. loan_vals["credit"] = line.amount
  43. loaner_vals["account_id"] = company.awaiting_loan_payment_account.id
  44. loaner_vals["debit"] = line.amount
  45. move_line_obj.create([loan_vals, loaner_vals])
  46. line.awaiting_move_id = move
  47. @api.multi
  48. def create_loan_fy_move(self):
  49. # this function generate the move for the loan
  50. # to reimburse for the current fiscal year
  51. for line in self:
  52. company = line.company_id
  53. move = self.create_move(
  54. line,
  55. line,
  56. company.awaiting_loan_payment_journal.id,
  57. )
  58. @api.multi
  59. def create_interest_payment_move(self):
  60. print()
  61. @api.multi
  62. def create_loan_reimbursement_move(self):
  63. print()
  64. @api.multi
  65. def action_request_payment(self):
  66. self.create_waiting_payment_move()
  67. super(LoanIssueLine, self).action_request_payment()
  68. @api.multi
  69. def action_paid(self):
  70. paid_by = self.env.context.get("paid_by_bank_statement")
  71. if paid_by:
  72. super(LoanIssueLine, self).action_paid()
  73. else:
  74. raise UserError(_("The payment must be registered"
  75. " by bank statement"))