From 500c478dae5bf02acd92ded684b853a3fa17a4aa Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 16 Oct 2015 14:16:03 +0200 Subject: [PATCH] [PORT] base_transaction_id to 9.0 - Reactivate module - move files in views and models dirs - create README.rst from description - make list of contributors - remove change for invoice created on picking as it doesn't exist anymore in Odoo Community - move overrides in bank statement as logic moved in move lines - adapt view inheritance to not depends on string attribute - Fix definition of javascript customization in reconciliation - Fix display transaction_ref label on move line view - Fix move proposition for reconcile. search with transaction_ref - Use short headers - Update README for bug tracking --- base_transaction_id/README.rst | 55 +++++++++++++++++ base_transaction_id/__init__.py | 30 ++------- base_transaction_id/__openerp__.py | 44 +++---------- base_transaction_id/account_bank_statement.py | 61 ------------------- base_transaction_id/account_move.py | 56 ----------------- base_transaction_id/models/__init__.py | 7 +++ .../models/account_bank_statement_line.py | 25 ++++++++ base_transaction_id/models/account_move.py | 46 ++++++++++++++ base_transaction_id/{ => models}/invoice.py | 23 +------ base_transaction_id/models/sale.py | 22 +++++++ base_transaction_id/sale.py | 48 --------------- .../static/src/js/account_widgets.js | 13 ++-- base_transaction_id/stock.py | 34 ----------- .../account_move_line.xml} | 4 +- .../{invoice_view.xml => views/invoice.xml} | 0 .../{sale_view.xml => views/sale.xml} | 0 16 files changed, 179 insertions(+), 289 deletions(-) create mode 100644 base_transaction_id/README.rst delete mode 100644 base_transaction_id/account_bank_statement.py delete mode 100644 base_transaction_id/account_move.py create mode 100644 base_transaction_id/models/__init__.py create mode 100644 base_transaction_id/models/account_bank_statement_line.py create mode 100644 base_transaction_id/models/account_move.py rename base_transaction_id/{ => models}/invoice.py (56%) create mode 100644 base_transaction_id/models/sale.py delete mode 100644 base_transaction_id/sale.py delete mode 100644 base_transaction_id/stock.py rename base_transaction_id/{account_move_line_view.xml => views/account_move_line.xml} (83%) rename base_transaction_id/{invoice_view.xml => views/invoice.xml} (100%) rename base_transaction_id/{sale_view.xml => views/sale.xml} (100%) diff --git a/base_transaction_id/README.rst b/base_transaction_id/README.rst new file mode 100644 index 00000000..9ea40ae0 --- /dev/null +++ b/base_transaction_id/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 + +============================================ +Base transaction id for financial institutes +============================================ + +Adds transaction id to invoice and sale models and views. + +On Sales order, you can specify the transaction ID used +for the payment and it will be propagated to the invoice (even if made from packing). +This is mostly used for e-commerce handling. + +You can then add a mapping on that SO field to save the e-commerce financial +Transaction ID into the Odoo sale order field. + +The main purpose is to ease the reconciliation process and be able to find the partner +when importing the bank statement. + +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 +======= + +Contributors +------------ + +* Yannick Vaucher +* Joël Grand-Guillaume +* Alexandre Fayolle +* Guewen Baconnier +* Pedro Baeza +* Lorenzo Battistini + +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 http://odoo-community.org. diff --git a/base_transaction_id/__init__.py b/base_transaction_id/__init__.py index 7241064a..038f720f 100644 --- a/base_transaction_id/__init__.py +++ b/base_transaction_id/__init__.py @@ -1,26 +1,4 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Yannick Vaucher (Camptocamp) -# Copyright 2012 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 invoice -from . import sale -from . import stock -from . import account_move -from . import account_bank_statement +# -*- coding: utf-8 -*# -*- coding: utf-8 -*- +# © 2012-2015 Yannick Vaucher (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import models diff --git a/base_transaction_id/__openerp__.py b/base_transaction_id/__openerp__.py index ae1b5050..18fab526 100644 --- a/base_transaction_id/__openerp__.py +++ b/base_transaction_id/__openerp__.py @@ -1,26 +1,8 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Yannick Vaucher (Camptocamp) -# Copyright 2012 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 . -# -############################################################################## - +# -*- coding: utf-8 -*# -*- coding: utf-8 -*- +# © 2012 Yannick Vaucher (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). {'name': 'Base transaction id for financial institutes', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'author': "Camptocamp,Odoo Community Association (OCA)", 'maintainer': 'Camptocamp', 'category': 'Hidden/Dependency', @@ -30,23 +12,11 @@ 'stock_account', 'sale_stock', ], - 'description': """ - Adds transaction id to invoice and sale models and views. - On Sales order, you can specify the transaction ID used - for the payment and it will be propagated to the invoice - (even if made from packing). - This is mostly used for e-commerce handling. - You can then add a mapping on that SO field to save - the e-commerce financial Transaction ID into the - OpenERP sale order field. - The main purpose is to ease the reconciliation process and - be able to find the partner when importing the bank statement. - """, 'website': 'http://www.openerp.com', 'data': [ - 'invoice_view.xml', - 'sale_view.xml', - 'account_move_line_view.xml', + 'views/invoice.xml', + 'views/sale.xml', + 'views/account_move_line.xml', 'views/base_transaction_id.xml', ], 'test': [], diff --git a/base_transaction_id/account_bank_statement.py b/base_transaction_id/account_bank_statement.py deleted file mode 100644 index e9d6346b..00000000 --- a/base_transaction_id/account_bank_statement.py +++ /dev/null @@ -1,61 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Guewen Baconnier -# Copyright 2014 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 orm - - -class account_bank_statement_line(orm.Model): - - _inherit = 'account.bank.statement.line' - - def _domain_move_lines_for_reconciliation(self, cr, uid, st_line, - excluded_ids=None, str=False, - additional_domain=None, - context=None): - _super = super(account_bank_statement_line, self) - _get_domain = _super._domain_move_lines_for_reconciliation - domain = _get_domain(cr, uid, st_line, excluded_ids=excluded_ids, - str=str, additional_domain=additional_domain, - context=context) - if not str and str != '/': - return domain - domain = domain[:] - domain.insert(-1, '|') - domain.append(('transaction_ref', 'ilike', str)) - return domain - - def _domain_reconciliation_proposition(self, cr, uid, st_line, - excluded_ids=None, context=None): - _super = super(account_bank_statement_line, self) - _get_domain = _super._domain_reconciliation_proposition - domain = _get_domain(cr, uid, st_line, excluded_ids=excluded_ids, - context=context) - new_domain = [] - for criterion in domain: - if len(criterion) == 3: - field, op, value = criterion - if (field, op) == ('ref', '='): - new_domain += [ - '|', - ('transaction_ref', '=', value), - ] - new_domain.append(criterion) - return new_domain diff --git a/base_transaction_id/account_move.py b/base_transaction_id/account_move.py deleted file mode 100644 index 77b73366..00000000 --- a/base_transaction_id/account_move.py +++ /dev/null @@ -1,56 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Guewen Baconnier -# Copyright 2014 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 orm, fields - - -class account_move_line(orm.Model): - _inherit = 'account.move.line' - - _columns = { - 'transaction_ref': fields.char('Transaction Ref.', - select=True), - } - - def copy_data(self, cr, uid, id, default=None, context=None): - if default is None: - default = {} - default['transaction_ref'] = False - _super = super(account_move_line, self) - return _super.copy_data(cr, uid, id, default=default, context=context) - - def prepare_move_lines_for_reconciliation_widget(self, cr, uid, lines, - target_currency=False, - target_date=False, - context=None): - _super = super(account_move_line, self) - prepare = _super.prepare_move_lines_for_reconciliation_widget - prepared_lines = [] - for line in lines: - # The super method loop over the lines and returns a list of - # prepared lines. Here we'll have 1 line per call to super. - # If we called super on the whole list, we would need to - # browse again the lines, or match the 'lines' vs - # 'prepared_lines' to update the transaction_ref. - vals = prepare(cr, uid, [line], target_currency=target_currency, - target_date=target_date, context=context)[0] - vals['transaction_ref'] = line.transaction_ref - prepared_lines.append(vals) - return prepared_lines diff --git a/base_transaction_id/models/__init__.py b/base_transaction_id/models/__init__.py new file mode 100644 index 00000000..f4d17648 --- /dev/null +++ b/base_transaction_id/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*# -*- coding: utf-8 -*- +# © 2012-2015 Yannick Vaucher (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import invoice +from . import sale +from . import account_move +from . import account_bank_statement_line diff --git a/base_transaction_id/models/account_bank_statement_line.py b/base_transaction_id/models/account_bank_statement_line.py new file mode 100644 index 00000000..49dc9618 --- /dev/null +++ b/base_transaction_id/models/account_bank_statement_line.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2016 Yannick Vaucher (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp import api, models + + +class AccountBankStatementLine(models.Model): + + _inherit = 'account.bank.statement.line' + + @api.multi + def get_reconciliation_proposition(self, excluded_ids=None): + """ Look for transaction_ref to give them as proposition move line """ + if self.name: + # If the transaction has no partner, look for match in payable and + # receivable account anyway + overlook_partner = not self.partner_id + domain = [('transaction_ref', 'ilike', self.name)] + match_recs = self.get_move_lines_for_reconciliation( + excluded_ids=excluded_ids, limit=2, additional_domain=domain, + overlook_partner=overlook_partner) + if match_recs and len(match_recs) == 1: + return match_recs + _super = super(AccountBankStatementLine, self) + return _super.get_reconciliation_proposition(excluded_ids=excluded_ids) diff --git a/base_transaction_id/models/account_move.py b/base_transaction_id/models/account_move.py new file mode 100644 index 00000000..45ddf7c2 --- /dev/null +++ b/base_transaction_id/models/account_move.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# © 2014 Guewen Baconnier (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp import models, fields, api +from openerp.osv import expression + + +class AccountMoveLine(models.Model): + _inherit = 'account.move.line' + + transaction_ref = fields.Char( + 'Transaction Ref.', + index=True, + copy=False + ) + + @api.multi + def prepare_move_lines_for_reconciliation_widget(self, + target_currency=False, + target_date=False): + prepared_lines = [] + for line in self: + _super = super(AccountMoveLine, line) + # The super method loop over the lines and returns a list of + # prepared lines. Here we'll have 1 line per call to super. + # If we called super on the whole list, we would need to + # browse again the lines, or match the 'lines' vs + # 'prepared_lines' to update the transaction_ref. + vals = _super.prepare_move_lines_for_reconciliation_widget( + target_currency=target_currency, + target_date=target_date)[0] + vals['transaction_ref'] = line.transaction_ref + prepared_lines.append(vals) + return prepared_lines + + @api.model + def domain_move_lines_for_reconciliation(self, excluded_ids=None, + str=False): + """ Add transaction_ref in search of move lines""" + _super = super(AccountMoveLine, self) + _get_domain = _super.domain_move_lines_for_reconciliation + domain = _get_domain(excluded_ids=excluded_ids, str=str) + if not str and str != '/': + return domain + domain_trans_ref = [('transaction_ref', 'ilike', str)] + return expression.OR([domain, domain_trans_ref]) diff --git a/base_transaction_id/invoice.py b/base_transaction_id/models/invoice.py similarity index 56% rename from base_transaction_id/invoice.py rename to base_transaction_id/models/invoice.py index 4b3745c5..1594adba 100644 --- a/base_transaction_id/invoice.py +++ b/base_transaction_id/models/invoice.py @@ -1,24 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Nicolas Bessi -# Copyright 2011-2012 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 . -# -############################################################################## - +# © 2011-2012 Nicolas Bessi (Camptocamp) +# © 2012-2015 Yannick Vaucher (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, fields, api diff --git a/base_transaction_id/models/sale.py b/base_transaction_id/models/sale.py new file mode 100644 index 00000000..45b8a102 --- /dev/null +++ b/base_transaction_id/models/sale.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2011-2012 Nicolas Bessi (Camptocamp) +# © 2012-2015 Yannick Vaucher (Camptocamp) +from openerp import models, fields, api + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + transaction_id = fields.Char( + 'Transaction ID', + required=False, + copy=False, + help="Transaction id from the financial institute" + ) + + @api.multi + def _prepare_invoice(self): + """ Propagate the transaction_id from the sale order to the invoice """ + invoice_vals = super(SaleOrder, self)._prepare_invoice() + invoice_vals['transaction_id'] = self.transaction_id + return invoice_vals diff --git a/base_transaction_id/sale.py b/base_transaction_id/sale.py deleted file mode 100644 index 159414fb..00000000 --- a/base_transaction_id/sale.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Nicolas Bessi -# Copyright 2011-2012 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 orm, fields - - -class SaleOrder(orm.Model): - _inherit = 'sale.order' - - _columns = { - 'transaction_id': fields.char( - 'Transaction ID', - required=False, - help="Transaction id from the financial institute"), - } - - def copy_data(self, cr, uid, id, default=None, context=None): - if default is None: - default = {} - default['transaction_id'] = False - _super = super(SaleOrder, self) - return _super.copy_data(cr, uid, id, default=default, context=context) - - def _prepare_invoice(self, cr, uid, order, lines, context=None): - """ Propagate the transaction_id from the sale order to the invoice """ - _super = super(SaleOrder, self) - invoice_vals = _super._prepare_invoice(cr, uid, order, lines, - context=context) - invoice_vals['transaction_id'] = order.transaction_id - return invoice_vals diff --git a/base_transaction_id/static/src/js/account_widgets.js b/base_transaction_id/static/src/js/account_widgets.js index 277c9c2c..c47dbc71 100644 --- a/base_transaction_id/static/src/js/account_widgets.js +++ b/base_transaction_id/static/src/js/account_widgets.js @@ -1,11 +1,14 @@ -openerp.base_transaction_id = function (instance) { +odoo.define('base_transaction_id.base_transaction_id', function (require) { - instance.web.account.bankStatementReconciliationLine.include({ - decorateMoveLine: function(line, currency_id) { - this._super(line, currency_id); + var AccountReconciliation = require('account.reconciliation'); + + AccountReconciliation.bankStatementReconciliation.include({ + decorateMoveLine: function(line) { + this._super(line); if (line.transaction_ref) { line.q_label += ' (' + line.transaction_ref + ')'; } }, }); -}; + +}); diff --git a/base_transaction_id/stock.py b/base_transaction_id/stock.py deleted file mode 100644 index 840aedf1..00000000 --- a/base_transaction_id/stock.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Nicolas Bessi -# Copyright 2011-2012 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 orm - - -class StockPicking(orm.Model): - _inherit = "stock.picking" - - def _create_invoice_from_picking(self, cr, uid, picking, vals, - context=None): - """ Propagate the transaction ID from sale to invoice """ - vals['transaction_id'] = picking.sale_id.transaction_id - _super = super(StockPicking, self) - return _super._create_invoice_from_picking(cr, uid, picking, vals, - context=context) diff --git a/base_transaction_id/account_move_line_view.xml b/base_transaction_id/views/account_move_line.xml similarity index 83% rename from base_transaction_id/account_move_line_view.xml rename to base_transaction_id/views/account_move_line.xml index 488968af..f7d3887b 100644 --- a/base_transaction_id/account_move_line_view.xml +++ b/base_transaction_id/views/account_move_line.xml @@ -6,9 +6,9 @@ account.move.line - + - + diff --git a/base_transaction_id/invoice_view.xml b/base_transaction_id/views/invoice.xml similarity index 100% rename from base_transaction_id/invoice_view.xml rename to base_transaction_id/views/invoice.xml diff --git a/base_transaction_id/sale_view.xml b/base_transaction_id/views/sale.xml similarity index 100% rename from base_transaction_id/sale_view.xml rename to base_transaction_id/views/sale.xml