Browse Source

[IMP] add reimbursement table report and add it to mail template

attachment
pull/134/head
houssine 4 years ago
parent
commit
af66d423c7
  1. 4
      easy_my_coop_loan/__manifest__.py
  2. 8
      easy_my_coop_loan/data/mail_template_data.xml
  3. 37
      easy_my_coop_loan/models/loan_issue_line.py
  4. 111
      easy_my_coop_loan/report/loan_issue_line_report.xml
  5. 17
      easy_my_coop_loan/report/loan_report.xml
  6. 2
      easy_my_coop_loan/security/ir.model.access.csv
  7. 13
      easy_my_coop_loan/views/loan_line_view.xml

4
easy_my_coop_loan/__manifest__.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Easy My Coop Bond and Subordinated Loan Issues",
"name": "Easy My Coop Loan Issues Management",
"version": "12.0.2.0.1",
"depends": ["easy_my_coop"],
"author": "Coop IT Easy SCRLfs",
@ -22,6 +22,8 @@
"views/partner_view.xml",
"views/menus.xml",
"data/mail_template_data.xml",
"report/loan_report.xml",
"report/loan_issue_line_report.xml",
],
"demo": ["demo/coop.xml"],
"installable": True,

8
easy_my_coop_loan/data/mail_template_data.xml

@ -92,7 +92,7 @@
<p>Amount: ${object.amount} ${object.loan_issue_id.company_currency_id.symbol}</p>
<p>Account number: ${object.company_id.bank_ids[0].sanitized_acc_number}</p>
<p>Communication: ${object.loan_issue_id.name} + ${object.partner_id.name}</p>
<p>Communication: ${object.reference}</p>
<p>Sustainably your,</p>
<p>${object.company_id.name}.</p>
@ -125,8 +125,8 @@
</div>
]]></field>
</record>
</data>
<data>
<record id="email_template_loan_confirm_paid" model="mail.template">
<field name="name">Loan Issue Confirm Payment Received - Send by Email</field>
<field name="email_from">
@ -140,6 +140,8 @@
<field name="model_id"
ref="easy_my_coop_loan.model_loan_issue_line"/>
<field name="auto_delete" eval="True"/>
<field name="report_template" ref="easy_my_coop_loan.action_loan_issue_line_report"/>
<field name="report_name">Reimbursement table report</field>
<field name="lang">${object.partner_id.lang}</field>
<field name="easy_my_coop" eval="True"/>
<field name="body_html"><![CDATA[

37
easy_my_coop_loan/models/loan_issue_line.py

@ -20,7 +20,12 @@ class LoanIssueLine(models.Model):
for line in self:
line.amount = line.face_value * line.quantity
name = fields.Char(string="Reference")
reference = fields.Char(
string="Reference",
copy=False,
readonly=True,
states={'draft': [('readonly', False)]}
)
loan_issue_id = fields.Many2one(
"loan.issue", string="Loan issue", required=True
)
@ -35,7 +40,9 @@ class LoanIssueLine(models.Model):
readonly=True,
)
partner_id = fields.Many2one(
"res.partner", string="Subscriber", required=True
"res.partner",
string="Subscriber",
required=True
)
date = fields.Date(
string="Subscription date",
@ -127,14 +134,14 @@ class LoanIssueLine(models.Model):
@api.multi
def action_paid(self):
loan_email_template = self.get_confirm_paid_email_template()
for line in self:
loan_email_template = self.get_confirm_paid_email_template()
loan_email_template.sudo().send_mail(line.id, force_send=False)
vals = {"state": "paid"}
if not line.payment_date:
vals["payement_date"] = fields.Date.today()
vals["payment_date"] = fields.Date.today()
line.write(vals)
line.action_compute_interest()
loan_email_template.sudo().send_mail(line.id, force_send=False)
def get_number_of_days(self, year):
if calendar.isleap(year):
@ -158,9 +165,18 @@ class LoanIssueLine(models.Model):
taxes_amount = 0
diff_days = 0
# TODO remove this line
line.interest_lines.unlink()
# Please Do not Forget
# In case of a recompute is done. Only the interest lines
# in the future will be deleted. We also needed to determine
# from which year we'll have to regenerate the lines.
# Through the beautiful mind of Houssine, we implemented
# a small piece code to allows it.
today = fields.Date.today()
posted_lines = line.interest_lines.filtered(
lambda r: r.state == "paid" or
r.due_date < today)
futur_lines = line.interest_lines - posted_lines
start_to_line = len(posted_lines) + 1
futur_lines.unlink()
loan_term = int(loan_issue.loan_term / 12)
@ -228,6 +244,7 @@ class LoanIssueLine(models.Model):
vals["accrued_net_interest"] = accrued_net_interest
vals["accrued_taxes"] = accrued_taxes
vals["name"] = year
list_vals.append(vals.copy())
if year >= start_to_line:
list_vals.append(vals.copy())
self.env["loan.interest.line"].create(list_vals)

111
easy_my_coop_loan/report/loan_issue_line_report.xml

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="loan_issue_line_document">
<t t-call="web.external_layout">
<t t-set="address">
<address t-field="o.partner_id"
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}'/>
</t>
<div class="page mt32">
<h2>
<span>Reimbursement table</span>
</h2>
<p name="loan_payment_date_date" class="mt16">
<span>Loan payment received on</span>
<span t-field="o.payment_date"/>
</p>
<table class="table table-sm o_main_table mt16"
name="invoice_line_table">
<thead>
<tr>
<t t-set="colspan" t-value="5"/>
<th class="text-left">Year</th>
<th class="text-right">Subscribed amount</th>
<th class="text-right">Accrued amount</th>
<th class="text-right">Gross interest</th>
<th class="text-right">Accrued gross interest</th>
<th class="text-right">Net interest</th>
<th class="text-right">Tax amount</th>
<th class="text-right">Due amount</th>
<th class="text-right">State</th>
</tr>
</thead>
<tbody class="invoice_tbody">
<t t-foreach="o.interest_lines" t-as="line">
<tr>
<td class="text-left" name="name">
<span t-field="line.name"/>
</td>
<td class="text-right" name="subscribed_amount">
<span t-field="line.amount"/>
</td>
<td class="text-right" name="accrued_amount">
<span t-field="line.accrued_amount"/>
</td>
<td class="text-right" name="interest">
<span t-field="line.interest"
t-options='{"widget": "monetary", "display_currency": o.loan_issue_id.company_currency_id}'/>
</td>
<td class="text-right" name="accrued_interest">
<span t-field="line.accrued_interest"
t-options='{"widget": "monetary", "display_currency": o.loan_issue_id.company_currency_id}'/>
</td>
<td class="text-right" name="net_interest">
<span t-field="line.net_interest"
t-options='{"widget": "monetary", "display_currency": o.loan_issue_id.company_currency_id}'/>
</td>
<td class="text-right" name="taxes_amount">
<span t-field="line.taxes_amount"
t-options='{"widget": "monetary", "display_currency": o.loan_issue_id.company_currency_id}'/>
</td>
<td class="text-right" name="due_amount">
<span t-field="line.due_amount"
t-options='{"widget": "monetary", "display_currency": o.loan_issue_id.company_currency_id}'/>
</td>
<td class="text-right" name="due_date">
<span t-field="line.due_date"/>
</td>
<td class="text-right" name="state">
<span t-field="line.state"/>
</td>
</tr>
</t>
</tbody>
</table>
<div class="row mt32">
<div name="board_commitee" class="col-sm-6">
<p>
For the board of<span t-field="o.company_id.name"/>.
</p>
<p>
<strong>
<span t-field="o.company_id.board_representative"/>
</strong>
</p>
<img t-if="o.company_id.signature_scan"
t-attf-class="mt16 w-50"
t-attf-style="{{ 'min-width: 100px; max-width: 250px' if report_type == 'pdf' else '' }}"
t-att-src="'data:image/png;base64,%s' % o.company_id.signature_scan.decode()"/>
</div>
</div>
</div>
</t>
</template>
<template id="loan_issue_line">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="easy_my_coop_loan.loan_issue_line_document"
t-lang="o.partner_id.lang"/>
</t>
</t>
</template>
</odoo>

17
easy_my_coop_loan/report/loan_report.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<report
id="action_loan_issue_line_report"
model="loan.issue.line"
string="Reimbursment table report"
report_type="qweb-pdf"
name="easy_my_coop_loan.loan_issue_line"
file="easy_my_coop_loan.loan_issue_line.xml"
multi="True"
menu="True"
/>
</data>
</odoo>

2
easy_my_coop_loan/security/ir.model.access.csv

@ -4,4 +4,4 @@ access_loan_issue_manager,loan.issue,model_loan_issue,easy_my_coop.group_easy_my
access_loan_issue_line_user,loan.issue.line,model_loan_issue_line,base.group_user,1,0,0,0
access_loan_issue_line_manager,loan.issue.line,model_loan_issue_line,easy_my_coop.group_easy_my_coop_user,1,1,1,0
access_loan_interest_line_user,loan.interest.line,model_loan_interest_line,base.group_user,1,0,0,0
access_loan_interest_line_manager,loan.interest.line,model_loan_interest_line,easy_my_coop.group_easy_my_coop_manager,1,1,1,0
access_loan_interest_line_manager,loan.interest.line,model_loan_interest_line,easy_my_coop.group_easy_my_coop_manager,1,1,1,1

13
easy_my_coop_loan/views/loan_line_view.xml

@ -11,9 +11,8 @@
<field name="model">loan.issue.line</field>
<field name="arch" type="xml">
<tree string="Loans">
<field name="name"/>
<field name="loan_issue_id"/>
<field name="partner_id"/>
<field name="loan_issue_id"/>
<field name="quantity"/>
<field name="face_value"/>
<field name="amount"/>
@ -34,13 +33,13 @@
<button name="action_request_payment"
string="Request Payment"
type="object" states="subscribed"/>
<button name="action_cancel" string="Cancel" type="object"
states="draft,subscribed,waiting"
confirm="Are you sure you want to cancel this loan subscription ?"/>
<button name="action_draft" string="Set to draft"
type="object" states="cancelled"/>
<button name="action_paid" string="Paid"
type="object" states="waiting"/>
<button name="action_cancel" string="Cancel" type="object"
states="draft,subscribed,waiting"
confirm="Are you sure you want to cancel this loan subscription ?"/>
<button name="action_compute_interest" string="Compute interest"
type="object" states="paid"/>
@ -49,15 +48,15 @@
<sheet>
<group>
<group>
<field name="partner_id"/>
<field name="loan_issue_id"/>
<field name="name"/>
<field name="quantity"/>
<field name="face_value"/>
</group>
<group>
<field name="date"/>
<field name="payment_date"/>
<field name="partner_id"/>
<field name="reference"/>
<field name="amount"/>
</group>
</group>

Loading…
Cancel
Save