GoodERP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

625 satır
29KB

  1. from odoo.tests.common import TransactionCase
  2. from odoo.exceptions import UserError
  3. from odoo.addons.finance.report.report import ReportVoucher
  4. class TestReport(TransactionCase):
  5. def setUp(self):
  6. super(TestReport, self).setUp()
  7. # 审核2015年12月和2016年1月的会计凭证
  8. self.env.ref('finance.voucher_12').voucher_done()
  9. self.env.ref('finance.voucher_1').voucher_done()
  10. self.env.ref('finance.voucher_2').voucher_done()
  11. self.env.ref('finance.voucher_12_1').voucher_done()
  12. self.period_id = self.env.ref('finance.period_201601').id
  13. self.period_201411 = self.env.ref('finance.period_201411')
  14. self.period_201512 = self.env.ref('finance.period_201512')
  15. ''' FIXME
  16. # 结转2015年12月的期间
  17. month_end = self.env['checkout.wizard'].create(
  18. {'date':'2015-12-31',
  19. 'period_id':self.env.ref('finance.period_201512').id})
  20. month_end.button_checkout()
  21. '''
  22. def test_trail_balance(self):
  23. ''' 测试科目余额表 '''
  24. # 上一期间未结账报错
  25. report = self.env['create.trial.balance.wizard'].create(
  26. {'period_id': self.period_id}
  27. )
  28. period_201411_wizard = self.env['create.trial.balance.wizard'].create(
  29. {'period_id': self.period_201411.id})
  30. with self.assertRaises(UserError):
  31. report.create_trial_balance()
  32. # 结转2015年12月的期间
  33. month_end = self.env['checkout.wizard'].create(
  34. {'date': '2015-12-31'})
  35. month_end.onchange_period_id()
  36. month_end.button_checkout()
  37. # 正常流程
  38. report.create_trial_balance()
  39. period_201411_wizard.create_trial_balance()
  40. # 执行 _default_period_id
  41. report_default_period = self.env[
  42. 'create.trial.balance.wizard'].create({})
  43. last_period = self.env[
  44. 'create.trial.balance.wizard'].compute_last_period_id(
  45. report_default_period.period_id)
  46. if last_period and not last_period.is_closed: # 如果上一个期间没有结账,则关闭
  47. last_period.is_closed = True
  48. report_default_period.create_trial_balance()
  49. def test_button_change_number(self):
  50. ''' 测试 调整累计数 弹窗'''
  51. report = self.env['create.trial.balance.wizard'].create(
  52. {'period_id': self.period_201512.id})
  53. # 创建科目余额表
  54. report.create_trial_balance()
  55. # 期间 period_201512,找到叶科目 银行存款-基本户,弹出 调整累计数向导 窗口
  56. for trial in self.env['trial.balance'].search([]):
  57. if trial.subject_name_id.id == self.env.ref(
  58. 'finance.account_bank').id:
  59. trial.button_change_number()
  60. break
  61. def test_change_cumulative_occurrence_wizard_default_get(self):
  62. ''' 测试 调整累计数 向导 default_get '''
  63. wizard_obj = self.env['change.cumulative.occurrence.wizard']
  64. report = self.env['create.trial.balance.wizard'].create(
  65. {'period_id': self.period_201512.id})
  66. # 创建科目余额表
  67. report.create_trial_balance()
  68. # 期间 period_201512,找到叶科目 银行存款-基本户,调整累计数
  69. for trial in self.env['trial.balance'].search([]):
  70. if trial.subject_name_id.id == self.env.ref(
  71. 'finance.account_bank').id:
  72. ctx = self.env.context.copy()
  73. ctx['active_id'] = trial.id
  74. ctx['active_ids'] = [trial.id]
  75. env2 = self.env(self.env.cr, self.env.uid, ctx)
  76. wizard_obj.with_env(env2).default_get([
  77. 'cumulative_occurrence_debit',
  78. 'cumulative_occurrence_credit',
  79. 'old_cumulative_occurrence_debit',
  80. 'old_cumulative_occurrence_credit',
  81. 'trial_balance_id', 'account_id'])
  82. # 只能调整末级科目相关的行 报错
  83. with self.assertRaises(UserError):
  84. trial.subject_name_id.account_type = 'view'
  85. env2 = self.env(self.env.cr, self.env.uid, ctx)
  86. wizard_obj.with_env(env2).default_get([
  87. 'cumulative_occurrence_debit',
  88. 'cumulative_occurrence_credit',
  89. 'old_cumulative_occurrence_debit',
  90. 'old_cumulative_occurrence_credit',
  91. 'trial_balance_id', 'account_id'])
  92. # 一次只能调整一行 报错
  93. with self.assertRaises(UserError):
  94. trial.subject_name_id.account_type = 'normal'
  95. ctx['active_ids'] = [trial.id, trial.id]
  96. env2 = self.env(self.env.cr, self.env.uid, ctx)
  97. wizard_obj.with_env(env2).default_get([
  98. 'cumulative_occurrence_debit',
  99. 'cumulative_occurrence_credit',
  100. 'old_cumulative_occurrence_debit',
  101. 'old_cumulative_occurrence_credit',
  102. 'trial_balance_id', 'account_id'])
  103. def test_update_cumulative_occurrence(self):
  104. ''' 测试:update_cumulative_occurrence '''
  105. wizard_obj = self.env['change.cumulative.occurrence.wizard']
  106. report = self.env['create.trial.balance.wizard'].create(
  107. {'period_id': self.period_201512.id})
  108. # 创建科目余额表
  109. report.create_trial_balance()
  110. # 期间 period_201512,找到叶科目 银行存款-基本户,调整累计数
  111. for trial in self.env['trial.balance'].search([]):
  112. ctx = self.env.context.copy()
  113. fields_list = ['cumulative_occurrence_debit',
  114. 'cumulative_occurrence_credit',
  115. 'old_cumulative_occurrence_debit',
  116. 'old_cumulative_occurrence_credit',
  117. 'trial_balance_id', 'account_id']
  118. # costs_types not in ('in', 'out')
  119. if trial.subject_name_id == self.env.ref('finance.account_bank'):
  120. ctx['active_id'] = trial.id
  121. ctx['active_ids'] = [trial.id]
  122. env2 = self.env(self.env.cr, self.env.uid, ctx)
  123. values = wizard_obj.with_env(env2).default_get(fields_list)
  124. wizard = wizard_obj.with_env(env2).create(values)
  125. wizard.update_cumulative_occurrence()
  126. # costs_types in ('in', 'out')
  127. if trial.subject_name_id == self.env.ref('finance.account_income'):
  128. ctx['active_id'] = trial.id
  129. ctx['active_ids'] = [trial.id]
  130. env2 = self.env(self.env.cr, self.env.uid, ctx)
  131. values = wizard_obj.with_env(env2).default_get(fields_list)
  132. wizard = wizard_obj.with_env(env2).create(values)
  133. wizard.update_cumulative_occurrence()
  134. def test_check_trial_balance_wizard_default_get(self):
  135. ''' 测试 试算平衡 向导 default_get '''
  136. wizard_obj = self.env['check.trial.balance.wizard']
  137. report = self.env['create.trial.balance.wizard'].create(
  138. {'period_id': self.period_201512.id})
  139. # 创建科目余额表
  140. report.create_trial_balance()
  141. field_list = [
  142. "total_year_init_debit", "total_year_init_credit",
  143. "total_initial_balance_debit", "total_initial_balance_credit",
  144. "total_current_occurrence_debit",
  145. "total_current_occurrence_credit",
  146. "total_ending_balance_debit", "total_ending_balance_credit",
  147. "total_cumulative_occurrence_debit",
  148. "total_cumulative_occurrence_credit"
  149. ]
  150. # 期间 period_201512,找到叶科目 银行存款-基本户,试算平衡
  151. for trial in self.env['trial.balance'].search([]):
  152. if trial.subject_name_id.id == self.env.ref(
  153. 'finance.account_bank').id:
  154. ctx = self.env.context.copy()
  155. ctx['active_id'] = trial.id
  156. ctx['active_ids'] = [trial.id]
  157. env2 = self.env(self.env.cr, self.env.uid, ctx)
  158. wizard_obj.with_env(env2).default_get(field_list)
  159. # init period
  160. # 创建科目余额表
  161. report.create_trial_balance()
  162. # 期间 period_201512,找到叶科目 银行存款-基本户,试算平衡
  163. for trial in self.env['trial.balance'].search([]):
  164. if trial.subject_name_id.id == self.env.ref(
  165. 'finance.account_bank').id:
  166. ctx = self.env.context.copy()
  167. ctx['active_id'] = trial.id
  168. ctx['active_ids'] = [trial.id]
  169. self.env.ref('base.main_company').start_date = '2015-12-12'
  170. env2 = self.env(self.env.cr, self.env.uid, ctx)
  171. wizard_obj.with_env(env2).default_get(field_list)
  172. def test_check_trial_balance_wizard_default_get_diff_exists(self):
  173. ''' 测试 试算平衡 向导 default_get diff exists '''
  174. wizard_obj = self.env['check.trial.balance.wizard']
  175. report = self.env['create.trial.balance.wizard'].create(
  176. {'period_id': self.period_201512.id})
  177. # 修改当期 一个凭证行的贷方金额,使贷方金额不等于借方金额
  178. self.env.ref('finance.voucher_12_2_credit').credit = 4999
  179. # 修改上期 一个凭证行的贷方金额,使贷方金额不等于借方金额
  180. self.env.ref('finance.voucher_12').period_id = self.env.ref(
  181. 'finance.period_201511').id
  182. self.env.ref('finance.voucher_line_12_credit').credit = 1000002
  183. # 创建科目余额表
  184. report.create_trial_balance()
  185. field_list = [
  186. "total_year_init_debit", "total_year_init_credit",
  187. "total_initial_balance_debit", "total_initial_balance_credit",
  188. "total_current_occurrence_debit",
  189. "total_current_occurrence_credit",
  190. "total_ending_balance_debit",
  191. "total_ending_balance_credit",
  192. "total_cumulative_occurrence_debit",
  193. "total_cumulative_occurrence_credit"
  194. ]
  195. # 期间 period_201512,找到叶科目 银行存款-基本户,试算平衡
  196. for trial in self.env['trial.balance'].search([]):
  197. if trial.subject_name_id.id == self.env.ref(
  198. 'finance.account_bank').id:
  199. ctx = self.env.context.copy()
  200. ctx['active_id'] = trial.id
  201. ctx['active_ids'] = [trial.id]
  202. env2 = self.env(self.env.cr, self.env.uid, ctx)
  203. wizard_obj.with_env(env2).default_get(field_list)
  204. # init period
  205. # 创建科目余额表
  206. report.create_trial_balance()
  207. # 期间 period_201512,找到叶科目 银行存款-基本户,试算平衡
  208. for trial in self.env['trial.balance'].search([]):
  209. if trial.subject_name_id.id == self.env.ref(
  210. 'finance.account_bank').id:
  211. ctx = self.env.context.copy()
  212. ctx['active_id'] = trial.id
  213. ctx['active_ids'] = [trial.id]
  214. self.env.ref('base.main_company').start_date = '2015-12-12'
  215. env2 = self.env(self.env.cr, self.env.uid, ctx)
  216. wizard_obj.with_env(env2).default_get(field_list)
  217. def test_check_trial_balance(self):
  218. ''' 测试 试算平衡 check_trial_balance '''
  219. report = self.env['create.trial.balance.wizard'].create(
  220. {'period_id': self.period_201512.id})
  221. # 创建科目余额表
  222. report.create_trial_balance()
  223. # 期间 period_201512,找到叶科目 银行存款-基本户,试算平衡
  224. for trial in self.env['trial.balance'].search([]):
  225. if trial.subject_name_id.id == self.env.ref(
  226. 'finance.account_bank').id:
  227. if trial.period_id == self.period_201512:
  228. trial.check_trial_balance(self.period_201512)
  229. def test_check_trial_balance_init_period(self):
  230. ''' 测试 试算平衡 check_trial_balance init period '''
  231. report = self.env['create.trial.balance.wizard'].create(
  232. {'period_id': self.period_201512.id})
  233. # 创建科目余额表
  234. report.create_trial_balance()
  235. # 期间 period_201512,找到叶科目 银行存款-基本户,试算平衡
  236. for trial in self.env['trial.balance'].search([]):
  237. if trial.subject_name_id.id == self.env.ref(
  238. 'finance.account_bank').id:
  239. self.env.ref('base.main_company').start_date = '2015-12-12'
  240. if trial.period_id == trial.period_id.get_init_period():
  241. trial.check_trial_balance(
  242. trial.period_id.get_init_period())
  243. def test_check_trial_balance_diff_exists(self):
  244. ''' 测试 试算平衡 check_trial_balance diff exists '''
  245. report = self.env['create.trial.balance.wizard'].create(
  246. {'period_id': self.period_201512.id})
  247. # 修改当期 一个凭证行的贷方金额,使贷方金额不等于借方金额
  248. self.env.ref('finance.voucher_12_2_credit').credit = 4999
  249. # 修改上期 一个凭证行的贷方金额,使贷方金额不等于借方金额
  250. self.env.ref('finance.voucher_12').period_id = self.env.ref(
  251. 'finance.period_201511').id
  252. self.env.ref('finance.voucher_line_12_credit').credit = 1000002
  253. # 创建科目余额表
  254. report.create_trial_balance()
  255. # 期间 period_201512,init_period 试算平衡
  256. for trial in self.env['trial.balance'].search([]):
  257. if trial.subject_name_id.id == self.env.ref(
  258. 'finance.account_bank').id:
  259. if trial.period_id == self.period_201512:
  260. with self.assertRaises(UserError):
  261. trial.check_trial_balance(self.period_201512)
  262. def test_check_trial_balance_diff_exists_init_period(self):
  263. ''' 测试 试算平衡 check_trial_balance diff exists init period '''
  264. report = self.env['create.trial.balance.wizard'].create(
  265. {'period_id': self.period_201512.id})
  266. # 修改当期 一个凭证行的贷方金额,使贷方金额不等于借方金额
  267. self.env.ref('finance.voucher_12_2_credit').credit = 4999
  268. # 修改上期 一个凭证行的贷方金额,使贷方金额不等于借方金额
  269. self.env.ref('finance.voucher_12').period_id = self.env.ref(
  270. 'finance.period_201511').id
  271. self.env.ref('finance.voucher_line_12_credit').credit = 1000002
  272. # 创建科目余额表
  273. report.create_trial_balance()
  274. # 期间 period_201512,init_period 试算平衡
  275. for trial in self.env['trial.balance'].search([]):
  276. if trial.subject_name_id.id == self.env.ref(
  277. 'finance.account_bank').id:
  278. self.env.ref('base.main_company').start_date = '2015-12-12'
  279. if trial.period_id == trial.period_id.get_init_period():
  280. with self.assertRaises(UserError):
  281. trial.check_trial_balance(
  282. trial.period_id.get_init_period())
  283. def test_vouchers_summary(self):
  284. ''' 测试总账和明细账'''
  285. report = self.env['create.vouchers.summary.wizard'].create(
  286. {'period_begin_id': self.period_id,
  287. 'period_end_id': self.period_id,
  288. 'subject_name_id': self.env.ref('finance.account_fund').id,
  289. 'subject_name_end_id': self.env.ref('finance.account_fund').id,
  290. }
  291. )
  292. # 会计期间相同时报错
  293. report.period_end_id = self.env.ref('finance.period_201512')
  294. report.onchange_period()
  295. with self.assertRaises(UserError):
  296. report.create_general_ledger_account()
  297. # 上一期间未结账报错
  298. with self.assertRaises(UserError):
  299. report.create_vouchers_summary()
  300. with self.assertRaises(UserError):
  301. report.create_general_ledger_account()
  302. # 正常流程
  303. report.period_end_id = self.period_id
  304. # 结转2015年12月的期间
  305. month_end = self.env['checkout.wizard'].create(
  306. {'date': '2015-12-31'})
  307. month_end.onchange_period_id()
  308. month_end.button_checkout()
  309. report.create_vouchers_summary()
  310. report.create_general_ledger_account()
  311. report.period_end_id = self.env.ref('finance.period_201602')
  312. report.create_vouchers_summary()
  313. report.create_general_ledger_account()
  314. # 没有生成科目余额表的情况
  315. trial_balance_obj = self.env['trial.balance'].search([
  316. ('period_id', '=', self.env.ref('finance.period_201512').id),
  317. ('subject_name_id', '=', report.subject_name_id.id)])
  318. trial_balance_obj.unlink()
  319. report.create_vouchers_summary()
  320. report.create_general_ledger_account()
  321. # 执行 _default_end_period_id,_default_begin_period_id,
  322. # _default_subject_name_id,_default_subject_name_end_id
  323. report_default = self.env['create.vouchers.summary.wizard'].create({})
  324. report_default.create_vouchers_summary()
  325. # 执行 明细账 无下一期间,退出循环
  326. report_default = self.env['create.vouchers.summary.wizard'].create({})
  327. report_default.period_begin_id = self.env.ref('finance.period_201412')
  328. report_default.create_vouchers_summary()
  329. def test_vouchers_summary_onchange_period(self):
  330. ''' 测试总账和明细账 onchange_period '''
  331. report_default = self.env['create.vouchers.summary.wizard'].create({})
  332. report_default.period_begin_id = self.env.ref(
  333. 'finance.period_201512').id
  334. report_default.period_end_id = self.env.ref('finance.period_201411').id
  335. report_default.onchange_period()
  336. report_default.create_vouchers_summary()
  337. def test_create_general_ledger_account(self):
  338. ''' 测试总账 '''
  339. report = self.env['create.vouchers.summary.wizard'].create(
  340. {'period_begin_id': self.period_id,
  341. 'period_end_id': self.period_id,
  342. 'subject_name_id': self.env.ref('finance.account_fund').id,
  343. 'subject_name_end_id': self.env.ref('finance.account_fund').id,
  344. })
  345. # 当前期间已关闭
  346. self.period_201512.is_closed = True
  347. self.env.ref('finance.period_201601').is_closed = True
  348. report.create_general_ledger_account()
  349. # 执行 总账 无下一期间,退出循环
  350. report.period_begin_id = self.env.ref('finance.period_201412')
  351. report.create_general_ledger_account()
  352. def test_get_initial_balance(self):
  353. '''取得期初余额'''
  354. wizard = self.env['create.vouchers.summary.wizard'].create(
  355. {'period_begin_id': self.period_201411.id,
  356. 'period_end_id': self.period_201411.id,
  357. 'subject_name_id': self.env.ref('finance.account_fund').id,
  358. 'subject_name_end_id': self.env.ref('finance.account_fund').id,
  359. }
  360. )
  361. wizard.get_initial_balance(self.period_201411, wizard.subject_name_id)
  362. # get_initial_balance period 不存在
  363. wizard.get_initial_balance(False, wizard.subject_name_id)
  364. def test_get_current_occurrence_amount(self):
  365. '''测试 本期的科目的 voucher_line的明细记录'''
  366. wizard = self.env['create.vouchers.summary.wizard'].create(
  367. {'period_begin_id': self.period_201512.id,
  368. 'period_end_id': self.period_201512.id,
  369. 'subject_name_id': self.env.ref('finance.account_cash').id,
  370. 'subject_name_end_id': self.env.ref('finance.account_bank').id,
  371. })
  372. wizard.get_current_occurrence_amount(
  373. self.period_201512, self.env.ref('finance.account_bank'))
  374. def test_view_detail_voucher(self):
  375. '''在明细账上查看凭证明细按钮'''
  376. report = self.env['create.vouchers.summary.wizard'].create(
  377. {'period_begin_id': self.period_id,
  378. 'period_end_id': self.period_id,
  379. 'subject_name_id': self.env.ref('finance.account_fund').id,
  380. 'subject_name_end_id': self.env.ref('finance.account_fund').id,
  381. })
  382. # 结转2015年12月的期间
  383. month_end = self.env['checkout.wizard'].create(
  384. {'date': '2015-12-31'})
  385. month_end.onchange_period_id()
  386. month_end.button_checkout()
  387. result = report.create_vouchers_summary()
  388. ids = result['domain'][0][2]
  389. for line in self.env['vouchers.summary'].browse(ids):
  390. if line.voucher_id:
  391. line.view_detail_voucher()
  392. def test_get_year_balance(self):
  393. '''根据期间和科目名称 计算出本期合计 和本年累计 (已经关闭的期间)'''
  394. wizard = self.env['create.vouchers.summary.wizard'].create(
  395. {'period_begin_id': self.period_201411.id,
  396. 'period_end_id': self.period_201411.id,
  397. 'subject_name_id': self.env.ref('finance.account_fund').id,
  398. 'subject_name_end_id': self.env.ref('finance.account_fund').id,
  399. }
  400. )
  401. wizard.get_year_balance(self.period_201411, wizard.subject_name_id)
  402. voucher = self.env['checkout.wizard'].create({
  403. 'date': '2015-12-31'})
  404. voucher.onchange_period_id()
  405. voucher.button_checkout()
  406. trial_wizard = self.env['create.vouchers.summary.wizard'].create({
  407. 'period_begin_id': self.env.ref('finance.period_201512').id,
  408. 'period_end_id': self.env.ref('finance.period_201601').id,
  409. 'subject_name_id': self.env.ref('finance.account_income').id,
  410. 'subject_name_end_id': self.env.ref('finance.account_income').id,
  411. })
  412. trial_wizard.create_vouchers_summary()
  413. def test_balance_sheet(self):
  414. ''' 测试资产负债表 '''
  415. report = self.env['create.balance.sheet.wizard'].create(
  416. {'period_id': self.period_id})
  417. with self.assertRaises(UserError):
  418. report.create_balance_sheet()
  419. with self.assertRaises(UserError):
  420. report.create_profit_statement()
  421. # 结转2015年12月的期间
  422. month_end = self.env['checkout.wizard'].create(
  423. {'date': '2015-12-31'})
  424. month_end.onchange_period_id()
  425. month_end.button_checkout()
  426. report.create_balance_sheet()
  427. report.create_profit_statement()
  428. self.env.ref('finance.account_cost').balance_directions = 'out'
  429. report.create_profit_statement()
  430. balance_sheet_objs = self.env['profit.statement'].search([])
  431. # for balance_sheet_obj in balance_sheet_objs:
  432. # balance_sheet_obj.cumulative_occurrence_balance_formula = ''
  433. report.create_profit_statement()
  434. def test_balance_sheet_default_period(self):
  435. ''' 测试资产负债表 wizard no period'''
  436. self.env['create.balance.sheet.wizard'].create({})
  437. def test_balance_sheet_compute_balance(self):
  438. ''' 测试资产负债表 compute balance'''
  439. report = self.env['create.balance.sheet.wizard'].create(
  440. {'period_id': self.period_id})
  441. self.env.ref('finance.bs_1').balance_formula = '1001'
  442. # 结转2015年12月的期间
  443. month_end = self.env['checkout.wizard'].create({'date': '2015-12-31'})
  444. month_end.onchange_period_id()
  445. month_end.button_checkout()
  446. report.create_balance_sheet()
  447. class TestCheckoutWizard(TransactionCase):
  448. def setUp(self):
  449. super(TestCheckoutWizard, self).setUp()
  450. self.voucher_15_12 = self.env.ref('finance.voucher_12')
  451. self.checkout_voucher = self.env.ref('finance.voucher_12_1')
  452. self.period_15_12 = self.env.ref('finance.period_201512')
  453. def test_button_checkout(self):
  454. '''结账按钮,及新建wizard时的onchange'''
  455. checkout_obj = self.env['checkout.wizard']
  456. wizard = checkout_obj.create({'date': '2016-01-02'})
  457. # onchange 拿到会计期间
  458. wizard.onchange_period_id()
  459. self.assertTrue(wizard.period_id.name == '201601')
  460. # 上期间未关闭报错
  461. with self.assertRaises(UserError):
  462. wizard.button_checkout()
  463. wizard.date = '2015-12-31'
  464. wizard.onchange_period_id()
  465. # 本期间已结账报错
  466. self.period_15_12.is_closed = True
  467. with self.assertRaises(UserError):
  468. wizard.button_checkout()
  469. self.period_15_12.is_closed = False
  470. # 期间内凭证未审核报错
  471. with self.assertRaises(UserError):
  472. wizard.button_checkout()
  473. # 正常流程
  474. self.voucher_15_12.voucher_done()
  475. self.checkout_voucher.voucher_done()
  476. wizard.button_checkout()
  477. # 费用大于收入
  478. wizard.button_counter_checkout()
  479. self.env.ref('finance.voucher_12_2_debit').debit = 100000
  480. self.env.ref('finance.voucher_12_2_credit').credit = 100000
  481. wizard.button_checkout()
  482. # 检查下一个会计期间
  483. self.env.ref('finance.voucher_1').voucher_done()
  484. self.env.ref('finance.voucher_2').voucher_done()
  485. self.env.ref('finance.voucher_4').voucher_done()
  486. self.env.ref('finance.voucher_14_12').voucher_done()
  487. wizard.date = '2016-01-31'
  488. wizard.onchange_period_id()
  489. wizard.button_checkout()
  490. wizard.date = '2016-02-28'
  491. wizard.onchange_period_id()
  492. wizard.button_checkout()
  493. wizard.date = '2014-12-28'
  494. wizard.onchange_period_id()
  495. wizard.button_checkout()
  496. # 反结账时下一期间已关闭
  497. next_period = self.env[
  498. 'create.trial.balance.wizard'].compute_next_period_id(
  499. wizard.period_id)
  500. next_period.is_closed = True
  501. with self.assertRaises(UserError):
  502. wizard.button_counter_checkout()
  503. next_period.is_closed = False
  504. # 重复反结账
  505. wizard.button_counter_checkout()
  506. with self.assertRaises(UserError):
  507. wizard.button_counter_checkout()
  508. # 公司科目未配置报错
  509. company_pro = self.env.ref('base.main_company')
  510. company_pro.profit_account = False
  511. with self.assertRaises(UserError):
  512. wizard.button_checkout()
  513. company_pro.profit_account = self.env.ref('finance.account_profit')
  514. company_pro.remain_account = False
  515. with self.assertRaises(UserError):
  516. wizard.button_checkout()
  517. def test_button_checkout_period_month_notEuqal_12(self):
  518. ''' 结账按钮, 下一个期间不存在 month 不等于 12 '''
  519. wizard = self.env['checkout.wizard'].create({'date': '2016-05-13'})
  520. self.voucher_15_12.date = '2016-05-12'
  521. self.voucher_15_12.voucher_done()
  522. wizard.onchange_period_id()
  523. self.env.ref('finance.period_201604').is_closed = True
  524. wizard.button_checkout()
  525. def test_recreate_voucher_name(self):
  526. '''按用户设置重排结账会计期间凭证号(会计要求凭证号必须连续)'''
  527. # FIXME: 没有成功
  528. self.env['ir.default'].set(
  529. 'finance.config.settings', 'defaul_auto_reset', True)
  530. # 结转2015年12月的期间
  531. wizard = self.env['checkout.wizard'].create(
  532. {'date': '2015-12-31'})
  533. self.voucher_15_12.voucher_done()
  534. self.checkout_voucher.voucher_done()
  535. wizard.button_checkout()
  536. def test_recreate_voucher_name_1(self):
  537. ''' Test: recreate_voucher_name 按年重排 '''
  538. wizard = self.env['checkout.wizard'].create(
  539. {'date': '2015-12-31'})
  540. self.env['ir.default'].set(
  541. 'finance.config.settings', 'defaul_reset_period', 'year')
  542. self.env['ir.default'].set(
  543. 'finance.config.settings', 'defaul_auto_reset', True)
  544. self.env['ir.default'].set(
  545. 'finance.config.settings', 'defaul_reset_init_number', 2)
  546. wizard.period_id = self.env.ref('finance.period_201512')
  547. self.voucher_15_12.voucher_done()
  548. self.checkout_voucher.voucher_done()
  549. wizard.button_checkout()
  550. class TestReportVoucher(TransactionCase):
  551. def test_action_report(self):
  552. arpw = ReportVoucher
  553. arpw._rmb_upper(self, 1000)
  554. arpw._rmb_format(self, 1000)
  555. arpw._rmb_format(self, 0.001)
  556. arpw._paginate(self, [190, 2092, 34934, 5405])
  557. class TestReportAuxiliaryAccounting(TransactionCase):
  558. ''' 测试 辅助核算余额表 '''
  559. def setUp(self):
  560. super(TestReportAuxiliaryAccounting, self).setUp()
  561. self.voucher_15_12 = self.env.ref('finance.voucher_12')
  562. self.checkout_voucher = self.env.ref('finance.voucher_12_1')
  563. self.period_15_12 = self.env.ref('finance.period_201512')
  564. def test_view_voucher_line_detail(self):
  565. ''' 测试 辅助核算余额表 查看明细 按钮 '''
  566. # 创建 辅助核算项目
  567. auxiliary_id = self.env['auxiliary.financing'].create({
  568. 'name': 'gooderp project',
  569. 'code': '20160001',
  570. 'type': 'project',
  571. })
  572. self.env.ref(
  573. 'finance.voucher_line_12_debit').auxiliary_id = auxiliary_id.id
  574. self.env['report.auxiliary.accounting'].view_voucher_line_detail()
上海开阖软件有限公司 沪ICP备12045867号-1