Browse Source

Merge pull request #141 from coopiteasy/12.O-batch-process-loans

[IMP] emc_loan: add batch buttons for loan issue lines
12.0
Robin Keunen 4 years ago
committed by GitHub
parent
commit
1dab475f36
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      easy_my_coop_loan/__manifest__.py
  2. 56
      easy_my_coop_loan/data/actions.xml
  3. 39
      easy_my_coop_loan/models/loan_issue_line.py

3
easy_my_coop_loan/__manifest__.py

@ -16,10 +16,11 @@
""",
"data": [
"security/ir.model.access.csv",
"data/actions.xml",
"data/mail_template_data.xml",
"views/loan_view.xml",
"views/partner_view.xml",
"views/menus.xml",
"data/mail_template_data.xml",
],
"demo": ["demo/coop.xml"],
"installable": True,

56
easy_my_coop_loan/data/actions.xml

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Coop IT Easy
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="batch_loan_issue_line_validate_action" model="ir.actions.server">
<field name="name">Validate Loans</field>
<field name="model_id" ref="easy_my_coop_loan.model_loan_issue_line"/>
<field name="binding_model_id" ref="easy_my_coop_loan.model_loan_issue_line" />
<field name="state">code</field>
<field name="code">
records.action_validate()
</field>
</record>
<record id="batch_loan_issue_line_request_payment_action" model="ir.actions.server">
<field name="name">Request Payments</field>
<field name="model_id" ref="easy_my_coop_loan.model_loan_issue_line"/>
<field name="binding_model_id" ref="easy_my_coop_loan.model_loan_issue_line" />
<field name="state">code</field>
<field name="code">
records.action_request_payment()
</field>
</record>
<record id="batch_loan_issue_line_cancel_action" model="ir.actions.server">
<field name="name">Cancel Loans</field>
<field name="model_id" ref="easy_my_coop_loan.model_loan_issue_line"/>
<field name="binding_model_id" ref="easy_my_coop_loan.model_loan_issue_line" />
<field name="state">code</field>
<field name="code">
records.action_cancel()
</field>
</record>
<record id="batch_loan_issue_line_set_as_paid_action" model="ir.actions.server">
<field name="name">Set as Paid</field>
<field name="model_id" ref="easy_my_coop_loan.model_loan_issue_line"/>
<field name="binding_model_id" ref="easy_my_coop_loan.model_loan_issue_line" />
<field name="state">code</field>
<field name="code">
records.action_paid()
</field>
</record>
<record id="batch_loan_issue_line_set_as_draft_action" model="ir.actions.server">
<field name="name">Set to Draft</field>
<field name="model_id" ref="easy_my_coop_loan.model_loan_issue_line"/>
<field name="binding_model_id" ref="easy_my_coop_loan.model_loan_issue_line" />
<field name="state">code</field>
<field name="code">
records.action_draft()
</field>
</record>
</odoo>

39
easy_my_coop_loan/models/loan_issue_line.py

@ -4,7 +4,8 @@
from datetime import datetime
from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class LoanIssueLine(models.Model):
@ -93,26 +94,41 @@ class LoanIssueLine(models.Model):
@api.multi
def action_draft(self):
for line in self:
line.write({"state": "draft"})
if self.filtered(lambda l: l.state != "cancelled"):
raise ValidationError(
_("You can only set cancelled loans to draft")
)
self.write({"state": "draft"})
@api.multi
def action_validate(self):
for line in self:
line.write({"state": "subscribed"})
if self.filtered(lambda l: l.state != "draft"):
raise ValidationError(_("You can only validate draft loans"))
self.write({"state": "subscribed"})
@api.multi
def action_request_payment(self):
pay_req_mail_template = self.get_loan_pay_req_mail_template()
if self.filtered(lambda l: l.state != "subscribed"):
raise ValidationError(
_("You can only request payment for validated loans")
)
for line in self:
pay_req_mail_template = line.get_loan_pay_req_mail_template()
pay_req_mail_template.send_mail(line.id)
line.write({"state": "waiting"})
@api.multi
def action_cancel(self):
for line in self:
line.write({"state": "cancelled"})
allowed_states = ["draft", "subscribed", "waiting"]
if self.filtered(lambda l: l.state not in allowed_states):
raise ValidationError(
_(
"You can only cancel loans in states draft, "
"subscribed or waiting for payment."
)
)
self.write({"state": "cancelled"})
@api.multi
def get_confirm_paid_email_template(self):
@ -123,8 +139,13 @@ class LoanIssueLine(models.Model):
@api.multi
def action_paid(self):
if self.filtered(lambda l: l.state != "waiting"):
raise ValidationError(
_("You can only park as paid loans waiting for payment")
)
for line in self:
loan_email_template = self.get_confirm_paid_email_template()
loan_email_template = line.get_confirm_paid_email_template()
loan_email_template.sudo().send_mail(line.id, force_send=False)
line.write({"state": "paid"})
Loading…
Cancel
Save