From 01a1ef359bb2bbfa9abdab009af5d3bbd3eddd5c Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 28 Apr 2016 11:55:22 +0200 Subject: [PATCH 01/15] ADD account_tax_balance: Compute tax balances based on date range --- account_tax_balance/__init__.py | 6 +++ account_tax_balance/__openerp__.py | 22 +++++++++ account_tax_balance/models/__init__.py | 5 ++ account_tax_balance/models/account_tax.py | 45 +++++++++++++++++ .../views/account_tax_view.xml | 18 +++++++ account_tax_balance/wizard/__init__.py | 5 ++ .../wizard/open_tax_balances.py | 48 +++++++++++++++++++ .../wizard/open_tax_balances_view.xml | 40 ++++++++++++++++ 8 files changed, 189 insertions(+) create mode 100644 account_tax_balance/__init__.py create mode 100644 account_tax_balance/__openerp__.py create mode 100644 account_tax_balance/models/__init__.py create mode 100644 account_tax_balance/models/account_tax.py create mode 100644 account_tax_balance/views/account_tax_view.xml create mode 100644 account_tax_balance/wizard/__init__.py create mode 100644 account_tax_balance/wizard/open_tax_balances.py create mode 100644 account_tax_balance/wizard/open_tax_balances_view.xml diff --git a/account_tax_balance/__init__.py b/account_tax_balance/__init__.py new file mode 100644 index 000000000000..11805bd0be8a --- /dev/null +++ b/account_tax_balance/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2016 Lorenzo Battistini - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models +from . import wizard \ No newline at end of file diff --git a/account_tax_balance/__openerp__.py b/account_tax_balance/__openerp__.py new file mode 100644 index 000000000000..60683bb338f0 --- /dev/null +++ b/account_tax_balance/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2016 Lorenzo Battistini - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Tax Balance", + "summary": "Compute tax balances based on date range", + "version": "9.0.1.0.0", + "category": "Accounting & Finance", + "website": "https://www.agilebg.com/", + "author": "Agile Business Group, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "account", + "date_range", + ], + "data": [ + "wizard/open_tax_balances_view.xml", + "views/account_tax_view.xml", + ], +} diff --git a/account_tax_balance/models/__init__.py b/account_tax_balance/models/__init__.py new file mode 100644 index 000000000000..4e12d8813568 --- /dev/null +++ b/account_tax_balance/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Lorenzo Battistini - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import account_tax \ No newline at end of file diff --git a/account_tax_balance/models/account_tax.py b/account_tax_balance/models/account_tax.py new file mode 100644 index 000000000000..37541ac6d111 --- /dev/null +++ b/account_tax_balance/models/account_tax.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# © 2016 Lorenzo Battistini - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields + + +class AccountTax(models.Model): + _inherit = 'account.tax' + + balance = fields.Float(string="Balance", compute="_compute_balance") + + def _compute_balance(self): + if not self.env.context.get('from_date'): + from_date = fields.Date.context_today(self) + else: + from_date = self.env.context['from_date'] + if not self.env.context.get('to_date'): + to_date = fields.Date.context_today(self) + else: + to_date = self.env.context['to_date'] + if not self.env.context.get('move_state'): + move_state = 'posted' + else: + move_state = self.env.context['move_state'] + if not self.env.context.get('company_id'): + company_id = self.env.user.company_id.id + else: + company_id = self.env.context['company_id'] + for tax in self: + tax.balance = tax.compute_balance( + from_date, to_date, company_id, move_state) + + def compute_balance(self, from_date, to_date, company_id, state="posted"): + self.ensure_one() + move_line_model = self.env['account.move.line'] + move_lines = move_line_model.search([ + ('tax_line_id', '=', self.id), + ('date', '<=', to_date), + ('date', '>=', from_date), + ('move_id.state', '=', state), + ('company_id', '=', company_id), + ]) + total = sum([l.balance for l in move_lines]) + return total \ No newline at end of file diff --git a/account_tax_balance/views/account_tax_view.xml b/account_tax_balance/views/account_tax_view.xml new file mode 100644 index 000000000000..6109523a3398 --- /dev/null +++ b/account_tax_balance/views/account_tax_view.xml @@ -0,0 +1,18 @@ + + + + + + account.tax.tree.balance + account.tax + + + + + + + + + + + \ No newline at end of file diff --git a/account_tax_balance/wizard/__init__.py b/account_tax_balance/wizard/__init__.py new file mode 100644 index 000000000000..d625c4308dab --- /dev/null +++ b/account_tax_balance/wizard/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Lorenzo Battistini - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import open_tax_balances \ No newline at end of file diff --git a/account_tax_balance/wizard/open_tax_balances.py b/account_tax_balance/wizard/open_tax_balances.py new file mode 100644 index 000000000000..ba6f1efaf43c --- /dev/null +++ b/account_tax_balance/wizard/open_tax_balances.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# © 2016 Lorenzo Battistini - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields, api +from openerp.tools.translate import _ + + +class OpenTaxBalances(models.TransientModel): + _name = 'wizard.open.tax.balances' + company_id = fields.Many2one( + 'res.company', 'Company', required=True, + default=lambda self: self.env.user.company_id) + from_date = fields.Date('From date', required=True) + to_date = fields.Date('To date', required=True) + date_range_id = fields.Many2one('date.range', 'Date range') + move_state = fields.Selection( + [('draft', 'Unposted'), ('posted', 'Posted')], + string="Move state", required=True, default='posted' + ) + + @api.onchange('date_range_id') + def onchange_date_range_id(self): + if self.date_range_id: + self.from_date = self.date_range_id.date_start + self.to_date = self.date_range_id.date_end + else: + self.from_date = self.to_date = None + + @api.multi + def open_taxes(self): + self.ensure_one() + view = self.env.ref('account_tax_balance.view_tax_tree_balance') + action = { + 'name': _("Tax Balances"), + 'res_model': 'account.tax', + 'view_type': 'form', + 'view_mode': 'tree', + 'view_id': view.id, + 'type': 'ir.actions.act_window', + 'context': { + 'from_date': self.from_date, + 'to_date': self.to_date, + 'move_state': self.move_state, + 'company_id': self.company_id.id, + }, + } + return action \ No newline at end of file diff --git a/account_tax_balance/wizard/open_tax_balances_view.xml b/account_tax_balance/wizard/open_tax_balances_view.xml new file mode 100644 index 000000000000..b49e97edd295 --- /dev/null +++ b/account_tax_balance/wizard/open_tax_balances_view.xml @@ -0,0 +1,40 @@ + + + + + wizard_open_tax_balances + wizard.open.tax.balances + +
+ + + + + + + +
+
+
+
+
+ + + Open Tax Balances + wizard.open.tax.balances + form + form + + new + + + +
+
\ No newline at end of file From af053a3395ebd9be1acc4b6458757b6c8b4e6ae5 Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 28 Apr 2016 13:15:08 +0200 Subject: [PATCH 02/15] IMP filters and views --- account_tax_balance/models/account_tax.py | 20 ++++++++---- .../views/account_tax_view.xml | 25 +++++++++++++++ .../wizard/open_tax_balances.py | 31 +++++++------------ .../wizard/open_tax_balances_view.xml | 2 +- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/account_tax_balance/models/account_tax.py b/account_tax_balance/models/account_tax.py index 37541ac6d111..3b3bc9ac3138 100644 --- a/account_tax_balance/models/account_tax.py +++ b/account_tax_balance/models/account_tax.py @@ -19,26 +19,34 @@ def _compute_balance(self): to_date = fields.Date.context_today(self) else: to_date = self.env.context['to_date'] - if not self.env.context.get('move_state'): - move_state = 'posted' + if not self.env.context.get('target_move'): + target_move = 'posted' else: - move_state = self.env.context['move_state'] + target_move = self.env.context['target_move'] if not self.env.context.get('company_id'): company_id = self.env.user.company_id.id else: company_id = self.env.context['company_id'] for tax in self: tax.balance = tax.compute_balance( - from_date, to_date, company_id, move_state) + from_date, to_date, company_id, target_move) - def compute_balance(self, from_date, to_date, company_id, state="posted"): + def compute_balance( + self, from_date, to_date, company_id, target_move="posted" + ): self.ensure_one() move_line_model = self.env['account.move.line'] + if target_move == 'posted': + state = ['posted'] + elif target_move == 'all': + state = ['posted', 'draft'] + else: + state = [] move_lines = move_line_model.search([ ('tax_line_id', '=', self.id), ('date', '<=', to_date), ('date', '>=', from_date), - ('move_id.state', '=', state), + ('move_id.state', 'in', state), ('company_id', '=', company_id), ]) total = sum([l.balance for l in move_lines]) diff --git a/account_tax_balance/views/account_tax_view.xml b/account_tax_balance/views/account_tax_view.xml index 6109523a3398..c609a5fa15b4 100644 --- a/account_tax_balance/views/account_tax_view.xml +++ b/account_tax_balance/views/account_tax_view.xml @@ -14,5 +14,30 @@ + + account.tax.search.balance + account.tax + + + + + + + + + + + + + + + + Tax Balances + account.tax + form + tree + + + \ No newline at end of file diff --git a/account_tax_balance/wizard/open_tax_balances.py b/account_tax_balance/wizard/open_tax_balances.py index ba6f1efaf43c..e0eda7dd4619 100644 --- a/account_tax_balance/wizard/open_tax_balances.py +++ b/account_tax_balance/wizard/open_tax_balances.py @@ -14,10 +14,10 @@ class OpenTaxBalances(models.TransientModel): from_date = fields.Date('From date', required=True) to_date = fields.Date('To date', required=True) date_range_id = fields.Many2one('date.range', 'Date range') - move_state = fields.Selection( - [('draft', 'Unposted'), ('posted', 'Posted')], - string="Move state", required=True, default='posted' - ) + target_move = fields.Selection([ + ('posted', 'All Posted Entries'), + ('all', 'All Entries'), + ], 'Target Moves', required=True, default='posted') @api.onchange('date_range_id') def onchange_date_range_id(self): @@ -30,19 +30,12 @@ def onchange_date_range_id(self): @api.multi def open_taxes(self): self.ensure_one() - view = self.env.ref('account_tax_balance.view_tax_tree_balance') - action = { - 'name': _("Tax Balances"), - 'res_model': 'account.tax', - 'view_type': 'form', - 'view_mode': 'tree', - 'view_id': view.id, - 'type': 'ir.actions.act_window', - 'context': { - 'from_date': self.from_date, - 'to_date': self.to_date, - 'move_state': self.move_state, - 'company_id': self.company_id.id, - }, + action = self.env.ref('account_tax_balance.action_tax_balances_tree') + vals = action.read()[0] + vals['context'] = { + 'from_date': self.from_date, + 'to_date': self.to_date, + 'target_move': self.target_move, + 'company_id': self.company_id.id, } - return action \ No newline at end of file + return vals \ No newline at end of file diff --git a/account_tax_balance/wizard/open_tax_balances_view.xml b/account_tax_balance/wizard/open_tax_balances_view.xml index b49e97edd295..fed17d33a40c 100644 --- a/account_tax_balance/wizard/open_tax_balances_view.xml +++ b/account_tax_balance/wizard/open_tax_balances_view.xml @@ -11,7 +11,7 @@ - +