res_partner.py 1.43 KB
Newer Older
François C. committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# @author: Julien Weste
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import api, models, fields


class ResPartner(models.Model):
    _inherit = 'res.partner'

    fundraising_partner_type_ids = fields.Many2many(
        comodel_name='capital.fundraising.partner.type',
        string='Fundraising Partner Type')

    amount_subscription = fields.Float(
        string="Total Subscribed Amount",
        compute='compute_amount_subscription')

    # Compute section
    @api.multi
    def compute_amount_subscription(self):
        inv_obj = self.env['account.invoice'].sudo()
        for partner in self:
            amount_subscription = sum(inv_obj.search([
                ('type', '=', 'out_invoice'),
                ('partner_id', '=', partner.id),
                ('is_capital_fundraising', '=', True),
                ('state', 'in', ['paid', 'open'])
            ]).mapped('amount_total_signed'))
            partner.amount_subscription = amount_subscription + sum(
                inv_obj.search([
                    ('type', '=', 'out_refund'),
                    ('partner_id', '=', partner.id),
                    ('is_capital_fundraising', '=', True),
                    ('state', 'in', ['paid', 'open'])
                ]).mapped('amount_total_signed'))