Browse Source

[CHG] change the computation of maximum amount subscriable

pull/36/head
houssine 5 years ago
committed by robin.keunen
parent
commit
72a558eaee
  1. 23
      easy_my_coop_loan/models/loan.py
  2. 5
      easy_my_coop_loan/views/loan_view.xml
  3. 4
      easy_my_coop_loan_website/controllers/main.py

23
easy_my_coop_loan/models/loan.py

@ -37,9 +37,14 @@ class LoanIssue(models.Model):
currency_field='company_currency_id') currency_field='company_currency_id')
maximum_amount = fields.Monetary(string="Maximum amount", maximum_amount = fields.Monetary(string="Maximum amount",
currency_field='company_currency_id') currency_field='company_currency_id')
maximum_amount_per_sub = fields.Monetary(
string="Maximum amount per subscription",
currency_field='company_currency_id')
min_amount_company = fields.Monetary(string="Minimum amount for a company",
currency_field='company_currency_id')
max_amount_company = fields.Monetary(string="Maximum amount for a company",
currency_field='company_currency_id')
min_amount_person = fields.Monetary(string="Minimum amount for a person",
currency_field='company_currency_id')
max_amount_person = fields.Monetary(string="Maximum amount for a person",
currency_field='company_currency_id')
subscribed_amount = fields.Monetary(string="Subscribed amount", subscribed_amount = fields.Monetary(string="Subscribed amount",
compute="_compute_subscribed_amount", compute="_compute_subscribed_amount",
currency_field='company_currency_id') currency_field='company_currency_id')
@ -71,6 +76,18 @@ class LoanIssue(models.Model):
taxes_rate = fields.Float(string="Taxes on interest", taxes_rate = fields.Float(string="Taxes on interest",
required=True) required=True)
@api.multi
def get_max_amount(self, partner):
max_amount = 0
lines = self.loan_issue_lines.filtered(
lambda r: r.partner_id == partner and r.state != 'cancelled')
already_subscribed = sum(line.amount for line in lines)
if partner.is_company:
max_amount = self.max_amount_company - already_subscribed
else:
max_amount = self.max_amount_person - already_subscribed
return max_amount
@api.multi @api.multi
def toggle_display(self): def toggle_display(self):
for loan_issue in self: for loan_issue in self:

5
easy_my_coop_loan/views/loan_view.xml

@ -61,8 +61,11 @@
<field name="face_value" /> <field name="face_value" />
<field name="minimum_amount" /> <field name="minimum_amount" />
<field name="maximum_amount" /> <field name="maximum_amount" />
<field name="maximum_amount_per_sub" />
<field name="subscribed_amount" /> <field name="subscribed_amount" />
<field name="min_amount_person" />
<field name="max_amount_person" />
<field name="min_amount_company" />
<field name="max_amount_company" />
<field name="by_individual" /> <field name="by_individual" />
<field name="by_company" /> <field name="by_company" />
</group> </group>

4
easy_my_coop_loan_website/controllers/main.py

@ -12,11 +12,13 @@ class WebsiteLoanIssueSubscription(http.Controller):
methods=['POST'], website=True) methods=['POST'], website=True)
def get_loan_issue(self, loan_issue_id, **kw): def get_loan_issue(self, loan_issue_id, **kw):
loan_issue_obj = request.env['loan.issue'] loan_issue_obj = request.env['loan.issue']
partner = request.env.user.partner_id
if loan_issue_id: if loan_issue_id:
loan_issue = loan_issue_obj.sudo().browse(int(loan_issue_id)) loan_issue = loan_issue_obj.sudo().browse(int(loan_issue_id))
max_amount = loan_issue.get_max_amount(partner)
return { return {
loan_issue.id: { loan_issue.id: {
'max_amount': loan_issue.maximum_amount_per_sub,
'max_amount': max_amount,
'face_value': loan_issue.face_value, 'face_value': loan_issue.face_value,
} }
} }

Loading…
Cancel
Save