GoodERP
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

326 Zeilen
12KB

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