From 4e8f9bbf977c9e59e80ade360d24d185ee61d0dd Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 10 Jul 2015 19:36:04 +0200 Subject: [PATCH] Add new module partner_aged_open_invoices --- partner_aged_open_invoices/__init__.py | 3 + partner_aged_open_invoices/__openerp__.py | 44 ++++++++++++++ partner_aged_open_invoices/partner.py | 65 +++++++++++++++++++++ partner_aged_open_invoices/partner_view.xml | 37 ++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 partner_aged_open_invoices/__init__.py create mode 100644 partner_aged_open_invoices/__openerp__.py create mode 100644 partner_aged_open_invoices/partner.py create mode 100644 partner_aged_open_invoices/partner_view.xml diff --git a/partner_aged_open_invoices/__init__.py b/partner_aged_open_invoices/__init__.py new file mode 100644 index 0000000..84d775d --- /dev/null +++ b/partner_aged_open_invoices/__init__.py @@ -0,0 +1,3 @@ +# -*- encoding: utf-8 -*- + +from . import partner diff --git a/partner_aged_open_invoices/__openerp__.py b/partner_aged_open_invoices/__openerp__.py new file mode 100644 index 0000000..4c5de2f --- /dev/null +++ b/partner_aged_open_invoices/__openerp__.py @@ -0,0 +1,44 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Partner Aged Open Invoices module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'Partner Aged Open Invoices', + 'version': '0.1', + 'category': 'Accounting & Finance', + 'license': 'AGPL-3', + 'summary': 'Direct access to the aged open invoice report from the partner form', + 'description': """ +Partner Aged Open Invoices +========================== + +This module adds a button on the partner form view (the icon on the button is a banknote) to easily open the aged open invoices report of this partner. + +It requires the updated version of the account_financial_report_webkit module that has the aged open invoice report. + +This module has been written by Alexis de Lattre from Akretion . + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['account_financial_report_webkit'], + 'data': ['partner_view.xml'], +} diff --git a/partner_aged_open_invoices/partner.py b/partner_aged_open_invoices/partner.py new file mode 100644 index 0000000..f655009 --- /dev/null +++ b/partner_aged_open_invoices/partner.py @@ -0,0 +1,65 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Partner Aged Open Invoices module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, fields, api +import openerp.addons.decimal_precision as dp + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.one + @api.depends('credit', 'debit') + def _compute_balance(self): + self.balance = self.credit - self.debit + + balance = fields.Float( + compute='_compute_balance', readonly=True, + digits=dp.get_precision('Account'), string="Account Balance") + + @api.multi + def open_aged_open_invoices_report(self): + aoiwo = self.env['aged.open.invoices.webkit'] + fy_id = aoiwo._get_fiscalyear() + filter_change = aoiwo.onchange_filter( + filter='filter_date', fiscalyear_id=fy_id) + vals = { + 'fiscalyear_id': fy_id, + 'filter': 'filter_date', + 'partner_ids': [(6, 0, [self.commercial_partner_id.id])], + 'target_move': 'all', + } + vals.update(filter_change['value']) + wizard = self.env['aged.open.invoices.webkit'].create(vals) + data = {'form': { + 'chart_account_id': wizard.chart_account_id.id, + 'filter': 'filter_date', + 'date_from': vals['date_from'], + 'date_to': vals['date_to'], + 'period_to': False, + 'fiscalyear_id': fy_id, + 'partner_ids': [self.commercial_partner_id.id], + 'target_move': 'all', + } + } + action = wizard._print_report(data) + return action diff --git a/partner_aged_open_invoices/partner_view.xml b/partner_aged_open_invoices/partner_view.xml new file mode 100644 index 0000000..64a12f1 --- /dev/null +++ b/partner_aged_open_invoices/partner_view.xml @@ -0,0 +1,37 @@ + + + + + + + + + account.balance.button.partner.form + res.partner + + + + + + + + + +