[MIG] port partner_aged_open_invoices to v10 and rename it to account_aged_balance_from_partner

This commit is contained in:
Alexis de Lattre
2018-06-18 18:11:43 +02:00
parent 4e8c6f47f6
commit 1a9126d9a1
8 changed files with 89 additions and 163 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import partner

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2018 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Aged Partner Balance from Partner',
'version': '10.0.0.1.0',
'category': 'Accounting',
'license': 'AGPL-3',
'summary': 'Direct access to the aged partner balance report from the partner form',
'description': """
Aged Partner Balance from Partner
=================================
This module adds a button on the partner form view (the icon on the button is a banknote) to easily open the detailed aged partner balance of the partner in PDF format.
This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['account_financial_report_qweb'],
'data': ['partner_view.xml'],
'installable': True,
}

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015-2018 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
class ResPartner(models.Model):
_inherit = 'res.partner'
@api.depends('credit', 'debit')
def _compute_balance(self):
for partner in self:
partner.balance = partner.credit - partner.debit
# The field 'currency_id' defined in the account module
# is a computed field that gets the company currency
balance = fields.Monetary(
compute='_compute_balance', readonly=True,
string="Account Balance")
def open_aged_open_invoices_report(self):
wiz = self.env['aged.partner.balance.wizard'].create({
'show_move_line_details': True,
'partner_ids': [(6, 0, self.ids)],
})
action = wiz.button_export_pdf()
return action

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015-2018 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">account.balance.button.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.partner_view_buttons"/>
<field name="arch" type="xml">
<button name="open_partner_history" type="object" position="after">
<button class="oe_stat_button" type="object"
name="open_aged_open_invoices_report"
attrs="{'invisible': [('parent_id', '!=', False)]}"
icon="fa-money">
<div class="o_form_field o_stat_info">
<span class="o_stat_value"><field name="balance"/></span>
<span class="o_stat_text">Account Balance</span>
</div>
</button>
</button>
</field>
</record>
</odoo>

View File

@@ -1,3 +0,0 @@
# -*- encoding: utf-8 -*-
from . import partner

View File

@@ -1,45 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Partner Aged Open Invoices module for Odoo
# Copyright (C) 2015-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Partner Aged Open Invoices',
'version': '10.0.0.1.0',
'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 the partner.
It requires the updated version of the module **account_financial_report_webkit** that has the aged open invoice report ; you can find it in this pull request https://github.com/OCA/account-financial-reporting/pull/102
This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['account_financial_report_webkit'],
'data': ['partner_view.xml'],
'installable': False,
}

View File

@@ -1,74 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Partner Aged Open Invoices module for Odoo
# Copyright (C) 2015 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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']
afo = self.env['account.fiscalyear']
# Force 'date_from' to the first day of the company's life
# in order to get the full picture of the partner's account
# (we could also do that via a filter by period, but, in this case,
# account_financial_report_webkit doesn't accept "until_date = today" ;
# until_date has to be the end date of the last period
fy_years = afo.search([], order='date_start')
date_from = fy_years[0].date_start
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'])
vals['date_from'] = date_from
wizard = aoiwo.create(vals)
data = {'form': {
'chart_account_id': wizard.chart_account_id.id,
'filter': vals['filter'],
'date_from': vals['date_from'],
'date_to': vals['date_to'],
'period_to': False,
'fiscalyear_id': vals['fiscalyear_id'],
'partner_ids': vals['partner_ids'][0][2],
'target_move': vals['target_move'],
}
}
action = wizard._print_report(data)
return action

View File

@@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">account.balance.button.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<!-- Put the button after the "Journal Items" without depending
on the view account.partner_view_button_journal_item_count
which is linked to the group account.group_account_user -->
<field name="priority" eval="22"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_stat_button" type="object"
name="open_aged_open_invoices_report"
attrs="{'invisible': [('parent_id', '!=', False)]}"
icon="fa-money"
>
<div>
<strong>
<field string="Account Balance" name="balance"
widget="monetary"/>
</strong>
<br/>
Account Balance
</div>
</button>
</xpath>
</field>
</record>
</data>
</openerp>