-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_analytic_distribution: new module for analytical distri…
…bution
- Loading branch information
agaldona
committed
Aug 30, 2016
1 parent
921179d
commit 0a1bae0
Showing
10 changed files
with
475 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. 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 Analytic Distribution | ||
============================= | ||
|
||
New module to develop analytical distribution. New distribution line | ||
object created for analytic accounts. Whenever there is an analytic | ||
line created against an analytical account with distributions, the | ||
analytical line will be divided depending on the distribution | ||
defined in the account. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
* Ainara Galdona <[email protected]> | ||
* Ana Juaristi <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# (c) 2016 Ainara Galdona - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# (c) 2016 Ainara Galdona - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
{ | ||
"name": "Account Analytic Distribution", | ||
'version': '8.0.1.1.0', | ||
'license': "AGPL-3", | ||
'author': "AvanzOSC", | ||
'website': "http://www.avanzosc.es", | ||
'contributors': [ | ||
"Ainara Galdona <[email protected]>", | ||
"Ana Juaristi <[email protected]>", | ||
], | ||
"category": "Analytic", | ||
"depends": [ | ||
'analytic', | ||
'account' | ||
], | ||
"data": ['security/ir.model.access.csv', | ||
'views/analytic_view.xml', | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * account_analytic_distribution | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 8.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2016-08-05 12:32+0000\n" | ||
"PO-Revision-Date: 2016-08-05 14:39+0100\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: \n" | ||
"X-Generator: Poedit 1.5.4\n" | ||
|
||
#. module: account_analytic_distribution | ||
#: selection:account.analytic.account,distribution_type:0 | ||
msgid "Amount" | ||
msgstr "Importe" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,analytic_id:0 | ||
#: model:ir.model,name:account_analytic_distribution.model_account_analytic_account | ||
msgid "Analytic Account" | ||
msgstr "Cuenta analítica" | ||
|
||
#. module: account_analytic_distribution | ||
#: view:analytic.distribution.line:account_analytic_distribution.analytic_distribution_form | ||
#: view:analytic.distribution.line:account_analytic_distribution.analytic_distribution_tree | ||
msgid "Analytic Distribution" | ||
msgstr "Distribución Analítica" | ||
|
||
#. module: account_analytic_distribution | ||
#: model:ir.model,name:account_analytic_distribution.model_account_analytic_line | ||
msgid "Analytic Line" | ||
msgstr "Línea analítica" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,create_uid:0 | ||
msgid "Created by" | ||
msgstr "Creado por" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,create_date:0 | ||
msgid "Created on" | ||
msgstr "Creado el" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,display_name:0 | ||
msgid "Display Name" | ||
msgstr "Mostrar nombre" | ||
|
||
#. module: account_analytic_distribution | ||
#: view:account.analytic.account:account_analytic_distribution.view_account_analytic_account_form | ||
msgid "Distribution" | ||
msgstr "Distribución" | ||
|
||
#. module: account_analytic_distribution | ||
#: view:account.analytic.account:account_analytic_distribution.view_account_analytic_account_form | ||
#: field:account.analytic.account,distribution_line_ids:0 | ||
msgid "Distribution Lines" | ||
msgstr "Líneas de distribución" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:account.analytic.account,distribution_type:0 | ||
msgid "Distribution Type" | ||
msgstr "Tipo de distribución" | ||
|
||
#. module: account_analytic_distribution | ||
#: code:addons/account_analytic_distribution/models/analytic.py:36 | ||
#, python-format | ||
msgid "Error! The sum of distribution lines percent is not 100." | ||
msgstr "¡Error! La suma de las líneas de distribución no es 100." | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,id:0 | ||
msgid "ID" | ||
msgstr "ID" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,__last_update:0 | ||
msgid "Last Modified on" | ||
msgstr "Última modificación el" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,write_uid:0 | ||
msgid "Last Updated by" | ||
msgstr "Última vez modificado por" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,write_date:0 | ||
msgid "Last Updated on" | ||
msgstr "Última vez modificado el" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,parent_id:0 | ||
msgid "Parent" | ||
msgstr "Padre" | ||
|
||
#. module: account_analytic_distribution | ||
#: view:analytic.distribution.line:account_analytic_distribution.analytic_distribution_tree | ||
msgid "Percent" | ||
msgstr "Porcentaje" | ||
|
||
#. module: account_analytic_distribution | ||
#: field:analytic.distribution.line,percent:0 | ||
msgid "Percentage" | ||
msgstr "Porcentaje" | ||
|
||
#. module: account_analytic_distribution | ||
#: selection:account.analytic.account,distribution_type:0 | ||
msgid "Quantity" | ||
msgstr "Cantidad" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# (c) 2016 Ainara Galdona - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import analytic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -*- coding: utf-8 -*- | ||
# (c) 2016 Ainara Galdona - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from openerp import models, fields, api, exceptions, _ | ||
|
||
|
||
class AnalyticDistributionLine(models.Model): | ||
|
||
_name = 'analytic.distribution.line' | ||
|
||
analytic_id = fields.Many2one(comodel_name='account.analytic.account', | ||
string="Analytic Account", | ||
domain=[('type', '!=', 'view')]) | ||
parent_id = fields.Many2one(comodel_name='account.analytic.account', | ||
string="Parent") | ||
percent = fields.Integer(string="Percentage %") | ||
|
||
|
||
class AccountAnalyticAccount(models.Model): | ||
|
||
_inherit = 'account.analytic.account' | ||
|
||
distribution_line_ids = fields.One2many( | ||
comodel_name='analytic.distribution.line', inverse_name='parent_id', | ||
string='Distribution Lines') | ||
distribution_type = fields.Selection( | ||
[('amount', 'Amount'), ('qty', 'Quantity')], | ||
string='Distribution Type') | ||
|
||
@api.constrains('distribution_line_ids') | ||
def _distribution_percentage_sum(self): | ||
if (self.distribution_line_ids and | ||
sum([x.percent for x in self.distribution_line_ids]) != 100): | ||
raise exceptions.Warning( | ||
_("Error! The sum of distribution lines percent is not 100.")) | ||
|
||
def _get_child_accounts(self, account): | ||
accounts = self.env['account.analytic.account'] | ||
for record in self: | ||
my_accounts = record.distribution_line_ids.mapped('analytic_id') | ||
accounts |= my_accounts | ||
if account.id in accounts.ids: | ||
return accounts | ||
for my_account in my_accounts: | ||
accounts |= my_account._get_child_accounts(account=account) | ||
return accounts | ||
|
||
@api.constrains('distribution_line_ids') | ||
def check_recursion(self): | ||
if self.id in self._get_child_accounts(account=self).ids: | ||
raise exceptions.Warning(_("Error! There is recursion between this" | ||
" account and distribution lines.")) | ||
|
||
|
||
class AccountAnalyticLine(models.Model): | ||
|
||
_inherit = 'account.analytic.line' | ||
|
||
@api.multi | ||
def needs_distribution(self, account): | ||
return bool(self.env['account.analytic.account'].browse( | ||
account).distribution_line_ids) | ||
|
||
@api.multi | ||
def load_distribution_data(self, account, type, percent, amount, qty): | ||
load_amount = amount | ||
load_qty = qty | ||
if type == 'amount': | ||
load_amount = amount * percent / 100 | ||
elif type == 'qty': | ||
load_qty = qty * percent / 100 | ||
self.write({'account_id': account.id, | ||
'amount': load_amount, | ||
'unit_amount': load_qty}) | ||
|
||
@api.multi | ||
def make_distribution(self): | ||
for line in self: | ||
type = line.account_id.distribution_type | ||
amount = line.amount | ||
qty = line.unit_amount | ||
distribution_lines = line.account_id.distribution_line_ids | ||
distribution_line = distribution_lines[0] | ||
line.load_distribution_data(distribution_line.analytic_id, type, | ||
distribution_line.percent, amount, qty) | ||
for distribution_line in distribution_lines[1:]: | ||
new_line = line.copy() | ||
new_line.load_distribution_data( | ||
distribution_line.analytic_id, type, | ||
distribution_line.percent, amount, qty) | ||
|
||
@api.multi | ||
def write(self, vals): | ||
res = super(AccountAnalyticLine, self).write(vals) | ||
if (vals.get('account_id', False) and | ||
self.needs_distribution(vals.get('account_id'))): | ||
self.make_distribution() | ||
return res | ||
|
||
@api.model | ||
def create(self, vals): | ||
res = super(AccountAnalyticLine, self).create(vals) | ||
if (vals.get('account_id', False) and | ||
self.needs_distribution(vals.get('account_id'))): | ||
res.make_distribution() | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_analytic_distribution_line,analytic.distribution.line,account_analytic_distribution.model_analytic_distribution_line,analytic.group_analytic_accounting,1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# (c) 2016 Ainara Galdona - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import test_account_analytic_distribution |
Oops, something went wrong.