From 2867c1cbdbaadf375d6007dd38eeb0762dfe3c4f Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Wed, 16 Oct 2019 16:53:29 +0200 Subject: [PATCH 1/2] [ADD] emc_loan: loaners field and menu --- easy_my_coop_loan/models/partner.py | 31 ++++++++++++++++++++---- easy_my_coop_loan/views/menus.xml | 2 ++ easy_my_coop_loan/views/partner_view.xml | 31 ++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/easy_my_coop_loan/models/partner.py b/easy_my_coop_loan/models/partner.py index 7b6a2f2..61e3f03 100644 --- a/easy_my_coop_loan/models/partner.py +++ b/easy_my_coop_loan/models/partner.py @@ -1,9 +1,30 @@ -from odoo import fields, models +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# 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' + _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, + ) - loan_line_ids = fields.One2many('loan.issue.line', - 'partner_id', - string="Loans") + @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) diff --git a/easy_my_coop_loan/views/menus.xml b/easy_my_coop_loan/views/menus.xml index 6ed2243..55f577f 100644 --- a/easy_my_coop_loan/views/menus.xml +++ b/easy_my_coop_loan/views/menus.xml @@ -8,5 +8,7 @@ + + diff --git a/easy_my_coop_loan/views/partner_view.xml b/easy_my_coop_loan/views/partner_view.xml index 60ad0f7..59577bf 100644 --- a/easy_my_coop_loan/views/partner_view.xml +++ b/easy_my_coop_loan/views/partner_view.xml @@ -1,11 +1,19 @@ + + res.partner.form.loan.issue res.partner - + + + + @@ -20,4 +28,23 @@ - \ No newline at end of file + + + res.partner.select + res.partner + + + + + + + + + + Loaners + res.partner + form + kanban,tree,form + {'search_default_loaners':1} + + From df6f2c3e76254b483e917b6cb753ca90d13586d6 Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Wed, 16 Oct 2019 16:56:17 +0200 Subject: [PATCH 2/2] [REF] emc_loan: menu ids consistency --- easy_my_coop_loan/views/loan_view.xml | 2 +- easy_my_coop_loan/views/menus.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/easy_my_coop_loan/views/loan_view.xml b/easy_my_coop_loan/views/loan_view.xml index a9b6277..0dd8860 100644 --- a/easy_my_coop_loan/views/loan_view.xml +++ b/easy_my_coop_loan/views/loan_view.xml @@ -104,7 +104,7 @@ tree,form - + Loans loan.issue.line form diff --git a/easy_my_coop_loan/views/menus.xml b/easy_my_coop_loan/views/menus.xml index 55f577f..91d6dc3 100644 --- a/easy_my_coop_loan/views/menus.xml +++ b/easy_my_coop_loan/views/menus.xml @@ -6,7 +6,7 @@ - +