Skip to content
Snippets Groups Projects
Commit 30de83a5 authored by Mathieu Walravens's avatar Mathieu Walravens
Browse files

[FIX] stock_account: correct accounts for dropship return


Before this commit:
When returning a dropshipping, the valuation layers created do not have
the correct accounts on it:
 - Valuation -> Input   for the first SVL
 - Output -> Valuation  for the second SVL

After this commit:
For a dropshipped move, valuation layers have the following chain
of accounts:
 - Input -> Valuation   for the first SVL
 - Valuation -> Output  for the second SVL
Therefore, the return should have it reversed:
 - Output -> Valuation  for the first SVL
 - Valuation -> Input   for the second SVL

Steps to reproduce:
1. Create a dropship product with automated inventory valuation
2. Create a Sales Order, go on the PO and confirm it
3. Set quantities and validate dropshipping
4. Return delivered product (dropship return)

opw-3391174

closes odoo/odoo#132864

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent f5fca171
No related branches found
No related tags found
No related merge requests found
......@@ -515,11 +515,13 @@ class StockMove(models.Model):
cost = -1 * cost
self.with_company(self.company_id)._create_account_move_line(acc_valuation, acc_dest, journal_id, qty, description, svl_id, cost)
elif self._is_dropshipped_returned():
if cost > 0:
if cost > 0 and self.location_dest_id._should_be_valued():
self.with_company(self.company_id)._create_account_move_line(acc_valuation, acc_src, journal_id, qty, description, svl_id, cost)
elif cost > 0:
self.with_company(self.company_id)._create_account_move_line(acc_dest, acc_valuation, journal_id, qty, description, svl_id, cost)
else:
cost = -1 * cost
self.with_company(self.company_id)._create_account_move_line(acc_dest, acc_valuation, journal_id, qty, description, svl_id, cost)
self.with_company(self.company_id)._create_account_move_line(acc_valuation, acc_src, journal_id, qty, description, svl_id, cost)
if self.company_id.anglo_saxon_accounting:
# Eventually reconcile together the invoice and valuation accounting entries on the stock interim accounts
......
......@@ -1076,3 +1076,89 @@ class TestAngloSaxonAccounting(TestStockValuationCommon):
self.assertEqual(len(anglo_lines), 2)
self.assertEqual(abs(anglo_lines[0].balance), 10)
self.assertEqual(abs(anglo_lines[1].balance), 10)
def test_dropship_return_accounts_1(self):
"""
When returning a dropshipped move, make sure the correct accounts are used
"""
# pylint: disable=bad-whitespace
self.product1.categ_id.property_cost_method = 'fifo'
move1 = self._make_dropship_move(self.product1, 2, unit_cost=10)
move2 = self._make_return(move1, 2)
# First: Input -> Valuation
# Second: Valuation -> Output
origin_svls = move1.stock_valuation_layer_ids.sorted('quantity', reverse=True)
# First: Output -> Valuation
# Second: Valuation -> Input
return_svls = move2.stock_valuation_layer_ids.sorted('quantity', reverse=True)
self.assertEqual(len(origin_svls), 2)
self.assertEqual(len(return_svls), 2)
acc_in, acc_out, acc_valuation = self.stock_input_account, self.stock_output_account, self.stock_valuation_account
# Dropshipping should be: Input -> Output
self.assertRecordValues(origin_svls[0].account_move_id.line_ids, [
{'account_id': acc_in.id, 'debit': 0, 'credit': 20},
{'account_id': acc_valuation.id, 'debit': 20, 'credit': 0},
])
self.assertRecordValues(origin_svls[1].account_move_id.line_ids, [
{'account_id': acc_valuation.id, 'debit': 0, 'credit': 20},
{'account_id': acc_out.id, 'debit': 20, 'credit': 0},
])
# Return should be: Output -> Input
self.assertRecordValues(return_svls[0].account_move_id.line_ids, [
{'account_id': acc_out.id, 'debit': 0, 'credit': 20},
{'account_id': acc_valuation.id, 'debit': 20, 'credit': 0},
])
self.assertRecordValues(return_svls[1].account_move_id.line_ids, [
{'account_id': acc_valuation.id, 'debit': 0, 'credit': 20},
{'account_id': acc_in.id, 'debit': 20, 'credit': 0},
])
def test_dropship_return_accounts_2(self):
"""
When returning a dropshipped move, make sure the correct accounts are used
"""
# pylint: disable=bad-whitespace
self.product1.categ_id.property_cost_method = 'fifo'
move1 = self._make_dropship_move(self.product1, 2, unit_cost=10)
# return to WH/Stock
stock_return_picking = Form(self.env['stock.return.picking']\
.with_context(active_ids=[move1.picking_id.id], active_id=move1.picking_id.id, active_model='stock.picking'))
stock_return_picking = stock_return_picking.save()
stock_return_picking.product_return_moves.quantity = 2
stock_return_picking.location_id = self.stock_location
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
return_pick._action_done()
move2 = return_pick.move_lines
# First: Input -> Valuation
# Second: Valuation -> Output
origin_svls = move1.stock_valuation_layer_ids.sorted('quantity', reverse=True)
# Only one: Output -> Valuation
return_svl = move2.stock_valuation_layer_ids
self.assertEqual(len(origin_svls), 2)
self.assertEqual(len(return_svl), 1)
acc_in, acc_out, acc_valuation = self.stock_input_account, self.stock_output_account, self.stock_valuation_account
# Dropshipping should be: Input -> Output
self.assertRecordValues(origin_svls[0].account_move_id.line_ids, [
{'account_id': acc_in.id, 'debit': 0, 'credit': 20},
{'account_id': acc_valuation.id, 'debit': 20, 'credit': 0},
])
self.assertRecordValues(origin_svls[1].account_move_id.line_ids, [
{'account_id': acc_valuation.id, 'debit': 0, 'credit': 20},
{'account_id': acc_out.id, 'debit': 20, 'credit': 0},
])
# Return should be: Output -> Valuation
self.assertRecordValues(return_svl.account_move_id.line_ids, [
{'account_id': acc_out.id, 'debit': 0, 'credit': 20},
{'account_id': acc_valuation.id, 'debit': 20, 'credit': 0},
])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment