GoodERP
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

327 líneas
12KB

  1. # -*- coding: utf-8 -*-
  2. from odoo.tests.common import TransactionCase
  3. from odoo.exceptions import UserError
  4. class TestAsset(TransactionCase):
  5. def setUp(self):
  6. '''固定资产准备数据'''
  7. super(TestAsset, self).setUp()
  8. self.asset = self.env.ref('asset.asset_car')
  9. def test_unlink(self):
  10. '''测试删除已审核的固定资产'''
  11. asset = self.asset.copy({'code': '001copy'})
  12. self.asset.asset_done()
  13. with self.assertRaises(UserError):
  14. self.asset.unlink()
  15. # 删除草稿状态的固定资产
  16. asset.unlink()
  17. def test_onchange(self):
  18. '''资产相关科目由资产类别带出'''
  19. self.asset.category_id = self.env.ref('asset.house')
  20. self.asset.onchange_category_id()
  21. self.asset.cost = 2000
  22. self.asset.onchange_cost()
  23. self.asset.partner_id = self.env.ref('core.zt')
  24. self.asset.onchange_partner_id()
  25. self.asset.bank_account = self.env.ref('core.alipay')
  26. self.asset.onchange_bank_account()
  27. def test_wrong_asset_done_repeat(self):
  28. '''错误审核: 重复审核'''
  29. self.asset.asset_done()
  30. with self.assertRaises(UserError):
  31. self.asset.asset_done()
  32. def test_wrong_asset_done_period_closed(self):
  33. '''错误审核: 该会计期间已结账! 不能审核'''
  34. self.env.ref('finance.period_201804').is_closed = True
  35. with self.assertRaises(UserError):
  36. self.asset.asset_done()
  37. def test_wrong_asset_done_amount(self):
  38. '''错误审核: 金额必须大于0'''
  39. self.asset.cost = 0
  40. with self.assertRaises(UserError):
  41. self.asset.asset_done()
  42. def test_wrong_asset_done_tax(self):
  43. '''错误审核: 税额必须大于0'''
  44. self.asset.tax = -1
  45. with self.assertRaises(UserError):
  46. self.asset.asset_done()
  47. def test_wrong_asset_done_depreciation_previous(self):
  48. '''错误审核: 以前折旧必须大于0'''
  49. self.asset.depreciation_previous = -1
  50. with self.assertRaises(UserError):
  51. self.asset.asset_done()
  52. def test_asset_done_bank_account(self):
  53. '''选择账号,生成其他支出单'''
  54. self.asset.bank_account = self.env.ref('core.alipay')
  55. self.asset.onchange_bank_account()
  56. self.asset.asset_done()
  57. def test_asset_done_construction(self):
  58. '''贷方科目选择在建工程,直接生成凭证'''
  59. self.asset.account_credit = self.env.ref(
  60. 'finance.small_business_chart1604')
  61. self.asset.asset_done()
  62. self.asset.asset_draft()
  63. def test_asset_done_money_invoice_not_done(self):
  64. ''' Test: asset done, but money invoice not done '''
  65. self.env.user.company_id.draft_invoice = True
  66. self.asset.asset_done()
  67. def test_asset_draft_repeat(self):
  68. '''反审核报错: 重复反审核'''
  69. with self.assertRaises(UserError):
  70. self.asset.asset_draft()
  71. def test_asset_draft_asset_line(self):
  72. '''反审核报错: 已折旧不能反审核'''
  73. self.asset.asset_done()
  74. wizard = self.env['create.depreciation.wizard'].create(
  75. {'date': '2018-05-01'})
  76. wizard._compute_period_id()
  77. wizard.create_depreciation()
  78. with self.assertRaises(UserError):
  79. self.asset.asset_draft()
  80. def test_asset_draft_change_line(self):
  81. '''反审核报错: 已变更不能反审核'''
  82. self.asset.asset_done()
  83. wizard = self.env['create.chang.wizard'].with_context({'active_id': self.asset.id}).create({
  84. 'chang_date': '2018-04-02',
  85. 'chang_cost': 100,
  86. 'chang_depreciation_number': 1,
  87. 'chang_tax': 17,
  88. 'chang_partner_id': self.env.ref('core.lenovo').id})
  89. wizard._compute_period_id()
  90. wizard.create_chang_account()
  91. for line in self.asset.chang_ids:
  92. self.assertTrue(line.period_id)
  93. with self.assertRaises(UserError):
  94. self.asset.asset_draft()
  95. def test_asset_draft_period_closed(self):
  96. '''反审核报错: 该会计期间已结账! 不能反审核'''
  97. self.asset.asset_done()
  98. self.env.ref('finance.period_201804').is_closed = True
  99. with self.assertRaises(UserError):
  100. self.asset.asset_draft()
  101. def test_asset_draft_partner(self):
  102. '''正常反审核: 选择往来单位,生成结算单'''
  103. self.asset.asset_done()
  104. self.asset.asset_draft()
  105. def test_asset_draft_after_invoice_paid(self):
  106. self.asset.asset_done()
  107. self.asset.money_invoice.reconciled = 6
  108. with self.assertRaises(UserError):
  109. self.asset.asset_draft()
  110. def test_asset_draft_bank_account(self):
  111. '''正常反审核: 选择账号,生成其他支出单'''
  112. self.asset.bank_account = self.env.ref('core.alipay')
  113. self.asset.bank_account.balance = 1000000 # 确保审核其他支出单时账户余额充足
  114. self.asset.onchange_bank_account()
  115. self.asset.asset_done()
  116. self.asset.other_money_order.other_money_done()
  117. self.asset.asset_draft()
  118. def test_asset_draft_construction(self):
  119. '''正常反审核: 贷方科目选择在建工程,直接生成凭证'''
  120. self.asset.account_credit = self.env.ref(
  121. 'finance.small_business_chart1604')
  122. #self.asset.asset_done()
  123. #self.asset.asset_draft()
  124. def test_get_cost_depreciation(self):
  125. ''' Test: _get_cost_depreciation '''
  126. self.asset.asset_done()
  127. # 提一次折旧 wizard = self.env['create.depreciation.wizard'].create({'date': '2018-05-01'})
  128. wizard.create_depreciation()
  129. self.asset.depreciation_number = 12
  130. # 已计提 self.asset.depreciation_number = 1
  131. wizard = self.env['create.depreciation.wizard'].create({'date': '2016-06-01'})
  132. wizard.create_depreciation()
  133. def test_no_depreciation(self):
  134. ''' 不提折旧 '''
  135. self.asset.no_depreciation = True
  136. self.asset._get_cost_depreciation()
  137. def test_core_category_unlink(self):
  138. """不能删除系统创建的类别"""
  139. with self.assertRaises(UserError):
  140. self.env.ref('asset.asset').unlink()
  141. class TestCreateCleanWizard(TransactionCase):
  142. def setUp(self):
  143. '''固定资产清理准备数据'''
  144. super(TestCreateCleanWizard, self).setUp()
  145. self.asset = self.env.ref('asset.asset_car')
  146. def test_compute_period_id(self):
  147. '''固定资产清理: 计算期间'''
  148. wizard = self.env['create.clean.wizard'].create({
  149. 'date': '2018-04-02',
  150. 'clean_cost': 50,
  151. 'residual_income': 100,
  152. 'sell_tax_amount': 17,
  153. 'bank_account': self.env.ref('core.alipay').id
  154. })
  155. wizard._compute_period_id()
  156. wizard.create_clean_account() # 不传context执行不成功 wizard.with_context({'active_id': self.asset.id}).create_clean_account()
  157. self.assertTrue(self.asset.net_value == 0)
  158. def test_create_clean_account(self):
  159. '''清理固定资产'''
  160. wizard = self.env['create.clean.wizard'].with_context({'active_id': self.asset.id}).create({
  161. 'date': '2018-04-02',
  162. 'clean_cost': 50,
  163. 'residual_income': 100,
  164. 'sell_tax_amount': 17,
  165. 'bank_account': self.env.ref('core.alipay').id
  166. })
  167. wizard._compute_period_id()
  168. #wizard.create_clean_account()
  169. class TestCreateChangWizard(TransactionCase):
  170. def setUp(self):
  171. '''固定资产变更准备数据'''
  172. super(TestCreateChangWizard, self).setUp()
  173. self.asset = self.env.ref('asset.asset_car')
  174. def test_compute_period_id(self):
  175. '''固定资产变更: 计算期间'''
  176. wizard = self.env['create.chang.wizard'].create({
  177. 'chang_date': '2018-04-02',
  178. 'chang_cost': 100,
  179. 'chang_depreciation_number': 1,
  180. 'chang_tax': 17,
  181. 'chang_partner_id': self.env.ref('core.lenovo').id
  182. })
  183. wizard._compute_period_id()
  184. wizard.create_chang_account()
  185. def test_create_chang_account(self):
  186. '''变更固定资产'''
  187. wizard = self.env['create.chang.wizard'].with_context({'active_id': self.asset.id}).create({
  188. 'chang_date': '2018-04-02',
  189. 'chang_cost': 100,
  190. 'chang_depreciation_number': 1,
  191. 'chang_tax': 17,
  192. 'chang_partner_id': self.env.ref('core.lenovo').id
  193. })
  194. wizard._compute_period_id()
  195. # 生成功money invoice 默认没有审核
  196. self.env.user.company_id.draft_invoice = True
  197. wizard.create_chang_account()
  198. class TestAssetLine(TransactionCase):
  199. def setUp(self):
  200. '''折旧明细准备数据'''
  201. super(TestAssetLine, self).setUp()
  202. self.asset = self.env.ref('asset.asset_car')
  203. self.asset_line = self.env['asset.line'].create({
  204. 'order_id': self.asset.id,
  205. 'date': '2018-04-02',
  206. 'cost_depreciation': 100,
  207. })
  208. self.period_201804 = self.env.ref('finance.period_201804')
  209. def test_compute_period_id(self):
  210. '''折旧明细计算期间'''
  211. self.asset_line._compute_period_id()
  212. self.assertTrue(self.asset_line.period_id == self.period_201804)
  213. self.asset_line.view_asset()
  214. class TestDepreciationWizard(TransactionCase):
  215. def setUp(self):
  216. '''折旧向导准备数据'''
  217. super(TestDepreciationWizard, self).setUp()
  218. self.asset = self.env.ref('asset.asset_car')
  219. self.wizard = self.env['create.depreciation.wizard'].create(
  220. {'date': '2018-05-01'})
  221. def test_get_last_date(self):
  222. ''' 取本月的最后一天作为默认折旧日 '''
  223. self.env['create.depreciation.wizard'].create({})
  224. def test_period_not_there(self):
  225. self.env['finance.period'].get_date_now_period_id().unlink()
  226. with self.assertRaises(UserError):
  227. # 当前日期对应的会计期间不存在,请先创建
  228. self.env['create.depreciation.wizard'].create({})
  229. def test_compute_period_id(self):
  230. '''资产折旧: 计算期间'''
  231. self.wizard._compute_period_id()
  232. def test_create_depreciation(self):
  233. '''资产折旧,生成凭证和折旧明细'''
  234. self.asset.depreciation_number = 1
  235. self.asset.depreciation_previous = 950
  236. with self.assertRaises(UserError):
  237. self.wizard.create_depreciation()
  238. def test_create_depreciation_surplusValue(self):
  239. ''' 测试 surplus_value <= (total + cost_depreciation) '''
  240. self.asset.asset_done()
  241. self.asset.depreciation_number = 1
  242. self.asset.depreciation_previous = 950
  243. self.asset.depreciation_value = 1000
  244. self.wizard.create_depreciation()
  245. def test_create_depreciation_no_voucher_line(self):
  246. '''报错: 本期所有固定资产都已折旧'''
  247. wizard = self.env['create.depreciation.wizard'].create(
  248. {'date': '2018-04-01'})
  249. with self.assertRaises(UserError):
  250. wizard.create_depreciation()
  251. def test_create_depreciation_account_diff(self):
  252. ''' 多个固定资产生成凭证 '''
  253. asset_2 = self.asset.copy({'code': '001copyagain'})
  254. asset_2.asset_done()
  255. self.asset.asset_done()
  256. wizard = self.env['create.depreciation.wizard'].create({'date': '2018-05-01'})
  257. wizard.create_depreciation()
  258. class TestVoucher(TransactionCase):
  259. def setUp(self):
  260. '''折旧明细准备数据'''
  261. super(TestVoucher, self).setUp()
  262. self.asset = self.env.ref('asset.asset_car')
  263. self.asset.is_init = True
  264. self.voucher = self.env.ref('finance.voucher_4')
  265. self.voucher.is_init = True
  266. def test_init_asset(self):
  267. '''引入固定资产'''
  268. with self.assertRaises(UserError):
  269. self.voucher.init_asset()
  270. self.asset.asset_done()
  271. self.voucher.init_asset()
  272. # 删除以前引入的固定资产内容,然后再引入 self.voucher.init_asset()
上海开阖软件有限公司 沪ICP备12045867号-1