2
0

[10.0][ADD] Module which display the fiscal year on journal entries/items

This commit is contained in:
Benjamin Willig 2017-10-12 13:42:47 +02:00 committed by BT-anieto
parent 21a0a1997d
commit 38548915b2
No known key found for this signature in database
11 changed files with 385 additions and 0 deletions

View File

@ -0,0 +1,62 @@
.. 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 Move Fiscal Year
========================
Display the fiscal year on journal entries/items.
Installation
============
You need to install account_fiscal_year.
Configuration
=============
You just need to create date ranges associated to 'Fiscal Year' type.
Usage
=====
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/92/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-financial-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Benjamin Willig <benjamin.willig@acsone.eu>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

View File

@ -0,0 +1 @@
from . import models

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Account Move Fiscal Year',
'summary': """
Display the fiscal year on journal entries/item""",
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/account-financial-tools',
'depends': [
'account_fiscal_year',
],
'data': [
'views/account_move.xml',
'views/account_move_line.xml',
],
'demo': [
],
}

View File

@ -0,0 +1,2 @@
from . import account_move
from . import account_move_line

View File

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.osv import expression
class AccountMove(models.Model):
_inherit = 'account.move'
date_range_fy_id = fields.Many2one(
comodel_name='date.range', string="Fiscal year",
domain=lambda self: self._get_date_range_fy_domain(),
compute='_compute_date_range_fy', search='_search_date_range_fy')
@api.model
def _get_date_range_fy_domain(self):
fiscal_year_type = self.env.ref('account_fiscal_year.fiscalyear')
return "[('type_id', '=', %d)]" % fiscal_year_type.id
@api.multi
@api.depends('date', 'company_id')
def _compute_date_range_fy(self):
for rec in self:
date = fields.Date.from_string(rec.date)
company = rec.company_id
rec.date_range_fy_id = company.find_daterange_fy(date)
@api.model
def _search_date_range_fy(self, operator, value):
if operator in ('=', '!=', 'in', 'not in'):
date_range_domain = [('id', operator, value)]
else:
date_range_domain = [('name', operator, value)]
fiscal_year_type = self.env.ref('account_fiscal_year.fiscalyear')
date_range_domain.append(('type_id', '=', fiscal_year_type.id))
date_ranges = self.env['date.range'].search(date_range_domain)
domain = []
for date_range in date_ranges:
domain = expression.OR([domain, [
'&',
'&',
('date', '>=', date_range.date_start),
('date', '<=', date_range.date_end),
'|',
('company_id', '=', False),
('company_id', '=', date_range.company_id.id),
]])
return domain

View File

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
date_range_fy_id = fields.Many2one(
related='move_id.date_range_fy_id', readonly=True)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1 @@
from . import test_account_move_fiscal_year

View File

@ -0,0 +1,133 @@
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.fields import Date
from odoo.tests.common import TransactionCase
class TestAccountMoveFiscalYear(TransactionCase):
def setUp(self):
super(TestAccountMoveFiscalYear, self).setUp()
self.AccountObj = self.env['account.account']
self.AccountJournalObj = self.env['account.journal']
self.AccountMoveObj = self.env['account.move']
self.DateRangeObj = self.env['date.range']
self.bank_journal = self.AccountJournalObj.search([
('type', '=', 'bank')
], limit=1)
self.account_type_recv = self.env.ref(
'account.data_account_type_receivable')
self.account_type_rev = self.env.ref(
'account.data_account_type_revenue')
self.account_recv = self.AccountObj.create({
'code': 'RECV_DR',
'name': "Receivable (test)",
'reconcile': True,
'user_type_id': self.account_type_recv.id,
})
self.account_sale = self.AccountObj.create({
'code': 'SALE_DR',
'name': "Receivable (sale)",
'reconcile': True,
'user_type_id': self.account_type_rev.id,
})
self.date_range_type_year = self.env.ref(
'account_fiscal_year.fiscalyear')
self.date_range_2017 = self.DateRangeObj.create({
'name': "2017",
'date_start': '2017-01-01',
'date_end': '2017-12-31',
'type_id': self.date_range_type_year.id,
})
self.date_range_2018 = self.DateRangeObj.create({
'name': "2018",
'date_start': '2018-01-01',
'date_end': '2018-12-31',
'type_id': self.date_range_type_year.id,
})
def create_account_move(self, date_str):
return self.AccountMoveObj.create({
'journal_id': self.bank_journal.id,
'date': date_str,
'line_ids': [
(0, 0, {
'name': "Debit",
'debit': 1000,
'account_id': self.account_recv.id,
}),
(0, 0, {
'name': "Credit",
'credit': 1000,
'account_id': self.account_sale.id,
}),
]
})
def test_01_account_move_date_range_fy_id_compute(self):
january_1st = Date.from_string('2017-01-01')
move = self.create_account_move(january_1st)
self.assertEquals(
move.date_range_fy_id, self.date_range_2017,
msg="Move period should be 2017")
self.assertTrue(all([
line.date_range_fy_id == self.date_range_2017
for line in move.line_ids
]), msg="All lines period should be 2017")
january_2019 = Date.from_string('2019-01-01')
move = self.create_account_move(january_2019)
self.assertFalse(
bool(move.date_range_fy_id),
msg="Move shouldn't have any date range")
def test_02_account_move_date_range_fy_id_search(self):
january_2017 = Date.from_string('2017-01-01')
january_2018 = Date.from_string('2018-01-01')
january_2019 = Date.from_string('2019-01-01')
move_2017 = self.create_account_move(january_2017)
move_2018 = self.create_account_move(january_2018)
move_2019 = self.create_account_move(january_2019)
moves = self.AccountMoveObj.search([
('date_range_fy_id', 'ilike', '2017'),
])
self.assertTrue(all([
move_2017 in moves,
move_2018 not in moves,
move_2019 not in moves,
]), msg="There should be only moves in 2017")
moves = self.AccountMoveObj.search([
('date_range_fy_id', '=', self.date_range_2017.id),
])
self.assertTrue(all([
move_2017 in moves,
move_2018 not in moves,
move_2019 not in moves,
]))
moves = self.AccountMoveObj.search([
('date_range_fy_id', 'in', (
self.date_range_2017.id,
self.date_range_2018.id
)),
])
self.assertTrue(all([
move_2017 in moves,
move_2018 in moves,
move_2019 not in moves,
]))

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="account_move_form_view">
<field name="name">account.move.form (in account_move_fiscal_year)</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="date_range_fy_id" options="{'no_open': True}"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="account_move_search_view">
<field name="name">account.move.search (in account_move_fiscal_year)</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_account_move_filter"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="date_range_fy_id"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="account_move_tree_view">
<field name="name">account.move.tree (in account_move_fiscal_year)</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_tree"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="date_range_fy_id"/>
</field>
</field>
</record>
</odoo>

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="account_move_line_form_view">
<field name="name">account.move.line.form (in account_move_fiscal_year)</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_form"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="date_range_fy_id" options="{'no_open': True}"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="account_move_line_search_view">
<field name="name">account.move.line.search (in account_move_fiscal_year)</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_account_move_line_filter"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="date_range_fy_id"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="account_move_line_tree_view">
<field name="name">account.move.line.tree (in account_move_fiscal_year)</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_tree"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="date_range_fy_id"/>
</field>
</field>
</record>
</odoo>