|
- from odoo.tests.common import TransactionCase
- from odoo.exceptions import UserError
-
-
- class TestAsset(TransactionCase):
-
- def setUp(self):
- '''固定资产准备数�'''
- super(TestAsset, self).setUp()
- self.asset = self.env.ref('asset.asset_car')
-
- def test_unlink(self):
- '''æµ‹è¯•åˆ é™¤å·²å®¡æ ¸çš„å›ºå®šèµ„äº§'''
- asset = self.asset.copy({'code': '001copy'})
- self.asset.asset_done()
- with self.assertRaises(UserError):
- self.asset.unlink()
- # åˆ é™¤è�‰ç¨¿çжæ€�的固定资产
- asset.unlink()
-
- def test_onchange(self):
- '''资产相关科目由资产类别带�''
- self.asset.category_id = self.env.ref('asset.house')
- self.asset.onchange_category_id()
- self.asset.cost = 2000
- self.asset.onchange_cost()
- self.asset.partner_id = self.env.ref('core.zt')
- self.asset.onchange_partner_id()
- self.asset.bank_account = self.env.ref('core.alipay')
- self.asset.onchange_bank_account()
-
- def test_wrong_asset_done_repeat(self):
- '''é”™è¯¯å®¡æ ¸: é‡�å¤�å®¡æ ¸'''
- self.asset.asset_done()
- with self.assertRaises(UserError):
- self.asset.asset_done()
-
- def test_wrong_asset_done_period_closed(self):
- '''é”™è¯¯å®¡æ ¸: 该会计期间已结账ï¼�ä¸�能审æ ?''
- self.env.ref('finance.period_201804').is_closed = True
- with self.assertRaises(UserError):
- self.asset.asset_done()
-
- def test_wrong_asset_done_amount(self):
- '''é”™è¯¯å®¡æ ¸: 金é¢�必须大于0'''
- self.asset.cost = 0
- with self.assertRaises(UserError):
- self.asset.asset_done()
-
- def test_wrong_asset_done_tax(self):
- '''é”™è¯¯å®¡æ ¸: 税é¢�必须大于0'''
- self.asset.tax = -1
- with self.assertRaises(UserError):
- self.asset.asset_done()
-
- def test_wrong_asset_done_depreciation_previous(self):
- '''é”™è¯¯å®¡æ ¸: 以å‰�折旧必须大于0'''
- self.asset.depreciation_previous = -1
- with self.assertRaises(UserError):
- self.asset.asset_done()
-
- def test_asset_done_bank_account(self):
- '''选择账�,生�其他支出�'''
- self.asset.bank_account = self.env.ref('core.alipay')
- self.asset.onchange_bank_account()
- self.asset.asset_done()
-
- def test_asset_done_construction(self):
- '''贷方科目选择在建工程,直接生æˆ�å‡è¯?''
- self.asset.account_credit = self.env.ref(
- 'finance.small_business_chart1604')
- self.asset.asset_done()
- self.asset.asset_draft()
-
- def test_asset_done_money_invoice_not_done(self):
- ''' Test: asset done, but money invoice not done '''
- self.env.user.company_id.draft_invoice = True
- self.asset.asset_done()
-
- def test_asset_draft_repeat(self):
- '''å��å®¡æ ¸æŠ¥é”? é‡�å¤�å��审æ ?''
- with self.assertRaises(UserError):
- self.asset.asset_draft()
-
- def test_asset_draft_asset_line(self):
- '''å��å®¡æ ¸æŠ¥é”? 已折旧ä¸�能å��å®¡æ ¸'''
- self.asset.asset_done()
- wizard = self.env['create.depreciation.wizard'].create(
- {'date': '2018-05-01'})
- wizard._compute_period_id()
- wizard.create_depreciation()
- with self.assertRaises(UserError):
- self.asset.asset_draft()
-
- def test_asset_draft_change_line(self):
- '''å��å®¡æ ¸æŠ¥é”? å·²å�˜æ›´ä¸�能å��å®¡æ ¸'''
- self.asset.asset_done()
- wizard = self.env['create.chang.wizard'].with_context({'active_id': self.asset.id}).create({
- 'chang_date': '2018-04-02',
- 'chang_cost': 100,
- 'chang_depreciation_number': 1,
- 'chang_tax': 17,
- 'chang_partner_id': self.env.ref('core.lenovo').id})
- wizard._compute_period_id()
- wizard.create_chang_account()
- for line in self.asset.chang_ids:
- self.assertTrue(line.period_id)
- with self.assertRaises(UserError):
- self.asset.asset_draft()
-
- def test_asset_draft_period_closed(self):
- '''å��å®¡æ ¸æŠ¥é”? 该会计期间已结账ï¼�ä¸�能å��å®¡æ ¸'''
- self.asset.asset_done()
- self.env.ref('finance.period_201804').is_closed = True
- with self.assertRaises(UserError):
- self.asset.asset_draft()
-
- def test_asset_draft_partner(self):
- '''æ£å¸¸å��å®¡æ ¸ï¼šé€‰æ‹©å¾€æ�¥å�•ä½�,生æˆ�结算å�?''
- self.asset.asset_done()
- self.asset.asset_draft()
-
- def test_asset_draft_after_invoice_paid(self):
- self.asset.asset_done()
- self.asset.money_invoice.reconciled = 6
- with self.assertRaises(UserError):
- self.asset.asset_draft()
-
-
- def test_asset_draft_bank_account(self):
- '''æ£å¸¸å��å®¡æ ¸ï¼šé€‰æ‹©è´¦å�·ï¼Œç”Ÿæˆ�其他支出å�•'''
- self.asset.bank_account = self.env.ref('core.alipay')
- self.asset.bank_account.balance = 1000000 # ç¡®ä¿�å®¡æ ¸å…¶ä»–æ”¯å‡ºå�•时账户余é¢�å……è¶³
- self.asset.onchange_bank_account()
- self.asset.asset_done()
- self.asset.other_money_order.other_money_done()
- self.asset.asset_draft()
-
- def test_asset_draft_construction(self):
- '''æ£å¸¸å��å®¡æ ¸ï¼šè´·æ–¹ç§‘ç›®é€‰æ‹©åœ¨å»ºå·¥ç¨‹ï¼Œç›´æŽ¥ç”Ÿæˆ�å‡è¯?''
- self.asset.account_credit = self.env.ref(
- 'finance.small_business_chart1604')
- #self.asset.asset_done()
- #self.asset.asset_draft()
-
- def test_get_cost_depreciation(self):
- ''' Test: _get_cost_depreciation '''
- self.asset.asset_done()
- # �一次折� wizard = self.env['create.depreciation.wizard'].create({'date': '2018-05-01'})
- wizard.create_depreciation()
- self.asset.depreciation_number = 12
- # 已�� self.asset.depreciation_number = 1
- wizard = self.env['create.depreciation.wizard'].create({'date': '2016-06-01'})
- wizard.create_depreciation()
-
- def test_no_depreciation(self):
- ''' ��折旧 '''
- self.asset.no_depreciation = True
- self.asset._get_cost_depreciation()
-
- def test_core_category_unlink(self):
- """ä¸�èƒ½åˆ é™¤ç³»ç»Ÿåˆ›å»ºçš„ç±»åˆ?""
- with self.assertRaises(UserError):
- self.env.ref('asset.asset').unlink()
-
-
- class TestCreateCleanWizard(TransactionCase):
-
- def setUp(self):
- '''固定资产清�准备数�'''
- super(TestCreateCleanWizard, self).setUp()
- self.asset = self.env.ref('asset.asset_car')
-
- def test_compute_period_id(self):
- '''固定资产清�:计算期�''
- wizard = self.env['create.clean.wizard'].create({
- 'date': '2018-04-02',
- 'clean_cost': 50,
- 'residual_income': 100,
- 'sell_tax_amount': 17,
- 'bank_account': self.env.ref('core.alipay').id
- })
- wizard._compute_period_id()
- wizard.create_clean_account() # ä¸�ä¼ context执行ä¸�æˆ�åŠ? wizard.with_context({'active_id': self.asset.id}).create_clean_account()
- self.assertTrue(self.asset.net_value == 0)
-
- def test_create_clean_account(self):
- '''清�固定资产'''
- wizard = self.env['create.clean.wizard'].with_context({'active_id': self.asset.id}).create({
- 'date': '2018-04-02',
- 'clean_cost': 50,
- 'residual_income': 100,
- 'sell_tax_amount': 17,
- 'bank_account': self.env.ref('core.alipay').id
- })
- wizard._compute_period_id()
- #wizard.create_clean_account()
-
-
- class TestCreateChangWizard(TransactionCase):
-
- def setUp(self):
- '''固定资产�更准备数�'''
- super(TestCreateChangWizard, self).setUp()
- self.asset = self.env.ref('asset.asset_car')
-
- def test_compute_period_id(self):
- '''固定资产�更:计算期�''
- wizard = self.env['create.chang.wizard'].create({
- 'chang_date': '2018-04-02',
- 'chang_cost': 100,
- 'chang_depreciation_number': 1,
- 'chang_tax': 17,
- 'chang_partner_id': self.env.ref('core.lenovo').id
- })
- wizard._compute_period_id()
- wizard.create_chang_account()
-
- def test_create_chang_account(self):
- '''�更固定资产'''
- wizard = self.env['create.chang.wizard'].with_context({'active_id': self.asset.id}).create({
- 'chang_date': '2018-04-02',
- 'chang_cost': 100,
- 'chang_depreciation_number': 1,
- 'chang_tax': 17,
- 'chang_partner_id': self.env.ref('core.lenovo').id
- })
- wizard._compute_period_id()
-
- # 生æˆ�çš?money invoice é»˜è®¤æ²¡æœ‰å®¡æ ¸
- self.env.user.company_id.draft_invoice = True
- wizard.create_chang_account()
-
-
- class TestAssetLine(TransactionCase):
-
- def setUp(self):
- '''折旧明细准备数�'''
- super(TestAssetLine, self).setUp()
- self.asset = self.env.ref('asset.asset_car')
- self.asset_line = self.env['asset.line'].create({
- 'order_id': self.asset.id,
- 'date': '2018-04-02',
- 'cost_depreciation': 100,
- })
- self.period_201804 = self.env.ref('finance.period_201804')
-
- def test_compute_period_id(self):
- '''折旧明细计算期间'''
- self.asset_line._compute_period_id()
- self.assertTrue(self.asset_line.period_id == self.period_201804)
- self.asset_line.view_asset()
-
-
- class TestDepreciationWizard(TransactionCase):
-
- def setUp(self):
- '''折旧�导准备数�'''
- super(TestDepreciationWizard, self).setUp()
- self.asset = self.env.ref('asset.asset_car')
- self.wizard = self.env['create.depreciation.wizard'].create(
- {'date': '2018-05-01'})
-
- def test_get_last_date(self):
- ''' �本月的最�一天作为默认折旧日 '''
- self.env['create.depreciation.wizard'].create({})
-
- def test_period_not_there(self):
- self.env['finance.period'].get_date_now_period_id().unlink()
- with self.assertRaises(UserError):
- # 当å‰�日期对应的会计期间ä¸�å˜åœ¨ï¼Œè¯·å…ˆåˆ›å»ºï¼�
- self.env['create.depreciation.wizard'].create({})
-
- def test_compute_period_id(self):
- '''资产折旧:计算期�''
- self.wizard._compute_period_id()
-
- def test_create_depreciation(self):
- '''资产折旧,生æˆ�å‡è¯�和折旧明细'''
- self.asset.depreciation_number = 1
- self.asset.depreciation_previous = 950
- with self.assertRaises(UserError):
- self.wizard.create_depreciation()
-
- def test_create_depreciation_surplusValue(self):
- ''' 测试 surplus_value <= (total + cost_depreciation) '''
- self.asset.asset_done()
- self.asset.depreciation_number = 1
- self.asset.depreciation_previous = 950
- self.asset.depreciation_value = 1000
- self.wizard.create_depreciation()
-
- def test_create_depreciation_no_voucher_line(self):
- '''报错:本期所有固定资产都已折�''
- wizard = self.env['create.depreciation.wizard'].create(
- {'date': '2018-04-01'})
- with self.assertRaises(UserError):
- wizard.create_depreciation()
-
- def test_create_depreciation_account_diff(self):
- ''' 多个固定资产生æˆ�å‡è¯� '''
- asset_2 = self.asset.copy({'code': '001copyagain'})
- asset_2.asset_done()
- self.asset.asset_done()
- wizard = self.env['create.depreciation.wizard'].create({'date': '2018-05-01'})
- wizard.create_depreciation()
-
-
- class TestVoucher(TransactionCase):
-
- def setUp(self):
- '''折旧明细准备数�'''
- super(TestVoucher, self).setUp()
- self.asset = self.env.ref('asset.asset_car')
- self.asset.is_init = True
- self.voucher = self.env.ref('finance.voucher_4')
- self.voucher.is_init = True
-
- def test_init_asset(self):
- '''引入固定资产'''
- with self.assertRaises(UserError):
- self.voucher.init_asset()
- self.asset.asset_done()
- self.voucher.init_asset()
- # åˆ é™¤ä»¥å‰�引入的固定资产内容,然å�Žå†�引å…? self.voucher.init_asset()
|