Skip to content

Commit

Permalink
Merge d99ce3b into b101214
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Sep 22, 2019
2 parents b101214 + d99ce3b commit 972a9bc
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 0 deletions.
2 changes: 2 additions & 0 deletions account_balance_line_progressive/__init__.py
@@ -0,0 +1,2 @@

from . import models
20 changes: 20 additions & 0 deletions account_balance_line_progressive/__manifest__.py
@@ -0,0 +1,20 @@
# Copyright 2016-2019 Sergio Corato <https://github.com/sergiocorato>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
'name': 'Account balance line progressive',
'version': '12.0.1.0.0',
'category': 'Account',
'description': 'View balance in account line tree. '
'Instead of module account_balance_line, wich show the balance only of the'
' single line, it compute progressive balance for the account selected.',
'author': 'Sergio Corato',
'website': 'https://efatto.it',
'license': 'LGPL-3',
'depends': [
'account',
],
'data': [
'views/account_move_line.xml',
],
'installable': True,
}
41 changes: 41 additions & 0 deletions account_balance_line_progressive/i18n/it.po
@@ -0,0 +1,41 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_balance_line_progressive
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-08-12 22:58+0000\n"
"PO-Revision-Date: 2018-08-12 22:58+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_balance_line_progressive
#: model:ir.ui.view,arch_db:account_balance_line_progressive.view_account_move_line_filter_balance
msgid "Account"
msgstr "Conto"

#. module: account_balance_line_progressive
#: model:ir.ui.view,arch_db:account_balance_line_progressive.view_account_move_line_filter_balance
msgid "Date"
msgstr "Data"

#. module: account_balance_line_progressive
#: model:ir.ui.view,arch_db:account_balance_line_progressive.view_account_move_line_filter_balance
msgid "Journal"
msgstr "Sezionale"

#. module: account_balance_line_progressive
#: model:ir.model,name:account_balance_line_progressive.model_account_move_line
msgid "Journal Item"
msgstr "Voce sezionale"

#. module: account_balance_line_progressive
#: model:ir.ui.view,arch_db:account_balance_line_progressive.view_account_move_line_filter_balance
msgid "Partner"
msgstr "Partner"
2 changes: 2 additions & 0 deletions account_balance_line_progressive/models/__init__.py
@@ -0,0 +1,2 @@

from . import account_move_line
45 changes: 45 additions & 0 deletions account_balance_line_progressive/models/account_move_line.py
@@ -0,0 +1,45 @@
# Copyright 2019 Sergio Corato <https://github.com/sergiocorato>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from odoo import models, fields, api


class AccountMoveLine(models.Model):
_inherit = "account.move.line"
_order = 'date desc, id desc'

@api.depends('debit', 'credit')
def _store_balance_progressive(self):
tables, where_clause, where_params = self.with_context(
initial_bal=True)._query_get()
where_params = [tuple(self.ids)] + where_params
if where_clause:
where_clause = 'AND ' + where_clause
where_clause = where_clause.replace('account_move_line', 'l1')
self._cr.execute(
"""SELECT l1.id, COALESCE(SUM(l2.debit-l2.credit), 0)
FROM account_move_line l1
LEFT JOIN account_account a
ON (a.id = l1.account_id)
LEFT JOIN account_account_type at
ON (at.id = a.user_type_id)
JOIN account_move m on (m.id = l1.move_id AND m.state <> 'draft')
LEFT JOIN account_move_line l2
ON (l1.account_id = l2.account_id
AND (
l1.partner_id = l2.partner_id
OR
at.type not in ('receivable', 'payable')
)
)
AND (l2.date < l1.date OR (l2.date = l1.date AND l2.id <= l1.id))
WHERE l1.id IN %s """ + where_clause + " GROUP BY l1.id",
where_params)
for id, val in self._cr.fetchall():
self.browse(id).balance_progressive = val

balance_progressive = fields.Monetary(
compute='_store_balance_progressive', store=False,
currency_field='company_currency_id',
help="Technical field holding the progressive debit - credit in order "
"to open meaningful graph views from reports")
1 change: 1 addition & 0 deletions account_balance_line_progressive/tests/__init__.py
@@ -0,0 +1 @@
from . import test_account_balance_line_progressive
@@ -0,0 +1,85 @@
# Copyright 2019 Sergio Corato <https://github.com/sergiocorato>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from datetime import timedelta

import odoo.tests.common as common
from odoo import fields, _


class TestAccountBalanceProgressive(common.TransactionCase):

def setUp(self):
super(TestAccountBalanceProgressive, self).setUp()
self.miscellaneous_journal = self.env['account.journal'].create({
'name': 'Miscellaneus journal',
'type': 'general',
'code': 'OTHER',
})
self.account = self.env['account.account'].create({
'code': 'TEST_CREDIT_PROGRESSIVE',
'name': 'Credit progressive',
'user_type_id': self.env.ref(
'account.data_account_type_payable').id,
'reconcile': True,
})
self.account_expenses = self.env['account.account'].create({
'code': 'TEST_EXPENSE_PROGRESSIVE',
'name': 'Expense progressive',
'user_type_id': self.env.ref(
'account.data_account_type_expenses').id,
})

def create_move(self, date, debit, credit):
move = self.env['account.move'].create({
'name': _('Account move'),
'journal_id': self.miscellaneous_journal.id,
'date': date,
'line_ids': [
(0, 0, {
'account_id': self.account.id,
'partner_id': self.env.ref('base.res_partner_12').id,
'debit': debit,
'credit': credit,
'name': 'Test move line',
'currency_id': self.ref('base.EUR'),
}),
(0, 0, {
'account_id': self.account_expenses.id,
'debit': credit,
'credit': debit,
'name': 'Test move line',
'currency_id': self.ref('base.EUR'),
}),
]
})
return move

def test_account_move(self):
date = fields.Datetime.to_string(
fields.Datetime.today() - timedelta(days=50))
move = self.create_move(date, debit=50, credit=0)
move.action_post()
self.assertAlmostEqual(
move.line_ids.filtered(
lambda x: x.account_id == self.account
).balance_progressive, 50)
date = fields.Datetime.to_string(
fields.Datetime.today() - timedelta(days=30))
move1 = self.create_move(date, debit=0, credit=15)
move1.action_post()
self.assertAlmostEqual(
move1.line_ids.filtered(
lambda x: x.account_id == self.account
).balance_progressive, 35)
date = fields.Datetime.to_string(fields.Datetime.today())
move2 = self.create_move(date, debit=0, credit=30)
move2.action_post()
self.assertAlmostEqual(
move2.line_ids.filtered(
lambda x: x.account_id == self.account
).balance_progressive, 5)
self.assertAlmostEqual(
move2.line_ids.filtered(
lambda x: x.account_id == self.account_expenses
).balance_progressive, -5)
12 changes: 12 additions & 0 deletions account_balance_line_progressive/views/account_move_line.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="account_move_line_balance_custom">
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_tree"/>
<field name="arch" type="xml">
<field name="credit" position="after">
<field name="balance_progressive" invisible="0"/>
</field>
</field>
</record>
</odoo>

0 comments on commit 972a9bc

Please sign in to comment.