From 2443cf00368b61774f70ce0dc1e84b2820735d8d Mon Sep 17 00:00:00 2001 From: etobella Date: Tue, 17 Oct 2017 16:02:57 +0200 Subject: [PATCH] [MIG] account_payment_order --- account_payment_order/README.rst | 16 ++--- account_payment_order/__manifest__.py | 12 ++-- account_payment_order/data/payment_seq.xml | 4 +- .../models/account_invoice.py | 4 +- account_payment_order/models/account_move.py | 2 +- .../models/account_move_line.py | 2 +- .../models/account_payment_line.py | 10 +-- .../models/account_payment_mode.py | 9 ++- .../models/account_payment_order.py | 38 +++++----- .../models/bank_payment_line.py | 9 ++- account_payment_order/models/res_bank.py | 2 +- .../report/account_payment_order.py | 2 +- .../report/account_payment_order.xml | 2 +- .../report/print_account_payment_order.xml | 2 +- account_payment_order/tests/__init__.py | 4 +- account_payment_order/tests/test_bank.py | 15 ++++ .../tests/test_payment_mode.py | 65 +++++++++++++++++ .../tests/test_payment_order.py | 72 +++++++++++++++---- .../views/account_invoice_view.xml | 2 +- .../views/account_move_line.xml | 7 +- .../views/account_payment_line.xml | 3 +- .../views/bank_payment_line.xml | 4 +- .../account_invoice_payment_line_multi.py | 4 +- ...ccount_invoice_payment_line_multi_view.xml | 2 +- .../wizard/account_payment_line_create.py | 8 +-- .../account_payment_line_create_view.xml | 4 +- 26 files changed, 222 insertions(+), 82 deletions(-) create mode 100644 account_payment_order/tests/test_bank.py create mode 100644 account_payment_order/tests/test_payment_mode.py diff --git a/account_payment_order/README.rst b/account_payment_order/README.rst index 26e94fdfa..46ba8bdf2 100644 --- a/account_payment_order/README.rst +++ b/account_payment_order/README.rst @@ -21,22 +21,22 @@ This modules is part of the OCA/bank-payment suite. Configuration ============= -This module adds several options on Payment Modes, cf Accounting > Configuration > Management > Payment Modes. +This module adds several options on Payment Modes, cf Invoicing/Accounting > Configuration > Management > Payment Modes. Usage ===== -You can create a Payment Order via the menu Accounting > Payments > Payment Orders and then select the move lines to pay. +You can create a Payment Order via the menu Invoicing/Accounting > Payments > Payment Orders and then select the move lines to pay. -You can create a Debit Order via the menu Accounting > Payments > Debit Orders and then select the move lines to debit. +You can create a Debit Order via the menu Invoicing/Accounting > Payments > Debit Orders and then select the move lines to debit. This module also adds a button *Add to Payment Order* on supplier invoices and a button *Add to Debit Order* on customer invoices. -You can print a Payment Order via the menu Accounting > Payments > Payment Orders and then select the payment oder to print. +You can print a Payment Order via the menu Invoicing/Accounting > Payments > Payment Orders and then select the payment oder to print. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/173/10.0 + :target: https://runbot.odoo-community.org/runbot/173/11.0 Known issues / Roadmap ====================== @@ -75,12 +75,12 @@ Contributors Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :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. +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_payment_order/__manifest__.py b/account_payment_order/__manifest__.py index a9767234f..3d1f71838 100644 --- a/account_payment_order/__manifest__.py +++ b/account_payment_order/__manifest__.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # © 2009 EduSense BV () -# © 2011-2013 Therp BV () -# © 2013-2014 ACSONE SA (). +# © 2011-2013 Therp BV () +# © 2013-2014 ACSONE SA (). # © 2014-2016 Tecnativa - Pedro M. Baeza -# © 2016 Akretion (). -# © 2016 Aselcis (). -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# © 2016 Akretion (). +# © 2016 Aselcis (). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { 'name': 'Account Payment Order', - 'version': '10.0.1.3.2', + 'version': '11.0.1.0.0', 'license': 'AGPL-3', 'author': "ACSONE SA/NV, " "Therp BV, " diff --git a/account_payment_order/data/payment_seq.xml b/account_payment_order/data/payment_seq.xml index ff6c704c5..db5a3d54b 100644 --- a/account_payment_order/data/payment_seq.xml +++ b/account_payment_order/data/payment_seq.xml @@ -1,8 +1,8 @@ diff --git a/account_payment_order/models/account_invoice.py b/account_payment_order/models/account_invoice.py index 847df3604..63b94628e 100644 --- a/account_payment_order/models/account_invoice.py +++ b/account_payment_order/models/account_invoice.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# © 2013-2014 ACSONE SA (). +# © 2013-2014 ACSONE SA (). # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2016 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api, _ from odoo.exceptions import UserError diff --git a/account_payment_order/models/account_move.py b/account_payment_order/models/account_move.py index 85343f413..2348b379c 100644 --- a/account_payment_order/models/account_move.py +++ b/account_payment_order/models/account_move.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2016 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields diff --git a/account_payment_order/models/account_move_line.py b/account_payment_order/models/account_move_line.py index 6f8748ed7..2d7be343a 100644 --- a/account_payment_order/models/account_move_line.py +++ b/account_payment_order/models/account_move_line.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2014-2016 Akretion (Alexis de Lattre ) # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api diff --git a/account_payment_order/models/account_payment_line.py b/account_payment_order/models/account_payment_line.py index 08ffa9002..f47d3ce15 100644 --- a/account_payment_order/models/account_payment_line.py +++ b/account_payment_order/models/account_payment_line.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2015-2016 Akretion - Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api, _ from odoo.exceptions import UserError @@ -89,15 +89,15 @@ class AccountPaymentLine(models.Model): bplo = self.env['bank.payment.line'] values = [] for field in bplo.same_fields_payment_line_and_bank_payment_line(): - values.append(unicode(self[field])) + values.append(str(self[field])) # Don't group the payment lines that are attached to the same supplier # but to move lines with different accounts (very unlikely), # for easier generation/comprehension of the transfer move - values.append(unicode(self.move_line_id.account_id or False)) + values.append(str(self.move_line_id.account_id or False)) # Don't group the payment lines that use a structured communication # otherwise it would break the structured communication system ! if self.communication_type != 'normal': - values.append(unicode(self.id)) + values.append(str(self.id)) hashcode = '-'.join(values) return hashcode @@ -113,7 +113,7 @@ class AccountPaymentLine(models.Model): if self.move_line_id: vals = self.move_line_id._prepare_payment_line_vals(self.order_id) vals.pop('order_id') - for field, value in vals.iteritems(): + for field, value in vals.items(): self[field] = value else: self.partner_id = False diff --git a/account_payment_order/models/account_payment_mode.py b/account_payment_order/models/account_payment_mode.py index accb78d1c..ece9d2d71 100644 --- a/account_payment_order/models/account_payment_mode.py +++ b/account_payment_order/models/account_payment_mode.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- # © 2009 EduSense BV () -# © 2011-2013 Therp BV () +# © 2011-2013 Therp BV () # © 2014-2016 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2016 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api, _ from odoo.exceptions import ValidationError @@ -29,7 +29,10 @@ class AccountPaymentMode(models.Model): ('any', 'Any'), ], string='Payment Mode on Invoice', default='same') default_journal_ids = fields.Many2many( - 'account.journal', string="Journals Filter") + 'account.journal', + string="Journals Filter", + domain="[('company_id', '=', company_id)]" + ) default_invoice = fields.Boolean( string='Linked to an Invoice or Refund', default=False) default_target_move = fields.Selection([ diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index 8736b5283..5bafd4f5c 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- # © 2009 EduSense BV () -# © 2011-2013 Therp BV () +# © 2011-2013 Therp BV () # © 2016 Serv. Tecnol. Avanzados - Pedro M. Baeza # © 2016 Akretion (Alexis de Lattre - alexis.delattre@akretion.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import base64 from odoo import models, fields, api, _ from odoo.exceptions import UserError, ValidationError @@ -15,6 +16,15 @@ class AccountPaymentOrder(models.Model): _inherit = ['mail.thread'] _order = 'id desc' + def domain_journal_id(self): + if not self.payment_mode_id: + return [('id', '=', False)] + if self.payment_mode_id.bank_account_link == 'fixed': + return [('id', '=', self.payment_mode_id.fixed_journal_id.id)] + elif self.payment_mode_id.bank_account_link == 'variable': + jrl_ids = self.payment_mode_id.variable_journal_ids.ids + return [('id', 'in', jrl_ids)] + name = fields.Char( string='Number', readonly=True, copy=False) # v8 field : name payment_mode_id = fields.Many2one( @@ -38,6 +48,7 @@ class AccountPaymentOrder(models.Model): journal_id = fields.Many2one( 'account.journal', string='Bank Journal', ondelete='restrict', readonly=True, states={'draft': [('readonly', False)]}, + domain=domain_journal_id, track_visibility='onchange') # The journal_id field is only required at confirm step, to # allow auto-creation of payment order from invoice @@ -161,18 +172,13 @@ class AccountPaymentOrder(models.Model): @api.onchange('payment_mode_id') def payment_mode_id_change(self): - journal_id = False + domain = self.domain_journal_id() res = {'domain': { - 'journal_id': "[('id', '=', False)]", - }} - if self.payment_mode_id: - if self.payment_mode_id.bank_account_link == 'fixed': - journal_id = self.payment_mode_id.fixed_journal_id.id - res['domain']['journal_id'] = "[('id', '=', %d)]" % journal_id - elif self.payment_mode_id.bank_account_link == 'variable': - jrl_ids = self.payment_mode_id.variable_journal_ids.ids - res['domain']['journal_id'] = "[('id', 'in', %s)]" % jrl_ids - self.journal_id = journal_id + 'journal_id': domain + }} + journals = self.env['account.journal'].search(domain) + if len(journals) == 1: + self.journal_id = journals if self.payment_mode_id.default_date_prefered: self.date_prefered = self.payment_mode_id.default_date_prefered return res @@ -289,7 +295,7 @@ class AccountPaymentOrder(models.Model): 'total': payline.amount_currency, } # Create bank payment lines - for paydict in group_paylines.values(): + for paydict in list(group_paylines.values()): # Block if a bank payment line is <= 0 if paydict['total'] <= 0: raise UserError(_( @@ -323,7 +329,7 @@ class AccountPaymentOrder(models.Model): 'res_model': 'account.payment.order', 'res_id': self.id, 'name': filename, - 'datas': payment_file_str.encode('base64'), + 'datas': base64.b64encode(payment_file_str), 'datas_fname': filename, }) simplified_form_view = self.env.ref( @@ -472,7 +478,7 @@ class AccountPaymentOrder(models.Model): else: trfmoves[hashcode] = bline - for hashcode, blines in trfmoves.iteritems(): + for hashcode, blines in trfmoves.items(): mvals = self._prepare_move(blines) total_company_currency = total_payment_currency = 0 for bline in blines: diff --git a/account_payment_order/models/bank_payment_line.py b/account_payment_order/models/bank_payment_line.py index 83a0198cd..ef20197f2 100644 --- a/account_payment_order/models/bank_payment_line.py +++ b/account_payment_order/models/bank_payment_line.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2015-2016 Akretion - Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api, _ from odoo.exceptions import UserError @@ -52,9 +52,11 @@ class BankPaymentLine(models.Model): string='Communication', required=True, readonly=True) company_id = fields.Many2one( + 'res.company', related='order_id.payment_mode_id.company_id', store=True, readonly=True) company_currency_id = fields.Many2one( + 'res.currency', related='order_id.payment_mode_id.company_id.currency_id', readonly=True, store=True) @@ -77,6 +79,9 @@ class BankPaymentLine(models.Model): for bline in self: amount_currency = sum( bline.mapped('payment_line_ids.amount_currency')) + import logging + logging.info(bline.company_id) + logging.info(bline.company_currency_id) amount_company_currency = bline.currency_id.with_context( date=bline.date).compute( amount_currency, bline.company_currency_id) @@ -101,7 +106,7 @@ class BankPaymentLine(models.Model): if self.order_id.payment_mode_id.move_option == 'date': hashcode = self.date else: - hashcode = unicode(self.id) + hashcode = str(self.id) return hashcode @api.multi diff --git a/account_payment_order/models/res_bank.py b/account_payment_order/models/res_bank.py index 0f0c7cdc3..55c93a839 100644 --- a/account_payment_order/models/res_bank.py +++ b/account_payment_order/models/res_bank.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2015-2016 Akretion - Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import models, api, _ from odoo.exceptions import ValidationError diff --git a/account_payment_order/report/account_payment_order.py b/account_payment_order/report/account_payment_order.py index 1674137e8..43edaf238 100644 --- a/account_payment_order/report/account_payment_order.py +++ b/account_payment_order/report/account_payment_order.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # © 2017 Acsone SA/NV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, models from odoo.tools.misc import formatLang diff --git a/account_payment_order/report/account_payment_order.xml b/account_payment_order/report/account_payment_order.xml index 53264b030..b5875c26a 100644 --- a/account_payment_order/report/account_payment_order.xml +++ b/account_payment_order/report/account_payment_order.xml @@ -1,6 +1,6 @@ + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->