From e103486c63a000a09f5d28c2868bad69a46e2ba0 Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Fri, 29 Apr 2016 14:03:13 +0200 Subject: [PATCH] Initial migration of so_completion --- account_statement_so_completion/__init__.py | 2 +- .../__openerp__.py | 8 +-- account_statement_so_completion/data.xml | 12 ---- .../data/completion_rule_data.xml | 10 +++ .../models/__init__.py | 25 ++++++++ .../{statement.py => models/account_move.py} | 53 ++++++---------- .../test/completion_so_test.yml | 61 ++++++++++++------- 7 files changed, 97 insertions(+), 74 deletions(-) delete mode 100644 account_statement_so_completion/data.xml create mode 100644 account_statement_so_completion/data/completion_rule_data.xml create mode 100644 account_statement_so_completion/models/__init__.py rename account_statement_so_completion/{statement.py => models/account_move.py} (58%) diff --git a/account_statement_so_completion/__init__.py b/account_statement_so_completion/__init__.py index 34a7ad21..568a6211 100644 --- a/account_statement_so_completion/__init__.py +++ b/account_statement_so_completion/__init__.py @@ -22,4 +22,4 @@ # # ############################################################################### -from . import statement +from . import models diff --git a/account_statement_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py index d5a53bd6..7b7234f2 100644 --- a/account_statement_so_completion/__openerp__.py +++ b/account_statement_so_completion/__openerp__.py @@ -28,7 +28,7 @@ 'maintainer': 'Camptocamp', 'category': 'Finance', 'complexity': 'easy', - 'depends': ['account_statement_base_completion', 'sale'], + 'depends': ['account_statement_base_import', '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 @@ -41,12 +41,12 @@ """, 'website': 'http://www.camptocamp.com', 'data': [ - 'data.xml', + 'data/completion_rule_data.xml', ], 'test': [ 'test/completion_so_test.yml'], - 'installable': False, + 'installable': True, 'images': [], - 'auto_install': True, + 'auto_install': False, 'license': 'AGPL-3', } diff --git a/account_statement_so_completion/data.xml b/account_statement_so_completion/data.xml deleted file mode 100644 index 89fedef2..00000000 --- a/account_statement_so_completion/data.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Match from line reference (based on SO number) - 50 - get_from_ref_and_so - - - - diff --git a/account_statement_so_completion/data/completion_rule_data.xml b/account_statement_so_completion/data/completion_rule_data.xml new file mode 100644 index 00000000..7ef4271c --- /dev/null +++ b/account_statement_so_completion/data/completion_rule_data.xml @@ -0,0 +1,10 @@ + + + + + Match from line name (based on SO number) + 50 + get_from_name_and_so + + + diff --git a/account_statement_so_completion/models/__init__.py b/account_statement_so_completion/models/__init__.py new file mode 100644 index 00000000..a1d6f04a --- /dev/null +++ b/account_statement_so_completion/models/__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 . # +# # +############################################################################### + +from . import account_move diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/models/account_move.py similarity index 58% rename from account_statement_so_completion/statement.py rename to account_statement_so_completion/models/account_move.py index 8ca744f2..8e7e15ae 100644 --- a/account_statement_so_completion/statement.py +++ b/account_statement_so_completion/models/account_move.py @@ -22,27 +22,25 @@ # # ############################################################################### -from openerp.osv import orm -from tools.translate import _ -from openerp.addons.account_statement_base_completion.statement import \ - ErrorTooManyPartner +from openerp import _, models +from openerp.addons.account_statement_base_import.models.account_move \ + import ErrorTooManyPartner -class AccountStatementCompletionRule(orm.Model): +class AccountMoveCompletionRule(models.Model): - _name = "account.statement.completion.rule" - _inherit = "account.statement.completion.rule" + _name = "account.move.completion.rule" + _inherit = "account.move.completion.rule" - def _get_functions(self, cr, uid, context=None): - res = super(AccountStatementCompletionRule, self)._get_functions( - cr, uid, context=context) + def _get_functions(self): + res = super(AccountMoveCompletionRule, self)._get_functions() res.append( - ('get_from_ref_and_so', 'From line reference (based on SO number)') + ('get_from_name_and_so', 'From line name (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): + def get_from_name_and_so(self, line): """ 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 @@ -60,27 +58,14 @@ class AccountStatementCompletionRule(orm.Model): ...} """ - st_obj = self.pool['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) + so_obj = self.env['sale.order'] + orders = so_obj.search([('name', '=', line.name)]) + if len(orders) > 1: + raise ErrorTooManyPartner( + _('Line named "%s" was matched by more ' + 'than one partner while looking on SO by ref.') % + line.name) + if len(orders) == 1: + res['partner_id'] = orders[0].partner_id.id return res diff --git a/account_statement_so_completion/test/completion_so_test.yml b/account_statement_so_completion/test/completion_so_test.yml index 3b0bda3f..e445b507 100644 --- a/account_statement_so_completion/test/completion_so_test.yml +++ b/account_statement_so_completion/test/completion_so_test.yml @@ -1,44 +1,59 @@ +- + I import account minimal data +- + !python {model: account.invoice}: | + openerp.tools.convert_file(cr, + 'account', + openerp.modules.get_module_resource( + 'account', + 'test', + 'account_minimal_test.xml'), + {}, 'init', False, 'test') - 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 + !record {model: account.journal, id: account.bank_journal}: + used_for_completion: 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 + - account_statement_base_import.bank_statement_completion_rule_4 + - account_statement_base_import.bank_statement_completion_rule_5 + - account_statement_base_import.bank_statement_completion_rule_2 + - account_statement_base_import.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}: + !record {model: account.move, id: move_test_sale1}: name: Statement for SO - profile_id: profile_test_so + journal_id: account.bank_journal company_id: base.main_company - - I create a statement line for a SO + I create a move 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 + !record {model: account.move.line, id: move_line_so}: + name: SO007 + account_id: account.a_sale + move_id: move_test_sale1 + date_maturity: '2013-12-20' + credit: 0.0 +- + and add the correct name +- + !python {model: account.move.line}: | + context['check_move_validity'] = False + model.write(cr, uid, [ref('move_line_so')], + {'credit': 14981.0}, + context) - I run the auto complete - - !python {model: account.bank.statement}: | - result = self.button_auto_completion(cr, uid, [ref("statement_test_sale1")]) + !python {model: account.move}: | + result = self.button_auto_completion(cr, uid, [ref("move_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' + !assert {model: account.move.line, id: move_line_so, string: Check completion by SO number}: + - partner_id.name == u'China Export'