From 36cf314066f401fec5792ccafb34ee74b8749a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 14 Mar 2024 14:04:31 +0100 Subject: [PATCH] Add company to journal-period --- modules/account/journal.py | 20 +++++++++++++++++-- modules/account/view/journal_period_form.xml | 8 ++++++-- .../view/journal_period_list_close.xml | 1 + modules/account/view/journal_period_tree.xml | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/account/journal.py b/modules/account/journal.py index 1ab7dfafa7..27a2cc8c0d 100644 --- a/modules/account/journal.py +++ b/modules/account/journal.py @@ -228,10 +228,18 @@ class JournalCashContext(ModelView): class JournalPeriod(Workflow, ModelSQL, ModelView): 'Journal - Period' __name__ = 'account.journal.period' - journal = fields.Many2One('account.journal', 'Journal', required=True, - ondelete='CASCADE', states=STATES) + journal = fields.Many2One( + 'account.journal', 'Journal', required=True, ondelete='CASCADE', + states=STATES, + context={ + 'company': Eval('company', None), + }, + depends=['company']) period = fields.Many2One('account.period', 'Period', required=True, ondelete='CASCADE', states=STATES) + company = fields.Function(fields.Many2One( + 'company.company', "Company"), + 'on_change_with_company', searcher='search_company') icon = fields.Function(fields.Char('Icon'), 'get_icon') state = fields.Selection([ ('open', 'Open'), @@ -270,6 +278,14 @@ class JournalPeriod(Workflow, ModelSQL, ModelView): cursor.execute( *t.update([t.state], ['closed'], where=t.state == 'close')) + @fields.depends('period') + def on_change_with_company(self, name=None): + return self.period.company if self.period else None + + @classmethod + def search_company(cls, name, clause): + return [('period.' + clause[0], *clause[1:])] + @staticmethod def default_state(): return 'open' diff --git a/modules/account/view/journal_period_form.xml b/modules/account/view/journal_period_form.xml index 63ca431968..bd0a40c404 100644 --- a/modules/account/view/journal_period_form.xml +++ b/modules/account/view/journal_period_form.xml @@ -2,10 +2,14 @@
-