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.

71 lines
2.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. # Copyright 2020 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. comodel_name="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,
  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. comp = line.company_id
  34. move = self.create_move(
  35. line,
  36. date.today(),
  37. comp.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"] = comp.debt_long_term_account.id
  42. loan_vals["credit"] = line.amount
  43. loaner_vals["account_id"] = comp.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 action_request_payment(self):
  49. self.create_waiting_payment_move()
  50. super(LoanIssueLine, self).action_request_payment()
  51. @api.multi
  52. def action_paid(self):
  53. paid_by = self.env.context.get("paid_by_bank_statement")
  54. if paid_by:
  55. super(LoanIssueLine, self).action_paid()
  56. else:
  57. raise UserError(_("The payment must be registered"
  58. " by bank statement"))