From c72657cfa3cb3c4ad030ecf95f1d46783508ef99 Mon Sep 17 00:00:00 2001 From: Artem Kostyuk Date: Mon, 23 Jul 2018 18:13:38 +0300 Subject: [PATCH] fixup! [REF] Split valuation accounts on locations --- .../models/stock_location.py | 3 +- .../tests/test_stock_move_confirmation.py | 84 +++++++++++++------ 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/stock_account_internal_move/models/stock_location.py b/stock_account_internal_move/models/stock_location.py index 70b37ce6f..1c76663c9 100644 --- a/stock_account_internal_move/models/stock_location.py +++ b/stock_account_internal_move/models/stock_location.py @@ -23,7 +23,8 @@ class StockLocation(models.Model): NOT force_accounting_entries OR force_accounting_entries AND usage = 'internal')""", - _('You cannot force accounting entries on a non-internal locations.')), + _('You cannot force accounting entries' + ' on a non-internal locations.')), ] force_accounting_entries = fields.Boolean( diff --git a/stock_account_internal_move/tests/test_stock_move_confirmation.py b/stock_account_internal_move/tests/test_stock_move_confirmation.py index 97cc503dd..737e84deb 100644 --- a/stock_account_internal_move/tests/test_stock_move_confirmation.py +++ b/stock_account_internal_move/tests/test_stock_move_confirmation.py @@ -15,19 +15,54 @@ class StockMoveConfirmationCase(common.SavepointCase): 'type': 'product', 'uom_id': cls.env.ref('product.product_uom_kgm').id, 'uom_po_id': cls.env.ref('product.product_uom_kgm').id, + 'standard_price': 100., + 'valuation': 'real_time', }) cls.location_from = cls.env.ref('stock.location_gate_a') cls.location_to = cls.env.ref('stock.location_gate_b') - cls.account_from = cls.env['account.account'].create({ + cls.location_from.usage = cls.location_to.usage = 'internal' + account_type_revenue_id = cls.env.ref( + 'account.data_account_type_revenue').id + + cls.account_from_in = cls.env['account.account'].create({ 'name': 'From Location valuation account', - 'code': 'fr0m10c4t10n', - 'user_type_id': cls.env.ref( - 'account.data_account_type_revenue').id, + 'code': 'fr0m10c4t10n-1n', + 'user_type_id': account_type_revenue_id, + }) + cls.account_to_in = cls.env['account.account'].create({ + 'name': 'To Location valuation account', + 'code': 't010c4t10n-1n', + 'user_type_id': account_type_revenue_id, + }) + cls.account_from_out = cls.env['account.account'].create({ + 'name': 'From Location valuation account', + 'code': 'fr0m10c4t10n-0u7', + 'user_type_id': account_type_revenue_id, + }) + cls.account_to_out = cls.env['account.account'].create({ + 'name': 'To Location valuation account', + 'code': 't010c4t10n-0u7', + 'user_type_id': account_type_revenue_id, + }) + cls.location_from.write({ + 'force_accounting_entries': True, + 'valuation_in_internal_account_id': cls.account_from_in.id, + 'valuation_out_internal_account_id': cls.account_from_out.id, + }) + cls.location_to.write({ + 'force_accounting_entries': True, + 'valuation_in_internal_account_id': cls.account_to_in.id, + 'valuation_out_internal_account_id': cls.account_to_out.id, + }) + cls.fake_stock_journal = cls.env['account.journal'].create({ + 'name': 'Stock journal (that\'s **not really true)', + 'code': '7h47\'5-n07-|?3411y-7|?u3', + 'type': 'general', }) - def _create_move(self): + def _create_done_move(self): """Create a dummy move from Gate A to Gate B.""" - return self.env['stock.move'].create({ + res = self.env['stock.move'].create({ 'location_id': self.location_from.id, 'name': self.product.name, 'product_id': self.product.id, @@ -43,6 +78,9 @@ class StockMoveConfirmationCase(common.SavepointCase): }), ], }) + res._action_done() + res.value = res.product_id.standard_price * res.quantity_done + return res def test_00_regular_move(self): """Ensure that we didn't broke anything completely. @@ -50,13 +88,10 @@ class StockMoveConfirmationCase(common.SavepointCase): Regular case, customization shouldn't have any effect on it. """ # ensure that we're running in a regular setup - self.assertFalse(self.location_from.force_accounting_entries) - self.assertFalse(self.location_to.force_accounting_entries) - self.assertFalse(self.location_from.valuation_internal_account_id) - self.assertFalse(self.location_to.valuation_internal_account_id) - # then: simple as that - we're just ensuring that we can do that. - move = self._create_move() - move._action_done() + self.location_from.force_accounting_entries = False + self.location_to.force_accounting_entries = False + # simple as that - we're just ensuring that we're allowed to do it. + move = self._create_done_move() @mute_logger('odoo.sql_db') def test_10_constraint(self): @@ -73,21 +108,22 @@ class StockMoveConfirmationCase(common.SavepointCase): while the other does - this should prevent users from creating moves between those locations. """ - self.location_from.write({ - 'force_accounting_entries': True, - 'valuation_internal_account_id': self.account_from.id, - }) with self.assertRaises(ValidationError): - self._create_move()._action_done() + self._create_done_move() - def test_40_wrongly_configured_to_location(self): + def test_30_wrongly_configured_to_location(self): """Test behavior when one of locations isn't configured properly. Same as above, but now it is dest location that is misconfigured. """ - self.location_to.write({ - 'force_accounting_entries': True, - 'valuation_internal_account_id': self.account_from.id, - }) with self.assertRaises(ValidationError): - self._create_move()._action_done() + self._create_done_move() + + def test_50_create_account_move_line(self): + kekes = self._create_done_move() + # perform a manual evaluation of teh fresh move + # we don't really care about those numbers + kekes._create_account_move_line( + self.location_from.valuation_out_internal_account_id.id, + self.location_to.valuation_in_internal_account_id.id, + self.fake_stock_journal.id)