Browse Source
Merge pull request #48 from coopiteasy/12.0-payment-date
Merge pull request #48 from coopiteasy/12.0-payment-date
12.0 payment datepull/49/head
Houssine BAKKALI
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 512 additions and 510 deletions
-
9easy_my_coop_loan/models/__init__.py
-
124easy_my_coop_loan/models/interest_line.py
-
355easy_my_coop_loan/models/loan.py
-
3easy_my_coop_loan/models/loan_issue_line.py
-
10easy_my_coop_loan/models/mail_template.py
-
59easy_my_coop_loan/models/partner.py
-
462easy_my_coop_loan/views/loan_view.xml
@ -1,5 +1,4 @@ |
|||||
from . import loan |
|
||||
from . import loan_issue_line |
|
||||
from . import interest_line |
|
||||
from . import partner |
|
||||
from . import mail_template |
|
||||
|
from . import loan |
||||
|
from . import loan_issue_line |
||||
|
from . import interest_line |
||||
|
from . import partner |
@ -1,60 +1,64 @@ |
|||||
from odoo import fields, models |
|
||||
|
|
||||
|
|
||||
class LoanInterestLine(models.Model): |
|
||||
_name = 'loan.interest.line' |
|
||||
_description = "Loan Interest Line" |
|
||||
|
|
||||
name = fields.Integer(string="Year", |
|
||||
required=True) |
|
||||
issue_line = fields.Many2one('loan.issue.line', |
|
||||
string="Subscribed loan", |
|
||||
required=True) |
|
||||
partner_id = fields.Many2one(related='issue_line.partner_id', |
|
||||
store=True, |
|
||||
readlonly=True) |
|
||||
amount = fields.Monetary(related='issue_line.amount', |
|
||||
string="Subscribed amount", |
|
||||
currency_field='company_currency_id', |
|
||||
readonly=True) |
|
||||
interest = fields.Monetary(string="Gross interest amount", |
|
||||
currency_field='company_currency_id', |
|
||||
readonly=True) |
|
||||
net_interest = fields.Monetary(string="Net interest amount", |
|
||||
currency_field='company_currency_id', |
|
||||
readonly=True) |
|
||||
taxes_rate = fields.Float(string="Taxes on interest", |
|
||||
required=True) |
|
||||
taxes_amount = fields.Monetary(string="Taxes amount", |
|
||||
currency_field='company_currency_id', |
|
||||
readonly=True) |
|
||||
accrued_amount = fields.Monetary(string="Accrued amount", |
|
||||
currency_field='company_currency_id', |
|
||||
readonly=True) |
|
||||
accrued_interest = fields.Monetary(string="Accrued gross interest", |
|
||||
currency_field='company_currency_id', |
|
||||
readonly=True) |
|
||||
accrued_net_interest = fields.Monetary( |
|
||||
string="Accrued net interest", |
|
||||
currency_field='company_currency_id', |
|
||||
readonly=True) |
|
||||
accrued_taxes = fields.Monetary(string="Accrued taxes to pay", |
|
||||
currency_field='company_currency_id', |
|
||||
readonly=True) |
|
||||
due_date = fields.Date(string="Due date") |
|
||||
company_currency_id = fields.Many2one('res.currency', |
|
||||
related='company_id.currency_id', |
|
||||
string="Company Currency", |
|
||||
readonly=True) |
|
||||
company_id = fields.Many2one('res.company', |
|
||||
related='issue_line.company_id', |
|
||||
string="Company", |
|
||||
readonly=True) |
|
||||
state = fields.Selection([('draft', 'Draft'), |
|
||||
('due', 'Due'), |
|
||||
('requested', 'Payment requested'), |
|
||||
('donation', 'Donation'), |
|
||||
('paid', 'Paid') |
|
||||
], |
|
||||
string="State", |
|
||||
default="draft") |
|
||||
|
# Copyright 2019 Coop IT Easy SCRL fs |
||||
|
# Houssine BAKKALI <houssine@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class LoanInterestLine(models.Model): |
||||
|
_name = 'loan.interest.line' |
||||
|
_description = "Loan Interest Line" |
||||
|
|
||||
|
name = fields.Integer(string="Year", |
||||
|
required=True) |
||||
|
issue_line = fields.Many2one('loan.issue.line', |
||||
|
string="Subscribed loan", |
||||
|
required=True) |
||||
|
partner_id = fields.Many2one(related='issue_line.partner_id', |
||||
|
store=True, |
||||
|
readlonly=True) |
||||
|
amount = fields.Monetary(related='issue_line.amount', |
||||
|
string="Subscribed amount", |
||||
|
currency_field='company_currency_id', |
||||
|
readonly=True) |
||||
|
interest = fields.Monetary(string="Gross interest amount", |
||||
|
currency_field='company_currency_id', |
||||
|
readonly=True) |
||||
|
net_interest = fields.Monetary(string="Net interest amount", |
||||
|
currency_field='company_currency_id', |
||||
|
readonly=True) |
||||
|
taxes_rate = fields.Float(string="Taxes on interest", |
||||
|
required=True) |
||||
|
taxes_amount = fields.Monetary(string="Taxes amount", |
||||
|
currency_field='company_currency_id', |
||||
|
readonly=True) |
||||
|
accrued_amount = fields.Monetary(string="Accrued amount", |
||||
|
currency_field='company_currency_id', |
||||
|
readonly=True) |
||||
|
accrued_interest = fields.Monetary(string="Accrued gross interest", |
||||
|
currency_field='company_currency_id', |
||||
|
readonly=True) |
||||
|
accrued_net_interest = fields.Monetary( |
||||
|
string="Accrued net interest", |
||||
|
currency_field='company_currency_id', |
||||
|
readonly=True) |
||||
|
accrued_taxes = fields.Monetary(string="Accrued taxes to pay", |
||||
|
currency_field='company_currency_id', |
||||
|
readonly=True) |
||||
|
due_date = fields.Date(string="Due date") |
||||
|
company_currency_id = fields.Many2one('res.currency', |
||||
|
related='company_id.currency_id', |
||||
|
string="Company Currency", |
||||
|
readonly=True) |
||||
|
company_id = fields.Many2one('res.company', |
||||
|
related='issue_line.company_id', |
||||
|
string="Company", |
||||
|
readonly=True) |
||||
|
state = fields.Selection([('draft', 'Draft'), |
||||
|
('due', 'Due'), |
||||
|
('requested', 'Payment requested'), |
||||
|
('donation', 'Donation'), |
||||
|
('paid', 'Paid') |
||||
|
], |
||||
|
string="State", |
||||
|
default="draft") |
@ -1,177 +1,178 @@ |
|||||
import logging |
|
||||
|
|
||||
from odoo import api, fields, models, _ |
|
||||
|
|
||||
_logger = logging.getLogger(__name__) |
|
||||
|
|
||||
|
|
||||
class LoanIssue(models.Model): |
|
||||
_name = 'loan.issue' |
|
||||
_description = 'Loan Issue' |
|
||||
|
|
||||
@api.multi |
|
||||
def _compute_subscribed_amount(self): |
|
||||
for issue in self: |
|
||||
susbscribed_amount = 0.0 |
|
||||
for line in issue.loan_issue_lines.filtered( |
|
||||
lambda record: record.state != 'cancelled'): |
|
||||
susbscribed_amount += line.amount |
|
||||
issue.subscribed_amount = susbscribed_amount |
|
||||
|
|
||||
name = fields.Char(string="Name", |
|
||||
translate=True) |
|
||||
default_issue = fields.Boolean(string="Default issue") |
|
||||
subscription_start_date = fields.Date(string="Start date subscription period") |
|
||||
subscription_end_date = fields.Date(string="End date subscription period") |
|
||||
user_id = fields.Many2one('res.users', |
|
||||
string="Responsible") |
|
||||
term_date = fields.Date(string="Term date") |
|
||||
loan_term = fields.Float(string="Duration of the loan in month") |
|
||||
rate = fields.Float(string="Interest rate") |
|
||||
face_value = fields.Monetary(string="Facial value", |
|
||||
currency_field='company_currency_id', |
|
||||
required=True) |
|
||||
minimum_amount = fields.Monetary(string="Minimum amount of issue", |
|
||||
currency_field='company_currency_id') |
|
||||
maximum_amount = fields.Monetary(string="Maximum amount of issue", |
|
||||
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", |
|
||||
compute="_compute_subscribed_amount", |
|
||||
currency_field='company_currency_id') |
|
||||
interest_payment = fields.Selection([('end', 'End'), |
|
||||
('yearly', 'Yearly')], |
|
||||
string="Interest payment") |
|
||||
loan_issue_lines = fields.One2many('loan.issue.line', |
|
||||
'loan_issue_id', |
|
||||
string="Loan issue lines") |
|
||||
state = fields.Selection([('draft', 'Draft'), |
|
||||
('confirmed', 'Confirmed'), |
|
||||
('cancelled', 'Cancelled'), |
|
||||
('ongoing', 'Ongoing'), |
|
||||
('closed', 'Closed')], |
|
||||
string="State", |
|
||||
default='draft') |
|
||||
company_currency_id = fields.Many2one('res.currency', |
|
||||
related='company_id.currency_id', |
|
||||
string="Company Currency", |
|
||||
readonly=True) |
|
||||
company_id = fields.Many2one('res.company', |
|
||||
string='Company', |
|
||||
required=True, |
|
||||
readonly=True, |
|
||||
default=lambda self: self.env['res.company']._company_default_get()) # noqa |
|
||||
by_company = fields.Boolean(string="By company") |
|
||||
by_individual = fields.Boolean(string='By individuals') |
|
||||
display_on_website = fields.Boolean(sting='Display on website') |
|
||||
taxes_rate = fields.Float(string="Taxes on interest", |
|
||||
required=True) |
|
||||
|
|
||||
@api.multi |
|
||||
def get_max_amount(self, partner): |
|
||||
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 |
|
||||
def toggle_display(self): |
|
||||
for loan_issue in self: |
|
||||
loan_issue.display_on_website = not loan_issue.display_on_website |
|
||||
|
|
||||
@api.multi |
|
||||
def get_web_issues(self, is_company): |
|
||||
bond_issues = self.search([ |
|
||||
('display_on_website', '=', True), |
|
||||
('state', '=', 'ongoing') |
|
||||
]) |
|
||||
if is_company is True: |
|
||||
return bond_issues.filtered('by_company') |
|
||||
else: |
|
||||
return bond_issues.filtered('by_company') |
|
||||
|
|
||||
@api.multi |
|
||||
def action_confirm(self): |
|
||||
self.ensure_one() |
|
||||
self.write({'state': 'confirmed'}) |
|
||||
|
|
||||
@api.multi |
|
||||
def action_open(self): |
|
||||
self.ensure_one() |
|
||||
self.write({'state': 'ongoing'}) |
|
||||
|
|
||||
@api.multi |
|
||||
def action_draft(self): |
|
||||
self.ensure_one() |
|
||||
self.write({'state': 'draft'}) |
|
||||
|
|
||||
@api.multi |
|
||||
def action_cancel(self): |
|
||||
self.ensure_one() |
|
||||
self.write({'state': 'cancelled'}) |
|
||||
|
|
||||
@api.multi |
|
||||
def action_close(self): |
|
||||
self.ensure_one() |
|
||||
self.write({'state': 'closed'}) |
|
||||
|
|
||||
def get_interest_vals(self, line, vals): |
|
||||
interest_obj = self.env['loan.interest.line'] |
|
||||
accrued_amount = line.amount |
|
||||
accrued_interest = 0 |
|
||||
accrued_net_interest = 0 |
|
||||
accrued_taxes = 0 |
|
||||
for year in range(1, int(self.loan_term) + 1): |
|
||||
interest = accrued_amount * (line.loan_issue_id.rate / 100) |
|
||||
accrued_amount += interest |
|
||||
taxes_amount = interest * (self.taxes_rate / 100) |
|
||||
net_interest = interest - taxes_amount |
|
||||
accrued_interest += interest |
|
||||
accrued_net_interest += net_interest |
|
||||
accrued_taxes += taxes_amount |
|
||||
vals['interest'] = interest |
|
||||
vals['net_interest'] = net_interest |
|
||||
vals['taxes_amount'] = taxes_amount |
|
||||
vals['accrued_amount'] = accrued_amount |
|
||||
vals['accrued_interest'] = accrued_interest |
|
||||
vals['accrued_net_interest'] = accrued_net_interest |
|
||||
vals['accrued_taxes'] = accrued_taxes |
|
||||
vals['name'] = year |
|
||||
interest_obj.create(vals) |
|
||||
|
|
||||
@api.multi |
|
||||
def compute_loan_interest(self): |
|
||||
self.ensure_one() |
|
||||
|
|
||||
if self.interest_payment == 'end': |
|
||||
due_date = self.term_date |
|
||||
else: |
|
||||
raise NotImplementedError(_("Interest payment by year hasn't been " |
|
||||
"implemented yet")) |
|
||||
for line in self.loan_issue_lines: |
|
||||
# TODO remove this line |
|
||||
line.interest_lines.unlink() |
|
||||
# Please Do not Forget |
|
||||
vals = { |
|
||||
'issue_line': line.id, |
|
||||
'due_date': due_date, |
|
||||
'taxes_rate': self.taxes_rate |
|
||||
} |
|
||||
self.get_interest_vals(line, vals) |
|
||||
|
|
||||
rounded_term = int(self.loan_term) |
|
||||
if self.loan_term - rounded_term > 0: |
|
||||
# TODO Handle this case |
|
||||
raise NotImplementedError(_("Calculation on non entire year " |
|
||||
"hasn't been implemented yet")) |
|
||||
|
# Copyright 2019 Coop IT Easy SCRL fs |
||||
|
# Houssine BAKKALI <houssine@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
import logging |
||||
|
|
||||
|
from odoo import api, fields, models, _ |
||||
|
|
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
class LoanIssue(models.Model): |
||||
|
_name = 'loan.issue' |
||||
|
_description = 'Loan Issue' |
||||
|
|
||||
|
@api.multi |
||||
|
def _compute_subscribed_amount(self): |
||||
|
for issue in self: |
||||
|
susbscribed_amount = 0.0 |
||||
|
for line in issue.loan_issue_lines.filtered( |
||||
|
lambda record: record.state != 'cancelled'): |
||||
|
susbscribed_amount += line.amount |
||||
|
issue.subscribed_amount = susbscribed_amount |
||||
|
|
||||
|
name = fields.Char(string="Name", |
||||
|
translate=True) |
||||
|
default_issue = fields.Boolean(string="Default issue") |
||||
|
subscription_start_date = fields.Date(string="Start date subscription period") |
||||
|
subscription_end_date = fields.Date(string="End date subscription period") |
||||
|
user_id = fields.Many2one('res.users', |
||||
|
string="Responsible") |
||||
|
loan_start_date = fields.Date(string="Loan start date") |
||||
|
term_date = fields.Date(string="Term date") |
||||
|
loan_term = fields.Float(string="Duration of the loan in month") |
||||
|
rate = fields.Float(string="Interest rate") |
||||
|
face_value = fields.Monetary(string="Facial value", |
||||
|
currency_field='company_currency_id', |
||||
|
required=True) |
||||
|
minimum_amount = fields.Monetary(string="Minimum amount of issue", |
||||
|
currency_field='company_currency_id') |
||||
|
maximum_amount = fields.Monetary(string="Maximum amount of issue", |
||||
|
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", |
||||
|
compute="_compute_subscribed_amount", |
||||
|
currency_field='company_currency_id') |
||||
|
interest_payment = fields.Selection([('end', 'End'), |
||||
|
('yearly', 'Yearly')], |
||||
|
string="Interest payment") |
||||
|
interest_payment_info = fields.Char(string="Yearly payment on") |
||||
|
loan_issue_lines = fields.One2many('loan.issue.line', |
||||
|
'loan_issue_id', |
||||
|
string="Loan issue lines") |
||||
|
state = fields.Selection([('draft', 'Draft'), |
||||
|
('confirmed', 'Confirmed'), |
||||
|
('cancelled', 'Cancelled'), |
||||
|
('ongoing', 'Ongoing'), |
||||
|
('closed', 'Closed')], |
||||
|
string="State", |
||||
|
default='draft') |
||||
|
company_currency_id = fields.Many2one('res.currency', |
||||
|
related='company_id.currency_id', |
||||
|
string="Company Currency", |
||||
|
readonly=True) |
||||
|
company_id = fields.Many2one('res.company', |
||||
|
string='Company', |
||||
|
required=True, |
||||
|
readonly=True, |
||||
|
default=lambda self: self.env['res.company']._company_default_get()) # noqa |
||||
|
by_company = fields.Boolean(string="By company") |
||||
|
by_individual = fields.Boolean(string='By individuals') |
||||
|
display_on_website = fields.Boolean(sting='Display on website') |
||||
|
taxes_rate = fields.Float(string="Taxes on interest", |
||||
|
required=True) |
||||
|
|
||||
|
@api.multi |
||||
|
def get_max_amount(self, partner): |
||||
|
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 |
||||
|
def get_web_issues(self, is_company): |
||||
|
bond_issues = self.search([ |
||||
|
('display_on_website', '=', True), |
||||
|
('state', '=', 'ongoing') |
||||
|
]) |
||||
|
if is_company is True: |
||||
|
return bond_issues.filtered('by_company') |
||||
|
else: |
||||
|
return bond_issues.filtered('by_company') |
||||
|
|
||||
|
@api.multi |
||||
|
def action_confirm(self): |
||||
|
self.ensure_one() |
||||
|
self.write({'state': 'confirmed'}) |
||||
|
|
||||
|
@api.multi |
||||
|
def action_open(self): |
||||
|
self.ensure_one() |
||||
|
self.write({'state': 'ongoing'}) |
||||
|
|
||||
|
@api.multi |
||||
|
def action_draft(self): |
||||
|
self.ensure_one() |
||||
|
self.write({'state': 'draft'}) |
||||
|
|
||||
|
@api.multi |
||||
|
def action_cancel(self): |
||||
|
self.ensure_one() |
||||
|
self.write({'state': 'cancelled'}) |
||||
|
|
||||
|
@api.multi |
||||
|
def action_close(self): |
||||
|
self.ensure_one() |
||||
|
self.write({'state': 'closed'}) |
||||
|
|
||||
|
def get_interest_vals(self, line, vals): |
||||
|
interest_obj = self.env['loan.interest.line'] |
||||
|
accrued_amount = line.amount |
||||
|
accrued_interest = 0 |
||||
|
accrued_net_interest = 0 |
||||
|
accrued_taxes = 0 |
||||
|
for year in range(1, int(self.loan_term) + 1): |
||||
|
interest = accrued_amount * (line.loan_issue_id.rate / 100) |
||||
|
accrued_amount += interest |
||||
|
taxes_amount = interest * (self.taxes_rate / 100) |
||||
|
net_interest = interest - taxes_amount |
||||
|
accrued_interest += interest |
||||
|
accrued_net_interest += net_interest |
||||
|
accrued_taxes += taxes_amount |
||||
|
vals['interest'] = interest |
||||
|
vals['net_interest'] = net_interest |
||||
|
vals['taxes_amount'] = taxes_amount |
||||
|
vals['accrued_amount'] = accrued_amount |
||||
|
vals['accrued_interest'] = accrued_interest |
||||
|
vals['accrued_net_interest'] = accrued_net_interest |
||||
|
vals['accrued_taxes'] = accrued_taxes |
||||
|
vals['name'] = year |
||||
|
interest_obj.create(vals) |
||||
|
|
||||
|
@api.multi |
||||
|
def compute_loan_interest(self): |
||||
|
self.ensure_one() |
||||
|
|
||||
|
if self.interest_payment == 'end': |
||||
|
due_date = self.term_date |
||||
|
else: |
||||
|
raise NotImplementedError(_("Interest payment by year hasn't been " |
||||
|
"implemented yet")) |
||||
|
for line in self.loan_issue_lines: |
||||
|
# TODO remove this line |
||||
|
line.interest_lines.unlink() |
||||
|
# Please Do not Forget |
||||
|
vals = { |
||||
|
'issue_line': line.id, |
||||
|
'due_date': due_date, |
||||
|
'taxes_rate': self.taxes_rate |
||||
|
} |
||||
|
self.get_interest_vals(line, vals) |
||||
|
|
||||
|
rounded_term = int(self.loan_term) |
||||
|
if self.loan_term - rounded_term > 0: |
||||
|
# TODO Handle this case |
||||
|
raise NotImplementedError(_("Calculation on non entire year " |
||||
|
"hasn't been implemented yet")) |
@ -1,10 +0,0 @@ |
|||||
from odoo import models |
|
||||
|
|
||||
|
|
||||
class MailTemplate(models.Model): |
|
||||
_inherit = "mail.template" |
|
||||
|
|
||||
# def init(self): |
|
||||
# for template_id in EMAIL_TEMPLATE_IDS: |
|
||||
# mail_template = self.env.ref(template_id) |
|
||||
# mail_template.easy_my_coop = True |
|
@ -1,30 +1,29 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# Copyright 2019 Coop IT Easy SCRL fs |
|
||||
# Robin Keunen <robin@coopiteasy.be> |
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|
||||
|
|
||||
from odoo import fields, models, api |
|
||||
|
|
||||
|
|
||||
class ResPartner(models.Model): |
|
||||
_inherit = "res.partner" |
|
||||
|
|
||||
loan_line_ids = fields.One2many( |
|
||||
comodel_name="loan.issue.line", |
|
||||
inverse_name="partner_id", |
|
||||
string="Loans", |
|
||||
) |
|
||||
is_loaner = fields.Boolean( |
|
||||
string="Loaner", |
|
||||
compute="_compute_is_loaner", |
|
||||
store=True, |
|
||||
) |
|
||||
|
|
||||
@api.multi |
|
||||
@api.depends("loan_line_ids", "loan_line_ids.state") |
|
||||
def _compute_is_loaner(self): |
|
||||
for partner in self: |
|
||||
loans = partner.loan_line_ids.filtered( |
|
||||
lambda l: l.state in ["subscribed", "waiting", "paid"] |
|
||||
) |
|
||||
partner.is_loaner = bool(loans) |
|
||||
|
# Copyright 2019 Coop IT Easy SCRL fs |
||||
|
# Houssine BAKKALI <houssine@coopiteasy.be> |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from odoo import fields, models, api |
||||
|
|
||||
|
|
||||
|
class ResPartner(models.Model): |
||||
|
_inherit = "res.partner" |
||||
|
|
||||
|
loan_line_ids = fields.One2many( |
||||
|
comodel_name="loan.issue.line", |
||||
|
inverse_name="partner_id", |
||||
|
string="Loans", |
||||
|
) |
||||
|
is_loaner = fields.Boolean( |
||||
|
string="Loaner", |
||||
|
compute="_compute_is_loaner", |
||||
|
store=True, |
||||
|
) |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends("loan_line_ids", "loan_line_ids.state") |
||||
|
def _compute_is_loaner(self): |
||||
|
for partner in self: |
||||
|
loans = partner.loan_line_ids.filtered( |
||||
|
lambda l: l.state in ["subscribed", "waiting", "paid"] |
||||
|
) |
||||
|
partner.is_loaner = bool(loans) |
@ -1,228 +1,234 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<odoo> |
|
||||
<record id="view_loan_issue_tree" model="ir.ui.view"> |
|
||||
<field name="name">loan.issue.tree</field> |
|
||||
<field name="model">loan.issue</field> |
|
||||
<field name="arch" type="xml"> |
|
||||
<tree string="Loan issues"> |
|
||||
<field name="name" /> |
|
||||
<field name="subscription_start_date" /> |
|
||||
<field name="subscription_end_date" /> |
|
||||
<field name="term_date" /> |
|
||||
<field name="loan_term" /> |
|
||||
<field name="rate" /> |
|
||||
<field name="minimum_amount" /> |
|
||||
<field name="maximum_amount" /> |
|
||||
<field name="subscribed_amount" /> |
|
||||
<field name="user_id" /> |
|
||||
<field name="state" /> |
|
||||
</tree> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="view_loan_issue_form" model="ir.ui.view"> |
|
||||
<field name="name">loan.issue.form</field> |
|
||||
<field name="model">loan.issue</field> |
|
||||
<field name="arch" type="xml"> |
|
||||
<form string="Loan issue"> |
|
||||
<header> |
|
||||
<!-- todo check access rights --> |
|
||||
<button name="action_confirm" string="Confirm" type="object" states="draft" |
|
||||
groups="easy_my_coop.group_easy_my_coop_manager"/> |
|
||||
<button name="action_cancel" string="Cancel" type="object" states="draft,ongoing" |
|
||||
confirm="Are you sure you want to cancel this loan issue?" |
|
||||
groups="easy_my_coop.group_easy_my_coop_manager"/> |
|
||||
<button name="action_open" string="Open" type="object" |
|
||||
states="confirmed" groups="easy_my_coop.group_easy_my_coop_manager"/> |
|
||||
<button name="action_close" string="Close" type="object" states="ongoing" |
|
||||
confirm="Are you sure you want to close this loan issue?" |
|
||||
groups="easy_my_coop.group_easy_my_coop_manager"/> |
|
||||
<button name="action_draft" string="Set to draft" |
|
||||
type="object" states="confirmed,cancelled" |
|
||||
groups="easy_my_coop.group_easy_my_coop_manager"/> |
|
||||
<button name="compute_loan_interest" string="Compute interest" |
|
||||
type="object" states="closed,ongoing" |
|
||||
groups="easy_my_coop.group_easy_my_coop_manager"/> |
|
||||
|
|
||||
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,ongoing,closed"/> |
|
||||
</header> |
|
||||
<sheet> |
|
||||
<div class="oe_button_box" name="button_box"> |
|
||||
<button name="toggle_display" type="object" |
|
||||
class="oe_stat_button" icon="fa-globe"> |
|
||||
<field name="display_on_website" widget="website_button"/> |
|
||||
</button> |
|
||||
</div> |
|
||||
<group> |
|
||||
<group> |
|
||||
<field name="name" /> |
|
||||
<field name="default_issue" /> |
|
||||
<field name="face_value" /> |
|
||||
<field name="minimum_amount" /> |
|
||||
<field name="maximum_amount" /> |
|
||||
<field name="subscribed_amount" /> |
|
||||
<field name="by_individual" /> |
|
||||
<field name="min_amount_person" attrs="{'invisible':[('by_individual','=',False)]}" /> |
|
||||
<field name="max_amount_person" attrs="{'invisible':[('by_individual','=',False)]}" /> |
|
||||
<field name="by_company" /> |
|
||||
<field name="min_amount_company" attrs="{'invisible':[('by_company','=',False)]}" /> |
|
||||
<field name="max_amount_company" attrs="{'invisible':[('by_company','=',False)]}" /> |
|
||||
<field name="company_currency_id" invisible="True" /> |
|
||||
</group> |
|
||||
<group> |
|
||||
<field name="user_id" widget="selection" /> |
|
||||
<label for="rate" string="Interest rate"/> |
|
||||
<div> |
|
||||
<field name="rate" class="oe_inline"/> |
|
||||
<span class="o_form_label oe_inline">%</span> |
|
||||
</div> |
|
||||
<label for="taxes_rate" string="Taxes on interest"/> |
|
||||
<div> |
|
||||
<field name="taxes_rate" class="oe_inline"/> |
|
||||
<span class="o_form_label oe_inline">%</span> |
|
||||
</div> |
|
||||
<field name="subscription_start_date" /> |
|
||||
<field name="subscription_end_date" /> |
|
||||
<field name="term_date" /> |
|
||||
<field name="loan_term" /> |
|
||||
<field name="interest_payment" widget="selection" /> |
|
||||
</group> |
|
||||
</group> |
|
||||
<notebook> |
|
||||
<page name="lines" string="Lines"> |
|
||||
<field name="loan_issue_lines"> |
|
||||
<tree delete="false"> |
|
||||
<field name="name" /> |
|
||||
<field name="partner_id" /> |
|
||||
<field name="date" /> |
|
||||
<field name="quantity" /> |
|
||||
<field name="face_value" /> |
|
||||
<field name="amount" /> |
|
||||
<field name="state" /> |
|
||||
<field name="company_currency_id" invisible="True"/> |
|
||||
</tree> |
|
||||
</field> |
|
||||
</page> |
|
||||
</notebook> |
|
||||
</sheet> |
|
||||
</form> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="view_loan_issue_filter" model="ir.ui.view"> |
|
||||
<field name="name">Loans Issue Search</field> |
|
||||
<field name="model">loan.issue</field> |
|
||||
<field name="arch" type="xml"> |
|
||||
<search string="Search Loan Issue"> |
|
||||
<field name="name"/> |
|
||||
</search> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="action_loan_issue" model="ir.actions.act_window"> |
|
||||
<field name="name">Loan Issues</field> |
|
||||
<field name="res_model">loan.issue</field> |
|
||||
<field name="view_type">form</field> |
|
||||
<field name="view_mode">tree,form</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="action_loan_issue_lines" model="ir.actions.act_window"> |
|
||||
<field name="name">Loans</field> |
|
||||
<field name="res_model">loan.issue.line</field> |
|
||||
<field name="view_type">form</field> |
|
||||
<field name="view_mode">tree,form</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="loan_issue_line_view_tree" model="ir.ui.view"> |
|
||||
<field name="name">loan_issue_line_view_tree</field> |
|
||||
<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"/> |
|
||||
<field name="date"/> |
|
||||
<field name="state"/> |
|
||||
</tree> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="view_loan_issue_line_form" model="ir.ui.view"> |
|
||||
<field name="name">loan.issue.line.form</field> |
|
||||
<field name="model">loan.issue.line</field> |
|
||||
<field name="arch" type="xml"> |
|
||||
<form string="Loan issue"> |
|
||||
<header> |
|
||||
<button name="action_validate" string="Validate" |
|
||||
type="object" states="draft" /> |
|
||||
<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" /> |
|
||||
<field name="state" widget="statusbar" /> |
|
||||
</header> |
|
||||
<sheet> |
|
||||
<group> |
|
||||
<group> |
|
||||
<field name="loan_issue_id"/> |
|
||||
<field name="name" /> |
|
||||
<field name="quantity" /> |
|
||||
<field name="face_value" /> |
|
||||
</group> |
|
||||
<group> |
|
||||
<field name="date" /> |
|
||||
<field name="partner_id" /> |
|
||||
<field name="amount" /> |
|
||||
</group> |
|
||||
</group> |
|
||||
<notebook> |
|
||||
<page string="Interest lines"> |
|
||||
<field name="interest_lines"> |
|
||||
<tree delete="false" create="false"> |
|
||||
<field name="name" /> |
|
||||
<field name="amount" /> |
|
||||
<field name="accrued_amount" /> |
|
||||
<field name="interest" /> |
|
||||
<field name="net_interest" /> |
|
||||
<field name="taxes_amount" /> |
|
||||
<field name="due_date" /> |
|
||||
<field name="state" /> |
|
||||
</tree> |
|
||||
</field> |
|
||||
</page> |
|
||||
</notebook> |
|
||||
</sheet> |
|
||||
</form> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="view_loan_issue_line_filter" model="ir.ui.view"> |
|
||||
<field name="name">Loans Search</field> |
|
||||
<field name="model">loan.issue.line</field> |
|
||||
<field name="arch" type="xml"> |
|
||||
<search string="Search Loans"> |
|
||||
<field name="name"/> |
|
||||
<field name="partner_id"/> |
|
||||
<field name="loan_issue_id"/> |
|
||||
<separator/> |
|
||||
<filter string="Draft" name="state_draft" domain="[('state','=','draft')]"/> |
|
||||
<filter string="Paid" name="state_paid" domain="[('state','=','paid')]"/> |
|
||||
<filter string="Done" name="state_done" domain="[('state','=','done')]"/> |
|
||||
<filter string="Subscribed" name="state_subscribed" domain="[('state','=','subscribed')]"/> |
|
||||
<group expand="0" name="group_by" string="Group By"> |
|
||||
<filter name="loan_issue_id" string="Loan Issue" context="{'group_by' : 'loan_issue_id'}" /> |
|
||||
<filter name="date" string="Subscription Date" context="{'group_by': 'date'}"/> |
|
||||
</group> |
|
||||
</search> |
|
||||
</field> |
|
||||
</record> |
|
||||
</odoo> |
|
||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<record id="view_loan_issue_tree" model="ir.ui.view"> |
||||
|
<field name="name">loan.issue.tree</field> |
||||
|
<field name="model">loan.issue</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<tree string="Loan issues"> |
||||
|
<field name="name" /> |
||||
|
<field name="subscription_start_date" /> |
||||
|
<field name="subscription_end_date" /> |
||||
|
<field name="loan_start_date" /> |
||||
|
<field name="term_date" /> |
||||
|
<field name="loan_term" /> |
||||
|
<field name="rate" /> |
||||
|
<field name="minimum_amount" /> |
||||
|
<field name="maximum_amount" /> |
||||
|
<field name="subscribed_amount" /> |
||||
|
<field name="user_id" /> |
||||
|
<field name="state" /> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="view_loan_issue_form" model="ir.ui.view"> |
||||
|
<field name="name">loan.issue.form</field> |
||||
|
<field name="model">loan.issue</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Loan issue"> |
||||
|
<header> |
||||
|
<!-- todo check access rights --> |
||||
|
<button name="action_confirm" string="Confirm" type="object" states="draft" |
||||
|
groups="easy_my_coop.group_easy_my_coop_manager"/> |
||||
|
<button name="action_cancel" string="Cancel" type="object" states="draft,ongoing" |
||||
|
confirm="Are you sure you want to cancel this loan issue?" |
||||
|
groups="easy_my_coop.group_easy_my_coop_manager"/> |
||||
|
<button name="action_open" string="Open" type="object" |
||||
|
states="confirmed" groups="easy_my_coop.group_easy_my_coop_manager"/> |
||||
|
<button name="action_close" string="Close" type="object" states="ongoing" |
||||
|
confirm="Are you sure you want to close this loan issue?" |
||||
|
groups="easy_my_coop.group_easy_my_coop_manager"/> |
||||
|
<button name="action_draft" string="Set to draft" |
||||
|
type="object" states="confirmed,cancelled" |
||||
|
groups="easy_my_coop.group_easy_my_coop_manager"/> |
||||
|
<button name="compute_loan_interest" string="Compute interest" |
||||
|
type="object" states="closed,ongoing" |
||||
|
groups="easy_my_coop.group_easy_my_coop_manager"/> |
||||
|
|
||||
|
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,ongoing,closed"/> |
||||
|
</header> |
||||
|
<sheet> |
||||
|
<div class="oe_title"> |
||||
|
<label class="oe_edit_only" for="name" string="Name"/> |
||||
|
<h1><field name="name" placeholder="Loan issue Name"/></h1> |
||||
|
<div name="options"> |
||||
|
<div> |
||||
|
<field name="display_on_website"/> |
||||
|
<label for="display_on_website"/> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<group> |
||||
|
<group> |
||||
|
<field name="default_issue" /> |
||||
|
<field name="face_value" /> |
||||
|
<field name="minimum_amount" /> |
||||
|
<field name="maximum_amount" /> |
||||
|
<field name="subscribed_amount" /> |
||||
|
<field name="by_individual" /> |
||||
|
<field name="min_amount_person" attrs="{'invisible':[('by_individual','=',False)]}" /> |
||||
|
<field name="max_amount_person" attrs="{'invisible':[('by_individual','=',False)]}" /> |
||||
|
<field name="by_company" /> |
||||
|
<field name="min_amount_company" attrs="{'invisible':[('by_company','=',False)]}" /> |
||||
|
<field name="max_amount_company" attrs="{'invisible':[('by_company','=',False)]}" /> |
||||
|
<field name="company_currency_id" invisible="True" /> |
||||
|
</group> |
||||
|
<group> |
||||
|
<field name="user_id" widget="selection" /> |
||||
|
<label for="rate" string="Interest rate"/> |
||||
|
<div> |
||||
|
<field name="rate" class="oe_inline"/> |
||||
|
<span class="o_form_label oe_inline">%</span> |
||||
|
</div> |
||||
|
<label for="taxes_rate" string="Taxes on interest"/> |
||||
|
<div> |
||||
|
<field name="taxes_rate" class="oe_inline"/> |
||||
|
<span class="o_form_label oe_inline">%</span> |
||||
|
</div> |
||||
|
<field name="subscription_start_date" /> |
||||
|
<field name="subscription_end_date" /> |
||||
|
<field name="loan_start_date" /> |
||||
|
<field name="term_date" /> |
||||
|
<field name="loan_term" /> |
||||
|
<field name="interest_payment" widget="selection" /> |
||||
|
<field name="interest_payment_info" attrs="{'invisible':[('interest_payment','not in',['end','yearly'])]}" /> |
||||
|
</group> |
||||
|
</group> |
||||
|
<notebook> |
||||
|
<page name="lines" string="Lines"> |
||||
|
<field name="loan_issue_lines"> |
||||
|
<tree delete="false"> |
||||
|
<field name="name" /> |
||||
|
<field name="partner_id" /> |
||||
|
<field name="date" /> |
||||
|
<field name="quantity" /> |
||||
|
<field name="face_value" /> |
||||
|
<field name="amount" /> |
||||
|
<field name="state" /> |
||||
|
<field name="company_currency_id" invisible="True"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</page> |
||||
|
</notebook> |
||||
|
</sheet> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="view_loan_issue_filter" model="ir.ui.view"> |
||||
|
<field name="name">Loans Issue Search</field> |
||||
|
<field name="model">loan.issue</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<search string="Search Loan Issue"> |
||||
|
<field name="name"/> |
||||
|
</search> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="action_loan_issue" model="ir.actions.act_window"> |
||||
|
<field name="name">Loan Issues</field> |
||||
|
<field name="res_model">loan.issue</field> |
||||
|
<field name="view_type">form</field> |
||||
|
<field name="view_mode">tree,form</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="action_loan_issue_lines" model="ir.actions.act_window"> |
||||
|
<field name="name">Loans</field> |
||||
|
<field name="res_model">loan.issue.line</field> |
||||
|
<field name="view_type">form</field> |
||||
|
<field name="view_mode">tree,form</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="loan_issue_line_view_tree" model="ir.ui.view"> |
||||
|
<field name="name">loan_issue_line_view_tree</field> |
||||
|
<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"/> |
||||
|
<field name="date"/> |
||||
|
<field name="state"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="view_loan_issue_line_form" model="ir.ui.view"> |
||||
|
<field name="name">loan.issue.line.form</field> |
||||
|
<field name="model">loan.issue.line</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Loan issue"> |
||||
|
<header> |
||||
|
<button name="action_validate" string="Validate" |
||||
|
type="object" states="draft" /> |
||||
|
<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" /> |
||||
|
<field name="state" widget="statusbar" /> |
||||
|
</header> |
||||
|
<sheet> |
||||
|
<group> |
||||
|
<group> |
||||
|
<field name="loan_issue_id"/> |
||||
|
<field name="name" /> |
||||
|
<field name="quantity" /> |
||||
|
<field name="face_value" /> |
||||
|
</group> |
||||
|
<group> |
||||
|
<field name="date" /> |
||||
|
<field name="partner_id" /> |
||||
|
<field name="amount" /> |
||||
|
</group> |
||||
|
</group> |
||||
|
<notebook> |
||||
|
<page string="Interest lines"> |
||||
|
<field name="interest_lines"> |
||||
|
<tree delete="false" create="false"> |
||||
|
<field name="name" /> |
||||
|
<field name="amount" /> |
||||
|
<field name="accrued_amount" /> |
||||
|
<field name="interest" /> |
||||
|
<field name="net_interest" /> |
||||
|
<field name="taxes_amount" /> |
||||
|
<field name="due_date" /> |
||||
|
<field name="state" /> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</page> |
||||
|
</notebook> |
||||
|
</sheet> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="view_loan_issue_line_filter" model="ir.ui.view"> |
||||
|
<field name="name">Loans Search</field> |
||||
|
<field name="model">loan.issue.line</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<search string="Search Loans"> |
||||
|
<field name="name"/> |
||||
|
<field name="partner_id"/> |
||||
|
<field name="loan_issue_id"/> |
||||
|
<separator/> |
||||
|
<filter string="Draft" name="state_draft" domain="[('state','=','draft')]"/> |
||||
|
<filter string="Paid" name="state_paid" domain="[('state','=','paid')]"/> |
||||
|
<filter string="Done" name="state_done" domain="[('state','=','done')]"/> |
||||
|
<filter string="Subscribed" name="state_subscribed" domain="[('state','=','subscribed')]"/> |
||||
|
<group expand="0" name="group_by" string="Group By"> |
||||
|
<filter name="loan_issue_id" string="Loan Issue" context="{'group_by' : 'loan_issue_id'}" /> |
||||
|
<filter name="date" string="Subscription Date" context="{'group_by': 'date'}"/> |
||||
|
</group> |
||||
|
</search> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue