From 5c0e625e11f3b1c84beb25a1c1bbae037223fbf6 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 3 Dec 2013 16:04:25 +0100 Subject: [PATCH 1/8] [imp] account_statement_base_completion: put what depends on sale on a separate module --- .../__openerp__.py | 1 - account_statement_base_completion/data.xml | 6 -- .../statement.py | 44 --------- account_statement_so_completion/__init__.py | 25 +++++ .../__openerp__.py | 53 ++++++++++ account_statement_so_completion/data.xml | 12 +++ .../partner_view.xml | 22 +++++ account_statement_so_completion/statement.py | 98 +++++++++++++++++++ 8 files changed, 210 insertions(+), 51 deletions(-) create mode 100644 account_statement_so_completion/__init__.py create mode 100644 account_statement_so_completion/__openerp__.py create mode 100644 account_statement_so_completion/data.xml create mode 100644 account_statement_so_completion/partner_view.xml create mode 100644 account_statement_so_completion/statement.py diff --git a/account_statement_base_completion/__openerp__.py b/account_statement_base_completion/__openerp__.py index d868a314..2d795534 100644 --- a/account_statement_base_completion/__openerp__.py +++ b/account_statement_base_completion/__openerp__.py @@ -35,7 +35,6 @@ 1) Match from statement line label (based on partner field 'Bank Statement Label') 2) Match from statement line label (based on partner name) - 3) Match from statement line reference (based on SO number) 3) Match from statement line reference (based on Invoice number) You can easily override this module and add your own rules in your own one. The basic rules only diff --git a/account_statement_base_completion/data.xml b/account_statement_base_completion/data.xml index 59a75228..595a4af3 100644 --- a/account_statement_base_completion/data.xml +++ b/account_statement_base_completion/data.xml @@ -14,12 +14,6 @@ get_from_label_and_partner_name - - Match from line reference (based on SO number) - 50 - get_from_ref_and_so - - Match from line reference (based on Invoice number) 40 diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 96ab741b..aacb7068 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -132,7 +132,6 @@ class AccountStatementCompletionRule(orm.Model): return [ ('get_from_ref_and_invoice', 'From line reference (based on customer invoice number)'), ('get_from_ref_and_supplier_invoice', 'From line reference (based on supplier invoice number)'), - ('get_from_ref_and_so', 'From line reference (based on SO number)'), ('get_from_label_and_partner_field', 'From line label (based on partner field)'), ('get_from_label_and_partner_name', 'From line label (based on partner name)')] @@ -232,49 +231,6 @@ class AccountStatementCompletionRule(orm.Model): """ return self._from_invoice(cr, uid, line, 'customer', context=context) - # Should be private but data are initialised with no update XML - def get_from_ref_and_so(self, cr, uid, st_line, context=None): - """ - Match the partner based on the SO number and the reference of the statement - line. Then, call the generic get_values_for_line method to complete other values. - If more than one partner matched, raise the ErrorTooManyPartner error. - - :param int/long st_line: read of the concerned account.bank.statement.line - :return: - A dict of value that can be passed directly to the write method of - the statement line or {} - {'partner_id': value, - 'account_id': value, - - ...} - """ - st_obj = self.pool.get('account.bank.statement.line') - res = {} - if st_line: - so_obj = self.pool.get('sale.order') - so_id = so_obj.search(cr, - uid, - [('name', '=', st_line['ref'])], - context=context) - if so_id: - if so_id and len(so_id) == 1: - so = so_obj.browse(cr, uid, so_id[0], context=context) - res['partner_id'] = so.partner_id.id - elif so_id and len(so_id) > 1: - raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more ' - 'than one partner while looking on SO by ref.') % - (st_line['name'], st_line['ref'])) - st_vals = st_obj.get_values_for_line(cr, - uid, - profile_id=st_line['profile_id'], - master_account_id=st_line['master_account_id'], - partner_id=res.get('partner_id', False), - line_type='customer', - amount=st_line['amount'] if st_line['amount'] else 0.0, - context=context) - res.update(st_vals) - return res - # Should be private but data are initialised with no update XML def get_from_label_and_partner_field(self, cr, uid, st_line, context=None): """ diff --git a/account_statement_so_completion/__init__.py b/account_statement_so_completion/__init__.py new file mode 100644 index 00000000..5c28ebc2 --- /dev/null +++ b/account_statement_so_completion/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################### +# # +# Author: Joel Grand-Guillaume +# Copyright 2011-2012 Camptocamp SA +# # +# Author: Leonardo Pistone # +# Copyright 2013 Camptocamp SA # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU Affero General Public License as # +# published by the Free Software Foundation, either version 3 of the # +# License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU Affero General Public License for more details. # +# # +# You should have received a copy of the GNU Affero General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import statement diff --git a/account_statement_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py new file mode 100644 index 00000000..9028d535 --- /dev/null +++ b/account_statement_so_completion/__openerp__.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +############################################################################### +# # +# Author: Joel Grand-Guillaume +# Copyright 2011-2012 Camptocamp SA +# # +# Author: Leonardo Pistone # +# Copyright 2013 Camptocamp SA # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU Affero General Public License as # +# published by the Free Software Foundation, either version 3 of the # +# License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU Affero General Public License for more details. # +# # +# You should have received a copy of the GNU Affero General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +{'name': "Bank statement Sale Order completion", + 'version': '0.1', + 'author': 'Camptocamp', + 'maintainer': 'Camptocamp', + 'category': 'Finance', + 'complexity': 'easy', + 'depends': ['account_statement_base_completion', 'sale'], + 'description': """ + This module improve the module account_statement_base_completion to add + support for completion rules based on Sale Orders. This was initially part of + the module account_statement_base_completion, but is now separate to keep + dependencies separate. + + This module provides the following rule: + + 1) Match from statement line reference (based on SO number) +""", + 'website': 'http://www.camptocamp.com', + 'init_xml': [], + 'update_xml': [ + 'data.xml', + ], + 'demo_xml': [], + 'test': [], + 'installable': True, + 'images': [], + 'auto_install': False, + 'license': 'AGPL-3', + } diff --git a/account_statement_so_completion/data.xml b/account_statement_so_completion/data.xml new file mode 100644 index 00000000..89fedef2 --- /dev/null +++ b/account_statement_so_completion/data.xml @@ -0,0 +1,12 @@ + + + + + + Match from line reference (based on SO number) + 50 + get_from_ref_and_so + + + + diff --git a/account_statement_so_completion/partner_view.xml b/account_statement_so_completion/partner_view.xml new file mode 100644 index 00000000..c7ec3f1a --- /dev/null +++ b/account_statement_so_completion/partner_view.xml @@ -0,0 +1,22 @@ + + + + + + + + account_bank_statement_import.view.partner.form + res.partner + form + 20 + + + + + + + + + + + diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/statement.py new file mode 100644 index 00000000..03d0a2b3 --- /dev/null +++ b/account_statement_so_completion/statement.py @@ -0,0 +1,98 @@ +# -*- coding: utf-8 -*- +############################################################################### +# # +# Author: Joel Grand-Guillaume +# Copyright 2011-2012 Camptocamp SA +# # +# Author: Leonardo Pistone # +# Copyright 2013 Camptocamp SA # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU Affero General Public License as # +# published by the Free Software Foundation, either version 3 of the # +# License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU Affero General Public License for more details. # +# # +# You should have received a copy of the GNU Affero General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +from openerp.osv import fields, orm +from tools.translate import _ + +from openerp.addons.account_statement_base_completion.statement import ErrorTooManyPartner + + +class account_statement_profile(orm.Model): + + _inherit = "account.statement.profile" + + # Should be private but data are initialised with no update XML + def get_from_ref_and_so(self, cr, uid, st_line, context=None): + """ + Match the partner based on the SO number and the reference of the + statement line. Then, call the generic get_values_for_line method to + complete other values. If more than one partner matched, raise the + ErrorTooManyPartner error. + + :param int/long st_line: read of the concerned + account.bank.statement.line + + :return: + A dict of value that can be passed directly to the write method of + the statement line or {} + {'partner_id': value, + 'account_id': value, + + ...} + """ + st_obj = self.pool.get('account.bank.statement.line') + res = {} + if st_line: + so_obj = self.pool.get('sale.order') + so_id = so_obj.search(cr, + uid, + [('name', '=', st_line['ref'])], + context=context) + if so_id: + if so_id and len(so_id) == 1: + so = so_obj.browse(cr, uid, so_id[0], context=context) + res['partner_id'] = so.partner_id.id + elif so_id and len(so_id) > 1: + raise ErrorTooManyPartner( + _('Line named "%s" (Ref:%s) was matched by more ' + 'than one partner while looking on SO by ref.') % + (st_line['name'], st_line['ref'])) + st_vals = st_obj.get_values_for_line( + cr, + uid, + profile_id=st_line['profile_id'], + master_account_id=st_line['master_account_id'], + partner_id=res.get('partner_id', False), + line_type='customer', + amount=st_line['amount'] if st_line['amount'] else 0.0, + context=context) + res.update(st_vals) + return res + + +class account_statement_completion_rule(orm.Model): + + _name = "account.statement.completion.rule" + _inherit = "account.statement.completion.rule" + + def _get_functions(self, cr, uid, context=None): + res = super(account_statement_completion_rule, self)._get_functions( + cr, uid, context=context) + return res.append( + ('get_from_ref_and_so', 'From line reference (based on SO number)') + ) + + _columns = { + 'function_to_call': fields.selection(_get_functions, 'Method'), + } From 95242cd44b93fbae301230813e57514694c231cb Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 3 Dec 2013 16:08:34 +0100 Subject: [PATCH 2/8] [del] unused file --- .../partner_view.xml | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 account_statement_so_completion/partner_view.xml diff --git a/account_statement_so_completion/partner_view.xml b/account_statement_so_completion/partner_view.xml deleted file mode 100644 index c7ec3f1a..00000000 --- a/account_statement_so_completion/partner_view.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - account_bank_statement_import.view.partner.form - res.partner - form - 20 - - - - - - - - - - - From f80bba275eec1133d3bf300bcb2c06b7259b40df Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 3 Dec 2013 16:10:22 +0100 Subject: [PATCH 3/8] [ref] minor refactor --- account_statement_so_completion/__init__.py | 2 +- account_statement_so_completion/statement.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/account_statement_so_completion/__init__.py b/account_statement_so_completion/__init__.py index 5c28ebc2..34a7ad21 100644 --- a/account_statement_so_completion/__init__.py +++ b/account_statement_so_completion/__init__.py @@ -22,4 +22,4 @@ # # ############################################################################### -import statement +from . import statement diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/statement.py index 03d0a2b3..439a66ad 100644 --- a/account_statement_so_completion/statement.py +++ b/account_statement_so_completion/statement.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################### # # -# Author: Joel Grand-Guillaume -# Copyright 2011-2012 Camptocamp SA +# Author: Joel Grand-Guillaume # +# Copyright 2011-2012 Camptocamp SA # # # # Author: Leonardo Pistone # # Copyright 2013 Camptocamp SA # From 53c5ab9c84e7ea6f206b3edb2d420594f7536161 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 3 Dec 2013 16:19:45 +0100 Subject: [PATCH 4/8] auto_install account_statement_so_completion --- account_statement_so_completion/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py index 9028d535..929e46c8 100644 --- a/account_statement_so_completion/__openerp__.py +++ b/account_statement_so_completion/__openerp__.py @@ -48,6 +48,6 @@ 'test': [], 'installable': True, 'images': [], - 'auto_install': False, + 'auto_install': True, 'license': 'AGPL-3', } From fc0b8ec312fed12ac4e4eb30a14fd12b61cc1ea0 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 13 Dec 2013 12:33:52 +0100 Subject: [PATCH 5/8] [fix] selection value --- account_statement_so_completion/statement.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/statement.py index 439a66ad..f41fd906 100644 --- a/account_statement_so_completion/statement.py +++ b/account_statement_so_completion/statement.py @@ -89,9 +89,10 @@ class account_statement_completion_rule(orm.Model): def _get_functions(self, cr, uid, context=None): res = super(account_statement_completion_rule, self)._get_functions( cr, uid, context=context) - return res.append( + res.append( ('get_from_ref_and_so', 'From line reference (based on SO number)') ) + return res _columns = { 'function_to_call': fields.selection(_get_functions, 'Method'), From aba2cd43974698a9f443d8579c6e453785d89d27 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 20 Dec 2013 16:43:01 +0100 Subject: [PATCH 6/8] [add] account_statement_so_completion/test --- .../__openerp__.py | 3 +- .../test/completion_so_test.yml | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 account_statement_so_completion/test/completion_so_test.yml diff --git a/account_statement_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py index 929e46c8..cc0e4286 100644 --- a/account_statement_so_completion/__openerp__.py +++ b/account_statement_so_completion/__openerp__.py @@ -45,7 +45,8 @@ 'data.xml', ], 'demo_xml': [], - 'test': [], + 'test': [ + 'test/completion_so_test.yml'], 'installable': True, 'images': [], 'auto_install': True, diff --git a/account_statement_so_completion/test/completion_so_test.yml b/account_statement_so_completion/test/completion_so_test.yml new file mode 100644 index 00000000..3b0bda3f --- /dev/null +++ b/account_statement_so_completion/test/completion_so_test.yml @@ -0,0 +1,44 @@ +- + In order to test the banking framework for Sale Orders, I first need to + create a profile +- + !record {model: account.statement.profile, id: profile_test_so}: + name: Bank EUR Profile for SO + journal_id: account.bank_journal + commission_account_id: account.a_expense + company_id: base.main_company + balance_check: True + rule_ids: + - account_statement_base_completion.bank_statement_completion_rule_4 + - account_statement_base_completion.bank_statement_completion_rule_5 + - account_statement_base_completion.bank_statement_completion_rule_2 + - account_statement_base_completion.bank_statement_completion_rule_3 + - bank_statement_completion_rule_1 +- + Now I create a statement. I create statment lines separately because I need + to find each one by XML id +- + !record {model: account.bank.statement, id: statement_test_sale1}: + name: Statement for SO + profile_id: profile_test_so + company_id: base.main_company +- + I create a statement line for a SO +- + !record {model: account.bank.statement.line, id: statement_line_so}: + name: Test autocompletion based on Sale Order Number + statement_id: statement_test_sale1 + ref: SO007 + date: '2013-12-20' + amount: 14981.0 +- + I run the auto complete +- + !python {model: account.bank.statement}: | + result = self.button_auto_completion(cr, uid, [ref("statement_test_sale1")]) +- + Now I can check that all is nice and shiny, line 1. I expect the Sale Order + Number to be recognised. +- + !assert {model: account.bank.statement.line, id: statement_line_so, string: Check completion by SO number}: + - partner_id.name == u'Luminous Technologies' From 655162b5993fdff88e2524c68267b42648dd2fb2 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 20 Dec 2013 16:45:19 +0100 Subject: [PATCH 7/8] [fix] function in the wrong place --- account_statement_so_completion/statement.py | 27 ++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/statement.py index f41fd906..dcf2378f 100644 --- a/account_statement_so_completion/statement.py +++ b/account_statement_so_completion/statement.py @@ -28,9 +28,18 @@ from tools.translate import _ from openerp.addons.account_statement_base_completion.statement import ErrorTooManyPartner -class account_statement_profile(orm.Model): +class account_statement_completion_rule(orm.Model): - _inherit = "account.statement.profile" + _name = "account.statement.completion.rule" + _inherit = "account.statement.completion.rule" + + def _get_functions(self, cr, uid, context=None): + res = super(account_statement_completion_rule, self)._get_functions( + cr, uid, context=context) + res.append( + ('get_from_ref_and_so', 'From line reference (based on SO number)') + ) + return res # Should be private but data are initialised with no update XML def get_from_ref_and_so(self, cr, uid, st_line, context=None): @@ -80,20 +89,6 @@ class account_statement_profile(orm.Model): res.update(st_vals) return res - -class account_statement_completion_rule(orm.Model): - - _name = "account.statement.completion.rule" - _inherit = "account.statement.completion.rule" - - def _get_functions(self, cr, uid, context=None): - res = super(account_statement_completion_rule, self)._get_functions( - cr, uid, context=context) - res.append( - ('get_from_ref_and_so', 'From line reference (based on SO number)') - ) - return res - _columns = { 'function_to_call': fields.selection(_get_functions, 'Method'), } From 19abe5ed0195c8f7b442720976bc9f706e55c945 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 16 Jan 2014 11:35:20 +0100 Subject: [PATCH 8/8] [imp] manifest: data --- account_statement_so_completion/__openerp__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/account_statement_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py index cc0e4286..30a7f581 100644 --- a/account_statement_so_completion/__openerp__.py +++ b/account_statement_so_completion/__openerp__.py @@ -40,11 +40,9 @@ 1) Match from statement line reference (based on SO number) """, 'website': 'http://www.camptocamp.com', - 'init_xml': [], - 'update_xml': [ + 'data': [ 'data.xml', ], - 'demo_xml': [], 'test': [ 'test/completion_so_test.yml'], 'installable': True,