From 2c763f77ebee70e5e961b5d282171d899edf644f Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 6 Mar 2014 17:39:02 +0100 Subject: [PATCH 1/3] [fix] account_statement_ext: trigger for a related field --- account_statement_ext/__openerp__.py | 2 +- account_statement_ext/statement.py | 23 ++++++--- .../test/test_balance_check.yml | 50 +++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 account_statement_ext/test/test_balance_check.yml diff --git a/account_statement_ext/__openerp__.py b/account_statement_ext/__openerp__.py index 0eb73d8d..a5e98cef 100644 --- a/account_statement_ext/__openerp__.py +++ b/account_statement_ext/__openerp__.py @@ -79,7 +79,7 @@ 'security/ir.model.access.csv', 'security/ir_rule.xml'], 'demo_xml': [], - 'test': [], + 'test': ['test/test_balance_check.yml'], 'installable': True, 'images': [], 'auto_install': False, diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 2cbd9e8f..bf65ddaf 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -159,6 +159,13 @@ class AccountBankStatement(Model): return profile_ids[0] if profile_ids else False + def _get_statement_from_profile(self, cr, uid, profile_ids, context=None): + """Weirdness warning! self is another class.""" + triggered = [] + for profile in self.browse(cr, uid, profile_ids, context=context): + triggered += [st.id for st in profile.bank_statement_ids] + return triggered + _columns = { 'profile_id': fields.many2one( 'account.statement.profile', @@ -174,12 +181,16 @@ class AccountBankStatement(Model): store=True, readonly=True), 'balance_check': fields.related( - 'profile_id', - 'balance_check', - type='boolean', - string='Balance check', - store=True, - readonly=True), + 'profile_id', + 'balance_check', + type='boolean', + string='Balance check', + store={ + 'account.statement.profile': ( + _get_statement_from_profile, ['balance_check'], 10), + }, + readonly=True + ), 'journal_id': fields.related( 'profile_id', 'journal_id', diff --git a/account_statement_ext/test/test_balance_check.yml b/account_statement_ext/test/test_balance_check.yml new file mode 100644 index 00000000..fdd4582e --- /dev/null +++ b/account_statement_ext/test/test_balance_check.yml @@ -0,0 +1,50 @@ +- + In order to test the banking framework, I first need to create a profile +- + !record {model: account.statement.profile, id: profile_test1}: + name: Bank EUR Profile + journal_id: account.bank_journal + commission_account_id: account.a_expense + company_id: base.main_company + balance_check: True +- + I create a second profile +- + !record {model: account.statement.profile, id: profile_test2}: + name: Second profile + journal_id: account.bank_journal + commission_account_id: account.a_expense + company_id: base.main_company + balance_check: True +- + Now I create a statement. +- + !record {model: account.bank.statement, id: statement_test1}: + name: Statement 1 + profile_id: profile_test1 + company_id: base.main_company +- + Now I check that the balance_check of the statement is enabled. +- + !assert {model: account.bank.statement, id: statement_test1, string: We should check the balance}: + - balance_check is True +- + Now I set the flag to False in the profile +- + !record {model: account.statement.profile, id: profile_test1}: + balance_check: False +- + It should be false in the statement as well. +- + !assert {model: account.bank.statement, id: statement_test1, string: We should not check the balance}: + - balance_check is False +- + Now I change the profile associated to the statement. +- + !record {model: account.bank.statement, id: statement_test1}: + profile_id: profile_test2 +- + The statement should receive information from the new statement. +- + !assert {model: account.bank.statement, id: statement_test1, string: We should check the balance}: + - balance_check is True From 063812d7c4353bc21063f403902f893fd641cbfe Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 6 Mar 2014 18:14:44 +0100 Subject: [PATCH 2/3] [fix] other related fields found in the statement --- account_statement_ext/__openerp__.py | 2 +- account_statement_ext/statement.py | 40 ++++++---- .../test/test_balance_check.yml | 50 ------------ .../test/test_profile_related_fields.yml | 78 +++++++++++++++++++ 4 files changed, 105 insertions(+), 65 deletions(-) delete mode 100644 account_statement_ext/test/test_balance_check.yml create mode 100644 account_statement_ext/test/test_profile_related_fields.yml diff --git a/account_statement_ext/__openerp__.py b/account_statement_ext/__openerp__.py index a5e98cef..6b574701 100644 --- a/account_statement_ext/__openerp__.py +++ b/account_statement_ext/__openerp__.py @@ -79,7 +79,7 @@ 'security/ir.model.access.csv', 'security/ir_rule.xml'], 'demo_xml': [], - 'test': ['test/test_balance_check.yml'], + 'test': ['test/test_profile_related_fields.yml'], 'installable': True, 'images': [], 'auto_install': False, diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index bf65ddaf..7d4d0f51 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -166,6 +166,9 @@ class AccountBankStatement(Model): triggered += [st.id for st in profile.bank_statement_ids] return triggered + def _us(self, cr, uid, ids, context=None): + return ids + _columns = { 'profile_id': fields.many2one( 'account.statement.profile', @@ -173,32 +176,41 @@ class AccountBankStatement(Model): required=True, states={'draft': [('readonly', False)]}), 'credit_partner_id': fields.related( - 'profile_id', - 'partner_id', - type='many2one', - relation='res.partner', - string='Financial Partner', - store=True, - readonly=True), + 'profile_id', + 'partner_id', + type='many2one', + relation='res.partner', + string='Financial Partner', + store={ + 'account.bank.statement': (_us, ['profile_id'], 10), + 'account.statement.profile': ( + _get_statement_from_profile, ['partner_id'], 10), + }, + readonly=True), 'balance_check': fields.related( 'profile_id', 'balance_check', type='boolean', string='Balance check', store={ + 'account.bank.statement': (_us, ['profile_id'], 10), 'account.statement.profile': ( _get_statement_from_profile, ['balance_check'], 10), }, readonly=True ), 'journal_id': fields.related( - 'profile_id', - 'journal_id', - type='many2one', - relation='account.journal', - string='Journal', - store=True, - readonly=True), + 'profile_id', + 'journal_id', + type='many2one', + relation='account.journal', + string='Journal', + store={ + 'account.bank.statement': (_us, ['profile_id'], 10), + 'account.statement.profile': ( + _get_statement_from_profile, ['journal_id'], 10), + }, + readonly=True), 'period_id': fields.many2one( 'account.period', 'Period', diff --git a/account_statement_ext/test/test_balance_check.yml b/account_statement_ext/test/test_balance_check.yml deleted file mode 100644 index fdd4582e..00000000 --- a/account_statement_ext/test/test_balance_check.yml +++ /dev/null @@ -1,50 +0,0 @@ -- - In order to test the banking framework, I first need to create a profile -- - !record {model: account.statement.profile, id: profile_test1}: - name: Bank EUR Profile - journal_id: account.bank_journal - commission_account_id: account.a_expense - company_id: base.main_company - balance_check: True -- - I create a second profile -- - !record {model: account.statement.profile, id: profile_test2}: - name: Second profile - journal_id: account.bank_journal - commission_account_id: account.a_expense - company_id: base.main_company - balance_check: True -- - Now I create a statement. -- - !record {model: account.bank.statement, id: statement_test1}: - name: Statement 1 - profile_id: profile_test1 - company_id: base.main_company -- - Now I check that the balance_check of the statement is enabled. -- - !assert {model: account.bank.statement, id: statement_test1, string: We should check the balance}: - - balance_check is True -- - Now I set the flag to False in the profile -- - !record {model: account.statement.profile, id: profile_test1}: - balance_check: False -- - It should be false in the statement as well. -- - !assert {model: account.bank.statement, id: statement_test1, string: We should not check the balance}: - - balance_check is False -- - Now I change the profile associated to the statement. -- - !record {model: account.bank.statement, id: statement_test1}: - profile_id: profile_test2 -- - The statement should receive information from the new statement. -- - !assert {model: account.bank.statement, id: statement_test1, string: We should check the balance}: - - balance_check is True diff --git a/account_statement_ext/test/test_profile_related_fields.yml b/account_statement_ext/test/test_profile_related_fields.yml new file mode 100644 index 00000000..56c93e8f --- /dev/null +++ b/account_statement_ext/test/test_profile_related_fields.yml @@ -0,0 +1,78 @@ +- + In order to test the related fields in the profile, I first need to create a profile +- + !record {model: account.statement.profile, id: profile_test1}: + name: Bank EUR Profile + journal_id: account.bank_journal + commission_account_id: account.a_expense + company_id: base.main_company + partner_id: base.res_partner_1 + journal_id: account.check_journal + balance_check: True +- + I create a second profile +- + !record {model: account.statement.profile, id: profile_test2}: + name: Second profile + journal_id: account.bank_journal + commission_account_id: account.a_expense + company_id: base.main_company + partner_id: base.res_partner_3 + journal_id: account.bank_journal + balance_check: True +- + Now I create a statement. +- + !record {model: account.bank.statement, id: statement_test1}: + name: Statement 1 + profile_id: profile_test1 + company_id: base.main_company +- + Now I check that the related data come from the profile +- + !assert {model: account.bank.statement, id: statement_test1, string: Initial data should come from the profile}: + - balance_check is True + - credit_partner_id.id == _ref('base.res_partner_1') + - journal_id.id == _ref('account.check_journal') +- + Now I set the balance flag to False in the profile +- + !record {model: account.statement.profile, id: profile_test1}: + balance_check: False +- + It should be false in the statement as well. +- + !assert {model: account.bank.statement, id: statement_test1, string: We should not check the balance}: + - balance_check is False +- + Now I change the journal in the profile +- + !record {model: account.statement.profile, id: profile_test1}: + journal_id: account.cash_journal +- + The journal should propagate to the statement +- + !assert {model: account.bank.statement, id: statement_test1, string: The journal should be updated}: + - journal_id.id == _ref('account.cash_journal') +- + Now I change the partner in the profile +- + !record {model: account.statement.profile, id: profile_test1}: + partner_id: base.res_partner_2 +- + The partner should propagate to the statement +- + !assert {model: account.bank.statement, id: statement_test1, string: The partner should be updated}: + - credit_partner_id.id == _ref('base.res_partner_2') +- + Now I change the profile associated to the statement. +- + !record {model: account.bank.statement, id: statement_test1}: + profile_id: profile_test2 +- + The statement should receive information from the new statement. +- + !assert {model: account.bank.statement, id: statement_test1, string: All information should be probagated from the new profile}: + - balance_check is True + - credit_partner_id.id == _ref('base.res_partner_3') + - journal_id.id == _ref('account.bank_journal') From fb9f6f4c32bedb2bf7865204b6fab53fdc06e7b5 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 7 Mar 2014 11:20:21 +0100 Subject: [PATCH 3/3] [imp] docstring for a function field trigger --- account_statement_ext/statement.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 7d4d0f51..faa98f58 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -160,7 +160,14 @@ class AccountBankStatement(Model): return profile_ids[0] if profile_ids else False def _get_statement_from_profile(self, cr, uid, profile_ids, context=None): - """Weirdness warning! self is another class.""" + """Stored function field trigger. + + Weirdness warning: we are in the class account.bank.statement, but + when the ORM calls this, self is an account.statement.profile. + + Returns a list of account.bank.statement ids to recompute. + + """ triggered = [] for profile in self.browse(cr, uid, profile_ids, context=context): triggered += [st.id for st in profile.bank_statement_ids]