Browse files


  • Loading branch information...
Whenrow committed Jan 30, 2019
1 parent d765216 commit 0fbc8a29382b3d23c126d3fe00789426bfad74eb
Showing with 41 additions and 6 deletions.
  1. +34 −5 addons/mrp/tests/
  2. +7 −1 addons/stock/models/
@@ -2,7 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import common
from odoo.exceptions import except_orm
from odoo.exceptions import except_orm, UserError
from odoo.tests import Form

@@ -97,11 +97,40 @@ def test_manufacturing_scrap(self):
# Scrap Product Wood with lot.
self.env['stock.scrap'].with_context(active_model='mrp.production',{'product_id':, 'scrap_qty': 1.0, 'product_uom_id':, 'location_id': location_id, 'lot_id':, 'production_id':})

#Check scrap move is created for this production order.
#TODO: should check with scrap objects link in between
def test_manufacturing_scrap_2(self):
""" Testing to do a scrap of serial tracked consumed materialself.
Then consuming again the same serial number. We should be blocked """

# scrap_move = production_3.move_raw_ids.filtered(lambda x: x.product_id == self.product_2 and x.scrapped)
# self.assertTrue(scrap_move, "There are no any scrap move created for production order.")
mo, bom, p_final, compo1, compo2 = self.generate_mo(tracking_base_1='serial', qty_final=1, qty_base_1=1, qty_base_2=1)
sn1 = self.env['stock.production.lot'].create({
'name': 'sn1',
stock_inv_compo1 = self.env['stock.inventory'].create({
'name': 'Stock Inventory for Stick',
'filter': 'product',
'line_ids': [
(0, 0, {'product_id':, 'product_uom_id':, 'product_qty': 1, 'prod_lot_id':, 'location_id': self.ref('stock.stock_location_14')}),


# Scrap Product.
scrap_id = self.env['stock.scrap'].with_context(active_model='mrp.production',{'product_id':, 'scrap_qty': 1.0, 'lot_id':, 'product_uom_id':, 'location_id': self.ref('stock.stock_location_14'), 'production_id':})

# Try to consume sn1
produce_form = Form(self.env['mrp.product.produce'].with_context({
'active_ids': [],
product_produce =
product_produce.produce_line_ids.filtered(lambda line: line.product_id == compo1).lot_id =
with self.assertRaises(UserError):

class TestKitPicking(common.TestMrpCommon):
@@ -458,8 +458,14 @@ def _action_done(self, cancel_backorder=False):
if ml.tracking == 'serial' and ml.lot_id: # see test_inventory_4:
similar_quant = self.env['stock.quant'].search([
('lot_id', '=',,
('location_id.usage', 'not in', ('supplier', 'inventory', 'production'))
('location_id.usage', 'not in', ('supplier', 'inventory', 'production')),
('location_id.scrap_location', '=', True)
# Check if SN has been scrapped
scrapped = any([quant.location_id.scrap_location for quant in similar_quant])
if scrapped and not ml.location_dest_id.scrap_location:
raise UserError(_('You cannot move product %s having the serial number %s as it was scrapped previously' % (ml.product_id.display_name,
if similar_quant:
# the following step will group the quants by location usage
# if similar_quant =

0 comments on commit 0fbc8a2

Please sign in to comment.