Skip to content
Permalink
Browse files

[IMP] stock: allow to change picking on returns

The code that generate the return lines is moved inside
an onchange. The purpose is to allow an inherit that will
modify the picking_id of the wizard. It should trigger the
new return lines without a call to default_get.

task_id 1909413
  • Loading branch information...
amoyaux committed Mar 18, 2019
1 parent 709b0bd commit 1138a9a05b37dde528f593b989a3165fc42fda34
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.tests import common, Form
from odoo.tests.common import Form, TransactionCase


class TestSaleMrpFlow(common.TransactionCase):
class TestSaleMrpFlow(TransactionCase):

def setUp(self):
super(TestSaleMrpFlow, self).setUp()
@@ -355,14 +355,10 @@ def test_01_sale_mrp_kit_qty_delivered(self):
self.assertEquals(order_line.qty_received, 7.0)

# Return all components processed by backorder_3
default_data = self.env['stock.return.picking'].with_context(
active_ids=backorder_3.ids,
active_id=backorder_3.ids[0]
).default_get(['move_dest_exists', 'original_location_id', 'product_return_moves', 'parent_location_id', 'location_id'])
return_wiz = self.env['stock.return.picking'].with_context(
active_ids=backorder_3.ids,
active_id=backorder_3.ids[0]
).create(default_data)
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=backorder_3.ids, active_id=backorder_3.ids[0],
active_model='stock.picking'))
return_wiz = stock_return_picking_form.save()
for return_move in return_wiz.product_return_moves:
return_move.write({
'quantity': expected_quantities[return_move.product_id],
@@ -379,14 +375,10 @@ def test_01_sale_mrp_kit_qty_delivered(self):
# Now quantity received should be 3 again
self.assertEquals(order_line.qty_received, 3)

default_data = self.env['stock.return.picking'].with_context(
active_ids=return_pick.ids,
active_id=return_pick.ids[0]
).default_get(['move_dest_exists', 'original_location_id', 'product_return_moves', 'parent_location_id', 'location_id'])
return_wiz = self.env['stock.return.picking'].with_context(
active_ids=return_pick.ids,
active_id=return_pick.ids[0]
).create(default_data)
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=return_pick.ids, active_id=return_pick.ids[0],
active_model='stock.picking'))
return_wiz = stock_return_picking_form.save()
for move in return_wiz.product_return_moves:
move.quantity = expected_quantities[move.product_id]
res = return_wiz.create_returns()
@@ -6,7 +6,7 @@
import time

from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import ValuationReconciliationTestCase
from odoo.tests import tagged
from odoo.tests.common import Form, tagged


@tagged('post_install', '-at_install')
@@ -113,8 +113,10 @@ def test_invoice_shipment(self):
})

# Return the goods and refund the invoice
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=[picking.id], active_id=picking.id).create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking.ids, active_id=picking.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 1.0
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
@@ -3,7 +3,7 @@
import time

from .common import TestPurchase

from odoo.tests.common import Form

class TestFifoReturns(TestPurchase):

@@ -72,8 +72,10 @@ def test_fifo_returns(self):

# Return the goods of purchase order 2
picking = purchase_order_2.picking_ids[0]
return_pick_wiz = self.env['stock.return.picking'].with_context(
active_model='stock.picking', active_id=picking.id).create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking.ids, active_id=picking.ids[0],
active_model='stock.picking'))
return_pick_wiz = stock_return_picking_form.save()
return_picking_id, dummy = return_pick_wiz.with_context(active_id=picking.id)._create_returns()

# Important to pass through confirmation and assignation
@@ -5,7 +5,7 @@

from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.tests import tagged
from odoo.tests import Form, tagged


@tagged('post_install', '-at_install')
@@ -129,11 +129,12 @@ def test_02_po_return(self):
self.assertEqual(received_qty, 10.0, 'Purchase: Received quantity should be 10.0 instead of %s after validating incoming shipment' % received_qty)

# Create return picking
StockReturnPicking = self.env['stock.return.picking']
pick = self.po.picking_ids
default_data = StockReturnPicking.with_context(active_ids=pick.ids, active_id=pick.ids[0]).default_get(['move_dest_exists', 'original_location_id', 'product_return_moves', 'parent_location_id', 'location_id'])
return_wiz = StockReturnPicking.with_context(active_ids=pick.ids, active_id=pick.ids[0]).create(default_data)
return_wiz.product_return_moves.write({'quantity': 2.0, 'to_refund': True}) # Return only 2
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=pick.ids, active_id=pick.ids[0],
active_model='stock.picking'))
return_wiz = stock_return_picking_form.save()
return_wiz.product_return_moves.write({'quantity': 2.0, 'to_refund': True}) # Return only 2
res = return_wiz.create_returns()
return_pick = self.env['stock.picking'].browse(res['res_id'])

@@ -391,9 +391,10 @@ def test_fifo_anglosaxon_return(self):
self.assertEqual(self.product1.stock_value, 300)

# return the second po
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=receipt_po2.ids, active_id=receipt_po2.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=receipt_po2.ids, active_id=receipt_po2.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 10
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
@@ -921,10 +921,10 @@ def test_04_sale_mrp_kit_qty_delivered(self):
self.assertEquals(order_line.qty_delivered, 7.0)

# Return all components processed by backorder_3
StockReturnPicking = self.env['stock.return.picking']
default_data = StockReturnPicking.with_context(active_ids=backorder_3.ids, active_id=backorder_3.ids[0]).default_get(
['move_dest_exists', 'original_location_id', 'product_return_moves', 'parent_location_id', 'location_id'])
return_wiz = StockReturnPicking.with_context(active_ids=backorder_3.ids, active_id=backorder_3.ids[0]).create(default_data)
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=backorder_3.ids, active_id=backorder_3.ids[0],
active_model='stock.picking'))
return_wiz = stock_return_picking_form.save()
for return_move in return_wiz.product_return_moves:
return_move.write({
'quantity': expected_quantities[return_move.product_id],
@@ -941,10 +941,10 @@ def test_04_sale_mrp_kit_qty_delivered(self):
# Now quantity delivered should be 3 again
self.assertEquals(order_line.qty_delivered, 3)

default_data = StockReturnPicking.with_context(active_ids=return_pick.ids, active_id=return_pick.ids[0]).default_get(
['move_dest_exists', 'original_location_id', 'product_return_moves', 'parent_location_id', 'location_id'])
return_wiz = StockReturnPicking.with_context(active_ids=return_pick.ids, active_id=return_pick.ids[0]).create(
default_data)
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=return_pick.ids, active_id=return_pick.ids[0],
active_model='stock.picking'))
return_wiz = stock_return_picking_form.save()
for move in return_wiz.product_return_moves:
move.quantity = expected_quantities[move.product_id]
res = return_wiz.create_returns()
@@ -4,7 +4,7 @@
import time

from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import ValuationReconciliationTestCase
from odoo.tests import tagged
from odoo.tests import Form, tagged


@tagged('post_install', '-at_install')
@@ -139,8 +139,10 @@ def test_invoice_shipment(self):
'rate': 10.54739702,
'name': '2018-03-01',
})
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=[picking.id], active_id=picking.id).create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking.ids, active_id=picking.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 1.0
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
@@ -3,7 +3,7 @@

from odoo.addons.sale.tests.test_sale_common import TestSale
from odoo.exceptions import UserError
from odoo.tests import tagged
from odoo.tests import Form, tagged


@tagged('post_install', '-at_install')
@@ -159,9 +159,10 @@ def test_02_sale_stock_return(self):
self.inv_1.action_invoice_open()

# Create return picking
StockReturnPicking = self.env['stock.return.picking']
default_data = StockReturnPicking.with_context(active_ids=pick.ids, active_id=pick.ids[0]).default_get(['move_dest_exists', 'original_location_id', 'product_return_moves', 'parent_location_id', 'location_id'])
return_wiz = StockReturnPicking.with_context(active_ids=pick.ids, active_id=pick.ids[0]).create(default_data)
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=pick.ids, active_id=pick.ids[0],
active_model='stock.picking'))
return_wiz = stock_return_picking_form.save()
return_wiz.product_return_moves.quantity = 2.0 # Return only 2
return_wiz.product_return_moves.to_refund = True # Refund these 2
res = return_wiz.create_returns()
@@ -3,8 +3,7 @@

from odoo.addons.stock.tests.common import TestStockCommon
from odoo.exceptions import UserError
from odoo import api, registry
from odoo.tests.common import TransactionCase
from odoo.tests import Form


class TestPickShip(TestStockCommon):
@@ -174,10 +173,12 @@ def test_mto_moves_return(self):
self.assertEqual(picking_client.state, 'assigned')

# return a part of what we've done
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0])\
.create({})
stock_return_picking.product_return_moves.quantity = 2.0 # Return only 2
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 2.0 # Return only 2
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
return_pick.move_lines[0].move_line_ids[0].qty_done = 2.0
@@ -197,9 +198,10 @@ def test_mto_moves_return_extra(self):
self.assertEqual(picking_client.state, 'assigned')

# return more than we've done
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 12.0 # Return 2 extra
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
@@ -440,18 +442,20 @@ def test_pick_ship_return(self):
output. This return should not be available and should only have
picking pick as origin move.
"""
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 10.0
stock_return_picking_action = stock_return_picking.create_returns()
return_pick_picking = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])

self.assertEqual(return_pick_picking.state, 'waiting')

stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_ship.ids, active_id=picking_ship.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_ship.ids, active_id=picking_ship.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 10.0
stock_return_picking_action = stock_return_picking.create_returns()
return_ship_picking = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
@@ -514,9 +518,10 @@ def test_pick_pack_ship_return(self):
picking_ship.move_lines[0].move_line_ids[0].qty_done = 1.0
picking_ship.action_done()

stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_ship.ids, active_id=picking_ship.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_ship.ids, active_id=picking_ship.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 1.0
stock_return_picking_action = stock_return_picking.create_returns()
return_ship_picking = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
@@ -527,19 +532,21 @@ def test_pick_pack_ship_return(self):
})
return_ship_picking.action_done()

stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_pack.ids, active_id=picking_pack.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_pack.ids, active_id=picking_pack.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 1.0
stock_return_picking_action = stock_return_picking.create_returns()
return_pack_picking = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])

return_pack_picking.move_lines[0].move_line_ids[0].qty_done = 1.0
return_pack_picking.action_done()

stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_pick.ids, active_id=picking_pick.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 1.0
stock_return_picking_action = stock_return_picking.create_returns()
return_pick_picking = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
@@ -680,9 +687,10 @@ def test_return_location(self):
picking_client.action_done()

# return half in the pick location
return1 = self.env['stock.return.picking']\
.with_context(active_ids=picking_pick.ids, active_id=picking_client.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_client.ids, active_id=picking_client.ids[0],
active_model='stock.picking'))
return1 = stock_return_picking_form.save()
return1.product_return_moves.quantity = 5.0
return1.location_id = pick_location.id
return_to_pick_picking_action = return1.create_returns()
@@ -692,9 +700,10 @@ def test_return_location(self):
return_to_pick_picking.action_done()

# return the remainig products in the return warehouse
return2 = self.env['stock.return.picking']\
.with_context(active_ids=picking_pick.ids, active_id=picking_client.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_client.ids, active_id=picking_client.ids[0],
active_model='stock.picking'))
return2 = stock_return_picking_form.save()
return2.product_return_moves.quantity = 5.0
return2.location_id = return_location.id
return_to_return_picking_action = return2.create_returns()
@@ -158,9 +158,10 @@ def test_inventory_adjustment_and_negative_quants_1(self):

quant = self.env['stock.quant'].search([('product_id', '=', productA.id), ('location_id', '=', stock_location.id)])
self.assertEqual(len(quant), 1)
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_out.ids, active_id=picking_out.ids[0])\
.create({})
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=picking_out.ids, active_id=picking_out.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 1.0
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
Oops, something went wrong.

0 comments on commit 1138a9a

Please sign in to comment.
You can’t perform that action at this time.