Skip to content

Commit

Permalink
Merge pull request #1873 from floraXiao/master
Browse files Browse the repository at this point in the history
[FIX]增加测试,变更单审核时检查属性是否填充
  • Loading branch information
floraXiao committed Jul 11, 2018
2 parents 580b5b7 + f8201b2 commit e06ed0c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
10 changes: 3 additions & 7 deletions buy/models/buy_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def buy_adjust_done(self):
if not buy_receipt:
raise UserError(u'采购入库单已全部入库,不能调整')
for line in self.line_ids:
# 检查属性是否填充,防止无权限人员不填就可以保存
if line.using_attribute and not line.attribute_id:
raise UserError(u'请输入商品:%s 的属性' % line.goods_id.name)
origin_line = self.env['buy.order.line'].search(
[('goods_id', '=', line.goods_id.id),
('attribute_id', '=', line.attribute_id.id),
Expand Down Expand Up @@ -239,10 +242,3 @@ def onchange_discount_rate(self):
self.price = self.price_taxed / (1 + self.tax_rate * 0.01)
self.discount_amount = (self.quantity * self.price *
self.discount_rate * 0.01)

@api.one
@api.constrains('attribute_id')
def check_attribute(self):
'''检查属性是否填充,防止无权限人员不填就可以保存'''
if self.using_attribute and not self.attribute_id:
raise UserError(u'请输入商品:%s 的属性' % self.goods_id.name)
11 changes: 11 additions & 0 deletions buy/tests/test_buy_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ def test_buy_adjust_done_goods_done(self):
with self.assertRaises(UserError):
adjust.buy_adjust_done()

def test_buy_adjust_done_no_attribute(self):
'''检查属性是否填充'''
adjust = self.env['buy.adjust'].create({
'order_id': self.order.id,
'line_ids': [(0, 0, {'goods_id': self.env.ref('goods.keyboard').id,
'quantity': 10,
})]
})
with self.assertRaises(UserError):
adjust.buy_adjust_done()


class TestBuyAdjustLine(TransactionCase):

Expand Down
10 changes: 3 additions & 7 deletions sell/models/sell_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def sell_adjust_done(self):
if not delivery:
raise UserError(u'销售发货单已全部出库,不能调整')
for line in self.line_ids:
# 检查属性是否填充,防止无权限人员不填就可以保存
if line.using_attribute and not line.attribute_id:
raise UserError(u'请输入商品:%s 的属性' % line.goods_id.name)
origin_line = self.env['sell.order.line'].search(
[('goods_id', '=', line.goods_id.id),
('attribute_id', '=', line.attribute_id.id),
Expand Down Expand Up @@ -245,10 +248,3 @@ def onchange_discount_rate(self):
self.price = self.price_taxed / (1 + self.tax_rate * 0.01)
self.discount_amount = (self.quantity * self.price *
self.discount_rate * 0.01)

@api.one
@api.constrains('attribute_id')
def check_attribute(self):
'''检查属性是否填充,防止无权限人员不填就可以保存'''
if self.using_attribute and not self.attribute_id:
raise UserError(u'请输入商品:%s 的属性' % self.goods_id.name)
18 changes: 18 additions & 0 deletions warehouse/tests/test_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,21 @@ def test_check_goods_qty(self):
# 鼠标进行了序列号管理
with self.assertRaises(ValidationError):
self.mouse_in_line.goods_qty = 2

def test_action_done_no_lot_raise_error(self):
'''检查属性或批号是否填充'''
# type=in,lot为空
self.mouse_in_line.lot = False
with self.assertRaises(UserError):
self.mouse_in_line.action_done()

# type=out,lot_id为空
self.mouse_out_line.lot_id = False
with self.assertRaises(UserError):
self.mouse_out_line.action_done()

# 属性为空
keyboard_line = self.env.ref('warehouse.wh_move_line_13')
keyboard_line.attribute_id = False
with self.assertRaises(UserError):
keyboard_line.action_done()

0 comments on commit e06ed0c

Please sign in to comment.