Upgrade from 4.2
This commit is contained in:
parent
3c81c91190
commit
ce1f780e9d
|
@ -1,8 +1,3 @@
|
|||
* Use BankMixin on payments
|
||||
* Allow to modify the bank account when payment type is of other kind
|
||||
* Remove bank_account for payment type
|
||||
* Add payment_type as filter of default bank accounts
|
||||
|
||||
Version 4.2.0 - 2016-11-28
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Remove bank_account from Account Move Lines
|
||||
|
|
|
@ -4,15 +4,13 @@
|
|||
from trytond.pool import Pool
|
||||
from .account import *
|
||||
from . import payment
|
||||
from . import party
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
PaymentType,
|
||||
BankAccount,
|
||||
party.Party,
|
||||
party.PartyDefaultBankAccount,
|
||||
Party,
|
||||
Invoice,
|
||||
Reconciliation,
|
||||
Line,
|
||||
|
@ -20,8 +18,8 @@ def register():
|
|||
payment.Journal,
|
||||
payment.Group,
|
||||
payment.Payment,
|
||||
payment.PayLine,
|
||||
module='account_bank', type_='model')
|
||||
Pool.register(
|
||||
CompensationMove,
|
||||
payment.PayLine,
|
||||
module='account_bank', type_='wizard')
|
||||
|
|
132
account.py
132
account.py
|
@ -12,7 +12,7 @@ from trytond.pyson import Eval, Bool, If
|
|||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import Wizard, StateTransition, StateView, Button
|
||||
|
||||
__all__ = ['PaymentType', 'BankAccount', 'Invoice', 'Reconciliation',
|
||||
__all__ = ['PaymentType', 'BankAccount', 'Party', 'Invoice', 'Reconciliation',
|
||||
'Line', 'CompensationMoveStart', 'CompensationMove']
|
||||
|
||||
ACCOUNT_BANK_KIND = [
|
||||
|
@ -34,6 +34,18 @@ class PaymentType:
|
|||
'invisible': Eval('account_bank') != 'other',
|
||||
},
|
||||
depends=['account_bank'])
|
||||
bank_account = fields.Many2One('bank.account', 'Bank Account',
|
||||
domain=[
|
||||
If(Eval('party', None) == None,
|
||||
('id', '=', -1),
|
||||
('owners.id', '=', Eval('party')),
|
||||
),
|
||||
],
|
||||
states={
|
||||
'required': Eval('account_bank') == 'other',
|
||||
'invisible': Eval('account_bank') != 'other',
|
||||
},
|
||||
depends=['party', 'account_bank'])
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -56,12 +68,11 @@ class BankAccount:
|
|||
cls._check_owners_fields = set(['owners'])
|
||||
cls._check_owners_related_models = set([
|
||||
('account.invoice', 'bank_account'),
|
||||
('account.payment', 'bank_account'),
|
||||
])
|
||||
cls._error_messages.update({
|
||||
'modify_with_related_model': ('It is not possible to modify '
|
||||
'modifiy_with_related_model': ('It is not possible to modify '
|
||||
'the owner of bank account "%(account)s" as it is used on '
|
||||
'the "%(field)s" of %(model)s "%(name)s".'),
|
||||
'en el %(field)s del %(model)s "%(name)s"'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
|
@ -99,10 +110,28 @@ class BankAccount:
|
|||
'field': field.field_description,
|
||||
'name': record.rec_name,
|
||||
}
|
||||
cls.raise_user_error('modify_with_related_model',
|
||||
cls.raise_user_error('modifiy_with_related_model',
|
||||
error_args)
|
||||
|
||||
|
||||
class Party:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'party.party'
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
pool = Pool()
|
||||
BankAccount = pool.get('bank.account')
|
||||
actions = iter(args)
|
||||
all_accounts = []
|
||||
for parties, values in zip(actions, actions):
|
||||
if set(values.keys()) & set(['bank_accounts']):
|
||||
all_accounts += list(set(
|
||||
[a for p in parties for a in p.bank_accounts]))
|
||||
super(Party, cls).write(*args)
|
||||
BankAccount.check_owners(all_accounts)
|
||||
|
||||
|
||||
class BankMixin(object):
|
||||
account_bank = fields.Function(fields.Selection(ACCOUNT_BANK_KIND,
|
||||
'Account Bank'),
|
||||
|
@ -112,9 +141,13 @@ class BankMixin(object):
|
|||
'on_change_with_account_bank_from')
|
||||
bank_account = fields.Many2One('bank.account', 'Bank Account',
|
||||
domain=[
|
||||
('owners.id', '=', Eval('account_bank_from')),
|
||||
If(Eval('account_bank_from', None) == None,
|
||||
('id', '=', -1),
|
||||
('owners.id', '=', Eval('account_bank_from')),
|
||||
),
|
||||
],
|
||||
states={
|
||||
'readonly': Eval('account_bank') == 'other',
|
||||
'invisible': ~Bool(Eval('account_bank_from')),
|
||||
},
|
||||
depends=['party', 'payment_type', 'account_bank_from', 'account_bank'],
|
||||
|
@ -126,44 +159,45 @@ class BankMixin(object):
|
|||
return self.payment_type.account_bank
|
||||
|
||||
def _get_bank_account(self):
|
||||
pattern = {}
|
||||
parties = []
|
||||
if not self.payment_type:
|
||||
return None
|
||||
if self.party:
|
||||
parties.append(self.party)
|
||||
if self.payment_type.account_bank == 'none':
|
||||
return None
|
||||
pattern['payment_type'] = self.payment_type.id
|
||||
if self.payment_type.kind != 'both':
|
||||
pattern['kind'] = self.payment_type.kind
|
||||
if self.account_bank_from:
|
||||
pattern['bank_account_owner'] = self.account_bank_from.id
|
||||
if self.company:
|
||||
pattern['company'] = self.company.id if self.company else None
|
||||
if self.payment_type.account_bank == 'company':
|
||||
parties.append(self.company.party)
|
||||
if self.payment_type.account_bank == 'other':
|
||||
parties.append(self.payment_type.party)
|
||||
for party in parties:
|
||||
bank_account = party.get_default_bank_account(pattern=pattern)
|
||||
if bank_account:
|
||||
return bank_account.id
|
||||
return None
|
||||
pool = Pool()
|
||||
Party = pool.get('party.party')
|
||||
|
||||
@fields.depends('party', 'payment_type', 'company', 'account_bank_from')
|
||||
def on_change_payment_type(self):
|
||||
self.account_bank_from = self.on_change_with_account_bank_from()
|
||||
self.bank_account = self.on_change_with_bank_account()
|
||||
self.bank_account = None
|
||||
if self.party and self.payment_type:
|
||||
if self.payment_type.account_bank == 'other':
|
||||
self.bank_account = self.payment_type.bank_account
|
||||
else:
|
||||
party_fname = '%s_bank_account' % self.payment_type.kind
|
||||
if hasattr(Party, party_fname):
|
||||
account_bank = self.payment_type.account_bank
|
||||
if account_bank == 'company':
|
||||
party_company_fname = ('%s_company_bank_account' %
|
||||
self.payment_type.kind)
|
||||
company_bank = getattr(self.party, party_company_fname,
|
||||
None)
|
||||
if company_bank:
|
||||
self.bank_account = company_bank
|
||||
elif hasattr(self, 'company') and self.company:
|
||||
default_bank = getattr(
|
||||
self.company.party, party_fname)
|
||||
self.bank_account = default_bank
|
||||
return
|
||||
elif account_bank == 'party' and self.party:
|
||||
default_bank = getattr(self.party, party_fname)
|
||||
self.bank_account = default_bank
|
||||
return
|
||||
|
||||
@fields.depends('party', 'payment_type', 'company', 'account_bank_from')
|
||||
@fields.depends('party', 'payment_type', methods=['payment_type'])
|
||||
def on_change_with_bank_account(self):
|
||||
'''
|
||||
Add account bank when changes payment_type or party.
|
||||
'''
|
||||
return self._get_bank_account()
|
||||
if hasattr(self, 'on_change_with_payment_type'):
|
||||
self.payment_type = self.on_change_with_payment_type()
|
||||
self._get_bank_account()
|
||||
return self.bank_account.id if self.bank_account else None
|
||||
|
||||
@fields.depends('payment_type', 'party', 'company')
|
||||
@fields.depends('payment_type', 'party', methods=['payment_type'])
|
||||
def on_change_with_account_bank_from(self, name=None):
|
||||
'''
|
||||
Sets the party where get bank account for this move line.
|
||||
|
@ -171,20 +205,18 @@ class BankMixin(object):
|
|||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
|
||||
if self.payment_type:
|
||||
if hasattr(self, 'on_change_with_payment_type'):
|
||||
self.payment_type = self.on_change_with_payment_type()
|
||||
if self.payment_type and self.party:
|
||||
payment_type = self.payment_type
|
||||
party = self.party
|
||||
if payment_type.account_bank == 'party':
|
||||
return self.party.id if self.party else None
|
||||
return party.id
|
||||
elif payment_type.account_bank == 'company':
|
||||
if self.company:
|
||||
return self.company.party.id
|
||||
else:
|
||||
company = Transaction().context.get('company', False)
|
||||
if company:
|
||||
return Company(company).party.id
|
||||
company = Transaction().context.get('company', False)
|
||||
return Company(company).party.id
|
||||
elif payment_type.account_bank == 'other':
|
||||
return payment_type.party.id
|
||||
return None
|
||||
|
||||
|
||||
class Invoice(BankMixin):
|
||||
|
@ -225,7 +257,9 @@ class Invoice(BankMixin):
|
|||
invoice.party = Party(party)
|
||||
invoice.company = Company(company)
|
||||
invoice.payment_type = PaymentType(payment_type)
|
||||
changes['bank_account'] = invoice._get_bank_account()
|
||||
invoice._get_bank_account()
|
||||
changes['bank_account'] = invoice.bank_account.id \
|
||||
if invoice.bank_account else None
|
||||
return changes
|
||||
|
||||
@classmethod
|
||||
|
@ -235,7 +269,7 @@ class Invoice(BankMixin):
|
|||
values.update(cls.compute_default_bank_account(values))
|
||||
return super(Invoice, cls).create(vlist)
|
||||
|
||||
@fields.depends('payment_type', 'party', 'company', 'account_bank_from')
|
||||
@fields.depends('payment_type', 'party', 'company')
|
||||
def on_change_party(self):
|
||||
'''
|
||||
Add account bank to invoice line when changes party.
|
||||
|
@ -243,7 +277,7 @@ class Invoice(BankMixin):
|
|||
super(Invoice, self).on_change_party()
|
||||
self.bank_account = None
|
||||
if self.payment_type:
|
||||
self.bank_account = self._get_bank_account()
|
||||
self._get_bank_account()
|
||||
|
||||
@classmethod
|
||||
def post(cls, invoices):
|
||||
|
|
112
locale/ca.po
112
locale/ca.po
|
@ -2,6 +2,22 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"%s has no any %s bank account.\n"
|
||||
"Please set up one if you want to use this payment type."
|
||||
msgstr ""
|
||||
"%s no té cap compte bancari %s.\n"
|
||||
"Si us plau, establiu un si voleu utilitzar aquest tipus de pagament."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" cannot be moved to \"Draft\" state because it is "
|
||||
"already used in statement line \"%(statement_line)s\"."
|
||||
msgstr ""
|
||||
"La factura \"%(invoice)s\" no es pot passar a estat \"Esborrany\" perquè ja "
|
||||
"s'utilitza en la línia d'extracte \"%(statement_line)s\"."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" has no bank account associated but payment type "
|
||||
|
@ -61,21 +77,13 @@ msgstr ""
|
|||
"No podeu modificar els apunts de l'assentament \"%s\" perquè ja està "
|
||||
"confirmat."
|
||||
|
||||
msgctxt "error:account.payment:"
|
||||
msgid ""
|
||||
"No valid mandate for payment \"%(payment)s\" of party \"%(party)s\" with "
|
||||
"amount \"%(amount)s\"."
|
||||
msgstr ""
|
||||
"No existeix cap mandat vàlid pel pagament \"%(payment)s\" del tercer "
|
||||
"\"%(party)s\" amb importe \"%(amount)s\"."
|
||||
|
||||
msgctxt "error:bank.account:"
|
||||
msgid ""
|
||||
"It is not possible to modify the owner of bank account \"%(account)s\" as it"
|
||||
" is used on the \"%(field)s\" of %(model)s \"%(name)s\"."
|
||||
" is used on en el %(field)s del %(model)s \"%(name)s\""
|
||||
msgstr ""
|
||||
"No es pot modificar el propietari del compte bancari \"%(account)s\" perquè "
|
||||
"s'utilitza en el \"%(field)s\" del %(model)s \"%(name)s\"."
|
||||
"No es possible modificar el titular del compte bancari \"%(account)s\" que "
|
||||
"ja es usa a %(field)s del %(model)s \"%(name)s\"."
|
||||
|
||||
msgctxt "field:account.invoice,account_bank:"
|
||||
msgid "Account Bank"
|
||||
|
@ -113,72 +121,22 @@ msgctxt "field:account.move.line,netting_moves:"
|
|||
msgid "With Netting Moves"
|
||||
msgstr "Amb movimients a compensar"
|
||||
|
||||
msgctxt "field:account.move.line,payment_blocked:"
|
||||
msgid "Blocked"
|
||||
msgstr "Bloquejada"
|
||||
|
||||
msgctxt "field:account.move.line,reverse_moves:"
|
||||
msgid "With Reverse Moves"
|
||||
msgstr "Amb apunts inversos"
|
||||
|
||||
msgctxt "field:account.move.line,second_currency_required:"
|
||||
msgid "Second Currency Required"
|
||||
msgstr "Segona moneda obligatoria"
|
||||
|
||||
msgctxt "field:account.payment,account_bank:"
|
||||
msgid "Account Bank"
|
||||
msgstr "Compte bancari"
|
||||
|
||||
msgctxt "field:account.payment,account_bank_from:"
|
||||
msgid "Account Bank From"
|
||||
msgstr "Compte bancari de"
|
||||
|
||||
msgctxt "field:account.payment,bank_account:"
|
||||
msgid "Bank Account"
|
||||
msgstr "Comptes bancaris"
|
||||
|
||||
msgctxt "field:account.payment,payment_type:"
|
||||
msgid "Payment Type"
|
||||
msgstr "Tipus de pagament"
|
||||
|
||||
msgctxt "field:account.payment.group,amount:"
|
||||
msgid "Total"
|
||||
msgstr "Total"
|
||||
|
||||
msgctxt "field:account.payment.group,currency_digits:"
|
||||
msgid "Currency Digits"
|
||||
msgstr "Decimals de la moneda"
|
||||
|
||||
msgctxt "field:account.payment.journal,party:"
|
||||
msgid "Party"
|
||||
msgstr "Tercer"
|
||||
|
||||
msgctxt "field:account.payment.type,account_bank:"
|
||||
msgid "Account Bank Kind"
|
||||
msgstr "Tipus compte bancari"
|
||||
|
||||
msgctxt "field:account.payment.type,bank_account:"
|
||||
msgid "Bank Account"
|
||||
msgstr "Compte bancari"
|
||||
|
||||
msgctxt "field:account.payment.type,party:"
|
||||
msgid "Party"
|
||||
msgstr "Tercer"
|
||||
|
||||
msgctxt "field:party.party,company_default_bank_accounts:"
|
||||
msgid "Default Bank Accounts"
|
||||
msgstr "Comptes bancaris per defecte"
|
||||
|
||||
msgctxt "field:party.party,currency_digits:"
|
||||
msgid "Currency Digits"
|
||||
msgstr "Decimals de la moneda"
|
||||
|
||||
msgctxt "field:party.party.default.bank_account,payment_type:"
|
||||
msgid "Payment Type"
|
||||
msgstr "Tipus de pagament"
|
||||
|
||||
msgctxt "help:account.payment.journal,party:"
|
||||
msgid ""
|
||||
"The party who sends the payment group, if it is different from the company."
|
||||
msgstr ""
|
||||
"El tercer que envia el grup de pagaments, si es diferent de l'empresa."
|
||||
|
||||
msgctxt "model:account.move.compensation_move.start,name:"
|
||||
msgid "Create Compensation Move Start"
|
||||
msgstr "Inici crea assentament de compensació"
|
||||
|
@ -218,22 +176,6 @@ msgctxt "selection:account.invoice,account_bank:"
|
|||
msgid "Party"
|
||||
msgstr "Tercer"
|
||||
|
||||
msgctxt "selection:account.payment,account_bank:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
||||
msgctxt "selection:account.payment,account_bank:"
|
||||
msgid "None"
|
||||
msgstr "Cap"
|
||||
|
||||
msgctxt "selection:account.payment,account_bank:"
|
||||
msgid "Other"
|
||||
msgstr "Un altre"
|
||||
|
||||
msgctxt "selection:account.payment,account_bank:"
|
||||
msgid "Party"
|
||||
msgstr "Tercers"
|
||||
|
||||
msgctxt "selection:account.payment.type,account_bank:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
@ -254,14 +196,6 @@ msgctxt "view:account.move.compensation_move.start:"
|
|||
msgid "Create Compensation Move"
|
||||
msgstr "Crea assentament de compensació"
|
||||
|
||||
msgctxt "view:account.move.line:"
|
||||
msgid "Total Credit"
|
||||
msgstr "Total haver"
|
||||
|
||||
msgctxt "view:account.move.line:"
|
||||
msgid "Total Debit"
|
||||
msgstr "Total deure"
|
||||
|
||||
msgctxt "view:account.payment.journal:"
|
||||
msgid "Sender data"
|
||||
msgstr "Dades de l'emissor"
|
||||
|
|
111
locale/es.po
111
locale/es.po
|
@ -2,6 +2,22 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"%s has no any %s bank account.\n"
|
||||
"Please set up one if you want to use this payment type."
|
||||
msgstr ""
|
||||
"%s no tiene ninguna cuenta bancaria %s.\n"
|
||||
"Por favor establezca una si quiere utilizar este tipo de pago."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" cannot be moved to \"Draft\" state because it is "
|
||||
"already used in statement line \"%(statement_line)s\"."
|
||||
msgstr ""
|
||||
"La factura \"%(invoice)s\" no se puede pasar a estado \"Borrador\" porqué se"
|
||||
" utiliza en la línea de extracto \"%(statement_line)s\"."
|
||||
|
||||
msgctxt "error:account.invoice:"
|
||||
msgid ""
|
||||
"Invoice \"%(invoice)s\" has no bank account associated but payment type "
|
||||
|
@ -58,21 +74,13 @@ msgctxt "error:account.move.line:"
|
|||
msgid "You can not modify lines of move \"%s\" because it is already posted."
|
||||
msgstr "No puede modificar apuntes del asiento \"%s\" porque ya está confirmado."
|
||||
|
||||
msgctxt "error:account.payment:"
|
||||
msgid ""
|
||||
"No valid mandate for payment \"%(payment)s\" of party \"%(party)s\" with "
|
||||
"amount \"%(amount)s\"."
|
||||
msgstr ""
|
||||
"No existe ningún mandato valido para el pago \"%(payment)s\" del tercero "
|
||||
"\"%(party)s\" con importe \"%(amount)s\"."
|
||||
|
||||
msgctxt "error:bank.account:"
|
||||
msgid ""
|
||||
"It is not possible to modify the owner of bank account \"%(account)s\" as it"
|
||||
" is used on the \"%(field)s\" of %(model)s \"%(name)s\"."
|
||||
" is used on en el %(field)s del %(model)s \"%(name)s\""
|
||||
msgstr ""
|
||||
"No se puede modificar el propietario de la cuenta banaria \"%(account)s\" "
|
||||
"porque se utiliza en el \"%(field)s\" del %(model)s \"%(name)s\"."
|
||||
"No se puede modificar el titular de la cuenta bancaria \"%(account)s\" que "
|
||||
"ya se usa a %(field)s del %(model)s \"%(name)s\"."
|
||||
|
||||
msgctxt "field:account.invoice,account_bank:"
|
||||
msgid "Account Bank"
|
||||
|
@ -110,71 +118,22 @@ msgctxt "field:account.move.line,netting_moves:"
|
|||
msgid "With Netting Moves"
|
||||
msgstr "Con movimientos a compensar"
|
||||
|
||||
msgctxt "field:account.move.line,payment_blocked:"
|
||||
msgid "Blocked"
|
||||
msgstr "Bloqueada"
|
||||
|
||||
msgctxt "field:account.move.line,reverse_moves:"
|
||||
msgid "With Reverse Moves"
|
||||
msgstr "Con apuntes inversos"
|
||||
|
||||
msgctxt "field:account.move.line,second_currency_required:"
|
||||
msgid "Second Currency Required"
|
||||
msgstr "Segona moneda obligatoria"
|
||||
|
||||
msgctxt "field:account.payment,account_bank:"
|
||||
msgid "Account Bank"
|
||||
msgstr "Cuenta bancaria"
|
||||
|
||||
msgctxt "field:account.payment,account_bank_from:"
|
||||
msgid "Account Bank From"
|
||||
msgstr "Cuenta bancaria de"
|
||||
|
||||
msgctxt "field:account.payment,bank_account:"
|
||||
msgid "Bank Account"
|
||||
msgstr "Cuenta bancaria"
|
||||
|
||||
msgctxt "field:account.payment,payment_type:"
|
||||
msgid "Payment Type"
|
||||
msgstr "Tipo de pago"
|
||||
|
||||
msgctxt "field:account.payment.group,amount:"
|
||||
msgid "Total"
|
||||
msgstr "Total"
|
||||
|
||||
msgctxt "field:account.payment.group,currency_digits:"
|
||||
msgid "Currency Digits"
|
||||
msgstr "Decimals de la moneda"
|
||||
|
||||
msgctxt "field:account.payment.journal,party:"
|
||||
msgid "Party"
|
||||
msgstr "Tercero"
|
||||
|
||||
msgctxt "field:account.payment.type,account_bank:"
|
||||
msgid "Account Bank Kind"
|
||||
msgstr "Tipo cuenta bancaria"
|
||||
|
||||
msgctxt "field:account.payment.type,bank_account:"
|
||||
msgid "Bank Account"
|
||||
msgstr "Cuenta bancaria"
|
||||
|
||||
msgctxt "field:account.payment.type,party:"
|
||||
msgid "Party"
|
||||
msgstr "Tercero"
|
||||
|
||||
msgctxt "field:party.party,company_default_bank_accounts:"
|
||||
msgid "Default Bank Accounts"
|
||||
msgstr "Cuentas bancarias por defecto"
|
||||
|
||||
msgctxt "field:party.party,currency_digits:"
|
||||
msgid "Currency Digits"
|
||||
msgstr "Decimals de la moneda"
|
||||
|
||||
msgctxt "field:party.party.default.bank_account,payment_type:"
|
||||
msgid "Payment Type"
|
||||
msgstr "Tipo de pago"
|
||||
|
||||
msgctxt "help:account.payment.journal,party:"
|
||||
msgid ""
|
||||
"The party who sends the payment group, if it is different from the company."
|
||||
msgstr "El tercero que envia el grupo de pago, si es distinto de la empresa."
|
||||
|
||||
msgctxt "model:account.move.compensation_move.start,name:"
|
||||
msgid "Create Compensation Move Start"
|
||||
msgstr "Inicio crear efecto de compensación"
|
||||
|
@ -214,22 +173,6 @@ msgctxt "selection:account.invoice,account_bank:"
|
|||
msgid "Party"
|
||||
msgstr "Tercero"
|
||||
|
||||
msgctxt "selection:account.payment,account_bank:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
||||
msgctxt "selection:account.payment,account_bank:"
|
||||
msgid "None"
|
||||
msgstr "Ninguno"
|
||||
|
||||
msgctxt "selection:account.payment,account_bank:"
|
||||
msgid "Other"
|
||||
msgstr "Otro"
|
||||
|
||||
msgctxt "selection:account.payment,account_bank:"
|
||||
msgid "Party"
|
||||
msgstr "Terceros"
|
||||
|
||||
msgctxt "selection:account.payment.type,account_bank:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
@ -250,14 +193,6 @@ msgctxt "view:account.move.compensation_move.start:"
|
|||
msgid "Create Compensation Move"
|
||||
msgstr "Crear efecto de compensación"
|
||||
|
||||
msgctxt "view:account.move.line:"
|
||||
msgid "Total Credit"
|
||||
msgstr "Total haber"
|
||||
|
||||
msgctxt "view:account.move.line:"
|
||||
msgid "Total Debit"
|
||||
msgstr "Total debe"
|
||||
|
||||
msgctxt "view:account.payment.journal:"
|
||||
msgid "Sender data"
|
||||
msgstr "Datos del emisor"
|
||||
|
|
55
party.py
55
party.py
|
@ -1,55 +0,0 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
||||
__all__ = ['Party', 'PartyDefaultBankAccount']
|
||||
|
||||
|
||||
class Party:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'party.party'
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
pool = Pool()
|
||||
BankAccount = pool.get('bank.account')
|
||||
actions = iter(args)
|
||||
all_accounts = []
|
||||
for parties, values in zip(actions, actions):
|
||||
if set(values.keys()) & set(['bank_accounts']):
|
||||
all_accounts += list(set(
|
||||
[a for p in parties for a in p.bank_accounts]))
|
||||
super(Party, cls).write(*args)
|
||||
BankAccount.check_owners(all_accounts)
|
||||
|
||||
|
||||
class PartyDefaultBankAccount:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'party.party.default.bank_account'
|
||||
|
||||
payment_type = fields.Many2One('account.payment.type', 'Payment Type',
|
||||
domain=[
|
||||
('account_bank', '!=', 'none'),
|
||||
])
|
||||
|
||||
@fields.depends('party', 'company', 'payment_type')
|
||||
def on_change_with_bank_account_owner(self, name=None):
|
||||
party = super(PartyDefaultBankAccount,
|
||||
self).on_change_with_bank_account_owner(name)
|
||||
if not self.payment_type or self.payment_type.account_bank == 'party':
|
||||
return party
|
||||
if self.payment_type.account_bank == 'company':
|
||||
return self.company.party.id if self.company else None
|
||||
if self.payment_type.account_bank == 'other':
|
||||
return self.payment_type.party.id
|
||||
|
||||
@fields.depends('party', 'company', 'payment_type', 'bank_account')
|
||||
def on_change_payment_type(self, name=None):
|
||||
if not self.bank_account:
|
||||
return
|
||||
bank_account_owner = self.on_change_with_bank_account_owner()
|
||||
if (not bank_account_owner
|
||||
or (bank_account_owner not in [o.id for
|
||||
o in self.bank_account.owners])):
|
||||
self.bank_account = None
|
27
party.xml
27
party.xml
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="default_bank_account_view_tree">
|
||||
<field name="model">party.party.default.bank_account</field>
|
||||
<field name="inherit"
|
||||
ref="company_bank.default_bank_account_view_tree"/>
|
||||
<field name="name">default_bank_account_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view"
|
||||
id="default_bank_account_view_tree_sequence">
|
||||
<field name="model">party.party.default.bank_account</field>
|
||||
<field name="inherit"
|
||||
ref="company_bank.default_bank_account_view_tree_sequence"/>
|
||||
<field name="name">default_bank_account_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="default_bank_account_view_form">
|
||||
<field name="model">party.party.default.bank_account</field>
|
||||
<field name="inherit"
|
||||
ref="company_bank.default_bank_account_view_form"/>
|
||||
<field name="name">default_bank_account_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
69
payment.py
69
payment.py
|
@ -5,7 +5,6 @@ from decimal import Decimal
|
|||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from .account import BankMixin
|
||||
|
||||
__all__ = ['Journal', 'Group', 'Payment', 'PayLine']
|
||||
|
||||
|
@ -15,6 +14,9 @@ _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.'))
|
||||
|
@ -23,6 +25,10 @@ class Journal:
|
|||
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,
|
||||
|
@ -54,35 +60,64 @@ class Group:
|
|||
return amount
|
||||
|
||||
|
||||
class Payment(BankMixin):
|
||||
class Payment:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'account.payment'
|
||||
payment_type = fields.Function(fields.Many2One('account.payment.type',
|
||||
'Payment Type'), 'on_change_with_payment_type')
|
||||
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 'payment_type' not in cls.journal.depends:
|
||||
cls.journal.depends.append('payment_type')
|
||||
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('journal')
|
||||
def on_change_with_payment_type(self, name=None):
|
||||
if self.journal:
|
||||
return self.journal.payment_type.id
|
||||
return None
|
||||
@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', 'journal', 'company', 'account_bank_from')
|
||||
def on_change_journal(self):
|
||||
self.payment_type = self.on_change_with_payment_type()
|
||||
self.account_bank = self.on_change_with_account_bank()
|
||||
self.account_bank_from = self.on_change_with_account_bank_from()
|
||||
self.bank_account = self.on_change_with_bank_account()
|
||||
@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.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):
|
||||
|
|
|
@ -13,6 +13,14 @@ copyright notices and license terms. -->
|
|||
<field name="name">payment_journal_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="payment_journal_view_list">
|
||||
<field name="model">account.payment.journal</field>
|
||||
<field name="type" eval="None"/>
|
||||
<field name="priority" eval="20"/>
|
||||
<field name="inherit" ref="account_payment.payment_journal_view_list"/>
|
||||
<field name="name">payment_journal_list</field>
|
||||
</record>
|
||||
|
||||
<!-- account.payment.group -->
|
||||
<record model="ir.ui.view" id="payment_group_view_form">
|
||||
<field name="model">account.payment.group</field>
|
||||
|
|
|
@ -1,216 +0,0 @@
|
|||
=====================
|
||||
Account Bank Scenario
|
||||
=====================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
>>> from trytond.modules.company.tests.tools import create_company, \
|
||||
... get_company
|
||||
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
|
||||
... create_chart, get_accounts
|
||||
>>> from trytond.modules.account_invoice.tests.tools import \
|
||||
... set_fiscalyear_invoice_sequences
|
||||
|
||||
Install account_bank Module::
|
||||
|
||||
>>> config = activate_modules('account_bank')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(company))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = get_accounts(company)
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create party::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> party = Party(name='Party')
|
||||
>>> party.save()
|
||||
|
||||
Create bank accounts::
|
||||
|
||||
>>> Bank = Model.get('bank')
|
||||
>>> BankAccount = Model.get('bank.account')
|
||||
>>> bank_party = Party(name='Bank')
|
||||
>>> bank_party.save()
|
||||
>>> bank = Bank(party=bank_party)
|
||||
>>> bank.save()
|
||||
>>> company_account = BankAccount()
|
||||
>>> company_account.bank = bank
|
||||
>>> company_account.owners.append(company.party)
|
||||
>>> number = company_account.numbers.new()
|
||||
>>> number.type = 'other'
|
||||
>>> number.number = 'Company Account Number'
|
||||
>>> company_account.save()
|
||||
>>> party_account = BankAccount()
|
||||
>>> party_account.bank = bank
|
||||
>>> party_account.owners.append(party)
|
||||
>>> number = party_account.numbers.new()
|
||||
>>> number.type = 'other'
|
||||
>>> number.number = 'Party Account Number'
|
||||
>>> party_account.save()
|
||||
|
||||
Create payment types::
|
||||
|
||||
>>> PaymentType = Model.get('account.payment.type')
|
||||
>>> cash = PaymentType(name='Cash', account_bank='none')
|
||||
>>> cash.save()
|
||||
>>> customer_transfer = PaymentType(name='Customer Transfer',
|
||||
... account_bank='party')
|
||||
>>> customer_transfer.save()
|
||||
>>> other_customer_transfer = PaymentType(name='Other Customer Transfer',
|
||||
... account_bank='party')
|
||||
>>> other_customer_transfer.save()
|
||||
>>> company_transfer = PaymentType(name='Company Transfer',
|
||||
... account_bank='company')
|
||||
>>> company_transfer.save()
|
||||
>>> other_company_transfer = PaymentType(name='Other Company Transfer',
|
||||
... account_bank='company')
|
||||
>>> other_company_transfer.save()
|
||||
|
||||
Check bank account is set when setting the party and payment_type::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> invoice.payment_type = customer_transfer
|
||||
>>> invoice.bank_account == party_account
|
||||
True
|
||||
|
||||
If we use a payment type with no bank account the bank_account is set to None::
|
||||
|
||||
>>> invoice.payment_type = cash
|
||||
>>> invoice.bank_account
|
||||
|
||||
And setting the previous payment_type updates the bank_account::
|
||||
|
||||
>>> invoice.payment_type = customer_transfer
|
||||
>>> invoice.bank_account == party_account
|
||||
True
|
||||
|
||||
The company bank account is used when the payment type requires it::
|
||||
|
||||
>>> invoice.payment_type = company_transfer
|
||||
>>> invoice.bank_account == company_account
|
||||
True
|
||||
|
||||
If the party has several bank accounts no one is picked by default::
|
||||
|
||||
>>> second_party_account = BankAccount()
|
||||
>>> second_party_account.bank = bank
|
||||
>>> second_party_account.owners.append(Party(party.id))
|
||||
>>> number = second_party_account.numbers.new()
|
||||
>>> number.type = 'other'
|
||||
>>> number.number = 'Second Party Account Number'
|
||||
>>> second_party_account.save()
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> invoice.payment_type = customer_transfer
|
||||
>>> invoice.bank_account
|
||||
|
||||
Unless we specify a default one for the party::
|
||||
|
||||
>>> default_bank_account = party.default_bank_accounts.new()
|
||||
>>> default_bank_account.sequence = 10
|
||||
>>> default_bank_account.bank_account = second_party_account
|
||||
>>> default_bank_account.save()
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> invoice.payment_type = customer_transfer
|
||||
>>> invoice.bank_account == second_party_account
|
||||
True
|
||||
|
||||
We can define the bank account per payment_type::
|
||||
|
||||
>>> default_bank_account = party.default_bank_accounts.new()
|
||||
>>> default_bank_account.sequence = 5
|
||||
>>> default_bank_account.payment_type = other_customer_transfer
|
||||
>>> default_bank_account.bank_account = party_account
|
||||
>>> default_bank_account.save()
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> invoice.payment_type = other_customer_transfer
|
||||
>>> invoice.bank_account == party_account
|
||||
True
|
||||
>>> invoice.payment_type = customer_transfer
|
||||
>>> invoice.bank_account == second_party_account
|
||||
True
|
||||
|
||||
And also the company bank account for company payment types::
|
||||
|
||||
>>> second_company_account = BankAccount()
|
||||
>>> second_company_account.bank = bank
|
||||
>>> second_company_account.owners.append(Party(company.party.id))
|
||||
>>> number = second_company_account.numbers.new()
|
||||
>>> number.type = 'other'
|
||||
>>> number.number = 'Second Company Account Number'
|
||||
>>> second_company_account.save()
|
||||
>>> default_bank_account = company.party.default_bank_accounts.new()
|
||||
>>> default_bank_account.sequence = 5
|
||||
>>> default_bank_account.bank_account = company_account
|
||||
>>> default_bank_account.save()
|
||||
>>> default_bank_account = party.default_bank_accounts.new()
|
||||
>>> default_bank_account.sequence = 5
|
||||
>>> default_bank_account.payment_type = other_company_transfer
|
||||
>>> default_bank_account.bank_account = second_company_account
|
||||
>>> default_bank_account.save()
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> invoice.payment_type = company_transfer
|
||||
>>> invoice.bank_account == company_account
|
||||
True
|
||||
>>> invoice.payment_type = other_company_transfer
|
||||
>>> invoice.bank_account == second_company_account
|
||||
True
|
||||
|
||||
Create payment journal for customer transfer::
|
||||
|
||||
>>> payment_journal = customer_transfer.journals.new()
|
||||
>>> payment_journal.name = 'Manual'
|
||||
>>> payment_journal.process_method = 'manual'
|
||||
>>> payment_journal.save()
|
||||
|
||||
The default bank accounts are used on payments also::
|
||||
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> payment = Payment()
|
||||
>>> payment.journal = payment_journal
|
||||
>>> payment.party = party
|
||||
>>> payment.bank_account == second_party_account
|
||||
True
|
||||
|
||||
The invoice bank account is used as default when creating the payments::
|
||||
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.account = revenue
|
||||
>>> line.description = 'Test'
|
||||
>>> line.unit_price = Decimal(10.0)
|
||||
>>> line.quantity = 1.0
|
||||
>>> invoice.payment_type = customer_transfer
|
||||
>>> invoice.bank_account = party_account
|
||||
>>> invoice.click('post')
|
||||
>>> line, = [l for l in invoice.move.lines if l.account == receivable]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.form.journal = payment_journal
|
||||
>>> pay_line.execute('start')
|
||||
>>> payment, = line.payments
|
||||
>>> payment.bank_account == party_account
|
||||
True
|
|
@ -18,10 +18,6 @@ def suite():
|
|||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
AccountBankTestCase))
|
||||
suite.addTests(doctest.DocFileSuite('scenario_account_bank.rst',
|
||||
tearDown=doctest_teardown, encoding='utf-8',
|
||||
checker=doctest_checker,
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
suite.addTests(doctest.DocFileSuite('scenario_compensation_move.rst',
|
||||
tearDown=doctest_teardown, encoding='utf-8',
|
||||
checker=doctest_checker,
|
||||
|
|
|
@ -9,4 +9,3 @@ depends:
|
|||
xml:
|
||||
account.xml
|
||||
payment.xml
|
||||
party.xml
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='kind']" position="after">
|
||||
<xpath expr="/form/field[@name='company']" position="after">
|
||||
<label name="account_bank"/>
|
||||
<field name="account_bank"/>
|
||||
<label name="party"/>
|
||||
<field name="party"/>
|
||||
<label name="bank_account"/>
|
||||
<field name="bank_account"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='company']" position="after">
|
||||
<label name="payment_type"/>
|
||||
<field name="payment_type"/>
|
||||
</xpath>
|
||||
</data>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='company']" position="after">
|
||||
<field name="payment_type"/>
|
||||
</xpath>
|
||||
</data>
|
|
@ -3,8 +3,10 @@
|
|||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='payment_type']"
|
||||
<xpath expr="/form/field[@name="kind"]"
|
||||
position="after">
|
||||
<label name="payment_type"/>
|
||||
<field name="payment_type"/>
|
||||
<label name="amount"/>
|
||||
<field name="amount"/>
|
||||
<field name="payments" colspan="4"/>
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='payment_type']" position="after">
|
||||
<xpath expr="/tree/field[@name="kind"]"
|
||||
position="after">
|
||||
<field name="payment_type"/>
|
||||
<field name="amount"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
|
@ -3,9 +3,12 @@
|
|||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='process_method']" position="after">
|
||||
<xpath expr="/form/field[@name="process_method"]"
|
||||
position="after">
|
||||
<separator string="Sender data" colspan="4" id="presenter_data"/>
|
||||
<label name="party"/>
|
||||
<field name="party"/>
|
||||
<label name="payment_type"/>
|
||||
<field name="payment_type"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part account_payment_bank module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name="process_method"]"
|
||||
position="after">
|
||||
<field name="payment_type"/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in New Issue