2014-12-02 12:54:48 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2022-04-16 18:30:16 +02:00
|
|
|
|
2014-08-29 16:13:52 +02:00
|
|
|
from decimal import Decimal
|
|
|
|
|
|
|
|
|
|
from trytond.exceptions import UserError
|
2016-02-06 19:12:09 +01:00
|
|
|
from trytond.modules.account.tests import create_chart
|
2021-12-11 17:58:41 +01:00
|
|
|
from trytond.modules.company.tests import (
|
|
|
|
|
CompanyTestMixin, create_company, set_company)
|
|
|
|
|
from trytond.pool import Pool
|
|
|
|
|
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
2016-02-06 19:12:09 +01:00
|
|
|
|
2009-06-27 11:05:52 +02:00
|
|
|
|
2021-04-10 23:46:23 +02:00
|
|
|
class AccountProductTestCase(CompanyTestMixin, ModuleTestCase):
|
2014-01-12 19:59:25 +01:00
|
|
|
'Test AccountProduct module'
|
2015-01-27 18:13:03 +01:00
|
|
|
module = 'account_product'
|
2019-03-03 23:06:25 +01:00
|
|
|
extras = ['analytic_account']
|
2015-01-02 16:07:54 +01:00
|
|
|
|
2021-10-31 18:46:32 +01:00
|
|
|
@with_transaction()
|
|
|
|
|
def test_account_chart(self):
|
|
|
|
|
"Test creation of chart of accounts"
|
|
|
|
|
company = create_company()
|
|
|
|
|
with set_company(company):
|
|
|
|
|
create_chart(company, tax=True)
|
|
|
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
|
def test_account_chart_many_companies(self):
|
|
|
|
|
"Test creation of chart of accounts for many companies"
|
|
|
|
|
company1 = create_company()
|
|
|
|
|
with set_company(company1):
|
|
|
|
|
create_chart(company1, tax=True)
|
|
|
|
|
|
|
|
|
|
company2 = create_company()
|
|
|
|
|
with set_company(company2):
|
|
|
|
|
create_chart(company2, tax=True)
|
|
|
|
|
|
2016-02-06 19:12:09 +01:00
|
|
|
@with_transaction()
|
2014-08-29 16:13:52 +02:00
|
|
|
def test_account_used(self):
|
|
|
|
|
'Test account used'
|
2016-02-06 19:12:09 +01:00
|
|
|
pool = Pool()
|
|
|
|
|
ProductTemplate = pool.get('product.template')
|
|
|
|
|
ProductCategory = pool.get('product.category')
|
|
|
|
|
Uom = pool.get('product.uom')
|
|
|
|
|
Account = pool.get('account.account')
|
|
|
|
|
|
|
|
|
|
company = create_company()
|
|
|
|
|
with set_company(company):
|
|
|
|
|
create_chart(company)
|
2014-08-29 16:13:52 +02:00
|
|
|
|
|
|
|
|
unit, = Uom.search([
|
|
|
|
|
('name', '=', 'Unit'),
|
|
|
|
|
])
|
2016-02-06 19:12:09 +01:00
|
|
|
account_expense, = Account.search([
|
2019-03-24 18:00:01 +01:00
|
|
|
('type.expense', '=', True),
|
2016-02-06 19:12:09 +01:00
|
|
|
])
|
2014-08-29 16:13:52 +02:00
|
|
|
|
2016-02-06 19:12:09 +01:00
|
|
|
# raise when empty
|
2014-08-29 16:13:52 +02:00
|
|
|
template = ProductTemplate(
|
2020-03-28 14:30:52 +01:00
|
|
|
name='Product',
|
2014-08-29 16:13:52 +02:00
|
|
|
list_price=Decimal(10),
|
2016-02-06 19:12:09 +01:00
|
|
|
default_uom=unit.id,
|
2017-07-05 14:51:42 +02:00
|
|
|
products=[],
|
2014-08-29 16:13:52 +02:00
|
|
|
)
|
|
|
|
|
template.save()
|
|
|
|
|
|
2020-03-28 14:30:52 +01:00
|
|
|
with self.assertRaisesRegex(
|
|
|
|
|
UserError, 'Account Category.*Product'):
|
2014-08-29 16:13:52 +02:00
|
|
|
template.account_expense_used
|
|
|
|
|
|
2016-02-06 19:12:09 +01:00
|
|
|
# with account on category
|
2020-03-28 14:30:52 +01:00
|
|
|
category = ProductCategory(
|
2021-10-07 15:18:37 +02:00
|
|
|
name='Category', accounting=True,
|
|
|
|
|
account_expense=None)
|
2014-08-29 16:13:52 +02:00
|
|
|
category.save()
|
2016-03-19 09:03:23 +01:00
|
|
|
template.account_category = category
|
2014-08-29 16:13:52 +02:00
|
|
|
template.save()
|
|
|
|
|
|
2020-03-28 14:30:52 +01:00
|
|
|
with self.assertRaisesRegex(
|
|
|
|
|
UserError, 'Account Expense.*Product'):
|
|
|
|
|
template.account_expense_used
|
|
|
|
|
|
|
|
|
|
category.account_expense = account_expense
|
|
|
|
|
category.save()
|
|
|
|
|
|
2014-08-29 16:13:52 +02:00
|
|
|
self.assertEqual(template.account_expense_used, account_expense)
|
|
|
|
|
|
2016-02-06 19:12:09 +01:00
|
|
|
# with account on grant category
|
2020-03-28 14:30:52 +01:00
|
|
|
parent_category = ProductCategory(name='Parent Category',
|
2016-03-19 09:03:23 +01:00
|
|
|
account_expense=account_expense, accounting=True)
|
2014-08-29 16:13:52 +02:00
|
|
|
parent_category.save()
|
|
|
|
|
category.account_expense = None
|
|
|
|
|
category.account_parent = True
|
|
|
|
|
category.parent = parent_category
|
|
|
|
|
category.save()
|
|
|
|
|
|
|
|
|
|
self.assertEqual(template.account_expense_used, account_expense)
|
|
|
|
|
self.assertEqual(category.account_expense_used, account_expense)
|
|
|
|
|
|
2016-02-06 19:12:09 +01:00
|
|
|
# raise only at direct usage
|
2018-06-20 12:09:04 +02:00
|
|
|
categories = ProductCategory.create([{
|
2020-03-28 14:30:52 +01:00
|
|
|
'name': 'Category 1',
|
2018-06-20 12:09:04 +02:00
|
|
|
'accounting': True,
|
2016-02-06 19:12:09 +01:00
|
|
|
'account_expense': account_expense.id,
|
2014-08-29 16:13:52 +02:00
|
|
|
}, {
|
2020-03-28 14:30:52 +01:00
|
|
|
'name': 'Category 2',
|
2018-06-20 12:09:04 +02:00
|
|
|
'accounting': True,
|
2014-08-29 16:13:52 +02:00
|
|
|
'account_expense': None,
|
|
|
|
|
}])
|
|
|
|
|
|
2018-06-20 12:09:04 +02:00
|
|
|
self.assertEqual(categories[0].account_expense_used.id,
|
2016-02-06 19:12:09 +01:00
|
|
|
account_expense.id)
|
2014-08-29 16:13:52 +02:00
|
|
|
|
2020-03-28 14:30:52 +01:00
|
|
|
with self.assertRaisesRegex(
|
|
|
|
|
UserError, 'Account Expense.*Category 2'):
|
2018-06-20 12:09:04 +02:00
|
|
|
categories[1].account_expense_used
|
2014-08-29 16:13:52 +02:00
|
|
|
|
2012-04-03 20:06:26 +02:00
|
|
|
|
2022-04-16 18:30:16 +02:00
|
|
|
del ModuleTestCase
|