GoodERP
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

281 行
12KB

  1. from odoo.tests.common import TransactionCase
  2. from odoo.exceptions import UserError
  3. class TestSellAdjust(TransactionCase):
  4. def setUp(self):
  5. '''销售变更单准备基本数据'''
  6. super(TestSellAdjust, self).setUp()
  7. self.env.ref('core.jd').credit_limit = 100000
  8. self.env.ref('core.goods_category_1').account_id = self.env.ref(
  9. 'finance.account_goods').id
  10. self.env.ref('warehouse.wh_in_whin0').date = '2016-02-06'
  11. # 销售订单 10个 网线
  12. self.order = self.env.ref('sell.sell_order_2')
  13. self.order.sell_order_done()
  14. self.keyboard = self.env.ref('goods.keyboard')
  15. self.keyboard_white = self.env.ref('goods.keyboard_white')
  16. self.mouse = self.env.ref('goods.mouse')
  17. self.cable = self.env.ref('goods.cable')
  18. # 因为下面要用到 商品在系统里面必须是有数量的 所以,找到一个简单的方式直接确认已有的盘点单
  19. warehouse_obj = self.env.ref('warehouse.wh_in_whin0')
  20. warehouse_obj.warehouse_dest_id = self.order.warehouse_id
  21. warehouse_obj.approve_order()
  22. for l in self.env['wh.move.line'].search([]):
  23. l.read()
  24. def test_unlink(self):
  25. '''测试删除已审核的销售变更单'''
  26. adjust = self.env['sell.adjust'].create({
  27. 'order_id': self.order.id,
  28. 'line_ids': [(0, 0, {'goods_id': self.cable.id,
  29. 'quantity': 2,
  30. }),
  31. ]
  32. })
  33. adjust.sell_adjust_done()
  34. with self.assertRaises(UserError):
  35. adjust.unlink()
  36. # 删除草稿状态的销售变更单
  37. new = adjust.copy()
  38. new.unlink()
  39. def test_sell_adjust_done(self):
  40. '''审核销售变更单:正常情况'''
  41. # 正常情况下审核,新增商品鼠标(每批次为1的)、键盘(无批次的)
  42. adjust = self.env['sell.adjust'].create({
  43. 'order_id': self.order.id,
  44. 'line_ids': [(0, 0, {'goods_id': self.cable.id,
  45. 'quantity': 2,
  46. }),
  47. (0, 0, {'goods_id': self.mouse.id,
  48. 'quantity': 1,
  49. }),
  50. (0, 0, {'goods_id': self.keyboard.id,
  51. 'attribute_id': self.keyboard_white.id,
  52. 'quantity': 1,
  53. })
  54. ]
  55. })
  56. adjust.sell_adjust_done()
  57. # 重复审核时报错
  58. with self.assertRaises(UserError):
  59. adjust.sell_adjust_done()
  60. def test_sell_adjust_done_no_line(self):
  61. '''审核销售变更单:没输入明细行,审核时报错'''
  62. adjust = self.env['sell.adjust'].create({
  63. 'order_id': self.order.id,
  64. })
  65. with self.assertRaises(UserError):
  66. adjust.sell_adjust_done()
  67. def test_sell_adjust_done_all_in(self):
  68. '''审核销售变更单:销售订单生成的发货单已全部出库,审核时报错'''
  69. new_order = self.order.copy()
  70. new_order.sell_order_done()
  71. delivery = self.env['sell.delivery'].search(
  72. [('order_id', '=', new_order.id)])
  73. delivery.discount_amount = 0 # 订单行中价格为0,所以整单金额0
  74. delivery.sell_delivery_done()
  75. adjust = self.env['sell.adjust'].create({
  76. 'order_id': new_order.id,
  77. 'line_ids': [(0, 0, {'goods_id': self.cable.id,
  78. 'quantity': 1,
  79. }),
  80. ]
  81. })
  82. with self.assertRaises(UserError):
  83. adjust.sell_adjust_done()
  84. def test_sell_adjust_done_more_same_line(self):
  85. '''审核销售变更单:查找到销售订单中多行同一商品,不能调整'''
  86. new_order = self.order.copy()
  87. new_order.line_ids.create({'order_id': new_order.id,
  88. 'goods_id': self.cable.id,
  89. 'quantity': 10,
  90. 'price_taxed': 10.0,
  91. })
  92. new_order.sell_order_done()
  93. delivery = self.env['sell.delivery'].search(
  94. [('order_id', '=', new_order.id)])
  95. for line in delivery.line_out_ids:
  96. line.goods_qty = 1
  97. delivery.discount_amount = 0 # 订单行中价格为0,所以整单金额0
  98. delivery.sell_delivery_done()
  99. adjust = self.env['sell.adjust'].create({
  100. 'order_id': new_order.id,
  101. 'line_ids': [(0, 0, {'goods_id': self.cable.id,
  102. 'quantity': 3.0,
  103. }),
  104. ]
  105. })
  106. with self.assertRaises(UserError):
  107. adjust.sell_adjust_done()
  108. def test_sell_adjust_done_quantity_lt(self):
  109. '''审核销售变更单:调整后数量 5 < 原订单已出库数量 6,审核时报错'''
  110. delivery = self.env['sell.delivery'].search(
  111. [('order_id', '=', self.order.id)])
  112. for line in delivery.line_out_ids:
  113. line.goods_qty = 6
  114. delivery.sell_delivery_done()
  115. adjust = self.env['sell.adjust'].create({
  116. 'order_id': self.order.id,
  117. 'line_ids': [(0, 0, {'goods_id': self.cable.id,
  118. 'quantity': -5,
  119. })]
  120. })
  121. with self.assertRaises(UserError):
  122. adjust.sell_adjust_done()
  123. def test_sell_adjust_done_quantity_equal(self):
  124. '''审核销售变更单:调整后数量6 == 原订单已出库数量 6,审核后将产生的发货单分单删除'''
  125. delivery = self.env['sell.delivery'].search(
  126. [('order_id', '=', self.order.id)])
  127. for line in delivery.line_out_ids:
  128. line.goods_qty = 6
  129. delivery.sell_delivery_done()
  130. adjust = self.env['sell.adjust'].create({
  131. 'order_id': self.order.id,
  132. 'line_ids': [(0, 0, {'goods_id': self.cable.id,
  133. 'quantity': -4,
  134. })]
  135. })
  136. adjust.sell_adjust_done()
  137. new_delivery = self.env['sell.delivery'].search(
  138. [('order_id', '=', self.order.id),
  139. ('state', '=', 'draft')])
  140. self.assertTrue(not new_delivery)
  141. def test_sell_adjust_done_goods_done(self):
  142. '''审核销售变更单:原始单据中一行商品已全部出库,另一行没有'''
  143. new_order = self.order.copy()
  144. new_order.line_ids.create({'order_id': new_order.id,
  145. 'goods_id': self.keyboard.id,
  146. 'attribute_id': self.keyboard_white.id,
  147. 'quantity': 10,
  148. 'price_taxed': 10.0,
  149. })
  150. new_order.sell_order_done()
  151. delivery = self.env['sell.delivery'].search(
  152. [('order_id', '=', new_order.id)])
  153. for line in delivery.line_out_ids:
  154. if line.goods_id.id != self.keyboard.id:
  155. line.unlink()
  156. delivery.discount_amount = 0 # 订单行中价格为0,所以整单金额0
  157. delivery.sell_delivery_done()
  158. adjust = self.env['sell.adjust'].create({
  159. 'order_id': new_order.id,
  160. 'line_ids': [(0, 0, {'goods_id': self.keyboard.id,
  161. 'attribute_id': self.keyboard_white.id,
  162. 'quantity': 3.0,
  163. }),
  164. ]
  165. })
  166. with self.assertRaises(UserError):
  167. adjust.sell_adjust_done()
  168. def test_sell_adjust_done_no_attribute(self):
  169. '''检查属性是否填充'''
  170. adjust = self.env['sell.adjust'].create({
  171. 'order_id': self.order.id,
  172. 'line_ids': [(0, 0, {'goods_id': self.keyboard.id,
  173. 'quantity': 3.0,
  174. }),
  175. ]
  176. })
  177. with self.assertRaises(UserError):
  178. adjust.sell_adjust_done()
  179. class TestSellAdjustLine(TransactionCase):
  180. def setUp(self):
  181. '''销售变更单明细基本数据'''
  182. super(TestSellAdjustLine, self).setUp()
  183. # 销售订单 10个 网线
  184. self.order = self.env.ref('sell.sell_order_2')
  185. self.order.sell_order_done()
  186. self.keyboard = self.env.ref('goods.keyboard')
  187. self.cable = self.env.ref('goods.cable')
  188. self.adjust = self.env['sell.adjust'].create({
  189. 'order_id': self.order.id,
  190. 'line_ids': [(0, 0, {'goods_id': self.cable.id,
  191. 'quantity': 1,
  192. })]
  193. })
  194. def test_compute_using_attribute(self):
  195. '''返回订单行中商品是否使用属性'''
  196. for line in self.adjust.line_ids:
  197. self.assertTrue(not line.using_attribute)
  198. line.goods_id = self.keyboard
  199. self.assertTrue(line.using_attribute)
  200. def test_compute_all_amount(self):
  201. '''当订单行的数量、单价、折扣额、税率改变时,改变销售金额、税额、价税合计'''
  202. for line in self.adjust.line_ids:
  203. line.price_taxed = 117
  204. self.assertTrue(line.amount == 100)
  205. self.assertTrue(line.tax_amount == 17)
  206. self.assertTrue(line.price_taxed == 117)
  207. self.assertTrue(line.subtotal == 117)
  208. def test_onchange_price(self):
  209. '''当订单行的不含税单价改变时,改变含税单价'''
  210. for line in self.adjust.line_ids:
  211. line.price_taxed = 0
  212. line.price = 10
  213. line.onchange_price()
  214. self.assertAlmostEqual(line.price_taxed, 11.7)
  215. def test_compute_all_amount_wrong_tax_rate(self):
  216. '''明细行上输入错误税率,应报错'''
  217. for line in self.adjust.line_ids:
  218. with self.assertRaises(UserError):
  219. line.tax_rate = -1
  220. with self.assertRaises(UserError):
  221. line.tax_rate = 102
  222. def test_onchange_goods_id(self):
  223. '''当销售订单行的商品变化时,带出商品上的单位、价格'''
  224. for line in self.adjust.line_ids:
  225. line.goods_id = self.keyboard
  226. line.onchange_goods_id()
  227. self.assertTrue(line.uom_id.name == '件')
  228. def test_onchange_discount_rate(self):
  229. ''' 订单行优惠率改变时,改变优惠金额'''
  230. for line in self.adjust.line_ids:
  231. line.price_taxed = 117
  232. line.discount_rate = 10
  233. line.onchange_discount_rate()
  234. def test_onchange_goods_id_tax_rate(self):
  235. ''' 测试 修改商品时,调整单行税率变化 '''
  236. self.adjust.partner_id = self.env.ref('core.jd')
  237. for order_line in self.adjust.line_ids:
  238. # partner 无 税率,调整单行商品无税率
  239. self.env.ref('core.jd').tax_rate = 0
  240. self.env.ref('goods.cable').tax_rate = 0
  241. order_line.onchange_goods_id()
  242. # partner 有 税率,调整单行商品无税率
  243. self.env.ref('core.jd').tax_rate = 10
  244. self.env.ref('goods.cable').tax_rate = 0
  245. order_line.onchange_goods_id()
  246. # partner 无税率,调整单行商品有税率
  247. self.env.ref('core.jd').tax_rate = 0
  248. self.env.ref('goods.cable').tax_rate = 10
  249. order_line.onchange_goods_id()
  250. # partner 税率 > 调整单行商品税率
  251. self.env.ref('core.jd').tax_rate = 11
  252. self.env.ref('goods.cable').tax_rate = 10
  253. order_line.onchange_goods_id()
  254. # partner 税率 =< 调整单行商品税率
  255. self.env.ref('core.jd').tax_rate = 9
  256. self.env.ref('goods.cable').tax_rate = 10
  257. order_line.onchange_goods_id()
上海开阖软件有限公司 沪ICP备12045867号-1