From 52bb75e13e3a1779876576d37297b12490d4bdb4 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Thu, 17 Nov 2016 12:48:35 +0100 Subject: [PATCH] Merge account_payment_bank functionality account_bank originally did not depend on the account_payment module, but since version 4.1 the account_payment_type depends on the account_payment module, and hence the account_bank indirectly depends on it. We now make this dependency explicit and deprecate the account_payment_bank functionality --- __init__.py | 5 ++ account.xml | 6 ++ doc/es/account_payment.rst | 4 + doc/es/index.rst | 4 + locale/ca.po | 25 +++++- locale/es.po | 27 +++++- payment.py | 157 ++++++++++++++++++++++++++++++++++ payment.xml | 87 +++++++++++++++++++ tryton.cfg | 4 +- view/move_line_list.xml | 11 +++ view/payment_form.xml | 11 +++ view/payment_group_form.xml | 14 +++ view/payment_group_list.xml | 11 +++ view/payment_journal_form.xml | 14 +++ view/payment_journal_list.xml | 10 +++ view/payment_list.xml | 10 +++ 16 files changed, 395 insertions(+), 5 deletions(-) create mode 100644 doc/es/account_payment.rst create mode 100644 payment.py create mode 100644 payment.xml create mode 100644 view/move_line_list.xml create mode 100644 view/payment_form.xml create mode 100644 view/payment_group_form.xml create mode 100644 view/payment_group_list.xml create mode 100644 view/payment_journal_form.xml create mode 100644 view/payment_journal_list.xml create mode 100644 view/payment_list.xml diff --git a/__init__.py b/__init__.py index fdfb5d2..abbbeed 100644 --- a/__init__.py +++ b/__init__.py @@ -3,6 +3,7 @@ # the full copyright notices and license terms. from trytond.pool import Pool from .account import * +from . import payment def register(): @@ -14,6 +15,10 @@ def register(): Reconciliation, Line, CompensationMoveStart, + payment.Journal, + payment.Group, + payment.Payment, + payment.PayLine, module='account_bank', type_='model') Pool.register( CompensationMove, diff --git a/account.xml b/account.xml index d3a7f83..1f7c55e 100644 --- a/account.xml +++ b/account.xml @@ -43,6 +43,12 @@ copyright notices and license terms. --> account.move.line,-1 + + account.move.line + + + move_line_list + diff --git a/doc/es/account_payment.rst b/doc/es/account_payment.rst new file mode 100644 index 0000000..46f7535 --- /dev/null +++ b/doc/es/account_payment.rst @@ -0,0 +1,4 @@ +#:after:account_payment/account_payment:paragraph:configuracion# + +A continuación deberá seleccionar el tercero que realizará +la orden de pago, la cuenta bancaria y el tipo de pago a realizar. diff --git a/doc/es/index.rst b/doc/es/index.rst index 90a7b83..e535cff 100644 --- a/doc/es/index.rst +++ b/doc/es/index.rst @@ -4,3 +4,7 @@ Contabilidad con banco Añade el banco mediante el que se hace el pago/cobro de las ventas/compras a las facturas y apuntes contables. + +Además proporciona: +* Una forma más eficiente de gestionar el pago de facturas. +* Un mecanismo básico para conectar fácilmente varios pagos automatizados. diff --git a/locale/ca.po b/locale/ca.po index 0931a41..1730a39 100644 --- a/locale/ca.po +++ b/locale/ca.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" @@ -117,6 +117,10 @@ msgctxt "field:account.move.compensation_move.start,party:" msgid "Party" msgstr "Tercer" +msgctxt "field:account.move.line,netting_moves:" +msgid "With Netting Moves" +msgstr "Amb movimients a compensar" + msgctxt "field:account.move.line,reverse_moves:" msgid "With Reverse Moves" msgstr "Amb apunts inversos" @@ -141,6 +145,21 @@ msgctxt "model:ir.action,name:act_compensation_move_lines" msgid "Create compensation move" msgstr "Crea assentament de compensació" +msgctxt "" +"model:ir.action.act_window.domain,name:act_move_line_form_domain_netting" +msgid "Netting" +msgstr "A compensar" + +msgctxt "" +"model:ir.action.act_window.domain,name:act_move_line_form_domain_payable_with_reverse" +msgid "Payable with reverse moves" +msgstr "A pagar amb apunts inversos" + +msgctxt "" +"model:ir.action.act_window.domain,name:act_move_line_form_domain_receivable_with_reverse" +msgid "Receivable with reverse moves" +msgstr "A cobrar amb apunts inversos" + msgctxt "selection:account.invoice,account_bank:" msgid "Company" msgstr "Empresa" @@ -177,6 +196,10 @@ msgctxt "view:account.move.compensation_move.start:" msgid "Create Compensation Move" msgstr "Crea assentament de compensació" +msgctxt "view:account.payment.journal:" +msgid "Sender data" +msgstr "Dades de l'emissor" + msgctxt "wizard_button:account.move.compensation_move,start,create_move:" msgid "Create" msgstr "Crea" diff --git a/locale/es.po b/locale/es.po index 38720fd..54a908d 100644 --- a/locale/es.po +++ b/locale/es.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" @@ -98,10 +98,10 @@ msgctxt "field:account.move.compensation_move.start,account:" msgid "Account" msgstr "Cuenta" - msgctxt "field:account.move.compensation_move.start,date:" msgid "Date" msgstr "Fecha" + msgctxt "field:account.move.compensation_move.start,id:" msgid "ID" msgstr "ID" @@ -114,6 +114,10 @@ msgctxt "field:account.move.compensation_move.start,party:" msgid "Party" msgstr "Terceros" +msgctxt "field:account.move.line,netting_moves:" +msgid "With Netting Moves" +msgstr "Con movimientos a compensar" + msgctxt "field:account.move.line,reverse_moves:" msgid "With Reverse Moves" msgstr "Con apuntes inversos" @@ -138,6 +142,21 @@ msgctxt "model:ir.action,name:act_compensation_move_lines" msgid "Create compensation move" msgstr "Crear efecto de compensación" +msgctxt "" +"model:ir.action.act_window.domain,name:act_move_line_form_domain_netting" +msgid "Netting" +msgstr "A compensar" + +msgctxt "" +"model:ir.action.act_window.domain,name:act_move_line_form_domain_payable_with_reverse" +msgid "Payable with reverse moves" +msgstr "A pagar con apuntes inversos" + +msgctxt "" +"model:ir.action.act_window.domain,name:act_move_line_form_domain_receivable_with_reverse" +msgid "Receivable with reverse moves" +msgstr "A cobrar con apuntes inversos" + msgctxt "selection:account.invoice,account_bank:" msgid "Company" msgstr "Empresa" @@ -174,6 +193,10 @@ msgctxt "view:account.move.compensation_move.start:" msgid "Create Compensation Move" msgstr "Crear efecto de compensación" +msgctxt "view:account.payment.journal:" +msgid "Sender data" +msgstr "Datos del emisor" + msgctxt "wizard_button:account.move.compensation_move,start,create_move:" msgid "Create" msgstr "Crear" diff --git a/payment.py b/payment.py new file mode 100644 index 0000000..8f229c0 --- /dev/null +++ b/payment.py @@ -0,0 +1,157 @@ +# The COPYRIGHT file at the top level of this repository contains +# the full copyright notices and license terms. +from decimal import Decimal + +from trytond.model import fields +from trytond.pool import Pool, PoolMeta +from trytond.pyson import Eval + +__all__ = ['Journal', 'Group', 'Payment', 'PayLine'] + +_ZERO = Decimal('0.0') + + +class Journal: + __metaclass__ = PoolMeta + __name__ = 'account.payment.journal' + + payment_type = fields.Many2One('account.payment.type', 'Payment Type', + required=True) + party = fields.Many2One('party.party', 'Party', + help=('The party who sends the payment group, if it is different from ' + 'the company.')) + + +class Group: + __metaclass__ = PoolMeta + __name__ = 'account.payment.group' + + payment_type = fields.Function(fields.Many2One('account.payment.type', + 'Payment Type'), + 'on_change_with_payment_type') + currency_digits = fields.Function(fields.Integer('Currency Digits'), + 'on_change_with_currency_digits') + amount = fields.Function(fields.Numeric('Total', digits=(16, + Eval('currency_digits', 2)), depends=['currency_digits']), + 'get_amount') + + @classmethod + def default_currency_digits(cls): + return 2 + + @fields.depends('journal') + def on_change_with_payment_type(self, name=None): + if self.journal and self.journal.payment_type: + return self.journal.payment_type.id + + @fields.depends('journal') + def on_change_with_currency_digits(self, name=None): + if self.journal and self.journal.currency: + return self.journal.currency.digits + return 2 + + def get_amount(self, name): + amount = _ZERO + for payment in self.payments: + amount += payment.amount + if self.journal and self.journal.currency: + return self.journal.currency.round(amount) + else: + return amount + + +class Payment: + __metaclass__ = PoolMeta + __name__ = 'account.payment' + bank_account = fields.Many2One('bank.account', 'Bank Account', + states={ + 'readonly': Eval('state') != 'draft', + }, + domain=[ + ('owners', '=', Eval('party')) + ], + depends=['party', 'kind']) + + @classmethod + def __setup__(cls): + super(Payment, cls).__setup__() + if 'party' not in cls.kind.on_change: + cls.kind.on_change.add('party') + if 'kind' not in cls.party.on_change: + cls.party.on_change.add('kind') + if 'kind' not in cls.line.on_change: + cls.line.on_change.add('kind') + if 'party' not in cls.line.on_change: + cls.line.on_change.add('party') + cls._error_messages.update({ + 'no_mandate_for_party': ('No valid mandate for payment ' + '"%(payment)s" of party "%(party)s" with amount ' + '"%(amount)s".'), + }) + + @fields.depends('party', 'kind') + def on_change_kind(self): + super(Payment, self).on_change_kind() + self.bank_account = None + party = self.party + if self.kind and party: + default_bank_account = getattr(party, self.kind + '_bank_account') + self.bank_account = (default_bank_account and + default_bank_account.id or None) + + @fields.depends('party', 'kind') + def on_change_party(self): + super(Payment, self).on_change_party() + self.bank_account = None + party = self.party + if party and self.kind: + default_bank_account = getattr(party, self.kind + '_bank_account') + self.bank_account = (default_bank_account and + default_bank_account.id or None) + + @fields.depends('party', 'line') + def on_change_line(self): + super(Payment, self).on_change_line() + self.bank_account = None + party = self.party + if self.line and self.line.bank_account: + self.bank_account = self.line.bank_account.id + elif party and self.kind: + default_bank_account = getattr(party, self.kind + '_bank_account') + self.bank_account = (default_bank_account and + default_bank_account.id or None) + + @classmethod + def get_sepa_mandates(cls, payments): + mandates = super(Payment, cls).get_sepa_mandates(payments) + mandates2 = [] + for payment, mandate in zip(payments, mandates): + if not mandate: + cls.raise_user_error('no_mandate_for_party', { + 'payment': payment.rec_name, + 'party': payment.party.rec_name, + 'amount': payment.amount, + }) + if payment.bank_account != mandate.account_number.account: + mandate = None + for mandate2 in payment.party.sepa_mandates: + if (mandate2.is_valid and + mandate2.account_number.account == payment.bank_account + ): + mandate = mandate2 + break + mandates2.append(mandate) + return mandates2 + + +class PayLine: + __metaclass__ = PoolMeta + __name__ = 'account.move.line.pay' + + def get_payment(self, line, journals): + pool = Pool() + Invoice = pool.get('account.invoice') + payment = super(PayLine, self).get_payment(line, journals) + if isinstance(line.origin, Invoice): + payment.bank_account = line.origin.bank_account + return payment diff --git a/payment.xml b/payment.xml new file mode 100644 index 0000000..1bf1b39 --- /dev/null +++ b/payment.xml @@ -0,0 +1,87 @@ + + + + + + + account.payment.journal + + + + payment_journal_form + + + + account.payment.journal + + + + payment_journal_list + + + + + account.payment.group + + + + payment_group_form + + + account.payment.group + + + + payment_group_list + + + + + account.payment + + + payment_form + + + account.payment + + + + payment_list + + + + + + + + Netting + + + + + + Payable with reverse moves + + + + + + Receivable with reverse moves + + + + + + diff --git a/tryton.cfg b/tryton.cfg index b90bd02..c56a449 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,11 +1,11 @@ [tryton] version=4.1.0 depends: - ir - res account account_invoice + account_payment account_payment_type company_bank xml: account.xml + payment.xml diff --git a/view/move_line_list.xml b/view/move_line_list.xml new file mode 100644 index 0000000..05e4d17 --- /dev/null +++ b/view/move_line_list.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/view/payment_form.xml b/view/payment_form.xml new file mode 100644 index 0000000..48f4f45 --- /dev/null +++ b/view/payment_form.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/view/payment_group_form.xml b/view/payment_group_form.xml new file mode 100644 index 0000000..b5ddbde --- /dev/null +++ b/view/payment_group_form.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/view/payment_group_list.xml b/view/payment_group_list.xml new file mode 100644 index 0000000..0bce331 --- /dev/null +++ b/view/payment_group_list.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/view/payment_journal_form.xml b/view/payment_journal_form.xml new file mode 100644 index 0000000..5ccf1b9 --- /dev/null +++ b/view/payment_journal_form.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/view/payment_journal_list.xml b/view/payment_journal_list.xml new file mode 100644 index 0000000..99c0e32 --- /dev/null +++ b/view/payment_journal_list.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/view/payment_list.xml b/view/payment_list.xml new file mode 100644 index 0000000..5bb09cf --- /dev/null +++ b/view/payment_list.xml @@ -0,0 +1,10 @@ + + + + + + +