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.

207 líneas
9.3KB

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests.common import TransactionCase
  4. from odoo.exceptions import UserError
  5. class TestInvoice(TransactionCase):
  6. def setUp(self):
  7. '''依赖设置'''
  8. super(TestInvoice, self).setUp()
  9. # 客户分类
  10. self.cate = self.env['core.category'].create({
  11. 'name': '测试客户',
  12. 'account_id': self.env.ref("finance.account_ar").id,
  13. 'type': 'customer',
  14. })
  15. self.partner = self.env['partner'].create({
  16. 'name': 'Jeff',
  17. 'c_category_id': self.cate.id,
  18. 'main_mobile': '14957236658',
  19. })
  20. def tearDown(self):
  21. '''依赖移除'''
  22. self.partner.unlink()
  23. self.cate.unlink()
  24. super(TestInvoice, self).tearDown()
  25. def test_create_delete(self):
  26. '''测试发票创建和删除'''
  27. # 创建发票
  28. invoice = self.env['money.invoice'].create({'name': 'new_test_invoice',
  29. 'partner_id': self.partner.id, 'date': "2016-02-20",
  30. 'category_id': self.env.ref('money.core_category_sale').id,
  31. 'amount': 10.0})
  32. # 如果公司的 draft_invoice参数未设,发票自动审核
  33. if self.env.ref('base.main_company').draft_invoice:
  34. self.assertEqual(invoice.state, 'draft')
  35. # 发票审核
  36. invoice.money_invoice_done()
  37. # 确认发票为已审核状态
  38. self.assertEqual(invoice.state, 'done')
  39. # 客户的应收余额
  40. self.assertEqual(self.partner.receivable, 10.0)
  41. # 已审核的发票应该不可删除
  42. with self.assertRaises(UserError):
  43. invoice.unlink()
  44. # 发票取消审核
  45. invoice.money_invoice_draft()
  46. # 客户的应收余额
  47. self.assertEqual(self.partner.receivable, 0.0)
  48. # 未审核的发票可以删除
  49. invoice.unlink()
  50. supplier = self.env.ref('core.lenovo')
  51. supplier.s_category_id.account_id = self.env.ref(
  52. "finance.account_ap").id
  53. # 执行money_invoice_draft()的if category_id.type == 'expense'
  54. invoice_buy = self.env['money.invoice'].create({'name': 'buy_invoice', 'date': "2016-02-20",
  55. 'partner_id': supplier.id,
  56. 'category_id': self.env.ref('money.core_category_purchase').id,
  57. 'amount': 10.0})
  58. invoice_buy.money_invoice_draft()
  59. # 只允许删除未审核的单据
  60. invoice_unlink = self.env['money.invoice'].create({'name': '.',
  61. 'date': "2016-02-20",
  62. 'partner_id': supplier.id,
  63. 'category_id': self.env.ref('money.core_category_purchase').id,
  64. 'amount': 10.0})
  65. invoice_unlink.unlink()
  66. def test_write(self):
  67. ''' Test: When change date_due, the one with the same bill_number update together '''
  68. # 创建发票
  69. invoice_obj = self.env['money.invoice']
  70. invoice_1 = invoice_obj.create({'name': 'test_invoice_1',
  71. 'partner_id': self.env.ref('core.jd').id,
  72. 'date': "2016-02-20",
  73. 'category_id': self.env.ref('money.core_category_sale').id,
  74. 'amount': 10.0})
  75. invoice_2 = invoice_obj.create({'name': 'test_invoice_2',
  76. 'partner_id': self.env.ref('core.yixun').id,
  77. 'date': "2016-02-26",
  78. 'category_id': self.env.ref('money.core_category_sale').id,
  79. 'amount': 20.0})
  80. invoice_1.bill_number = '666'
  81. invoice_2.bill_number = '666'
  82. invoice_1.date_due = '2016-02-28'
  83. invoice_1.money_invoice_draft()
  84. invoice_2.money_invoice_draft()
  85. # 结算单 不可重复撤销 报错
  86. with self.assertRaises(UserError):
  87. invoice_2.money_invoice_draft()
  88. def test_money_invoice_draft_voucher_done(self):
  89. '''发票生成的凭证已审核时,反审核发票'''
  90. supplier = self.env.ref('core.lenovo')
  91. supplier.s_category_id.account_id = self.env.ref(
  92. "finance.account_ap").id
  93. invoice_buy = self.env['money.invoice'].create({'name': 'buy_invoice', 'date': "2016-02-20",
  94. 'partner_id': supplier.id,
  95. 'category_id': self.env.ref('money.core_category_purchase').id,
  96. 'amount': 10.0})
  97. invoice_buy.money_invoice_draft()
  98. def test_money_invoice_voucher_line_currency(self):
  99. ''' 创建凭证行时,invoice与公司的币别不同的情况 '''
  100. invoice = self.env['money.invoice'].create({
  101. 'name': 'invoice', 'date': "2016-02-20",
  102. 'partner_id': self.env.ref('core.jd').id,
  103. 'category_id': self.env.ref('money.core_category_sale').id,
  104. 'amount': 10.0,
  105. 'currency_id': self.env.ref('base.USD').id})
  106. def test_money_invoice_company_no_tax_account(self):
  107. ''' 创建 进项税行 公司 进项税科目 未设置 '''
  108. self.env.user.company_id.draft_invoice = True
  109. # 进项税行 import_tax_account
  110. buy_invoice = self.env['money.invoice'].create({
  111. 'name': 'invoice', 'date': "2016-02-20",
  112. 'partner_id': self.env.ref('core.lenovo').id,
  113. 'category_id': self.env.ref('money.core_category_purchase').id,
  114. 'amount': 10.0,
  115. 'tax_amount': 11.7})
  116. self.env.user.company_id.import_tax_account = False
  117. with self.assertRaises(UserError):
  118. buy_invoice.money_invoice_done()
  119. # 销项税行 output_tax_account
  120. sell_invoice = self.env['money.invoice'].create({
  121. 'name': 'invoice', 'date': "2016-02-20",
  122. 'partner_id': self.env.ref('core.jd').id,
  123. 'category_id': self.env.ref('money.core_category_sale').id,
  124. 'amount': 10.0,
  125. 'tax_amount': 11.7})
  126. self.env.user.company_id.output_tax_account = False
  127. with self.assertRaises(UserError):
  128. sell_invoice.money_invoice_done()
  129. def test_money_invoice_done_no_category_account(self):
  130. '''结算单分类上无科目审核报错'''
  131. self.env.user.company_id.draft_invoice = True
  132. cate = self.env['core.category'].create({
  133. 'name': '测试客户类别',
  134. 'type': 'customer',
  135. })
  136. invoice = self.env['money.invoice'].create({
  137. 'name': 'invoice', 'date': "2016-02-20",
  138. 'partner_id': self.env.ref('core.lenovo').id,
  139. 'category_id': cate.id,
  140. 'amount': 10.0,
  141. 'tax_amount': 11.7})
  142. with self.assertRaises(UserError):
  143. invoice.money_invoice_done()
  144. def test_money_invoice_done_no_partner_category_account(self):
  145. '''结算单客户分类上无科目审核报错'''
  146. self.env.user.company_id.draft_invoice = True
  147. cate = self.env['core.category'].create({
  148. 'name': '测试客户类别',
  149. 'type': 'customer',
  150. })
  151. self.env.ref('core.jd').c_category_id = cate
  152. invoice = self.env['money.invoice'].create({
  153. 'name': 'invoice', 'date': "2016-02-20",
  154. 'partner_id': self.env.ref('core.jd').id,
  155. 'category_id': self.env.ref('money.core_category_sale').id,
  156. 'amount': 10.0,
  157. 'tax_amount': 11.7})
  158. with self.assertRaises(UserError):
  159. invoice.money_invoice_done()
  160. def test_money_invoice_name_get(self):
  161. ''' 测试 money invoice name_get 方法 '''
  162. inv = self.env['money.invoice'].create({
  163. 'name': 'invoice', 'date': "2016-02-20",
  164. 'partner_id': self.env.ref('core.jd').id,
  165. 'category_id': self.env.ref('money.core_category_sale').id,
  166. 'amount': 10.0,
  167. 'tax_amount': 11.7
  168. })
  169. # 发票号不存在取 订单编号
  170. inv_name = inv.name_get()
  171. real_name = '%s' % (inv.name)
  172. self.assertTrue(inv_name[0][1] == real_name)
  173. # 发票号存在取 发票号
  174. inv.bill_number = '201600001'
  175. inv_name_bill = inv.name_get()
  176. real_name_bill = '%s' % (inv.bill_number)
  177. self.assertTrue(inv_name_bill[0][1] == real_name_bill)
  178. def test_money_invoice_compute_overdue(self):
  179. """
  180. 计算逾期天数、计算逾期金额
  181. """
  182. invoice = self.env['money.invoice'].create({
  183. 'name': 'invoice', 'date': "2016-02-20",
  184. 'partner_id': self.env.ref('core.jd').id,
  185. 'category_id': self.env.ref('money.core_category_sale').id,
  186. 'amount': 117,
  187. 'tax_amount': 17,
  188. })
  189. invoice.date_due = '2016-04-10'
  190. self.assertEqual(invoice.overdue_amount, 117)
上海开阖软件有限公司 沪ICP备12045867号-1