Files
tryton/statement.py
T

584 lines
22 KiB
Python
Raw Normal View History

#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
2010-08-16 19:23:32 +02:00
from decimal import Decimal
2012-03-25 00:17:31 +01:00
from trytond.model import Workflow, ModelView, ModelSQL, fields
from trytond.pyson import Eval, If, Bool
2010-08-16 19:23:32 +02:00
from trytond.transaction import Transaction
2013-09-06 22:33:56 +02:00
from trytond import backend
2011-07-03 13:18:45 +02:00
from trytond.pool import Pool
2008-06-17 12:09:01 +02:00
2012-09-24 22:17:36 +02:00
__all__ = ['Statement', 'Line']
2011-08-21 11:20:33 +02:00
_STATES = {'readonly': Eval('state') != 'draft'}
2011-08-04 16:57:19 +02:00
_DEPENDS = ['state']
2008-06-10 22:01:27 +02:00
2008-06-17 12:09:01 +02:00
2012-03-25 00:17:31 +01:00
class Statement(Workflow, ModelSQL, ModelView):
'Account Statement'
2012-09-24 22:17:36 +02:00
__name__ = 'account.statement'
2011-04-10 20:59:25 +02:00
company = fields.Many2One('company.company', 'Company', required=True,
2012-03-05 10:52:58 +01:00
select=True, states=_STATES, domain=[
2011-08-21 11:20:33 +02:00
('id', If(Eval('context', {}).contains('company'), '=', '!='),
2013-10-09 18:25:13 +02:00
Eval('context', {}).get('company', -1)),
2011-08-04 16:57:19 +02:00
],
depends=_DEPENDS)
2012-04-03 20:06:27 +02:00
journal = fields.Many2One('account.statement.journal', 'Journal',
required=True,
2011-04-10 20:59:25 +02:00
domain=[
2013-10-09 18:25:13 +02:00
('company', '=', Eval('context', {}).get('company', -1)),
2011-08-04 16:57:19 +02:00
],
2011-04-10 20:59:25 +02:00
states={
2011-08-21 11:20:33 +02:00
'readonly': (Eval('state') != 'draft') | Eval('lines'),
2011-08-04 16:57:19 +02:00
},
2012-03-05 10:52:58 +01:00
on_change=['journal', 'state', 'lines'], select=True,
2011-08-04 16:57:19 +02:00
depends=['state', 'lines'])
2010-03-11 16:46:35 +01:00
currency_digits = fields.Function(fields.Integer('Currency Digits',
2012-09-24 22:17:36 +02:00
on_change_with=['journal']), 'on_change_with_currency_digits')
2011-08-04 16:57:19 +02:00
date = fields.Date('Date', required=True, states=_STATES, depends=_DEPENDS,
2012-03-05 10:52:58 +01:00
select=True)
start_balance = fields.Numeric('Start Balance', required=True,
2011-08-04 16:57:19 +02:00
digits=(16, Eval('currency_digits', 2)),
states=_STATES, depends=['state', 'currency_digits'])
end_balance = fields.Numeric('End Balance', required=True,
2011-08-04 16:57:19 +02:00
digits=(16, Eval('currency_digits', 2)),
states=_STATES, depends=['state', 'currency_digits'])
balance = fields.Function(
fields.Numeric('Balance',
digits=(16, Eval('currency_digits', 2)),
on_change_with=['start_balance', 'end_balance'],
depends=['currency_digits']),
2012-09-24 22:17:36 +02:00
'on_change_with_balance')
lines = fields.One2Many('account.statement.line', 'statement',
2011-08-04 16:57:19 +02:00
'Transactions', states={
2011-08-21 11:20:33 +02:00
'readonly': (Eval('state') != 'draft') | ~Eval('journal'),
2011-08-04 16:57:19 +02:00
}, on_change=['lines', 'journal'],
depends=['state', 'journal'])
state = fields.Selection([
('draft', 'Draft'),
('validated', 'Validated'),
2009-03-20 13:04:48 +01:00
('cancel', 'Canceled'),
('posted', 'Posted'),
2012-03-05 10:52:58 +01:00
], 'State', readonly=True, select=True)
2008-06-10 22:01:27 +02:00
2012-09-24 22:17:36 +02:00
@classmethod
def __setup__(cls):
super(Statement, cls).__setup__()
cls._order[0] = ('id', 'DESC')
cls._error_messages.update({
'wrong_end_balance': 'End Balance must be "%s".',
2013-02-17 00:37:49 +01:00
'delete_cancel': ('Statement "%s" must be cancelled before '
'deletion.'),
})
2012-09-24 22:17:36 +02:00
cls._transitions |= set((
2012-03-25 00:17:31 +01:00
('draft', 'validated'),
('draft', 'cancel'),
2012-03-25 00:17:31 +01:00
('validated', 'posted'),
('validated', 'cancel'),
('cancel', 'draft'),
))
2012-09-24 22:17:36 +02:00
cls._buttons.update({
2012-03-25 00:17:31 +01:00
'draft': {
'invisible': Eval('state') != 'cancel',
},
'validate_statement': {
2012-03-25 00:17:31 +01:00
'invisible': Eval('state') != 'draft',
},
'post': {
'invisible': Eval('state') != 'validated',
},
'cancel': {
'invisible': ~Eval('state').in_(['draft', 'validated']),
2012-03-25 00:17:31 +01:00
},
})
2008-06-10 22:01:27 +02:00
2012-09-24 22:17:36 +02:00
@classmethod
def __register__(cls, module_name):
2013-09-06 22:33:56 +02:00
TableHandler = backend.get('TableHandler')
2011-04-10 20:59:25 +02:00
cursor = Transaction().cursor
# Migration from 1.8: new field company
2012-09-24 22:17:36 +02:00
table = TableHandler(cursor, cls, module_name)
2011-04-10 20:59:25 +02:00
company_exist = table.column_exist('company')
2012-09-24 22:17:36 +02:00
super(Statement, cls).__register__(module_name)
2011-04-10 20:59:25 +02:00
# Migration from 1.8: fill new field company
if not company_exist:
offset = 0
limit = cursor.IN_MAX
2012-09-24 22:17:36 +02:00
statements = True
while statements:
statements = cls.search([], offset=offset, limit=limit)
2011-04-10 20:59:25 +02:00
offset += limit
2012-09-24 22:17:36 +02:00
for statement in statements:
cls.write([statement], {
'company': statement.journal.company.id,
})
table = TableHandler(cursor, cls, module_name)
2011-04-10 20:59:25 +02:00
table.not_null_action('company', action='add')
2012-09-24 22:17:36 +02:00
@staticmethod
def default_company():
2012-03-27 10:43:12 +02:00
return Transaction().context.get('company')
2011-04-10 20:59:25 +02:00
2012-09-24 22:17:36 +02:00
@staticmethod
def default_state():
2008-06-10 22:01:27 +02:00
return 'draft'
2012-09-24 22:17:36 +02:00
@staticmethod
def default_date():
Date = Pool().get('ir.date')
return Date.today()
2008-07-30 16:49:16 +02:00
2012-09-24 22:17:36 +02:00
@staticmethod
def default_currency_digits():
Company = Pool().get('company.company')
2010-08-16 19:23:32 +02:00
if Transaction().context.get('company'):
2012-09-24 22:17:36 +02:00
company = Company(Transaction().context['company'])
return company.currency.digits
return 2
2012-09-24 22:17:36 +02:00
def on_change_journal(self):
res = {}
2012-09-24 22:17:36 +02:00
if not self.journal:
return res
2012-09-24 22:17:36 +02:00
statements = self.search([
('journal', '=', self.journal.id),
], order=[
('date', 'DESC'),
2012-09-24 22:17:36 +02:00
], limit=1)
if not statements:
return res
2012-09-24 22:17:36 +02:00
statement, = statements
res['start_balance'] = statement.end_balance
return res
2008-06-10 22:01:27 +02:00
2012-09-24 22:17:36 +02:00
def on_change_with_currency_digits(self, name=None):
if self.journal:
return self.journal.currency.digits
return 2
2012-09-24 22:17:36 +02:00
@classmethod
def get_rec_name(cls, statements, name):
Lang = Pool().get('ir.lang')
2012-09-24 22:17:36 +02:00
lang, = Lang.search([
2012-01-27 21:15:07 +01:00
('code', '=', Transaction().language),
2010-08-16 19:23:32 +02:00
])
2008-12-18 20:13:43 +01:00
2008-06-10 22:01:27 +02:00
res = {}
for statement in statements:
2012-09-24 22:17:36 +02:00
res[statement.id] = (statement.journal.name + ' '
+ Lang.currency(lang, statement.start_balance,
statement.journal.currency, symbol=False, grouping=True)
2012-09-29 15:34:37 +02:00
+ ' - '
2012-09-24 22:17:36 +02:00
+ Lang.currency(lang, statement.end_balance,
statement.journal.currency, symbol=False, grouping=True))
2008-06-10 22:01:27 +02:00
return res
2012-09-24 22:17:36 +02:00
@classmethod
def search_rec_name(cls, name, clause):
statements = cls.search(['OR',
('start_balance',) + tuple(clause[1:]),
('end_balance',) + tuple(clause[1:]),
])
if statements:
return [('id', 'in', [s.id for s in statements])]
return [('journal',) + tuple(clause[1:])]
2012-09-24 22:17:36 +02:00
def get_end_balance(self, name):
end_balance = self.start_balance
for line in self.lines:
end_balance += line.amount
return end_balance
def on_change_with_balance(self, name=None):
return ((getattr(self, 'end_balance', 0) or 0)
- (getattr(self, 'start_balance', 0) or 0))
def on_change_lines(self):
2011-07-03 13:18:45 +02:00
pool = Pool()
2012-09-24 22:17:36 +02:00
Currency = pool.get('currency.currency')
Line = pool.get('account.statement.line')
res = {
'lines': {},
2012-09-24 22:17:36 +02:00
}
if self.journal and self.lines:
invoices = set()
for line in self.lines:
if line.invoice:
invoices.add(line.invoice)
invoice_id2amount_to_pay = {}
2012-09-24 22:17:36 +02:00
for invoice in invoices:
with Transaction().set_context(date=invoice.currency_date):
if invoice.type in ('out_invoice', 'in_credit_note'):
sign = -1
else:
sign = 1
invoice_id2amount_to_pay[invoice.id] = sign * (
2012-09-24 22:17:36 +02:00
Currency.compute(invoice.currency,
invoice.amount_to_pay, self.journal.currency))
2012-09-24 22:17:36 +02:00
for line in self.lines or []:
if line.invoice and line.id:
amount_to_pay = invoice_id2amount_to_pay[line.invoice.id]
res['lines'].setdefault('update', [])
if (not self.journal.currency.is_zero(amount_to_pay)
and (line.amount >= 0) == (amount_to_pay <= 0)):
res['lines']['update'].append({
2012-09-24 22:17:36 +02:00
'id': line.id,
'amount': (amount_to_pay.copy_sign(line.amount)
if abs(line.amount) > abs(amount_to_pay)
else line.amount)
})
if abs(line.amount) > abs(amount_to_pay):
res['lines'].setdefault('add', [])
2012-09-24 22:17:36 +02:00
vals = {}
for field_name, field in Line._fields.iteritems():
try:
value = getattr(line, field_name)
except AttributeError:
continue
if (value and field._type in ('many2one',
'one2one')):
vals[field_name] = value.id
vals[field_name + '.rec_name'] = \
value.rec_name
else:
vals[field_name] = value
del vals['id']
vals['amount'] = line.amount + amount_to_pay
2012-03-27 10:43:12 +02:00
vals['invoice'] = None
2012-09-24 22:17:36 +02:00
del vals['invoice.rec_name']
res['lines']['add'].append(vals)
invoice_id2amount_to_pay[line.invoice.id] = 0
else:
invoice_id2amount_to_pay[line.invoice.id] = (
line.amount + amount_to_pay)
else:
res['lines']['update'].append({
'id': line.id,
'invoice': None,
})
return res
2012-09-24 22:17:36 +02:00
@classmethod
def delete(cls, statements):
# Cancel before delete
2012-09-24 22:17:36 +02:00
cls.cancel(statements)
for statement in statements:
if statement.state != 'cancel':
cls.raise_user_error('delete_cancel', (statement.rec_name,))
2012-09-24 22:17:36 +02:00
super(Statement, cls).delete(statements)
2012-09-24 22:17:36 +02:00
@classmethod
2012-03-25 00:17:31 +01:00
@ModelView.button
@Workflow.transition('draft')
2012-09-24 22:17:36 +02:00
def draft(cls, statements):
2012-03-25 00:17:31 +01:00
pass
2012-09-24 22:17:36 +02:00
@classmethod
2012-03-25 00:17:31 +01:00
@ModelView.button
@Workflow.transition('validated')
def validate_statement(cls, statements):
2012-09-24 22:17:36 +02:00
Lang = Pool().get('ir.lang')
2012-09-24 22:17:36 +02:00
for statement in statements:
2012-03-25 00:17:31 +01:00
computed_end_balance = statement.start_balance
for line in statement.lines:
computed_end_balance += line.amount
if computed_end_balance != statement.end_balance:
2012-09-24 22:17:36 +02:00
lang, = Lang.search([
2012-03-25 00:17:31 +01:00
('code', '=', Transaction().language),
])
2012-09-24 22:17:36 +02:00
amount = Lang.format(lang,
2012-03-25 00:17:31 +01:00
'%.' + str(statement.journal.currency.digits) + 'f',
computed_end_balance, True)
2012-09-24 22:17:36 +02:00
cls.raise_user_error('wrong_end_balance',
2012-04-03 20:06:27 +02:00
error_args=(amount,))
2012-03-25 00:17:31 +01:00
for line in statement.lines:
2012-09-24 22:17:36 +02:00
line.create_move()
2008-06-10 22:01:27 +02:00
2012-09-24 22:17:36 +02:00
@classmethod
2012-03-25 00:17:31 +01:00
@ModelView.button
@Workflow.transition('posted')
2012-09-24 22:17:36 +02:00
def post(cls, statements):
StatementLine = Pool().get('account.statement.line')
2012-03-25 00:17:31 +01:00
lines = [l for s in statements for l in s.lines]
2012-09-24 22:17:36 +02:00
StatementLine.post_move(lines)
2008-06-10 22:01:27 +02:00
2012-09-24 22:17:36 +02:00
@classmethod
2012-03-25 00:17:31 +01:00
@ModelView.button
@Workflow.transition('cancel')
2012-09-24 22:17:36 +02:00
def cancel(cls, statements):
StatementLine = Pool().get('account.statement.line')
2012-03-25 00:17:31 +01:00
lines = [l for s in statements for l in s.lines]
2012-09-24 22:17:36 +02:00
StatementLine.delete_move(lines)
2008-06-10 22:01:27 +02:00
2008-06-17 12:09:01 +02:00
2009-02-28 16:58:08 +01:00
class Line(ModelSQL, ModelView):
'Account Statement Line'
2012-09-24 22:17:36 +02:00
__name__ = 'account.statement.line'
statement = fields.Many2One('account.statement', 'Statement',
required=True, ondelete='CASCADE')
2008-06-10 22:01:27 +02:00
date = fields.Date('Date', required=True)
amount = fields.Numeric('Amount', required=True,
2012-04-03 20:06:27 +02:00
digits=(16, Eval('_parent_statement', {}).get('currency_digits', 2)),
2011-08-21 11:20:33 +02:00
on_change=['amount', 'party', 'account', 'invoice',
'_parent_statement.journal'])
2008-10-22 20:09:11 +02:00
party = fields.Many2One('party.party', 'Party',
on_change=['amount', 'party', 'invoice'])
account = fields.Many2One('account.account', 'Account', required=True,
2011-08-21 11:20:33 +02:00
on_change=['account', 'invoice'], domain=[
('company', '=', Eval('_parent_statement', {}).get('company', 0)),
('kind', '!=', 'view'),
])
description = fields.Char('Description')
move = fields.Many2One('account.move', 'Account Move', readonly=True)
invoice = fields.Many2One('account.invoice', 'Invoice',
on_change=['party', 'account', 'invoice'],
2011-08-04 16:57:19 +02:00
domain=[
If(Bool(Eval('party')), [('party', '=', Eval('party'))], []),
If(Bool(Eval('party')), [('account', '=', Eval('account'))], []),
2012-06-01 23:44:37 +02:00
If(Eval('_parent_statement', {}).get('state') == 'draft',
2012-12-23 22:29:15 +01:00
('state', '=', 'posted'),
2012-06-01 23:44:37 +02:00
('state', '!=', '')),
2010-01-20 10:57:50 +01:00
],
depends=['party', 'account'])
2008-06-10 22:01:27 +02:00
2012-09-24 22:17:36 +02:00
@classmethod
def __setup__(cls):
super(Line, cls).__setup__()
cls._error_messages.update({
'debit_credit_account_statement_journal': ('Please provide '
'debit and credit account on statement journal "%s".'),
'same_debit_credit_account': ('Account "%(account)s" in '
'statement line "%(line)s" is the same as the one '
'configured as credit or debit on journal "%(journal)s".'),
'amount_greater_invoice_amount_to_pay': ('Amount "%s" is '
'greater than the amount to pay of invoice.'),
})
2012-09-24 22:17:36 +02:00
cls._sql_constraints += [
('check_statement_line_amount', 'CHECK(amount != 0)',
'Amount should be a positive or negative value.'),
]
2008-07-17 19:36:26 +02:00
2012-09-24 22:17:36 +02:00
@staticmethod
def default_amount():
2012-04-02 10:52:36 +02:00
return Decimal(0)
2012-09-24 22:17:36 +02:00
def on_change_party(self):
res = {}
2012-09-24 22:17:36 +02:00
if self.party:
if self.amount:
if self.amount > Decimal("0.0"):
account = self.party.account_receivable
else:
2012-09-24 22:17:36 +02:00
account = self.party.account_payable
res['account'] = account.id
res['account.rec_name'] = account.rec_name
2012-09-24 22:17:36 +02:00
if self.invoice:
if self.party:
if self.invoice.party != self.party:
2012-03-27 10:43:12 +02:00
res['invoice'] = None
else:
2012-03-27 10:43:12 +02:00
res['invoice'] = None
return res
2008-06-10 22:01:27 +02:00
2012-09-24 22:17:36 +02:00
def on_change_amount(self):
Currency = Pool().get('currency.currency')
res = {}
2012-09-24 22:17:36 +02:00
if self.party:
if self.account and self.account not in (
self.party.account_receivable, self.party.account_payable):
# The user has entered a non-default value, we keep it.
pass
2012-09-24 22:17:36 +02:00
elif self.amount:
if self.amount > Decimal("0.0"):
account = self.party.account_receivable
else:
2012-09-24 22:17:36 +02:00
account = self.party.account_payable
res['account'] = account.id
res['account.rec_name'] = account.rec_name
2012-09-24 22:17:36 +02:00
if self.invoice:
if self.amount and self.statement and self.statement.journal:
invoice = self.invoice
journal = self.statement.journal
with Transaction().set_context(date=invoice.currency_date):
2012-09-24 22:17:36 +02:00
amount_to_pay = Currency.compute(invoice.currency,
invoice.amount_to_pay, journal.currency)
if abs(self.amount) > amount_to_pay:
2012-03-27 10:43:12 +02:00
res['invoice'] = None
else:
2012-03-27 10:43:12 +02:00
res['invoice'] = None
return res
2012-09-24 22:17:36 +02:00
def on_change_account(self):
res = {}
2012-09-24 22:17:36 +02:00
if self.invoice:
if self.account:
if self.invoice.account != self.account:
2012-03-27 10:43:12 +02:00
res['invoice'] = None
else:
2012-03-27 10:43:12 +02:00
res['invoice'] = None
return res
2008-06-17 18:33:07 +02:00
def on_change_invoice(self):
changes = {}
if self.invoice:
if not self.party:
changes['party'] = self.invoice.party.id
changes['party.rec_name'] = self.invoice.party.rec_name
if not self.account:
changes['account'] = self.invoice.account.id
changes['account.rec_name'] = self.invoice.account.rec_name
return changes
2012-09-29 15:34:37 +02:00
def get_rec_name(self, name):
return self.statement.rec_name
2012-09-24 22:17:36 +02:00
@classmethod
def copy(cls, lines, default=None):
if default is None:
default = {}
default = default.copy()
default.setdefault('move', None)
default.setdefault('invoice', None)
2012-09-24 22:17:36 +02:00
return super(Line, cls).copy(lines, default=default)
2012-09-24 22:17:36 +02:00
def create_move(self):
2008-09-24 17:43:00 +02:00
'''
2012-09-24 22:17:36 +02:00
Create move for the statement line and return move if created.
2008-09-24 17:43:00 +02:00
'''
2011-07-03 13:18:45 +02:00
pool = Pool()
2012-09-24 22:17:36 +02:00
Move = pool.get('account.move')
Period = pool.get('account.period')
Invoice = pool.get('account.invoice')
Currency = pool.get('currency.currency')
MoveLine = pool.get('account.move.line')
Lang = pool.get('ir.lang')
2012-09-24 22:17:36 +02:00
if self.move:
2012-03-25 00:17:31 +01:00
return
2012-09-24 22:17:36 +02:00
period_id = Period.find(self.statement.company.id, date=self.date)
2012-09-24 22:17:36 +02:00
move_lines = self._get_move_lines()
move = Move(
period=period_id,
journal=self.statement.journal.journal,
date=self.date,
2012-09-29 15:34:37 +02:00
origin=self,
2012-09-24 22:17:36 +02:00
lines=move_lines,
)
move.save()
2012-09-24 22:17:36 +02:00
self.write([self], {
'move': move.id,
})
2012-09-24 22:17:36 +02:00
if self.invoice:
with Transaction().set_context(date=self.invoice.currency_date):
amount_to_pay = Currency.compute(self.invoice.currency,
self.invoice.amount_to_pay,
self.statement.journal.currency)
if abs(amount_to_pay) < abs(self.amount):
2012-09-24 22:17:36 +02:00
lang, = Lang.search([
2012-01-27 21:15:07 +01:00
('code', '=', Transaction().language),
2010-08-16 19:23:32 +02:00
])
2012-09-24 22:17:36 +02:00
amount = Lang.format(lang,
'%.' + str(self.statement.journal.currency.digits) + 'f',
self.amount, True)
2010-08-16 19:23:32 +02:00
self.raise_user_error('amount_greater_invoice_amount_to_pay',
error_args=(amount,))
2012-09-24 22:17:36 +02:00
with Transaction().set_context(date=self.invoice.currency_date):
amount = Currency.compute(self.statement.journal.currency,
self.amount, self.statement.company.currency)
2012-09-24 22:17:36 +02:00
reconcile_lines = self.invoice.get_reconcile_lines_for_amount(
amount)
for move_line in move.lines:
2012-09-24 22:17:36 +02:00
if move_line.account == self.invoice.account:
Invoice.write([self.invoice], {
'payment_lines': [('add', [move_line.id])],
})
break
if reconcile_lines[1] == Decimal('0.0'):
2012-09-24 22:17:36 +02:00
lines = reconcile_lines[0] + [move_line]
MoveLine.reconcile(lines)
return move
2008-06-17 19:21:23 +02:00
2012-09-24 22:17:36 +02:00
@classmethod
def post_move(cls, lines):
Move = Pool().get('account.move')
Move.post([l.move for l in lines if l.move])
2008-06-17 19:21:23 +02:00
2012-09-24 22:17:36 +02:00
@classmethod
def delete_move(cls, lines):
Move = Pool().get('account.move')
Move.delete([l.move for l in lines if l.move])
2008-07-25 12:51:24 +02:00
2012-09-24 22:17:36 +02:00
def _get_move_lines(self):
2008-09-24 17:43:00 +02:00
'''
2012-09-24 22:17:36 +02:00
Return the move lines for the statement line
2008-09-24 17:43:00 +02:00
'''
2012-09-24 22:17:36 +02:00
pool = Pool()
MoveLine = pool.get('account.move.line')
Currency = Pool().get('currency.currency')
zero = Decimal("0.0")
2012-09-24 22:17:36 +02:00
amount = Currency.compute(self.statement.journal.currency, self.amount,
self.statement.company.currency)
if self.statement.journal.currency != self.statement.company.currency:
second_currency = self.statement.journal.currency.id
amount_second_currency = abs(self.amount)
else:
amount_second_currency = None
second_currency = None
2012-09-24 22:17:36 +02:00
move_lines = []
move_lines.append(MoveLine(
2012-09-29 15:34:37 +02:00
description=self.description,
2012-09-24 22:17:36 +02:00
debit=amount < zero and -amount or zero,
credit=amount >= zero and amount or zero,
account=self.account,
party=self.party,
second_currency=second_currency,
amount_second_currency=amount_second_currency,
))
2012-09-24 22:17:36 +02:00
journal = self.statement.journal.journal
if self.amount >= zero:
account = journal.credit_account
else:
account = journal.debit_account
if not account:
self.raise_user_error('debit_credit_account_statement_journal',
(journal.rec_name,))
2012-09-24 22:17:36 +02:00
if self.account == account:
self.raise_user_error('same_debit_credit_account', {
'account': self.account.rec_name,
'line': self.rec_name,
'journal': journal,
})
2012-09-24 22:17:36 +02:00
move_lines.append(MoveLine(
2012-09-29 15:34:37 +02:00
description=self.description,
2012-09-24 22:17:36 +02:00
debit=amount >= zero and amount or zero,
credit=amount < zero and -amount or zero,
account=account,
party=self.party,
second_currency=second_currency,
amount_second_currency=amount_second_currency,
))
return move_lines