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.

188 lines
7.4 KiB

[ADD] bond and loan issues management [ADD] bond and loan issues management module skeleton [IMP] change increase menu sequence [IMP] add models, fields and views [IMP] add xml declaration in head of file [ADD] add easy_my_coop_loan_website - WIP [IMP] add access rights [IMP] this raise inconsistency so replace id by default_code. [IMP] change import openerp to odoo [IMP] add website loan module [FIX] put website display in loan [FIX] fix import [FIX] fix function [IMP] use correct name [IMP] make the loan and bond visible [IMP] add js, field and logic to set amount limit per subscription [IMP] remove dependency on recaptcha as user is logged to subscribe [IMP] add fields [IMP] save loan issue subscription still in WIP [IMP] remove alert pop up [IMP] add dependency to easy_my_coop_website [IMP] remove force send for sub request creation email notification [IMP] add mail templates [IMP] save subscription in the corresponding loan issue. add email notif [FIX] fix loan issue line view [FIX] add related field to loan issue. It is where the data stand [IMP] move term_view up [FIX] fix js error when false is returned [FIX] fix function when loan_issue_id in None [IMP] add actions and button [FIX] fix action [FIX] fix mail template [IMP] set noupdate=1 [IMP] change order [IMP] display loan issue lines on partner form [IMP] add loan view in partner form [IMP] add face value on loan issue and line add face value on loan issue and line. add as well the quantity and computation of the amount [FIX] missing id overriding values wasn't working [IMP] getting bond face value and setting it as step. [IMP] subscribed_amount computed field is the sum of the amount lines [IMP] allow a waiting payment to be cancelled [IMP] make field required [REFACT] move loan issue line code to dedicated file [IMP] add interest calculation and model [ADD] bond and loan issues management module skeleton [IMP] add models, fields and views [IMP] allow creation by hand [IMP] adding partner related field [IMP] put code in separate function [FIX] pass it to get method [IMP] routes consistent form [FIX] fix eof [FIX] GET is working for ajax call [IMP] website page for loan issue subscription
5 years ago
[ADD] bond and loan issues management [ADD] bond and loan issues management module skeleton [IMP] change increase menu sequence [IMP] add models, fields and views [IMP] add xml declaration in head of file [ADD] add easy_my_coop_loan_website - WIP [IMP] add access rights [IMP] this raise inconsistency so replace id by default_code. [IMP] change import openerp to odoo [IMP] add website loan module [FIX] put website display in loan [FIX] fix import [FIX] fix function [IMP] use correct name [IMP] make the loan and bond visible [IMP] add js, field and logic to set amount limit per subscription [IMP] remove dependency on recaptcha as user is logged to subscribe [IMP] add fields [IMP] save loan issue subscription still in WIP [IMP] remove alert pop up [IMP] add dependency to easy_my_coop_website [IMP] remove force send for sub request creation email notification [IMP] add mail templates [IMP] save subscription in the corresponding loan issue. add email notif [FIX] fix loan issue line view [FIX] add related field to loan issue. It is where the data stand [IMP] move term_view up [FIX] fix js error when false is returned [FIX] fix function when loan_issue_id in None [IMP] add actions and button [FIX] fix action [FIX] fix mail template [IMP] set noupdate=1 [IMP] change order [IMP] display loan issue lines on partner form [IMP] add loan view in partner form [IMP] add face value on loan issue and line add face value on loan issue and line. add as well the quantity and computation of the amount [FIX] missing id overriding values wasn't working [IMP] getting bond face value and setting it as step. [IMP] subscribed_amount computed field is the sum of the amount lines [IMP] allow a waiting payment to be cancelled [IMP] make field required [REFACT] move loan issue line code to dedicated file [IMP] add interest calculation and model [ADD] bond and loan issues management module skeleton [IMP] add models, fields and views [IMP] allow creation by hand [IMP] adding partner related field [IMP] put code in separate function [FIX] pass it to get method [IMP] routes consistent form [FIX] fix eof [FIX] GET is working for ajax call [IMP] website page for loan issue subscription
5 years ago
[ADD] bond and loan issues management [ADD] bond and loan issues management module skeleton [IMP] change increase menu sequence [IMP] add models, fields and views [IMP] add xml declaration in head of file [ADD] add easy_my_coop_loan_website - WIP [IMP] add access rights [IMP] this raise inconsistency so replace id by default_code. [IMP] change import openerp to odoo [IMP] add website loan module [FIX] put website display in loan [FIX] fix import [FIX] fix function [IMP] use correct name [IMP] make the loan and bond visible [IMP] add js, field and logic to set amount limit per subscription [IMP] remove dependency on recaptcha as user is logged to subscribe [IMP] add fields [IMP] save loan issue subscription still in WIP [IMP] remove alert pop up [IMP] add dependency to easy_my_coop_website [IMP] remove force send for sub request creation email notification [IMP] add mail templates [IMP] save subscription in the corresponding loan issue. add email notif [FIX] fix loan issue line view [FIX] add related field to loan issue. It is where the data stand [IMP] move term_view up [FIX] fix js error when false is returned [FIX] fix function when loan_issue_id in None [IMP] add actions and button [FIX] fix action [FIX] fix mail template [IMP] set noupdate=1 [IMP] change order [IMP] display loan issue lines on partner form [IMP] add loan view in partner form [IMP] add face value on loan issue and line add face value on loan issue and line. add as well the quantity and computation of the amount [FIX] missing id overriding values wasn't working [IMP] getting bond face value and setting it as step. [IMP] subscribed_amount computed field is the sum of the amount lines [IMP] allow a waiting payment to be cancelled [IMP] make field required [REFACT] move loan issue line code to dedicated file [IMP] add interest calculation and model [ADD] bond and loan issues management module skeleton [IMP] add models, fields and views [IMP] allow creation by hand [IMP] adding partner related field [IMP] put code in separate function [FIX] pass it to get method [IMP] routes consistent form [FIX] fix eof [FIX] GET is working for ajax call [IMP] website page for loan issue subscription
5 years ago
[ADD] bond and loan issues management [ADD] bond and loan issues management module skeleton [IMP] change increase menu sequence [IMP] add models, fields and views [IMP] add xml declaration in head of file [ADD] add easy_my_coop_loan_website - WIP [IMP] add access rights [IMP] this raise inconsistency so replace id by default_code. [IMP] change import openerp to odoo [IMP] add website loan module [FIX] put website display in loan [FIX] fix import [FIX] fix function [IMP] use correct name [IMP] make the loan and bond visible [IMP] add js, field and logic to set amount limit per subscription [IMP] remove dependency on recaptcha as user is logged to subscribe [IMP] add fields [IMP] save loan issue subscription still in WIP [IMP] remove alert pop up [IMP] add dependency to easy_my_coop_website [IMP] remove force send for sub request creation email notification [IMP] add mail templates [IMP] save subscription in the corresponding loan issue. add email notif [FIX] fix loan issue line view [FIX] add related field to loan issue. It is where the data stand [IMP] move term_view up [FIX] fix js error when false is returned [FIX] fix function when loan_issue_id in None [IMP] add actions and button [FIX] fix action [FIX] fix mail template [IMP] set noupdate=1 [IMP] change order [IMP] display loan issue lines on partner form [IMP] add loan view in partner form [IMP] add face value on loan issue and line add face value on loan issue and line. add as well the quantity and computation of the amount [FIX] missing id overriding values wasn't working [IMP] getting bond face value and setting it as step. [IMP] subscribed_amount computed field is the sum of the amount lines [IMP] allow a waiting payment to be cancelled [IMP] make field required [REFACT] move loan issue line code to dedicated file [IMP] add interest calculation and model [ADD] bond and loan issues management module skeleton [IMP] add models, fields and views [IMP] allow creation by hand [IMP] adding partner related field [IMP] put code in separate function [FIX] pass it to get method [IMP] routes consistent form [FIX] fix eof [FIX] GET is working for ajax call [IMP] website page for loan issue subscription
5 years ago
  1. import logging
  2. from odoo import api, fields, models
  3. _logger = logging.getLogger(__name__)
  4. class LoanTerm(models.Model):
  5. _name = 'loan.term'
  6. _description = 'Loan Term'
  7. name = fields.Char(string="Name",
  8. required=True)
  9. term = fields.Float(string="Term",
  10. required=True)
  11. class LoanIssue(models.Model):
  12. _name = 'loan.issue'
  13. _description = 'Loan Issue'
  14. @api.multi
  15. def _compute_subscribed_amount(self):
  16. for issue in self:
  17. susbscribed_amount = 0.0
  18. for line in issue.loan_issue_lines.filtered(
  19. lambda record: record.state != 'cancelled'):
  20. susbscribed_amount += line.amount
  21. issue.subscribed_amount = susbscribed_amount
  22. name = fields.Char(string="Name")
  23. is_bond = fields.Boolean(string="Is a bond issue?")
  24. is_loan = fields.Boolean(string="Is a subordinated loan issue?")
  25. default_issue = fields.Boolean(string="Default issue")
  26. subscription_start_date = fields.Date(string="Start date")
  27. subscription_end_date = fields.Date(string="End date")
  28. user_id = fields.Many2one('res.users',
  29. string="Responsible")
  30. term_date = fields.Date(string="Term date")
  31. rate = fields.Float(string="Interest rate")
  32. face_value = fields.Monetary(string="Facial value",
  33. currency_field='company_currency_id',
  34. required=True)
  35. minimum_amount = fields.Monetary(string="Minimum amount",
  36. currency_field='company_currency_id')
  37. maximum_amount = fields.Monetary(string="Maximum amount",
  38. currency_field='company_currency_id')
  39. maximum_amount_per_sub = fields.Monetary(
  40. string="Maximum amount per subscription",
  41. currency_field='company_currency_id')
  42. subscribed_amount = fields.Monetary(string="Subscribed amount",
  43. compute="_compute_subscribed_amount",
  44. currency_field='company_currency_id')
  45. interest_payment = fields.Selection([('end', 'End'),
  46. ('yearly', 'Yearly')],
  47. string="Interest payment")
  48. term = fields.Many2one('loan.term',
  49. string="term of the loan")
  50. loan_issue_lines = fields.One2many('loan.issue.line',
  51. 'loan_issue_id',
  52. string="Loan issue lines")
  53. state = fields.Selection([('draft', 'Draft'),
  54. ('confirmed', 'Confirmed'),
  55. ('cancelled', 'Cancelled'),
  56. ('ongoing', 'Ongoing'),
  57. ('closed', 'Closed')],
  58. string="State",
  59. default='draft')
  60. company_currency_id = fields.Many2one('res.currency',
  61. related='company_id.currency_id',
  62. string="Company Currency",
  63. readonly=True)
  64. company_id = fields.Many2one('res.company',
  65. string='Company',
  66. required=True,
  67. readonly=True,
  68. default=lambda self: self.env['res.company']._company_default_get()) #noqa
  69. by_company = fields.Boolean(string="By company")
  70. by_individual = fields.Boolean(string='By individuals')
  71. display_on_website = fields.Boolean(sting='Display on website')
  72. taxes_rate = fields.Float(string="Taxes on interest",
  73. required=True)
  74. @api.multi
  75. def toggle_display(self):
  76. for loan_issue in self:
  77. loan_issue.display_on_website = not loan_issue.display_on_website
  78. @api.multi
  79. def get_web_loan_issues(self, is_company):
  80. loan_issues = self.search([
  81. ('is_loan', '=', True),
  82. ('display_on_website', '=', True),
  83. ('state', '=', 'ongoing')
  84. ])
  85. if is_company is True:
  86. return loan_issues.filtered('by_company')
  87. else:
  88. return loan_issues.filtered('by_individual')
  89. @api.multi
  90. def get_web_bond_issues(self, is_company):
  91. bond_issues = self.search([
  92. ('is_bond', '=', True),
  93. ('display_on_website', '=', True),
  94. ('state', '=', 'ongoing')
  95. ])
  96. if is_company is True:
  97. return bond_issues.filtered('by_company')
  98. else:
  99. return bond_issues.filtered('by_company')
  100. @api.multi
  101. def get_web_issues(self, is_company):
  102. issues = self.get_web_loan_issues(is_company)
  103. issues = issues + self.get_web_bond_issues(is_company)
  104. return issues
  105. @api.multi
  106. def action_confirm(self):
  107. self.ensure_one()
  108. self.write({'state': 'confirmed'})
  109. @api.multi
  110. def action_open(self):
  111. self.ensure_one()
  112. self.write({'state': 'ongoing'})
  113. @api.multi
  114. def action_draft(self):
  115. self.ensure_one()
  116. self.write({'state': 'draft'})
  117. @api.multi
  118. def action_cancel(self):
  119. self.ensure_one()
  120. self.write({'state': 'cancelled'})
  121. @api.multi
  122. def action_close(self):
  123. self.ensure_one()
  124. self.write({'state': 'closed'})
  125. def get_interest_vals(self, line, vals):
  126. interest_obj = self.env['loan.interest.line']
  127. accrued_amount = line.amount
  128. accrued_interest = 0
  129. accrued_net_interest = 0
  130. accrued_taxes = 0
  131. for year in range(1, int(self.term.term) + 1):
  132. interest = accrued_amount * (line.loan_issue_id.rate / 100)
  133. accrued_amount += interest
  134. taxes_amount = interest * (self.taxes_rate / 100)
  135. net_interest = interest - taxes_amount
  136. accrued_interest += interest
  137. accrued_net_interest += net_interest
  138. accrued_taxes += taxes_amount
  139. vals['interest'] = interest
  140. vals['net_interest'] = net_interest
  141. vals['taxes_amount'] = taxes_amount
  142. vals['accrued_amount'] = accrued_amount
  143. vals['accrued_interest'] = accrued_interest
  144. vals['accrued_net_interest'] = accrued_net_interest
  145. vals['accrued_taxes'] = accrued_taxes
  146. vals['name'] = year
  147. interest_obj.create(vals)
  148. @api.multi
  149. def compute_loan_interest(self):
  150. self.ensure_one()
  151. if self.interest_payment == 'end':
  152. due_date = self.term_date
  153. for line in self.loan_issue_lines:
  154. # TODO remove this line
  155. line.interest_lines.unlink()
  156. # Please Do not Forget
  157. vals = {
  158. 'issue_line': line.id,
  159. 'due_date': due_date,
  160. 'taxes_rate': self.taxes_rate
  161. }
  162. self.get_interest_vals(line, vals)
  163. rounded_term = int(self.term.term)
  164. if self.term.term - rounded_term > 0:
  165. # TODO Handle this case
  166. _logger.info("todo")