[IMP] stock: should not generate sequence when scrap order is created

-It will not create sequence while creating a scrap order but it will
create it after validating scrap order.

task-1959647
This commit is contained in:
Shreya Modi
2019-08-23 12:42:39 +00:00
parent 83e1915edd
commit 976334dafb
2 changed files with 4 additions and 8 deletions
+2 -8
View File
@@ -37,7 +37,7 @@ class StockScrap(models.Model):
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
tracking = fields.Selection('Product Tracking', readonly=True, related="product_id.tracking")
lot_id = fields.Many2one(
'stock.production.lot', 'Lot',
'stock.production.lot', 'Lot/Serial',
states={'done': [('readonly', True)]}, domain="[('product_id', '=', product_id)]")
package_id = fields.Many2one(
'stock.quant.package', 'Package',
@@ -76,13 +76,6 @@ class StockScrap(models.Model):
self.location_id = move_line.location_id
break
@api.model
def create(self, vals):
if 'name' not in vals or vals['name'] == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('stock.scrap') or _('New')
scrap = super(StockScrap, self).create(vals)
return scrap
def unlink(self):
if 'done' in self.mapped('state'):
raise UserError(_('You cannot delete a scrap which is done.'))
@@ -121,6 +114,7 @@ class StockScrap(models.Model):
def do_scrap(self):
for scrap in self:
scrap.name = self.env['ir.sequence'].next_by_code('stock.scrap') or _('New')
move = self.env['stock.move'].create(scrap._prepare_move_values())
# master: replace context by cancel_backorder
move.with_context(is_scrap=True)._action_done()
+2
View File
@@ -3564,7 +3564,9 @@ class StockMove(SavepointCase):
'product_uom_id':self.product_consu.uom_id.id,
'scrap_qty': 1,
})
self.assertEqual(scrap.name, 'New', 'Name should be New in draft state')
scrap.do_scrap()
self.assertTrue(scrap.name.startswith('SP/'), 'Sequence should be Changed after do_scrap')
self.assertEqual(scrap.state, 'done')
move = scrap.move_id
self.assertEqual(move.state, 'done')