19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:07 +01:00
parent ba20ce7443
commit 768b70e05e
2357 changed files with 1057103 additions and 712486 deletions

View file

@ -2,5 +2,8 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_account_group
from . import test_balance_tag
from . import test_debit_credit
from . import test_company_fiscal_year
from . import test_residual_amount
from . import test_partner_balance

View file

@ -14,7 +14,7 @@ class SpreadsheetAccountGroupTest(AccountTestInvoicingCommon):
def test_group_with_no_account(self):
self.env['account.account']\
.search([('account_type', '=', 'income_other'), ('company_id', '=', self.env.company.id)])\
.search([('account_type', '=', 'income_other'), ('company_ids', '=', self.env.company.id)])\
.unlink()
self.assertEqual(self.env["account.account"].get_account_group(['income_other']), [[]])

View file

@ -0,0 +1,123 @@
from odoo import Command
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged('post_install', '-at_install')
class SpreadsheetAccountingBalanceTagFunctionTest(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.tag_1 = cls._create_account_tag('tag_1')
cls.tag_2 = cls._create_account_tag('tag_2')
cls.company_data['default_account_receivable'].tag_ids |= cls.tag_1
cls.company_data['default_account_revenue'].tag_ids |= cls.tag_1
cls.company_data['default_account_expense'].tag_ids |= cls.tag_2
cls.posted_move = cls.env['account.move'].create({
'company_id': cls.company_data['company'].id,
'move_type': 'entry',
'date': '2025-01-01',
'line_ids': [
Command.create({
'name': "posted line debit 1",
'account_id': cls.company_data['default_account_receivable'].id,
'debit': 100,
'company_id': cls.company_data['company'].id,
}),
Command.create({
'name': "posted line debit 2",
'account_id': cls.company_data['default_account_revenue'].id,
'debit': 50,
'company_id': cls.company_data['company'].id,
}),
Command.create({
'name': "posted line credit 1",
'account_id': cls.company_data['default_account_expense'].id,
'credit': 150,
'company_id': cls.company_data['company'].id,
}),
],
})
cls.posted_move.action_post()
cls.draft_move = cls.env['account.move'].create({
'company_id': cls.company_data['company'].id,
'move_type': 'entry',
'date': '2024-01-01',
'line_ids': [
Command.create({
'name': "draft line debit 1",
'account_id': cls.company_data['default_account_receivable'].id,
'debit': 100,
'company_id': cls.company_data['company'].id,
}),
Command.create({
'name': "draft line credit 1",
'account_id': cls.company_data['default_account_expense'].id,
'credit': 100,
'company_id': cls.company_data['company'].id,
}),
],
})
@classmethod
def _create_account_tag(cls, tag_name):
return cls.env['account.account.tag'].create([{
'name': tag_name,
'applicability': 'accounts',
}])
def test_sreadsheet_balance_tags_empty_payload(self):
self.assertEqual(
self.env["account.account"].spreadsheet_fetch_balance_tag([]), []
)
def test_spreadsheet_balance_tags(self):
tag_balances = self.env["account.account"].spreadsheet_fetch_balance_tag([
{
'date_range': {
'range_type': 'year',
'year': 2025,
},
'account_tag_ids': self.tag_1.ids,
'company_id': None,
'include_unposted': False,
},
{
'date_range': {
'range_type': 'year',
'year': 2025,
},
'account_tag_ids': (self.tag_1 + self.tag_2).ids,
'company_id': None,
'include_unposted': False,
},
{
'date_range': {
'range_type': 'year',
'year': 2024,
},
'account_tag_ids': self.tag_1.ids,
'company_id': None,
'include_unposted': False,
},
{
'date_range': {
'range_type': 'year',
'year': 2024,
},
'account_tag_ids': self.tag_1.ids,
'company_id': None,
'include_unposted': True,
},
])
self.assertEqual(tag_balances, [
{'balance': 150.0}, # year 2025, tag_1
{'balance': 0.0}, # year 2025, tag_1 & tag_2
{'balance': 0.0}, # year 2024, tag_1, posted_only
{'balance': 100.0}, # year 2024, tag_1, draft included
])

View file

@ -2,7 +2,7 @@
from datetime import date
from odoo import Command
from odoo.fields import Command, Domain
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@ -10,12 +10,13 @@ from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged("post_install", "-at_install")
class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
def setUpClass(cls):
super().setUpClass()
cls.company_data_2 = cls.setup_other_company()
cls.account_revenue_c1 = cls.env["account.account"].create(
{
"company_id": cls.company_data["company"].id,
"company_ids": [Command.link(cls.company_data["company"].id)],
"name": "spreadsheet revenue Company 1",
"account_type": "income",
"code": "sp1234566",
@ -24,25 +25,26 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
cls.account_expense_c1 = cls.env["account.account"].create(
{
"company_id": cls.company_data["company"].id,
"company_ids": [Command.link(cls.company_data["company"].id)],
"name": "spreadsheet expense Company 1",
"account_type": "expense",
"code": "sp1234577",
}
)
cls.account_revenue_c2 = cls.env["account.account"].create(
company_2 = cls.company_data_2["company"]
cls.account_revenue_c2 = cls.env["account.account"].with_company(company_2).create(
{
"company_id": cls.company_data_2["company"].id,
"company_ids": [Command.link(company_2.id)],
"name": "spreadsheet revenue Company 2",
"account_type": "income",
"code": "sp99887755",
}
)
cls.account_expense_c2 = cls.env["account.account"].create(
cls.account_expense_c2 = cls.env["account.account"].with_company(company_2).create(
{
"company_id": cls.company_data_2["company"].id,
"company_ids": [Command.link(company_2.id)],
"name": "spreadsheet expense Company 2",
"account_type": "expense",
"code": "sp99887766",
@ -141,7 +143,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
)
def test_two_codes_mixing_balance(self):
self.account_revenue_c1.sudo().include_initial_balance = True
self.account_revenue_c1.sudo().account_type = 'asset_receivable'
self.env["account.move"].create(
{
"company_id": self.company_data["company"].id,
@ -608,7 +610,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
def test_balance_account_by_year(self):
# On balance accounts, we sum the lines from the creation up to the last dat of date_range
self.account_revenue_c1.sudo().include_initial_balance = True
self.account_revenue_c1.sudo().account_type = 'asset_receivable'
self.assertEqual(
self.env["account.account"].spreadsheet_fetch_debit_credit(
[
@ -629,7 +631,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
)
def test_balance_quarter_date_period(self):
self.account_revenue_c1.sudo().include_initial_balance = True
self.account_revenue_c1.sudo().account_type = 'asset_receivable'
self.env["account.move"].create(
{
"company_id": self.company_data["company"].id,
@ -674,7 +676,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
)
def test_balance_month_date_period(self):
self.account_revenue_c1.sudo().include_initial_balance = True
self.account_revenue_c1.sudo().account_type = 'asset_receivable'
self.env["account.move"].create(
{
"company_id": self.company_data["company"].id,
@ -715,7 +717,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
)
def test_balance_day_date_period(self):
self.account_revenue_c1.sudo().include_initial_balance = True
self.account_revenue_c1.sudo().account_type = 'asset_receivable'
self.env["account.move"].create(
{
"company_id": self.company_data["company"].id,
@ -761,7 +763,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
)
def test_move_state_ignore_cancel(self):
self.account_revenue_c1.sudo().include_initial_balance = True
self.account_revenue_c1.sudo().account_type = 'asset_receivable'
self.env["account.move"].create(
{
"company_id": self.company_data["company"].id,
@ -824,7 +826,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
)
def test_move_state_unposted(self):
self.account_revenue_c1.sudo().include_initial_balance = True
self.account_revenue_c1.sudo().account_type = 'asset_receivable'
move = self.env["account.move"].create(
{
"company_id": self.company_data["company"].id,
@ -955,7 +957,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
"year": 2022,
},
"codes": [self.account_revenue_c1.code],
"company_id": self.account_revenue_c1.company_id.id,
"company_id": self.account_revenue_c1.company_ids.id,
"include_unposted": True,
}
)
@ -967,7 +969,7 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
"view_mode": "list",
"views": [[False, "list"]],
"target": "current",
"domain": [
"domain": Domain([
"&",
"&",
"&",
@ -981,10 +983,10 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
("account_id.include_initial_balance", "=", False),
("date", ">=", date(2022, 1, 1)),
("date", "<=", date(2022, 12, 31)),
("company_id", "=", self.account_revenue_c1.company_id.id),
("company_id", "=", self.account_revenue_c1.company_ids.id),
("move_id.state", "!=", "cancel"),
],
"name": "Journal items for account prefix sp1234566",
]),
"name": "Cell Audit",
},
)
@ -1000,6 +1002,10 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
"include_unposted": True,
}
)
company = self.company_data['company']
payable_receivable_accounts = self.env['account.account'].with_company(company).search([
('account_type', 'in', ['liability_payable', 'asset_receivable'])
])
self.assertEqual(
action,
{
@ -1008,7 +1014,23 @@ class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
"view_mode": "list",
"views": [[False, "list"]],
"target": "current",
"domain": [(0, "=", 1)],
"name": "Journal items for account prefix ",
"domain": Domain([
"&",
"&",
"&",
("account_id", "in", payable_receivable_accounts.ids),
"|",
"&",
("account_id.include_initial_balance", "=", True),
("date", "<=", date(2022, 12, 31)),
"&",
"&",
("account_id.include_initial_balance", "=", False),
("date", ">=", date(2022, 1, 1)),
("date", "<=", date(2022, 12, 31)),
("company_id", "=", company.id),
("move_id.state", "!=", "cancel")
]),
"name": "Cell Audit",
},
)

View file

@ -0,0 +1,226 @@
from odoo import Command
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged('post_install', '-at_install')
class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.move_22 = cls.env['account.move'].create(
{
'company_id': cls.company_data['company'].id,
'move_type': 'entry',
'date': '2022-02-02',
'partner_id': cls.partner_a.id,
'line_ids': [
Command.create(
{
'name': "line_debit_22",
'account_id': cls.company_data['default_account_receivable'].id,
'debit': 1500,
'company_id': cls.company_data['company'].id,
},
),
Command.create(
{
'name': "line_credit_22",
'account_id': cls.company_data['default_account_revenue'].id,
'credit': 1500,
'company_id': cls.company_data['company'].id,
},
),
],
}
)
cls.move_23 = cls.env['account.move'].create(
{
'company_id': cls.company_data['company'].id,
'move_type': 'entry',
'date': '2023-02-02',
'partner_id': cls.partner_a.id,
'line_ids': [
Command.create(
{
'name': "line_debit_23",
'account_id': cls.company_data['default_account_expense'].id,
'debit': 2500,
'company_id': cls.company_data['company'].id,
},
),
Command.create(
{
'name': "line_credit_23",
'account_id': cls.company_data['default_account_payable'].id,
'credit': 2500,
'company_id': cls.company_data['company'].id,
},
),
],
}
)
cls.move_23_partner_b = cls.move_23.copy({'partner_id': cls.partner_b.id})
def test_partner_balance_empty_params(self):
self.assertEqual(self.env['account.account'].spreadsheet_fetch_partner_balance([]), [])
def test_partner_balance_no_account_codes(self):
''' Tests that when no account codes are provided, we are returned the residual
amount for the receivable and payable accounts.
'''
(self.move_22 + self.move_23).action_post()
partner_balance = self.env['account.account'].spreadsheet_fetch_partner_balance([
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'year',
'year': 2023,
},
'codes': [],
'company_id': None,
'include_unposted': False,
},
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'year',
'year': 2023,
},
'codes': [self.company_data['default_account_receivable'].code],
'company_id': None,
'include_unposted': False,
}
])
self.assertEqual(partner_balance, [{'balance': 1500 - 2500}, {'balance': 1500}])
def test_partner_balance_yearly(self):
''' Test that only moves in the given year are returned when performing a yearly filtering. '''
partner_balance = self.env['account.account'].spreadsheet_fetch_partner_balance([
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'year',
'year': 2022,
},
'codes': [],
'company_id': None,
'include_unposted': True,
}
])
self.assertEqual(partner_balance, [{'balance': 1500}])
def test_partner_balance_quarterly(self):
''' Test that only moves in the given quarter are returned when performing a quarterly filtering. '''
partner_balance = self.env['account.account'].spreadsheet_fetch_partner_balance([
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'quarter',
'year': 2022,
'quarter': 4,
},
'codes': [],
'company_id': None,
'include_unposted': True,
},
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'quarter',
'year': 2023,
'quarter': 1,
},
'codes': [],
'company_id': None,
'include_unposted': True,
}
])
self.assertEqual(partner_balance, [{'balance': 1500}, {'balance': 1500 - 2500}])
def test_partner_balance_daily(self):
''' Test that only moves in the given day are returned when performing a daily filtering. '''
partner_balance = self.env['account.account'].spreadsheet_fetch_partner_balance([
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'day',
'year': 2022,
'month': 2,
'day': 1,
},
'codes': [],
'company_id': None,
'include_unposted': True,
},
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'day',
'year': 2022,
'month': 2,
'day': 2,
},
'codes': [],
'company_id': None,
'include_unposted': True,
}
])
self.assertEqual(partner_balance, [{'balance': 0.0}, {'balance': 1500}])
def test_partner_balance_posted_filter(self):
partner_balance = self.env['account.account'].spreadsheet_fetch_partner_balance([
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'year',
'year': 2023,
},
'codes': [],
'company_id': None,
'include_unposted': False,
}
])
self.assertEqual(partner_balance, [{'balance': 0.0}])
self.move_23.action_post()
partner_balance = self.env['account.account'].spreadsheet_fetch_partner_balance([
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'year',
'year': 2023,
},
'codes': [],
'company_id': None,
'include_unposted': False,
}
])
self.assertNotEqual(partner_balance, [{'balance': 2500}])
def test_partner_filter(self):
partner_balance = self.env['account.account'].spreadsheet_fetch_partner_balance([
{
'partner_ids': [self.move_23.partner_id.id],
'date_range': {
'range_type': 'year',
'year': 2023,
},
'codes': [],
'company_id': None,
'include_unposted': True,
},
{
'partner_ids': [self.move_23_partner_b.partner_id.id],
'date_range': {
'range_type': 'year',
'year': 2023,
},
'codes': [],
'company_id': None,
'include_unposted': True,
},
])
self.assertNotEqual(partner_balance, [{'balance': 1500 + 2500}, {'balance': 2500}])

View file

@ -0,0 +1,194 @@
from odoo import Command
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged('post_install', '-at_install')
class SpreadsheetAccountingFunctionsTest(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.move_22 = cls.env['account.move'].create(
{
'company_id': cls.company_data['company'].id,
'move_type': 'entry',
'date': '2022-02-02',
'line_ids': [
Command.create(
{
'name': "line_debit_22",
'account_id': cls.company_data['default_account_receivable'].id,
'debit': 1500,
'company_id': cls.company_data['company'].id,
},
),
Command.create(
{
'name': "line_credit_22",
'account_id': cls.company_data['default_account_revenue'].id,
'credit': 1500,
'company_id': cls.company_data['company'].id,
},
),
],
}
)
cls.move_23 = cls.env['account.move'].create(
{
'company_id': cls.company_data['company'].id,
'move_type': 'entry',
'date': '2023-02-02',
'line_ids': [
Command.create(
{
'name': "line_debit_23",
'account_id': cls.company_data['default_account_expense'].id,
'debit': 2500,
'company_id': cls.company_data['company'].id,
},
),
Command.create(
{
'name': "line_credit_23",
'account_id': cls.company_data['default_account_payable'].id,
'credit': 2500,
'company_id': cls.company_data['company'].id,
},
),
],
}
)
cls.payment_move_22 = cls.env['account.payment'].create({
'amount': 150.0,
'payment_type': 'inbound',
'partner_type': 'customer',
'partner_id': cls.partner_a.id,
'date': '2022-02-10',
})
cls.payment_move_23 = cls.env['account.payment'].create({
'amount': 250.0,
'payment_type': 'outbound',
'partner_type': 'customer',
'partner_id': cls.partner_a.id,
'date': '2023-02-10',
})
# Post the move and payment and reconcile them
(cls.move_22 + cls.move_23).action_post()
(cls.payment_move_22 + cls.payment_move_23).action_post()
(cls.move_22 + cls.payment_move_22.move_id).line_ids\
.filtered(lambda line: line.account_type == 'asset_receivable')\
.reconcile()
(cls.move_23 + cls.payment_move_23.move_id).line_ids\
.filtered(lambda line: line.account_type == 'asset_receivable')\
.reconcile()
def test_residual_empty_params(self):
self.assertEqual(self.env['account.account'].spreadsheet_fetch_residual_amount([]), [])
def test_residual_no_account_codes(self):
''' Tests that when no account codes are provided, we are returned the residual
amount for the receivable and payable accounts.
'''
residual_amount = self.env['account.account'].spreadsheet_fetch_residual_amount([
{
'date_range': {
'range_type': 'year',
'year': 2023,
},
'codes': [],
'company_id': None,
'include_unposted': False,
},
{
'date_range': {
'range_type': 'year',
'year': 2023,
},
'codes': [self.company_data['default_account_receivable'].code],
'company_id': None,
'include_unposted': False,
}
])
self.assertEqual(residual_amount, [
{'amount_residual': 1500 - 2500 + 250 - 150},
{'amount_residual': 1500 + 250 - 150}
])
def test_residual_yearly(self):
''' Test that only moves in the given year are returned when performing a yearly filtering. '''
residual_amount = self.env['account.account'].spreadsheet_fetch_residual_amount([
{
'date_range': {
'range_type': 'year',
'year': 2022,
},
'codes': [],
'company_id': None,
'include_unposted': True,
}
])
self.assertEqual(residual_amount, [{'amount_residual': 1500 - 150}])
def test_residual_quarterly(self):
''' Test that only moves in the given quarter are returned when performing a quarterly filtering. '''
residual_amount = self.env['account.account'].spreadsheet_fetch_residual_amount([
{
'date_range': {
'range_type': 'quarter',
'year': 2022,
'quarter': 4,
},
'codes': [],
'company_id': None,
'include_unposted': False,
},
{
'date_range': {
'range_type': 'quarter',
'year': 2023,
'quarter': 1,
},
'codes': [],
'company_id': None,
'include_unposted': False,
}
])
self.assertEqual(residual_amount, [
{'amount_residual': 1500 - 150},
{'amount_residual': 1500 - 2500 - 150 + 250},
])
def test_residual_daily(self):
''' Test that only moves in the given day are returned when performing a daily filtering. '''
residual_amount = self.env['account.account'].spreadsheet_fetch_residual_amount([
{
'date_range': {
'range_type': 'day',
'year': 2022,
'month': 2,
'day': 1,
},
'codes': [],
'company_id': None,
'include_unposted': False,
},
{
'date_range': {
'range_type': 'day',
'year': 2022,
'month': 2,
'day': 2,
},
'codes': [],
'company_id': None,
'include_unposted': False,
}
])
self.assertEqual(residual_amount, [
{'amount_residual': 0.0},
{'amount_residual': 1500 - 150},
])