[tryton-commits] changeset in modules/account:default Computes GeneralLedger time...

2021-10-12 Thread Nicolas Évrard
changeset 9f6bf9d17129 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset=9f6bf9d17129
description:
Computes GeneralLedger timespan on either dates or period (scenario 
patch)

issue10249
review351991002
diffstat:

 tests/scenario_reports.rst |  77 +++--
 1 files changed, 66 insertions(+), 11 deletions(-)

diffs (132 lines):

diff -r 1b3d9d7a758f -r 9f6bf9d17129 tests/scenario_reports.rst
--- a/tests/scenario_reports.rstTue Oct 12 11:29:34 2021 +0200
+++ b/tests/scenario_reports.rstTue Oct 12 11:32:48 2021 +0200
@@ -28,7 +28,8 @@
 
 >>> fiscalyear = create_fiscalyear(company)
 >>> fiscalyear.click('create_period')
->>> period = fiscalyear.periods[0]
+>>> periods = fiscalyear.periods
+>>> period_1, period_3, period_5 = periods[0], periods[2], periods[4]
 
 Create chart of accounts::
 
@@ -56,9 +57,9 @@
 ... ('code', '=', 'CASH'),
 ... ])
 >>> move = Move()
->>> move.period = period
+>>> move.period = period_3
 >>> move.journal = journal_revenue
->>> move.date = period.start_date
+>>> move.date = period_3.start_date
 >>> line = move.lines.new()
 >>> line.account = revenue
 >>> line.credit = Decimal(10)
@@ -69,9 +70,9 @@
 >>> move.save()
 
 >>> move = Move()
->>> move.period = period
+>>> move.period = period_5
 >>> move.journal = journal_cash
->>> move.date = period.start_date
+>>> move.date = period_5.start_date
 >>> line = move.lines.new()
 >>> line.account = cash
 >>> line.debit = Decimal(10)
@@ -128,8 +129,8 @@
 >>> context = {
 ... 'company': company.id,
 ... 'fiscalyear': fiscalyear.id,
-... 'from_date': fiscalyear.periods[0].start_date,
-... 'to_date': fiscalyear.periods[1].end_date,
+... 'from_date': period_1.start_date,
+... 'to_date': period_3.end_date,
 ... }
 >>> with config.set_context(context):
 ... gl_revenue, = GeneralLedgerAccount.find([
@@ -150,16 +151,70 @@
 >>> glp_receivable.start_balance
 Decimal('0.00')
 >>> glp_receivable.credit
-Decimal('10.00')
+Decimal('0.00')
 >>> glp_receivable.debit
 Decimal('10.00')
 >>> glp_receivable.end_balance
+Decimal('10.00')
+
+>>> context = {
+... 'company': company.id,
+... 'fiscalyear': fiscalyear.id,
+... 'start_period': period_3.id,
+... }
+>>> with config.set_context(context):
+... gl_revenue, = GeneralLedgerAccount.find([
+...   ('account', '=', revenue.id),
+...   ])
+>>> gl_revenue.start_balance
 Decimal('0.00')
+>>> gl_revenue.credit
+Decimal('10.00')
+>>> gl_revenue.debit
+Decimal('0.00')
+>>> gl_revenue.end_balance
+Decimal('-10.00')
 
 >>> context = {
 ... 'company': company.id,
 ... 'fiscalyear': fiscalyear.id,
-... 'start_period': fiscalyear.periods[1].id,
+... 'start_period': period_5.id,
+... }
+>>> with config.set_context(context):
+... gl_revenue, = GeneralLedgerAccount.find([
+...   ('account', '=', revenue.id),
+...   ])
+>>> gl_revenue.start_balance
+Decimal('-10.00')
+>>> gl_revenue.credit
+Decimal('0.00')
+>>> gl_revenue.debit
+Decimal('0.00')
+>>> gl_revenue.end_balance
+Decimal('-10.00')
+
+>>> context = {
+... 'company': company.id,
+... 'fiscalyear': fiscalyear.id,
+... 'from_date': period_3.start_date,
+... }
+>>> with config.set_context(context):
+... gl_revenue, = GeneralLedgerAccount.find([
+...   ('account', '=', revenue.id),
+...   ])
+>>> gl_revenue.start_balance
+Decimal('0.00')
+>>> gl_revenue.credit
+Decimal('10.00')
+>>> gl_revenue.debit
+Decimal('0.00')
+>>> gl_revenue.end_balance
+Decimal('-10.00')
+
+>>> context = {
+... 'company': company.id,
+... 'fiscalyear': fiscalyear.id,
+... 'from_date': period_5.start_date,
 ... }
 >>> with config.set_context(context):
 ... gl_revenue, = GeneralLedgerAccount.find([
@@ -204,8 +259,8 @@
 >>> _ = general_journal.execute(Move.find([]))
 
 >>> with config.set_context(
-... start_date=period.start_date,
-... end_date=period.end_date):
+... start_date=period_5.start_date,
+... end_date=period_5.end_date):
 ... journal_cash = Journal(journal_cash.id)
 >>> journal_cash.credit
 Decimal('0.00')



[tryton-commits] changeset in modules/account:default Computes GeneralLedger time...

2021-10-12 Thread Nicolas Évrard
changeset 1b3d9d7a758f in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset=1b3d9d7a758f
description:
Computes GeneralLedger timespan on either dates or period

issue10249
review351991002
diffstat:

 account.py |  49 ++---
 1 files changed, 42 insertions(+), 7 deletions(-)

diffs (97 lines):

diff -r 9f4fabb78e30 -r 1b3d9d7a758f account.py
--- a/account.pyMon Oct 11 23:21:55 2021 +0200
+++ b/account.pyTue Oct 12 11:29:34 2021 +0200
@@ -1059,7 +1059,7 @@
 values[name][account.id] += getattr(deferral, name)
 else:
 with Transaction().set_context(fiscalyear=fiscalyear.id,
-date=None, periods=None):
+date=None, periods=None, from_date=None, to_date=None):
 previous_result = func(accounts, names)
 for name in names:
 vals = values[name]
@@ -1680,8 +1680,16 @@
 def get_account(cls, records, name):
 Account = cls._get_account()
 
-period_ids = cls.get_period_ids(name)
-from_date, to_date = cls.get_dates(name)
+period_ids, from_date, to_date = None, None, None
+context_keys = Transaction().context.keys()
+if context_keys & {'start_period', 'end_period'}:
+period_ids = cls.get_period_ids(name)
+elif context_keys & {'from_date', 'end_date'}:
+from_date, to_date = cls.get_dates(name)
+else:
+if name.startswith('start_'):
+period_ids = []
+
 with Transaction().set_context(
 periods=period_ids,
 from_date=from_date, to_date=to_date):
@@ -1797,27 +1805,42 @@
 domain=[
 ('fiscalyear', '=', Eval('fiscalyear')),
 ('start_date', '<=', (Eval('end_period'), 'start_date')),
-], depends=['fiscalyear', 'end_period'])
+],
+states={
+'invisible': Eval('from_date', False) | Eval('to_date', False),
+},
+depends=['fiscalyear', 'end_period', 'from_date', 'to_date'])
 end_period = fields.Many2One('account.period', 'End Period',
 domain=[
 ('fiscalyear', '=', Eval('fiscalyear')),
 ('start_date', '>=', (Eval('start_period'), 'start_date'))
 ],
-depends=['fiscalyear', 'start_period'])
+states={
+'invisible': Eval('from_date', False) | Eval('to_date', False),
+},
+depends=['fiscalyear', 'start_period', 'from_date', 'to_date'])
 from_date = fields.Date("From Date",
 domain=[
 If(Eval('to_date') & Eval('from_date'),
 ('from_date', '<=', Eval('to_date')),
 ()),
 ],
-depends=['to_date'])
+states={
+'invisible': (Eval('start_period', 'False')
+| Eval('end_period', False)),
+},
+depends=['to_date', 'start_period', 'end_period'])
 to_date = fields.Date("To Date",
 domain=[
 If(Eval('from_date') & Eval('to_date'),
 ('to_date', '>=', Eval('from_date')),
 ()),
 ],
-depends=['from_date'])
+states={
+'invisible': (Eval('start_period', 'False')
+| Eval('end_period', False)),
+},
+depends=['from_date', 'start_period', 'end_period'])
 company = fields.Many2One('company.company', 'Company', required=True)
 posted = fields.Boolean('Posted Move', help="Only include posted moves.")
 journal = fields.Many2One(
@@ -1874,6 +1897,18 @@
 and self.end_period.fiscalyear != self.fiscalyear):
 self.end_period = None
 
+def on_change_start_period(self):
+self.from_date = self.to_date = None
+
+def on_change_end_period(self):
+self.from_date = self.to_date = None
+
+def on_change_from_date(self):
+self.start_period = self.end_period = None
+
+def on_change_to_date(self):
+self.start_period = self.end_period = None
+
 
 class GeneralLedgerAccountParty(_GeneralLedgerAccount):
 "General Ledger Account Party"