|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # Part of Odoo. See LICENSE file for full copyright and licensing details. |
3 | 3 |
|
| 4 | +from odoo import Command |
4 | 5 | from odoo.exceptions import UserError |
5 | 6 | from odoo.tests import Form |
6 | 7 | from odoo.addons.stock_account.tests.test_stockvaluation import _create_accounting_data |
@@ -321,3 +322,47 @@ def test_stock_valuation_layer_revaluation_partial(self): |
321 | 322 | 'active_ids': [old_layers[2].id], |
322 | 323 | 'active_model': 'stock.valuation.layer' |
323 | 324 | })).save() |
| 325 | + |
| 326 | + def test_multi_company_fifo_svl_negative_revaluation(self): |
| 327 | + """ |
| 328 | + Check that the journal entries and stock valuation layers are created for the company related |
| 329 | + to the stock move even if the picking is validated using a different one. |
| 330 | + """ |
| 331 | + company1 = self.env.company |
| 332 | + company2 = self.env['res.company'].create({ |
| 333 | + 'name': 'Lovely Company', |
| 334 | + }) |
| 335 | + self.env.companies = company1 | company2 |
| 336 | + |
| 337 | + product = self.product1 |
| 338 | + product.categ_id.write({ |
| 339 | + 'property_cost_method': 'fifo', |
| 340 | + 'property_valuation': 'real_time', |
| 341 | + }) |
| 342 | + # Modify valuation to manual_periodic for company2 |
| 343 | + product.categ_id.with_company(company2).property_valuation = 'manual_periodic' |
| 344 | + |
| 345 | + # Create moves to revaluate for company1 |
| 346 | + self._make_in_move(product, 10, unit_cost=10, create_picking=True) |
| 347 | + self._make_out_move(product, 15, create_picking=True) |
| 348 | + |
| 349 | + receipt = self.env['stock.picking'].create({ |
| 350 | + 'picking_type_id': self.picking_type_in.id, |
| 351 | + 'location_id': self.supplier_location.id, |
| 352 | + 'location_dest_id': self.stock_location.id, |
| 353 | + 'move_ids': [Command.create({ |
| 354 | + 'name': 'test fifo', |
| 355 | + 'product_id': product.id, |
| 356 | + 'location_id': self.supplier_location.id, |
| 357 | + 'location_dest_id': self.stock_location.id, |
| 358 | + 'product_uom': self.uom_unit.id, |
| 359 | + 'product_uom_qty': 10, |
| 360 | + 'price_unit': 7, |
| 361 | + })] |
| 362 | + }).with_company(company2) |
| 363 | + receipt.action_confirm() |
| 364 | + receipt.button_validate() |
| 365 | + |
| 366 | + svls = self.env['stock.valuation.layer'].search([('product_id', '=', product.id)]) |
| 367 | + self.assertEqual(len(svls), 4, "Expected 4 valuation layers") |
| 368 | + self.assertTrue(all(svl.account_move_id for svl in svls), "All SVLs should be linked to a journal entry") |
0 commit comments