diff --git a/account_move_fiscal_year/__manifest__.py b/account_move_fiscal_year/__manifest__.py index 68bfd6e5..7d2dee78 100644 --- a/account_move_fiscal_year/__manifest__.py +++ b/account_move_fiscal_year/__manifest__.py @@ -2,18 +2,18 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Account Move Fiscal Year', - 'summary': """ + "name": "Account Move Fiscal Year", + "summary": """ Display the fiscal year on journal entries/item""", - 'version': '12.0.1.1.0', - 'license': 'AGPL-3', - 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/account-financial-tools', - 'depends': [ - 'account_fiscal_year', + "version": "14.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', + "data": [ + "views/account_move.xml", + "views/account_move_line.xml", ], } diff --git a/account_move_fiscal_year/models/account_move.py b/account_move_fiscal_year/models/account_move.py index 3a5964bc..6ff3a8d3 100644 --- a/account_move_fiscal_year/models/account_move.py +++ b/account_move_fiscal_year/models/account_move.py @@ -7,38 +7,45 @@ from odoo.osv import expression class AccountMove(models.Model): - _inherit = 'account.move' + _inherit = "account.move" date_range_fy_id = fields.Many2one( - comodel_name='account.fiscal.year', string="Fiscal year", - compute='_compute_date_range_fy', search='_search_date_range_fy') + comodel_name="account.fiscal.year", + string="Fiscal year", + compute="_compute_date_range_fy", + search="_search_date_range_fy", + ) @api.multi - @api.depends('date', 'company_id') + @api.depends("date", "company_id") def _compute_date_range_fy(self): for rec in self: date = fields.Date.to_date(rec.date) company = rec.company_id - rec.date_range_fy_id =\ - company and company.find_daterange_fy(date) or False + rec.date_range_fy_id = company and company.find_daterange_fy(date) or False @api.model def _search_date_range_fy(self, operator, value): - if operator in ('=', '!=', 'in', 'not in'): - date_range_domain = [('id', operator, value)] + if operator in ("=", "!=", "in", "not in"): + date_range_domain = [("id", operator, value)] else: - date_range_domain = [('name', operator, value)] + date_range_domain = [("name", operator, value)] - date_ranges = self.env['account.fiscal.year'].search(date_range_domain) + date_ranges = self.env["account.fiscal.year"].search(date_range_domain) - domain = [('id', '=', -1)] + domain = [("id", "=", -1)] for date_range in date_ranges: - domain = expression.OR([domain, [ - '&', - ('date', '>=', date_range.date_from), - ('date', '<=', date_range.date_to), - '|', - ('company_id', '=', False), - ('company_id', '=', date_range.company_id.id), - ]]) + domain = expression.OR( + [ + domain, + [ + "&", + ("date", ">=", date_range.date_from), + ("date", "<=", date_range.date_to), + "|", + ("company_id", "=", False), + ("company_id", "=", date_range.company_id.id), + ], + ] + ) return domain diff --git a/account_move_fiscal_year/models/account_move_line.py b/account_move_fiscal_year/models/account_move_line.py index c85db8c7..a71bb2eb 100644 --- a/account_move_fiscal_year/models/account_move_line.py +++ b/account_move_fiscal_year/models/account_move_line.py @@ -6,8 +6,8 @@ from odoo import fields, models class AccountMoveLine(models.Model): - _inherit = 'account.move.line' + _inherit = "account.move.line" date_range_fy_id = fields.Many2one( - related='move_id.date_range_fy_id', + related="move_id.date_range_fy_id", ) diff --git a/account_move_fiscal_year/models/res_company.py b/account_move_fiscal_year/models/res_company.py index 9b228a2e..e34a5635 100644 --- a/account_move_fiscal_year/models/res_company.py +++ b/account_move_fiscal_year/models/res_company.py @@ -5,17 +5,20 @@ from odoo import models class ResCompany(models.Model): - _inherit = 'res.company' + _inherit = "res.company" def find_daterange_fy(self, date): """ try to find a date range with type 'fiscalyear' with @param:date contained in its date_start/date_end interval """ - fiscalyear = self.env['account.fiscal.year'].search([ - ('company_id', '=', self.id), - ('date_from', '<=', date), - ('date_to', '>=', date), - ], limit=1) + fiscalyear = self.env["account.fiscal.year"].search( + [ + ("company_id", "=", self.id), + ("date_from", "<=", date), + ("date_to", ">=", date), + ], + limit=1, + ) return fiscalyear diff --git a/account_move_fiscal_year/tests/test_account_move_fiscal_year.py b/account_move_fiscal_year/tests/test_account_move_fiscal_year.py index 10402be1..e91e198b 100644 --- a/account_move_fiscal_year/tests/test_account_move_fiscal_year.py +++ b/account_move_fiscal_year/tests/test_account_move_fiscal_year.py @@ -6,122 +6,164 @@ 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['account.fiscal.year'] + self.AccountObj = self.env["account.account"] + self.AccountJournalObj = self.env["account.journal"] + self.AccountMoveObj = self.env["account.move"] + self.DateRangeObj = self.env["account.fiscal.year"] - self.bank_journal = self.AccountJournalObj.search([ - ('type', '=', 'bank') - ], limit=1) + 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_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.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_2017 = self.DateRangeObj.create({ - 'name': "2017", - 'date_from': '2017-01-01', - 'date_to': '2017-12-31', - }) + self.date_range_2017 = self.DateRangeObj.create( + { + "name": "2017", + "date_from": "2017-01-01", + "date_to": "2017-12-31", + } + ) - self.date_range_2018 = self.DateRangeObj.create({ - 'name': "2018", - 'date_from': '2018-01-01', - 'date_to': '2018-12-31', - }) + self.date_range_2018 = self.DateRangeObj.create( + { + "name": "2018", + "date_from": "2018-01-01", + "date_to": "2018-12-31", + } + ) 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, - }), - ] - }) + 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.to_date('2017-01-01') + january_1st = Date.to_date("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") + 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.to_date('2019-01-01') + january_2019 = Date.to_date("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") + 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.to_date('2017-01-01') - january_2018 = Date.to_date('2018-01-01') - january_2019 = Date.to_date('2019-01-01') + january_2017 = Date.to_date("2017-01-01") + january_2018 = Date.to_date("2018-01-01") + january_2019 = Date.to_date("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'), - ]) + 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") + 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), - ]) + 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, - ])) + 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 - )), - ]) + 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, - ])) + self.assertTrue( + all( + [ + move_2017 in moves, + move_2018 in moves, + move_2019 not in moves, + ] + ) + ) diff --git a/account_move_fiscal_year/views/account_move.xml b/account_move_fiscal_year/views/account_move.xml index 6fcb1e8c..09941ad9 100644 --- a/account_move_fiscal_year/views/account_move.xml +++ b/account_move_fiscal_year/views/account_move.xml @@ -1,18 +1,17 @@ - + - account.move.form (in account_move_fiscal_year) account.move - - + + - + @@ -21,12 +20,12 @@ account.move.search (in account_move_fiscal_year) account.move - - + + - + @@ -35,12 +34,12 @@ account.move.tree (in account_move_fiscal_year) account.move - - + + - + diff --git a/account_move_fiscal_year/views/account_move_line.xml b/account_move_fiscal_year/views/account_move_line.xml index 6f218c35..9ae81a42 100644 --- a/account_move_fiscal_year/views/account_move_line.xml +++ b/account_move_fiscal_year/views/account_move_line.xml @@ -1,46 +1,47 @@ - + - account.move.line.form (in account_move_fiscal_year) account.move.line - - + + - + - account.move.line.search (in account_move_fiscal_year) + account.move.line.search (in account_move_fiscal_year) account.move.line - - + + - + - + account.move.line.tree (in account_move_fiscal_year) account.move.line - - + + - +