Commit 5005c662 authored by Jérome Perrin's avatar Jérome Perrin

Merge !236 accounting: fix accounting period constraint with node acquisition on invoices

from commit message
> We have a constraint preventing closing accounting periods if there are still some accounting transactions that are in "current states" (ie. not delivered / cancelled), but this constraint should not be fooled by accounting lines in stock table that does not have an account as node, but just an acquired organisation.

We already fixed another problem where such lines where "getting in the way" in c61cde5b

But here, it's at inventory level, we want to get "all accounting movements from this section during the period"., excluding these "not really accounting" lines.

I used the same approach as the one we applied when we discovered in !215 , there was code doing:
`getInventoryList(node_category="account_type")`
as a way to get only movements on accounts, relying on the facts that accounts have an account type category.  This stopped working and we accepted it because this use case was not really valid. Instead, we did a first query getting all account and passing this as a `getInventory(node_uid=`

I don't think we want to support `node_portal_type` in Inventory API, because the concept of *portal_types* does not really belong in Inventory API to me.

To  prevent creating many portal types (Tax, Discount etc) we concluded:
 * Resources (and Movements) are classified by their *use* category
 * Deliveries are classified by their *ledger* category
 * Nodes are classified by their *role* category

So the "pure" approach is maybe to add a role category on all accounts and query inventory with `getMovementHistoryList(node_category="role/accounting_node")`.

I'd say let's merge this for now, but if you have better idea or anything to add please go ahead, I wanted to create an open place for discussion and explaining why i did all this.

/cc @tc @vpelletier @georgios.dagkakis @Nicolas

/reviewed-on !236
parents d3e99c39 4613dd54
......@@ -73,6 +73,10 @@ movement_list = portal.portal_simulation.getMovementHistoryList(
from_date=period.getStartDate().earliestTime(),
at_date=period.getStopDate().latestTime(),
simulation_state=invalid_simulation_state_list,
# We only consider accounting movements really using accounts as node.
# There could be a line in stock table because the node is an organisation acquired
# from parent invoice.
node_uid=[node.uid for node in portal.portal_catalog(portal_type='Account')],
portal_type=portal.getPortalAccountingMovementTypeList(),
limit=1)
......
......@@ -3024,10 +3024,70 @@ class TestClosingPeriod(AccountingTestCase):
period, 'stop_action',
profit_and_loss_account=pl.getRelativeUrl())
self.assertRaises(ValidationFailed,
self.getPortal().portal_workflow.doActionFor,
period2, 'stop_action' )
with self.assertRaisesRegexp(ValidationFailed,
'.*Previous accounting periods has to be closed first.*'):
self.getPortal().portal_workflow.doActionFor(
period2, 'stop_action')
def test_PeriodClosingRefusedWhenTransactionAreNotStopped(self):
organisation_module = self.organisation_module
period = self.section.newContent(portal_type='Accounting Period')
period.setStartDate(DateTime(2006, 1, 1))
period.setStopDate(DateTime(2006, 12, 31))
period.start()
pl = self.portal.account_module.newContent(
portal_type='Account',
account_type='equity')
transaction1 = self._makeOne(
start_date=DateTime(2006, 1, 1),
destination_section_value=organisation_module.client_1,
portal_type='Sale Invoice Transaction',
simulation_state='stopped',
lines=(dict(source_value=self.account_module.goods_sales,
source_credit=100),
dict(source_value=self.account_module.receivable,
source_debit=100)))
with self.assertRaisesRegexp(
ValidationFailed,
'All Accounting Transactions for this organisation during'
' the period have to be closed first'):
self.portal.portal_workflow.doActionFor(
period,
'stop_action')
def test_PeriodClosingRefusedWhenTransactionAreNotStoppedIgnoreInternalLine(self):
period = self.section.newContent(portal_type='Accounting Period')
period.setStartDate(DateTime(2006, 1, 1))
period.setStopDate(DateTime(2006, 12, 31))
period.start()
pl = self.portal.account_module.newContent(
portal_type='Account',
account_type='equity')
# This transaction has lines that should block closing for `main_section`,
# but not for `section` because from `section` side there are no accounting lines.
transaction1 = self._makeOne(
start_date=DateTime(2006, 1, 1),
source_section_value=self.main_section,
source_value=self.main_section,
destination_section_value=self.section,
destination_value=self.section,
portal_type='Sale Invoice Transaction',
simulation_state='stopped',
lines=(dict(source_value=self.account_module.goods_sales,
source_credit=100),
dict(source_value=self.account_module.receivable,
source_debit=100)))
self.portal.portal_workflow.doActionFor(
period,
'stop_action',
profit_and_loss_account=pl.getRelativeUrl())
self.tic()
class TestAccountingExport(AccountingTestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment