Skip to content

Commit

Permalink
[MIG] account_analytic_compassion: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwul authored and ecino committed Feb 8, 2024
1 parent 555183d commit 8c17032
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 0 deletions.
27 changes: 27 additions & 0 deletions account_analytic_compassion/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

Compassion Analytic Accounts
============================

This module installs the needed analytic accounts for Compassion CH.

Installation
============

To install this module, you need to:

* Install this module before 'sponsorship_compassion' in test databases.

Credits
=======

Contributors
------------

* Emanuel Cino <[email protected]>

Maintainer
----------

This module is maintained by `Compassion Switzerland <https://www.compassion.ch>`.
11 changes: 11 additions & 0 deletions account_analytic_compassion/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
##############################################################################
#
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# Releasing children from poverty in Jesus' name
# @author: Emanuel Cino <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################

from . import models
51 changes: 51 additions & 0 deletions account_analytic_compassion/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
##############################################################################
#
# ______ Releasing children from poverty _
# / ____/___ ____ ___ ____ ____ ___________(_)___ ____
# / / / __ \/ __ `__ \/ __ \/ __ `/ ___/ ___/ / __ \/ __ \
# / /___/ /_/ / / / / / / /_/ / /_/ (__ |__ ) / /_/ / / / /
# \____/\____/_/ /_/ /_/ .___/\__,_/____/____/_/\____/_/ /_/
# /_/
# in Jesus' name
#
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# @author: Emanuel Cino <[email protected]>
#
# 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/>.
#
##############################################################################
# pylint: disable=C8101
{
'name': 'Compassion Analytic Accounts',
'version': "14.0.1.0.0",
'category': 'Other',
'author': 'Compassion CH',
'license': 'AGPL-3',
'website': 'http://www.compassion.ch',
'depends': [
'account_analytic_distribution_required',
'account_asset_management',
'analytic',
'account',
'product',
],
'data': [
'views/product_view.xml',
'views/res_config_setting_view.xml',
'views/account_asset_view.xml',
],
'demo': ['analytic_account_data.xml'],
'installable': True,
'auto_install': False,
}
56 changes: 56 additions & 0 deletions account_analytic_compassion/analytic_account_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!--
Resource: account.analytic.tag
-->
<record id="tag_income" model="account.analytic.tag">
<field name="name">Income</field>
</record>
<record id="tag_ps" model="account.analytic.tag">
<field name="name">PS</field>
</record>
<record id="tag_ss" model="account.analytic.tag">
<field name="name">SS</field>
</record>
<!--
Resource: account.analytic.account
-->
<record id="account_analytic_account_des" model="account.analytic.account">
<field name="name">DES</field>
<field name="type">normal</field>
<field name="code">AA102</field>
<field name="tag_ids" eval="[(4, ref('account_analytic_compassion.tag_income'))]"/>
</record>
<record id="account_analytic_account_undes" model="account.analytic.account">
<field name="name">UNDES</field>
<field name="type">normal</field>
<field name="code">AA110</field>
<field name="tag_ids" eval="[(4, ref('account_analytic_compassion.tag_income'))]"/>
</record>
<record id="account_analytic_account_adv" model="account.analytic.account">
<field name="name">ADV</field>
<field name="type">normal</field>
<field name="code">AA091</field>
<field name="tag_ids" eval="[(4, ref('account_analytic_compassion.tag_ps'))]"/>
</record>
<record id="account_analytic_account_cd" model="account.analytic.account">
<field name="name">CD</field>
<field name="type">normal</field>
<field name="code">AA092</field>
<field name="tag_ids" eval="[(4, ref('account_analytic_compassion.tag_ps'))]"/>
</record>
<record id="account_analytic_account_sdm" model="account.analytic.account">
<field name="name">SDM</field>
<field name="type">normal</field>
<field name="code">AA108</field>
<field name="tag_ids" eval="[(4, ref('account_analytic_compassion.tag_ps'))]"/>
</record>
<record id="account_analytic_account_adm" model="account.analytic.account">
<field name="name">ADM</field>
<field name="type">normal</field>
<field name="code">AA090</field>
<field name="tag_ids" eval="[(4, ref('account_analytic_compassion.tag_ss'))]"/>
</record>
</data>
</odoo>
14 changes: 14 additions & 0 deletions account_analytic_compassion/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
##############################################################################
#
# Copyright (C) 2020 Compassion CH (http://www.compassion.ch)
# @author: William Martin <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################

from . import account
from . import account_asset
from . import res_config_setting
from . import exchange_rate_analytic_tag
from . import product
28 changes: 28 additions & 0 deletions account_analytic_compassion/models/account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
##############################################################################
#
# Copyright (C) 2020 Compassion CH (http://www.compassion.ch)
# @author: William Martin <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################

from odoo import api, models
import re


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

def _check_analytic_distribution_required_msg(self):
message = super(AccountMoveLine, self).\
_check_analytic_distribution_required_msg()
pattern = r'.*mutually exclusive.*'
if message and not re.match(pattern, message, re.IGNORECASE):
return message

@api.model
def _get_asset_analytic_values(self, vals, asset_vals):
super()._get_asset_analytic_values(vals, asset_vals)
asset_vals['analytic_tag_ids'] = vals.get(
'analytic_tag_ids', False)
35 changes: 35 additions & 0 deletions account_analytic_compassion/models/account_asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
##############################################################################
#
# Copyright (C) 2020 Compassion CH (http://www.compassion.ch)
# @author: William Martin <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################
from odoo import models, fields


class AccountAsset(models.Model):
_inherit = 'account.asset'

# Many2many field to account.analytic.tag table
analytic_tag_ids = fields.Many2many(
comodel_name='account.analytic.tag',
string='Analytic Tags',
)


class AccountAssetLine(models.Model):
_inherit = 'account.asset.line'

# override of parent method _setup_move_line_data
# inherited from object AccountAssetLine
# at account-financial-tools/account_asset_management/models/account_asset_line.py
def _setup_move_line_data(self, depreciation_date, account, ml_type, move):
move_line_data = super()._setup_move_line_data(depreciation_date,
account,
ml_type,
move)
move_line_data['analytic_tag_ids'] = [
(6, 0, self.asset_id.analytic_tag_ids.ids)]
return move_line_data
22 changes: 22 additions & 0 deletions account_analytic_compassion/models/exchange_rate_analytic_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
##############################################################################
#
# Copyright (C) 2020 Compassion CH (http://www.compassion.ch)
# @author: David Wulliamoz <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################
from odoo import models, api


class AccountPartialReconcile(models.Model):
_inherit = "account.partial.reconcile"

@api.model
def create_exchange_rate_entry(self, aml_to_fix, move):
exchange_analytic_tag_id = self.env['ir.config_parameter'].\
search([('key', '=', 'account_analytic_compassion.analytic_tag_id')]).value
return super(AccountPartialReconcile, self.with_context(
default_analytic_tag_ids=[
(6, 0, [exchange_analytic_tag_id])
])).create_exchange_rate_entry(aml_to_fix, move)
19 changes: 19 additions & 0 deletions account_analytic_compassion/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##############################################################################
#
# Copyright (C) 2020 Compassion CH (http://www.compassion.ch)
# Releasing children from poverty in Jesus' name
# @author: William Martin <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################
from odoo import models, fields


class ProductTemplate(models.Model):
_inherit = "product.template"

analytic_default_id = fields.Many2one(
"account.analytic.default",
"Analytic Default",
)
28 changes: 28 additions & 0 deletions account_analytic_compassion/models/res_config_setting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from odoo import api, fields, models


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

analytic_tag_id = fields.Many2one('account.analytic.tag', string='Analytic Tag',
readonly=False, help="analytic tag id to use "
"when automatic move are created."
)

def set_values(self):
super().set_values()
self.env["ir.config_parameter"].sudo().set_param(
"account_analytic_compassion.analytic_tag_id",
str(self.analytic_tag_id.id),
)

@api.model
def get_values(self):
res = super().get_values()
param_obj = self.env["ir.config_parameter"].sudo()
res["analytic_tag_id"] = int(
param_obj.get_param(
"account_analytic_compassion.analytic_tag_id"
)
)
return res
27 changes: 27 additions & 0 deletions account_analytic_compassion/views/account_asset_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- inherited from account-financial-tools/account_asset_management/views/account_asset.xml -->
<odoo>
<record id="account_asset_view_form" model="ir.ui.view">
<field name="name">account.asset.view.form</field>
<field name="model">account.asset</field>
<field name="inherit_id" ref="account_asset_management.account_asset_view_form"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="account_analytic_id" position="after">
<field name="analytic_tag_ids" widget="many2many_tags"/>
</field>
</field>
</record>
<!-- inherited from /account-financial-tools/account_asset_management/views/account_asset.xml -->
<record id="account_asset_view_tree" model="ir.ui.view">
<field name="name">account.asset.view.tree</field>
<field name="model">account.asset</field>
<field name="inherit_id" ref="account_asset_management.account_asset_view_tree"/>
<field name="type">tree</field>
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="analytic_tag_ids"/>
</field>
</field>
</record>
</odoo>
14 changes: 14 additions & 0 deletions account_analytic_compassion/views/product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="product_view" model="ir.ui.view">
<field name="name">product.compassion.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="account.product_template_form_view"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="property_account_income_id" position="after">
<field name="analytic_default_id" required="1"/>
</field>
</field>
</record>
</odoo>
17 changes: 17 additions & 0 deletions account_analytic_compassion/views/res_config_setting_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.account</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='currency_exchange_journal_id']/parent::div" position="after">
<div class="row mt16">
<label for="analytic_tag_id" class="col-lg-3 o_light_label"/>
<field name="analytic_tag_id"/>
</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 8c17032

Please sign in to comment.