From fcce71e48361c8ded28890e8a216786327ee7ad4 Mon Sep 17 00:00:00 2001 From: Oihane Crucelaegui Date: Fri, 11 Jan 2019 14:51:36 +0100 Subject: [PATCH 1/6] [ADD] New module account_budget_distribution --- account_budget_distribution/README.rst | 27 +++++++++ account_budget_distribution/__init__.py | 5 ++ account_budget_distribution/__manifest__.py | 21 +++++++ .../models/__init__.py | 4 ++ .../models/crossovered_budget.py | 27 +++++++++ .../reports/__init__.py | 4 ++ .../reports/crossovered_budget_resume.py | 36 ++++++++++++ .../crossovered_budget_resume_view.xml | 58 +++++++++++++++++++ .../security/ir.model.access.csv | 2 + .../views/crossovered_budget_view.xml | 19 ++++++ .../wizards/__init__.py | 4 ++ .../crossovered_budget_distribution.py | 35 +++++++++++ .../crossovered_budget_distribution_view.xml | 36 ++++++++++++ 13 files changed, 278 insertions(+) create mode 100644 account_budget_distribution/README.rst create mode 100644 account_budget_distribution/__init__.py create mode 100644 account_budget_distribution/__manifest__.py create mode 100644 account_budget_distribution/models/__init__.py create mode 100644 account_budget_distribution/models/crossovered_budget.py create mode 100644 account_budget_distribution/reports/__init__.py create mode 100644 account_budget_distribution/reports/crossovered_budget_resume.py create mode 100644 account_budget_distribution/reports/crossovered_budget_resume_view.xml create mode 100755 account_budget_distribution/security/ir.model.access.csv create mode 100644 account_budget_distribution/views/crossovered_budget_view.xml create mode 100644 account_budget_distribution/wizards/__init__.py create mode 100644 account_budget_distribution/wizards/crossovered_budget_distribution.py create mode 100644 account_budget_distribution/wizards/crossovered_budget_distribution_view.xml diff --git a/account_budget_distribution/README.rst b/account_budget_distribution/README.rst new file mode 100644 index 00000000..79ff3b72 --- /dev/null +++ b/account_budget_distribution/README.rst @@ -0,0 +1,27 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=========================== +Account Budget Distribution +=========================== + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, +please check there if your issue has already been reported. If you spotted +it first, help us smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Oihane Crucelaegui +* Ana Juaristi diff --git a/account_budget_distribution/__init__.py b/account_budget_distribution/__init__.py new file mode 100644 index 00000000..047b5389 --- /dev/null +++ b/account_budget_distribution/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2019 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import models +from . import reports diff --git a/account_budget_distribution/__manifest__.py b/account_budget_distribution/__manifest__.py new file mode 100644 index 00000000..34614994 --- /dev/null +++ b/account_budget_distribution/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2019 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + "name": "Account Budget Distribution", + "version": "11.0.1.0.0", + "category": "Accounting", + "license": "AGPL-3", + "author": "AvanzOSC", + "website": "http://www.avanzosc.es", + "depends": [ + "account_budget", + ], + "data": [ + "security/ir.model.access.csv", + "reports/crossovered_budget_resume_view.xml", + "views/crossovered_budget_view.xml", + "wizards/crossovered_budget_distribution_view.xml", + ], + "installable": True, +} diff --git a/account_budget_distribution/models/__init__.py b/account_budget_distribution/models/__init__.py new file mode 100644 index 00000000..36cc21c2 --- /dev/null +++ b/account_budget_distribution/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2019 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import crossovered_budget diff --git a/account_budget_distribution/models/crossovered_budget.py b/account_budget_distribution/models/crossovered_budget.py new file mode 100644 index 00000000..75501068 --- /dev/null +++ b/account_budget_distribution/models/crossovered_budget.py @@ -0,0 +1,27 @@ +# Copyright 2019 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import api, fields, models + + +class CrossoveredBudget(models.Model): + _inherit = 'crossovered.budget' + + total_planned_amount = fields.Float( + string='Total Planned Amount', store=True) + summary_ids = fields.One2many( + comodel_name='crossovered.budget.summary', + inverse_name='crossovered_budget_id', string='Summary Lines') + + @api.multi + def button_divide_planned_amount(self): + for budget in self.filtered('crossovered_budget_line'): + try: + budget_lines = budget.crossovered_budget_line.filtered( + lambda l: not l.general_budget_id.expenses) + except Exception: + budget_lines = budget.crossovered_budget_line + budget_lines.write({ + 'planned_amount': ( + budget.total_planned_amount / len(budget_lines)) + }) diff --git a/account_budget_distribution/reports/__init__.py b/account_budget_distribution/reports/__init__.py new file mode 100644 index 00000000..c7d20864 --- /dev/null +++ b/account_budget_distribution/reports/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2018 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import crossovered_budget_resume diff --git a/account_budget_distribution/reports/crossovered_budget_resume.py b/account_budget_distribution/reports/crossovered_budget_resume.py new file mode 100644 index 00000000..4c43da28 --- /dev/null +++ b/account_budget_distribution/reports/crossovered_budget_resume.py @@ -0,0 +1,36 @@ +# Copyright 2019 Oihane Crucelaegui - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import tools +from odoo import api, fields, models + + +class CrossoveredBudgetSummary(models.Model): + _name = 'crossovered.budget.summary' + _description = 'Crossovered Budget Summary Lines' + _auto = False + _rec_name = 'crossovered_budget_id' + + crossovered_budget_id = fields.Many2one( + comodel_name='crossovered.budget', string='Budget') + general_budget_id = fields.Many2one( + comodel_name='account.budget.post', string='Budget Position') + planned_amount = fields.Float(string='Planned Amount') + + @api.model_cr + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE or REPLACE VIEW %s as ( + SELECT + row_number() OVER () AS id, + crossovered_budget_id, + general_budget_id, + SUM(planned_amount) as planned_amount + FROM + crossovered_budget_lines + GROUP BY + crossovered_budget_id, + general_budget_id + )""" % ( + self._table)) diff --git a/account_budget_distribution/reports/crossovered_budget_resume_view.xml b/account_budget_distribution/reports/crossovered_budget_resume_view.xml new file mode 100644 index 00000000..0df21b00 --- /dev/null +++ b/account_budget_distribution/reports/crossovered_budget_resume_view.xml @@ -0,0 +1,58 @@ + + + + crossovered.budget.summary + +
+ + + + + + + +
+
+
+ + + crossovered.budget.summary + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/account_budget_distribution/security/ir.model.access.csv b/account_budget_distribution/security/ir.model.access.csv new file mode 100755 index 00000000..0f869584 --- /dev/null +++ b/account_budget_distribution/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_crossovered_budget_summary,access_crossovered_budget_summary,model_crossovered_budget_summary,,1,0,0,0 diff --git a/account_budget_distribution/views/crossovered_budget_view.xml b/account_budget_distribution/views/crossovered_budget_view.xml new file mode 100644 index 00000000..aee45750 --- /dev/null +++ b/account_budget_distribution/views/crossovered_budget_view.xml @@ -0,0 +1,19 @@ + + + + crossovered.budget + + + +