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.

193 lines
7.8 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
[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. translate=True)
  24. is_bond = fields.Boolean(string="Is a bond issue?")
  25. is_loan = fields.Boolean(string="Is a subordinated loan issue?")
  26. default_issue = fields.Boolean(string="Default issue")
  27. subscription_start_date = fields.Date(string="Start date")
  28. subscription_end_date = fields.Date(string="End date")
  29. user_id = fields.Many2one('res.users',
  30. string="Responsible")
  31. term_date = fields.Date(string="Term date")
  32. rate = fields.Float(string="Interest rate")
  33. face_value = fields.Monetary(string="Facial value",
  34. currency_field='company_currency_id',
  35. required=True)
  36. minimum_amount = fields.Monetary(string="Minimum amount",
  37. currency_field='company_currency_id')
  38. maximum_amount = fields.Monetary(string="Maximum amount",
  39. currency_field='company_currency_id')
  40. maximum_amount_per_sub = fields.Monetary(
  41. string="Maximum amount per subscription",
  42. currency_field='company_currency_id')
  43. subscribed_amount = fields.Monetary(string="Subscribed amount",
  44. compute="_compute_subscribed_amount",
  45. currency_field='company_currency_id')
  46. interest_payment = fields.Selection([('end', 'End'),
  47. ('yearly', 'Yearly')],
  48. string="Interest payment")
  49. term = fields.Many2one('loan.term',
  50. string="term of the loan")
  51. loan_issue_lines = fields.One2many('loan.issue.line',
  52. 'loan_issue_id',
  53. string="Loan issue lines")
  54. state = fields.Selection([('draft', 'Draft'),
  55. ('confirmed', 'Confirmed'),
  56. ('cancelled', 'Cancelled'),
  57. ('ongoing', 'Ongoing'),
  58. ('closed', 'Closed')],
  59. string="State",
  60. default='draft')
  61. company_currency_id = fields.Many2one('res.currency',
  62. related='company_id.currency_id',
  63. string="Company Currency",
  64. readonly=True)
  65. company_id = fields.Many2one('res.company',
  66. string='Company',
  67. required=True,
  68. readonly=True,
  69. default=lambda self: self.env['res.company']._company_default_get()) #noqa
  70. by_company = fields.Boolean(string="By company")
  71. by_individual = fields.Boolean(string='By individuals')
  72. display_on_website = fields.Boolean(sting='Display on website')
  73. taxes_rate = fields.Float(string="Taxes on interest",
  74. required=True)
  75. @api.multi
  76. def toggle_display(self):
  77. for loan_issue in self:
  78. loan_issue.display_on_website = not loan_issue.display_on_website
  79. @api.multi
  80. def get_web_loan_issues(self, is_company):
  81. loan_issues = self.search([
  82. ('is_loan', '=', True),
  83. ('display_on_website', '=', True),
  84. ('state', '=', 'ongoing')
  85. ])
  86. if is_company is True:
  87. return loan_issues.filtered('by_company')
  88. else:
  89. return loan_issues.filtered('by_individual')
  90. @api.multi
  91. def get_web_bond_issues(self, is_company):
  92. bond_issues = self.search([
  93. ('is_bond', '=', True),
  94. ('display_on_website', '=', True),
  95. ('state', '=', 'ongoing')
  96. ])
  97. if is_company is True:
  98. return bond_issues.filtered('by_company')
  99. else:
  100. return bond_issues.filtered('by_company')
  101. @api.multi
  102. def get_web_issues(self, is_company):
  103. issues = self.get_web_loan_issues(is_company)
  104. issues = issues + self.get_web_bond_issues(is_company)
  105. return issues
  106. @api.multi
  107. def action_confirm(self):
  108. self.ensure_one()
  109. self.write({'state': 'confirmed'})
  110. @api.multi
  111. def action_open(self):
  112. self.ensure_one()
  113. self.write({'state': 'ongoing'})
  114. @api.multi
  115. def action_draft(self):
  116. self.ensure_one()
  117. self.write({'state': 'draft'})
  118. @api.multi
  119. def action_cancel(self):
  120. self.ensure_one()
  121. self.write({'state': 'cancelled'})
  122. @api.multi
  123. def action_close(self):
  124. self.ensure_one()
  125. self.write({'state': 'closed'})
  126. def get_interest_vals(self, line, vals):
  127. interest_obj = self.env['loan.interest.line']
  128. accrued_amount = line.amount
  129. accrued_interest = 0
  130. accrued_net_interest = 0
  131. accrued_taxes = 0
  132. for year in range(1, int(self.term.term) + 1):
  133. interest = accrued_amount * (line.loan_issue_id.rate / 100)
  134. accrued_amount += interest
  135. taxes_amount = interest * (self.taxes_rate / 100)
  136. net_interest = interest - taxes_amount
  137. accrued_interest += interest
  138. accrued_net_interest += net_interest
  139. accrued_taxes += taxes_amount
  140. vals['interest'] = interest
  141. vals['net_interest'] = net_interest
  142. vals['taxes_amount'] = taxes_amount
  143. vals['accrued_amount'] = accrued_amount
  144. vals['accrued_interest'] = accrued_interest
  145. vals['accrued_net_interest'] = accrued_net_interest
  146. vals['accrued_taxes'] = accrued_taxes
  147. vals['name'] = year
  148. interest_obj.create(vals)
  149. @api.multi
  150. def compute_loan_interest(self):
  151. self.ensure_one()
  152. if self.interest_payment == 'end':
  153. due_date = self.term_date
  154. else:
  155. raise NotImplementedError(_("Interest payment by year hasn't been "
  156. "implemented yet"))
  157. for line in self.loan_issue_lines:
  158. # TODO remove this line
  159. line.interest_lines.unlink()
  160. # Please Do not Forget
  161. vals = {
  162. 'issue_line': line.id,
  163. 'due_date': due_date,
  164. 'taxes_rate': self.taxes_rate
  165. }
  166. self.get_interest_vals(line, vals)
  167. rounded_term = int(self.term.term)
  168. if self.term.term - rounded_term > 0:
  169. # TODO Handle this case
  170. raise NotImplementedError(_("Calculation on non entire year "
  171. "hasn't been implemented yet"))