Revert remove bank_account from Account Move Lines

From changeset-08095bcad47f
This commit is contained in:
Raimon Esteve 2018-09-10 15:11:13 +02:00
parent 874a13e331
commit a881707765
9 changed files with 318 additions and 32 deletions

View File

@ -2,7 +2,6 @@ Version 4.8.0 - 2018-04-25
Version 4.2.0 - 2016-11-28
* Bug fixes (see mercurial logs for details)
* Remove bank_account from Account Move Lines
Version 4.0.0 - 2016-05-03
* Correctly read bank accounts from company

View File

@ -65,6 +65,7 @@ class BankAccount(metaclass=PoolMeta):
super(BankAccount, cls).__setup__()
cls._check_owners_fields = set(['owners'])
cls._check_owners_related_models = set([
('account.move.line', 'bank_account'),
('account.invoice', 'bank_account'),
])
cls._error_messages.update({
@ -266,6 +267,13 @@ class Invoice(BankMixin, metaclass=PoolMeta):
cls.save(to_save)
super(Invoice, cls).post(invoices)
def _get_move_line(self, date, amount):
'''Add account bank to move line when post invoice.'''
line = super(Invoice, self)._get_move_line(date, amount)
if self.bank_account:
line.bank_account = self.bank_account
return line
class Reconciliation(metaclass=PoolMeta):
__name__ = 'account.move.reconciliation'
@ -302,7 +310,7 @@ class Reconciliation(metaclass=PoolMeta):
Invoice.process(invoices)
class Line(metaclass=PoolMeta):
class Line(BankMixin, metaclass=PoolMeta):
__name__ = 'account.move.line'
reverse_moves = fields.Function(fields.Boolean('With Reverse Moves'),
@ -310,6 +318,38 @@ class Line(metaclass=PoolMeta):
netting_moves = fields.Function(fields.Boolean('With Netting Moves'),
'get_netting_moves', searcher='search_netting_moves')
@classmethod
def __setup__(cls):
super(Line, cls).__setup__()
if hasattr(cls, '_check_modify_exclude'):
cls._check_modify_exclude.add('bank_account')
readonly = Bool(Eval('reconciliation'))
previous_readonly = cls.bank_account.states.get('readonly')
if previous_readonly:
readonly = readonly | previous_readonly
cls.bank_account.states.update({
'readonly': readonly,
})
@fields.depends('party', 'payment_type')
def on_change_party(self):
'''Add account bank to account move line when changes party.'''
try:
super(Line, self).on_change_party()
except AttributeError:
pass
if self.payment_type and self.party:
self._get_bank_account()
@classmethod
def copy(cls, lines, default=None):
if default is None:
default = {}
if (Transaction().context.get('cancel_move')
and 'bank_account' not in default):
default['bank_account'] = None
return super(Line, cls).copy(lines, default)
def get_reverse_moves(self, name):
if (not self.account
or self.account.kind not in ['receivable', 'payable']):
@ -392,14 +432,26 @@ class Line(metaclass=PoolMeta):
return [('party', operator, query)]
class CompensationMoveStart(ModelView):
class CompensationMoveStart(ModelView, BankMixin):
'Create Compensation Move Start'
__name__ = 'account.move.compensation_move.start'
party = fields.Many2One('party.party', 'Party', readonly=True)
account = fields.Many2One('account.account', 'Account', required=True)
account = fields.Many2One('account.account', 'Account',
domain=[('kind', 'in', ['payable', 'receivable'])],
required=True)
date = fields.Date('Date')
maturity_date = fields.Date('Maturity Date')
description = fields.Char('Description')
payment_kind = fields.Selection([
('both', 'Both'),
('payable', 'Payable'),
('receivable', 'Receivable'),
], 'Payment Kind')
payment_type = fields.Many2One('account.payment.type', 'Payment Type',
domain=[
('kind', '=', Eval('payment_kind'))
],
depends=['payment_kind'])
@classmethod
def __setup__(cls):
@ -426,6 +478,7 @@ class CompensationMoveStart(ModelView):
def default_get(cls, fields, with_rec_name=True):
pool = Pool()
Line = pool.get('account.move.line')
PaymentType = pool.get('account.payment.type')
defaults = super(CompensationMoveStart, cls).default_get(fields,
with_rec_name)
@ -447,8 +500,31 @@ class CompensationMoveStart(ModelView):
if (company and company.currency.is_zero(amount)
and len(set([x.account for x in lines])) == 1):
cls.raise_user_error('normal_reconcile')
if amount > 0:
defaults['payment_kind'] = 'receivable'
else:
defaults['payment_kind'] = 'payable'
defaults['bank_account'] = None
if party:
defaults['party'] = party.id
if (defaults['payment_kind'] in ['receivable', 'both']
and party.customer_payment_type):
defaults['payment_type'] = party.customer_payment_type.id
elif (defaults['payment_kind'] in ['payable', 'both']
and party.supplier_payment_type):
defaults['payment_type'] = party.supplier_payment_type.id
if defaults.get('payment_type'):
payment_type = PaymentType(defaults['payment_type'])
defaults['account_bank'] = payment_type.account_bank
self = cls()
self.payment_type = payment_type
self.party = party
self._get_bank_account()
defaults['account_bank_from'] = (
self.on_change_with_account_bank_from())
defaults['bank_account'] = (self.bank_account.id
if self.bank_account else None)
if amount > 0:
defaults['account'] = (party.account_receivable.id
if party.account_receivable else None)
@ -513,7 +589,9 @@ class CompensationMove(Wizard):
" Returns true if both lines are equal"
return (line.debit == extra_line.debit and
line.credit == extra_line.credit and
line.maturity_date == extra_line.maturity_date)
line.maturity_date == extra_line.maturity_date and
line.payment_type == extra_line.payment_type and
line.bank_account == extra_line.bank_account)
def get_counterpart_line(self, line):
'Returns the counterpart line to create from line'
@ -569,6 +647,8 @@ class CompensationMove(Wizard):
extra_line.account = account
extra_line.party = party
extra_line.maturity_date = self.start.maturity_date
extra_line.payment_type = self.start.payment_type
extra_line.bank_account = self.start.bank_account
extra_line.description = self.start.description
extra_line.credit = extra_line.debit = Decimal('0.0')
if amount > 0:

View File

@ -5,7 +5,7 @@ copyright notices and license terms. -->
<tryton>
<data>
<!-- account.payment.type -->
<!-- account.payment.type -->
<record model="ir.ui.view" id="account_payment_type_view_tree">
<field name="model">account.payment.type</field>
<field name="inherit"
@ -19,7 +19,23 @@ copyright notices and license terms. -->
<field name="name">account_payment_type_form_view</field>
</record>
<!-- account.invoice -->
<!-- account.move.line -->
<record model="ir.ui.view" id="move_line_view_form">
<field name="model">account.move.line</field>
<field name="type" eval="None"/>
<field name="inherit" ref="account.move_line_view_form"/>
<field name="priority" eval="40"/>
<field name="name">move_line_form</field>
</record>
<record model="ir.ui.view" id="move_line_view_form_move">
<field name="model">account.move.line</field>
<field name="type" eval="None"/>
<field name="inherit" ref="account.move_line_view_form_move"/>
<field name="priority" eval="45"/>
<field name="name">move_line_form</field>
</record>
<!-- account.invoice -->
<record model="ir.ui.view" id="invoice_view_form">
<field name="model">account.invoice</field>
<field name="type" eval="None"/>
@ -49,6 +65,5 @@ copyright notices and license terms. -->
<field name="inherit" ref="account_payment.move_line_view_list"/>
<field name="name">move_line_list</field>
</record>
</data>
</tryton>

View File

@ -2,14 +2,6 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
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 "
@ -101,10 +93,26 @@ msgctxt "field:account.move.compensation_move.start,account:"
msgid "Account"
msgstr "Compte"
msgctxt "field:account.move.compensation_move.start,account_bank:"
msgid "Account Bank"
msgstr "Compte bancari"
msgctxt "field:account.move.compensation_move.start,account_bank_from:"
msgid "Account Bank From"
msgstr "Compte bancari de"
msgctxt "field:account.move.compensation_move.start,bank_account:"
msgid "Bank Account"
msgstr "Compte bancari"
msgctxt "field:account.move.compensation_move.start,date:"
msgid "Date"
msgstr "Data"
msgctxt "field:account.move.compensation_move.start,description:"
msgid "Description"
msgstr "Descripció"
msgctxt "field:account.move.compensation_move.start,id:"
msgid "ID"
msgstr "ID"
@ -117,6 +125,26 @@ msgctxt "field:account.move.compensation_move.start,party:"
msgid "Party"
msgstr "Tercer"
msgctxt "field:account.move.compensation_move.start,payment_kind:"
msgid "Payment Kind"
msgstr "Classe de pagament"
msgctxt "field:account.move.compensation_move.start,payment_type:"
msgid "Payment Type"
msgstr "Tipus de pagament"
msgctxt "field:account.move.line,account_bank:"
msgid "Account Bank"
msgstr "Compte bancari"
msgctxt "field:account.move.line,account_bank_from:"
msgid "Account Bank From"
msgstr "Compte bancari de"
msgctxt "field:account.move.line,bank_account:"
msgid "Bank Account"
msgstr "Compte bancari"
msgctxt "field:account.move.line,netting_moves:"
msgid "With Netting Moves"
msgstr "Amb movimients a compensar"
@ -205,6 +233,50 @@ msgctxt "selection:account.invoice,account_bank:"
msgid "Party"
msgstr "Tercer"
msgctxt "selection:account.move.compensation_move.start,account_bank:"
msgid "Company"
msgstr "Empresa"
msgctxt "selection:account.move.compensation_move.start,account_bank:"
msgid "None"
msgstr "Cap"
msgctxt "selection:account.move.compensation_move.start,account_bank:"
msgid "Other"
msgstr "Un altre"
msgctxt "selection:account.move.compensation_move.start,account_bank:"
msgid "Party"
msgstr "Tercer"
msgctxt "selection:account.move.compensation_move.start,payment_kind:"
msgid "Both"
msgstr "Ambdós"
msgctxt "selection:account.move.compensation_move.start,payment_kind:"
msgid "Payable"
msgstr "A pagar"
msgctxt "selection:account.move.compensation_move.start,payment_kind:"
msgid "Receivable"
msgstr "A cobrar"
msgctxt "selection:account.move.line,account_bank:"
msgid "Company"
msgstr "Empresa"
msgctxt "selection:account.move.line,account_bank:"
msgid "None"
msgstr "Cap"
msgctxt "selection:account.move.line,account_bank:"
msgid "Other"
msgstr "Un altre"
msgctxt "selection:account.move.line,account_bank:"
msgid "Party"
msgstr "Tercer"
msgctxt "selection:account.payment.type,account_bank:"
msgid "Company"
msgstr "Empresa"

View File

@ -2,14 +2,6 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
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 "
@ -98,10 +90,26 @@ msgctxt "field:account.move.compensation_move.start,account:"
msgid "Account"
msgstr "Cuenta"
msgctxt "field:account.move.compensation_move.start,account_bank:"
msgid "Account Bank"
msgstr "Tercero"
msgctxt "field:account.move.compensation_move.start,account_bank_from:"
msgid "Account Bank From"
msgstr "Cuenta bancaria de"
msgctxt "field:account.move.compensation_move.start,bank_account:"
msgid "Bank Account"
msgstr "Cuenta bancaria"
msgctxt "field:account.move.compensation_move.start,date:"
msgid "Date"
msgstr "Fecha"
msgctxt "field:account.move.compensation_move.start,description:"
msgid "Description"
msgstr "Descripción"
msgctxt "field:account.move.compensation_move.start,id:"
msgid "ID"
msgstr "ID"
@ -114,6 +122,26 @@ msgctxt "field:account.move.compensation_move.start,party:"
msgid "Party"
msgstr "Tercero"
msgctxt "field:account.move.compensation_move.start,payment_kind:"
msgid "Payment Kind"
msgstr "Clase de pago"
msgctxt "field:account.move.compensation_move.start,payment_type:"
msgid "Payment Type"
msgstr "Tipo de pago"
msgctxt "field:account.move.line,account_bank:"
msgid "Account Bank"
msgstr "Cuenta bancaria"
msgctxt "field:account.move.line,account_bank_from:"
msgid "Account Bank From"
msgstr "Cuenta bancaria de"
msgctxt "field:account.move.line,bank_account:"
msgid "Bank Account"
msgstr "Cuenta bancaria"
msgctxt "field:account.move.line,netting_moves:"
msgid "With Netting Moves"
msgstr "Con movimientos a compensar"
@ -202,6 +230,50 @@ msgctxt "selection:account.invoice,account_bank:"
msgid "Party"
msgstr "Tercero"
msgctxt "selection:account.move.compensation_move.start,account_bank:"
msgid "Company"
msgstr "Empresa"
msgctxt "selection:account.move.compensation_move.start,account_bank:"
msgid "None"
msgstr "Ninguno"
msgctxt "selection:account.move.compensation_move.start,account_bank:"
msgid "Other"
msgstr "Otro"
msgctxt "selection:account.move.compensation_move.start,account_bank:"
msgid "Party"
msgstr "Tercero"
msgctxt "selection:account.move.compensation_move.start,payment_kind:"
msgid "Both"
msgstr "Ambos"
msgctxt "selection:account.move.compensation_move.start,payment_kind:"
msgid "Payable"
msgstr "A pagar"
msgctxt "selection:account.move.compensation_move.start,payment_kind:"
msgid "Receivable"
msgstr "A cobrar"
msgctxt "selection:account.move.line,account_bank:"
msgid "Company"
msgstr "Empresa"
msgctxt "selection:account.move.line,account_bank:"
msgid "None"
msgstr "Ninguno"
msgctxt "selection:account.move.line,account_bank:"
msgid "Other"
msgstr "Otro"
msgctxt "selection:account.move.line,account_bank:"
msgid "Party"
msgstr "Tercero"
msgctxt "selection:account.payment.type,account_bank:"
msgid "Company"
msgstr "Empresa"

View File

@ -153,6 +153,8 @@ class PayLine(metaclass=PoolMeta):
pool = Pool()
Invoice = pool.get('account.invoice')
payment = super(PayLine, self).get_payment(line, journals)
if isinstance(line.origin, Invoice):
if hasattr(line, 'bank_account') and line.bank_account:
payment.bank_account = line.bank_account
elif isinstance(line.origin, Invoice):
payment.bank_account = line.origin.bank_account
return payment

View File

@ -52,6 +52,28 @@ Create party::
>>> party = Party(name='Party')
>>> party.save()
Create bank account::
>>> Bank = Model.get('bank')
>>> BankAccount = Model.get('bank.account')
>>> BankNumber = Model.get('bank.account.number')
>>> bparty = Party()
>>> bparty.name = 'Bank'
>>> bparty.save()
>>> bank = Bank(party=bparty)
>>> bank.save()
>>> bank_account = BankAccount()
>>> bank_account.bank = bank
>>> bank_number = bank_account.numbers.new()
>>> bank_number.type = 'iban'
>>> bank_number.number = 'BE82068896274468'
>>> bank_number = bank_account.numbers.new()
>>> bank_number.type = 'other'
>>> bank_number.number = 'not IBAN'
>>> bank_account.save()
>>> party.bank_accounts.append(bank_account)
>>> party.save()
Create account category::
>>> ProductCategory = Model.get('product.category')
@ -90,6 +112,7 @@ Create payment type and link to party::
>>> payable_payment_type = PaymentType(name='Type', kind='payable')
>>> payable_payment_type.save()
>>> receivable_payment_type = PaymentType(name='Type', kind='receivable')
>>> receivable_payment_type.account_bank = 'party'
>>> receivable_payment_type.save()
>>> party.customer_payment_type = receivable_payment_type
>>> party.supplier_payment_type = payable_payment_type
@ -121,13 +144,22 @@ Create invoice::
Decimal('240.00')
>>> invoice.payment_type == receivable_payment_type
True
>>> invoice.bank_account = bank_account
>>> invoice.save()
>>> Invoice.post([invoice.id], config.context)
>>> invoice.reload()
>>> invoice.click('post')
>>> invoice.state
'posted'
u'posted'
>>> invoice.amount_to_pay == Decimal(240)
True
>>> line1, line2, _, _ = invoice.move.lines
>>> line1.payment_type == receivable_payment_type
True
>>> line1.bank_account == bank_account
True
>>> line2.payment_type == None
True
>>> line2.bank_account == None
True
Create credit note::
@ -153,11 +185,10 @@ Create credit note::
>>> Invoice.post([credit_note.id], config.context)
>>> credit_note.reload()
>>> credit_note.state
'posted'
u'posted'
>>> credit_note.amount_to_pay == Decimal(-44)
True
Partialy reconcile both lines::
>>> MoveLine = Model.get('account.move.line')
@ -167,6 +198,8 @@ Partialy reconcile both lines::
... models=lines)
>>> compensation_move.form.maturity_date = today
>>> compensation_move.form.account = receivable
>>> compensation_move.form.payment_type = receivable_payment_type
>>> compensation_move.form.bank_account = None
>>> compensation_move.execute('create_move')
>>> credit_note.reload()
>>> credit_note.amount_to_pay
@ -175,7 +208,6 @@ Partialy reconcile both lines::
>>> invoice.amount_to_pay
Decimal('0.0')
Create a move that pays the pending amount::
>>> Period = Model.get('account.period')
@ -213,4 +245,4 @@ Create a move that pays the pending amount::
>>> invoice.amount_to_pay
Decimal('0.0')
>>> invoice.state
'paid'
u'paid'

View File

@ -10,6 +10,10 @@
<field name="date"/>
<label name="maturity_date"/>
<field name="maturity_date"/>
<label name="payment_type"/>
<field name="payment_type"/>
<label name="bank_account"/>
<field name="bank_account"/>
<label name="description"/>
<field name="description"/>
</form>

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part account_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="/form/notebook/page/field[@name='payment_type']" position="after">
<label name="bank_account"/>
<field name="bank_account"/>
</xpath>
</data>