From 94b071486935a9a545212bf16a5693d6de9f2732 Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Tue, 24 May 2016 11:51:51 +0200 Subject: [PATCH] Remane import modules --- account_move_so_import/README.rst | 55 +++++++++++++++++ account_move_so_import/__init__.py | 4 ++ account_move_so_import/__openerp__.py | 22 +++++++ .../data/completion_rule_data.xml | 10 ++++ .../i18n/account_statement_so_completion.pot | 28 +++++++++ account_move_so_import/i18n/es.po | 33 +++++++++++ account_move_so_import/models/__init__.py | 4 ++ account_move_so_import/models/account_move.py | 50 ++++++++++++++++ .../test/completion_so_test.yml | 59 +++++++++++++++++++ 9 files changed, 265 insertions(+) create mode 100644 account_move_so_import/README.rst create mode 100644 account_move_so_import/__init__.py create mode 100644 account_move_so_import/__openerp__.py create mode 100644 account_move_so_import/data/completion_rule_data.xml create mode 100644 account_move_so_import/i18n/account_statement_so_completion.pot create mode 100644 account_move_so_import/i18n/es.po create mode 100644 account_move_so_import/models/__init__.py create mode 100644 account_move_so_import/models/account_move.py create mode 100644 account_move_so_import/test/completion_so_test.yml diff --git a/account_move_so_import/README.rst b/account_move_so_import/README.rst new file mode 100644 index 00000000..f82d0ad1 --- /dev/null +++ b/account_move_so_import/README.rst @@ -0,0 +1,55 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +==================================== +Bank statement Sale Order completion +==================================== + +This module extends the functionality of account_statement_base_import +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. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/98/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of +trouble, please check there if your issue has already been reported. If you +spotted it first, help us smashing it by providing a detailed and welcomed +feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Joël Grand-Guillaume +* Leonardo Pistone +* Matthieu Dietrich + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_move_so_import/__init__.py b/account_move_so_import/__init__.py new file mode 100644 index 00000000..f85f8bc3 --- /dev/null +++ b/account_move_so_import/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2011-2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from . import models diff --git a/account_move_so_import/__openerp__.py b/account_move_so_import/__openerp__.py new file mode 100644 index 00000000..55126b6b --- /dev/null +++ b/account_move_so_import/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2011-2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +{ + 'name': "Bank statement Sale Order completion", + 'version': '9.0.1.0.0', + 'author': "Camptocamp,Odoo Community Association (OCA)", + 'maintainer': 'Camptocamp', + 'category': 'Finance', + 'complexity': 'easy', + 'depends': ['account_move_base_import', 'sale'], + 'website': 'http://www.camptocamp.com', + 'data': [ + 'data/completion_rule_data.xml', + ], + 'test': [ + 'test/completion_so_test.yml'], + 'installable': True, + 'images': [], + 'auto_install': False, + 'license': 'AGPL-3', +} diff --git a/account_move_so_import/data/completion_rule_data.xml b/account_move_so_import/data/completion_rule_data.xml new file mode 100644 index 00000000..7ef4271c --- /dev/null +++ b/account_move_so_import/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_move_so_import/i18n/account_statement_so_completion.pot b/account_move_so_import/i18n/account_statement_so_completion.pot new file mode 100644 index 00000000..69bf8c28 --- /dev/null +++ b/account_move_so_import/i18n/account_statement_so_completion.pot @@ -0,0 +1,28 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * account_statement_so_completion +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-01-21 12:04+0000\n" +"PO-Revision-Date: 2014-01-21 12:04+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_statement_so_completion +#: code:addons/account_statement_so_completion/statement.py:77 +#, python-format +msgid "Line named \"%s\" (Ref:%s) was matched by more than one partner while looking on SO by ref." +msgstr "" + +#. module: account_statement_so_completion +#: model:ir.model,name:account_statement_so_completion.model_account_statement_completion_rule +msgid "account.statement.completion.rule" +msgstr "" + diff --git a/account_move_so_import/i18n/es.po b/account_move_so_import/i18n/es.po new file mode 100644 index 00000000..4ff0d2ad --- /dev/null +++ b/account_move_so_import/i18n/es.po @@ -0,0 +1,33 @@ +# Spanish translation for banking-addons +# Copyright (c) 2014 Rosetta Contributors and Canonical Ltd 2014 +# This file is distributed under the same license as the banking-addons package. +# FIRST AUTHOR , 2014. +# +msgid "" +msgstr "" +"Project-Id-Version: banking-addons\n" +"Report-Msgid-Bugs-To: FULL NAME \n" +"POT-Creation-Date: 2014-01-21 12:04+0000\n" +"PO-Revision-Date: 2014-06-05 22:41+0000\n" +"Last-Translator: Pedro Manuel Baeza \n" +"Language-Team: Spanish \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-06-06 06:36+0000\n" +"X-Generator: Launchpad (build 17031)\n" + +#. module: account_statement_so_completion +#: code:addons/account_statement_so_completion/statement.py:77 +#, python-format +msgid "" +"Line named \"%s\" (Ref:%s) was matched by more than one partner while " +"looking on SO by ref." +msgstr "" +"La línea llamada \"%s\" (Ref: %s) se casó con más de una empresa al buscar " +"por referencia de pedido." + +#. module: account_statement_so_completion +#: model:ir.model,name:account_statement_so_completion.model_account_statement_completion_rule +msgid "account.statement.completion.rule" +msgstr "account.statement.completion.rule" diff --git a/account_move_so_import/models/__init__.py b/account_move_so_import/models/__init__.py new file mode 100644 index 00000000..8ac192f1 --- /dev/null +++ b/account_move_so_import/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2011-2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from . import account_move diff --git a/account_move_so_import/models/account_move.py b/account_move_so_import/models/account_move.py new file mode 100644 index 00000000..c4317167 --- /dev/null +++ b/account_move_so_import/models/account_move.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# © 2011-2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from openerp import _, models +from openerp.addons.account_move_base_import.models.account_move \ + import ErrorTooManyPartner + + +class AccountMoveCompletionRule(models.Model): + + _name = "account.move.completion.rule" + _inherit = "account.move.completion.rule" + + def _get_functions(self): + res = super(AccountMoveCompletionRule, self)._get_functions() + res.append( + ('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_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 + 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, + + ...} + """ + res = {} + 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_move_so_import/test/completion_so_test.yml b/account_move_so_import/test/completion_so_test.yml new file mode 100644 index 00000000..e445b507 --- /dev/null +++ b/account_move_so_import/test/completion_so_test.yml @@ -0,0 +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.journal, id: account.bank_journal}: + used_for_completion: True + rule_ids: + - 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.move, id: move_test_sale1}: + name: Statement for SO + journal_id: account.bank_journal + company_id: base.main_company +- + I create a move line for a SO +- + !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.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.move.line, id: move_line_so, string: Check completion by SO number}: + - partner_id.name == u'China Export'