Allow to use account instead of line for clearing

issue6722
review36561002
This commit is contained in:
Cédric Krier
2017-09-03 11:26:11 +02:00
parent e6bc99d75d
commit 54bbb5b323
3 changed files with 49 additions and 4 deletions
+2
View File
@@ -1,3 +1,5 @@
* Allow to use account instead of line for clearing
Version 4.4.0 - 2017-05-01
* Bug fixes (see mercurial logs for details)
* Allow to set the date of the clearing move
+42 -4
View File
@@ -30,12 +30,36 @@ class Journal:
class Payment:
__metaclass__ = PoolMeta
__name__ = 'account.payment'
account = fields.Many2One(
'account.account', "Account", ondelete='RESTRICT',
domain=[
('company', '=', Eval('company', -1)),
('kind', 'in', ['receivable', 'payable', 'deposit']),
['OR',
('second_currency', '=', Eval('currency', None)),
[
('company.currency', '=', Eval('currency', None)),
('second_currency', '=', None),
],
],
],
states={
'readonly': Eval('state') != 'draft',
'invisible': Bool(Eval('line')),
},
depends=['company', 'currency', 'state', 'line'],
help="Define the account to use for clearing move.")
clearing_move = fields.Many2One('account.move', 'Clearing Move',
readonly=True)
@classmethod
def __setup__(cls):
super(Payment, cls).__setup__()
line_invisible = Bool(Eval('account'))
if 'invisible' in cls.line.states:
cls.line.states['invisible'] &= line_invisible
else:
cls.line.states['invisible'] = line_invisible
cls._buttons.update({
'succeed_wizard': cls._buttons['succeed'],
})
@@ -78,6 +102,20 @@ class Payment:
for lines in to_reconcile:
Line.reconcile(lines)
@property
def clearing_account(self):
if self.line:
return self.line.account
elif self.account:
return self.account
@property
def clearing_party(self):
if self.line:
return self.line.party
else:
return self.party
def create_clearing_move(self, date=None):
pool = Pool()
Move = pool.get('account.move')
@@ -86,7 +124,7 @@ class Payment:
Period = pool.get('account.period')
Date = pool.get('ir.date')
if not self.line:
if not self.clearing_account:
return
if (not self.journal.clearing_account
or not self.journal.clearing_journal):
@@ -113,14 +151,14 @@ class Payment:
line.debit, line.credit = local_amount, 0
else:
line.debit, line.credit = 0, local_amount
line.account = self.line.account
line.account = self.clearing_account
if not local_currency:
line.amount_second_currency = self.amount.copy_sign(
line.debit - line.credit)
line.second_currency = self.journal.currency
line.party = (self.line.party
if self.line.account.party_required else None)
line.party = (self.clearing_party
if line.account.party_required else None)
counterpart = Line()
if self.kind == 'payable':
counterpart.debit, counterpart.credit = 0, local_amount
+5
View File
@@ -2,6 +2,11 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='line']" position="after">
<label name="account"/>
<field name="account"/>
<newline/>
</xpath>
<xpath expr="/form/notebook/page[@id='info']/field[@name='group']"
position="after">
<label name="clearing_move"/>