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.

103 lines
3.9 KiB

  1. from datetime import datetime
  2. from odoo import api, fields, models
  3. class LoanIssueLine(models.Model):
  4. _name = 'loan.issue.line'
  5. _description = 'Loan Issue Line'
  6. _order = 'date desc, id'
  7. @api.multi
  8. @api.depends('quantity', 'face_value')
  9. def _compute_amount(self):
  10. for line in self:
  11. line.amount = line.face_value * line.quantity
  12. name = fields.Char(string="Reference")
  13. loan_issue_id = fields.Many2one('loan.issue',
  14. string="Loan issue",
  15. required=True)
  16. interest_lines = fields.One2many('loan.interest.line',
  17. 'issue_line',
  18. string="Interest lines")
  19. quantity = fields.Integer(string='quantity',
  20. required=True)
  21. face_value = fields.Monetary(related='loan_issue_id.face_value',
  22. currency_field='company_currency_id',
  23. store=True,
  24. readonly=True)
  25. partner_id = fields.Many2one('res.partner',
  26. string="Subscriber",
  27. required=True)
  28. date = fields.Date(string="Subscription date",
  29. default=lambda self: datetime.strftime(datetime.now(),
  30. '%Y-%m-%d'),
  31. required=True)
  32. amount = fields.Monetary(string="Subscribed amount",
  33. currency_field='company_currency_id',
  34. compute='_compute_amount',
  35. store=True)
  36. state = fields.Selection([('draft', 'Draft'),
  37. ('subscribed', 'Subscribed'),
  38. ('waiting', 'Waiting payment'),
  39. ('paid', 'paid'),
  40. ('cancelled', 'Cancelled'),
  41. ('ended', 'Ended')],
  42. string="State",
  43. required=True,
  44. default="draft")
  45. company_currency_id = fields.Many2one('res.currency',
  46. related='company_id.currency_id',
  47. string="Company Currency",
  48. readonly=True)
  49. company_id = fields.Many2one('res.company',
  50. related='loan_issue_id.company_id',
  51. string="Company",
  52. readonly=True)
  53. def get_loan_sub_mail_template(self):
  54. return self.env.ref('easy_my_coop_loan.loan_subscription_confirmation',
  55. False)
  56. def get_loan_pay_req_mail_template(self):
  57. return self.env.ref('easy_my_coop_loan.loan_issue_payment_request',
  58. False)
  59. @api.model
  60. def create(self, vals):
  61. confirmation_mail_template = self.get_loan_sub_mail_template()
  62. line = super(LoanIssueLine, self).create(vals)
  63. confirmation_mail_template.send_mail(line.id)
  64. return line
  65. @api.multi
  66. def action_draft(self):
  67. for line in self:
  68. line.write({'state': 'draft'})
  69. @api.multi
  70. def action_validate(self):
  71. for line in self:
  72. line.write({'state': 'subscribed'})
  73. @api.multi
  74. def action_request_payment(self):
  75. pay_req_mail_template = self.get_loan_pay_req_mail_template()
  76. for line in self:
  77. pay_req_mail_template.send_mail(line.id)
  78. line.write({'state': 'waiting'})
  79. @api.multi
  80. def action_cancel(self):
  81. for line in self:
  82. line.write({'state': 'cancelled'})
  83. @api.multi
  84. def action_paid(self):
  85. for line in self:
  86. line.write({'state': 'paid'})