Files
tryton/modules/account_product/tests/test_module.py
T

119 lines
4.0 KiB
Python
Raw Normal View History

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.
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
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'
extras = ['analytic_account']
@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()
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)
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
])
2016-02-06 19:12:09 +01:00
# raise when empty
template = ProductTemplate(
name='Product',
list_price=Decimal(10),
2016-02-06 19:12:09 +01:00
default_uom=unit.id,
products=[],
)
template.save()
with self.assertRaisesRegex(
UserError, 'Account Category.*Product'):
template.account_expense_used
2016-02-06 19:12:09 +01:00
# with account on category
category = ProductCategory(
name='Category', accounting=True,
account_expense=None)
category.save()
2016-03-19 09:03:23 +01:00
template.account_category = category
template.save()
with self.assertRaisesRegex(
UserError, 'Account Expense.*Product'):
template.account_expense_used
category.account_expense = account_expense
category.save()
self.assertEqual(template.account_expense_used, account_expense)
2016-02-06 19:12:09 +01:00
# with account on grant category
parent_category = ProductCategory(name='Parent Category',
2016-03-19 09:03:23 +01:00
account_expense=account_expense, accounting=True)
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([{
'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,
}, {
'name': 'Category 2',
2018-06-20 12:09:04 +02:00
'accounting': True,
'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)
with self.assertRaisesRegex(
UserError, 'Account Expense.*Category 2'):
2018-06-20 12:09:04 +02:00
categories[1].account_expense_used
2012-04-03 20:06:26 +02:00
del ModuleTestCase