From 12311e6937dff472f19412eaa2fdd33f5f020d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 25 Jul 2008 18:34:31 +0200 Subject: [PATCH] Use account as first name for object and fix some guidelines --- journal.py | 5 +- journal.xml | 10 +-- statement.py | 171 ++++++++++++++++++++++++++------------------------ statement.xml | 30 ++++----- 4 files changed, 111 insertions(+), 105 deletions(-) diff --git a/journal.py b/journal.py index bb9bd2abba..cd022bb312 100644 --- a/journal.py +++ b/journal.py @@ -6,12 +6,11 @@ from trytond.osv import fields, OSV class Journal(OSV): 'Statement Journal' - _name = 'statement.journal' + _name = 'account.statement.journal' _description = __doc__ name = fields.Char('Name', required=True) - journal = fields.Many2One( - 'account.journal', 'Bank Journal', required=True, + journal = fields.Many2One('account.journal', 'Bank Journal', required=True, domain="[('type', '=', 'bank')]") currency = fields.Many2One('currency.currency', 'Currency', required=True) company = fields.Many2One('company.company', 'Company', required=True) diff --git a/journal.xml b/journal.xml index 06c3cf64ad..b8c804744f 100644 --- a/journal.xml +++ b/journal.xml @@ -3,7 +3,7 @@ - statement.journal + account.statement.journal form - statement.journal + account.statement.journal tree Statement Journals - statement.journal + account.statement.journal form @@ -58,14 +58,14 @@ action="act_statement_journal_form" id="menu_statement_journal_form"/> - + - + diff --git a/statement.py b/statement.py index a4a0718752..139fdd8c24 100644 --- a/statement.py +++ b/statement.py @@ -10,26 +10,23 @@ _STATES = {'readonly': 'state != "draft"'} class Statement(OSV): 'Bank Statement' - _name = 'statement.statement' + _name = 'account.statement' _description = __doc__ - journal = fields.Many2One( - 'statement.journal', 'Journal', required=True, states=_STATES, - on_change=['journal'], select=1) + journal = fields.Many2One('account.statement.journal', 'Journal', required=True, + states=_STATES, on_change=['journal'], select=1) date = fields.Date('Date', required=True, states=_STATES, select=1) - start_balance = fields.Numeric( - 'Start Balance', digits=(16, 2), states=_STATES) - end_balance = fields.Numeric( - 'End Balance', digits=(16, 2), states=_STATES) - lines = fields.One2Many( - 'statement.statement.line', 'statement', 'Transactions', - states=_STATES) - state = fields.Selection( - [('draft', 'Draft'), - ('validated', 'Validated'), - ('cancel', 'Cancel'), - ('posted', 'Posted'),], - 'State', readonly=True, select=1) + start_balance = fields.Numeric('Start Balance', digits=(16, 2), + states=_STATES) + end_balance = fields.Numeric('End Balance', digits=(16, 2), states=_STATES) + lines = fields.One2Many('account.statement.line', 'statement', + 'Transactions', states=_STATES) + state = fields.Selection([ + ('draft', 'Draft'), + ('validated', 'Validated'), + ('cancel', 'Cancel'), + ('posted', 'Posted'), + ], 'State', readonly=True, select=1) def __init__(self): super(Statement, self).__init__() @@ -47,15 +44,21 @@ class Statement(OSV): return 'draft' def on_change_journal(self, cursor, user, ids, value, context=None): + res = {} if not value.get('journal'): - return {} - statement_ids = self.search( - cursor, user, [('journal', '=', value['journal'])], - order=[('date','DESC')], limit=1, context=context) + return res + + statement_ids = self.search(cursor, user, [ + ('journal', '=', value['journal']), + ], order=[ + ('date', 'DESC'), + ], limit=1, context=context) if not statement_ids: - return {} + return res + statement = self.browse(cursor, user, statement_ids[0], context=context) - return {'start_balance': statement.end_balance} + res['start_balance'] = statement.end_balance + return res def get_end_balance(self, cursor, user, ids, name, arg, context=None): statements = self.browse(cursor, user, ids, context=context) @@ -67,7 +70,8 @@ class Statement(OSV): return res def set_state_validated(self, cursor, user, statement_id, context=None): - statement_line_obj = self.pool.get('statement.statement.line') + statement_line_obj = self.pool.get('account.statement.line') + statement = self.browse(cursor, user, statement_id, context=context) computed_end_balance = statement.start_balance @@ -79,34 +83,37 @@ class Statement(OSV): context=context) for line in statement.lines: statement_line_obj.create_move(cursor, user, line, context=context) - self.write(cursor, user, statement_id, - {'state':'validated',}, - context=context) + self.write(cursor, user, statement_id, { + 'state':'validated', + }, context=context) def set_state_posted(self, cursor, user, statement_id, context=None): - statement_line_obj = self.pool.get('statement.statement.line') + statement_line_obj = self.pool.get('account.statement.line') + statement = self.browse(cursor, user, statement_id, context=context) - statement_line_obj.post_move( - cursor, user, statement.lines, context=context) - self.write( - cursor, user, statement_id, {'state':'posted'}, context=context) + statement_line_obj.post_move(cursor, user, statement.lines, + context=context) + self.write(cursor, user, statement_id, { + 'state':'posted', + }, context=context) def set_state_cancel(self, cursor, user, statement_id, context=None): - statement_line_obj = self.pool.get('statement.statement.line') + statement_line_obj = self.pool.get('account.statement.line') + statement = self.browse(cursor, user, statement_id, context=context) - statement_line_obj.delete_move( - cursor, user, statement.lines, context=context) - self.write(cursor, user, statement_id, - {'state':'cancel',}, - context=context) + statement_line_obj.delete_move(cursor, user, statement.lines, + context=context) + self.write(cursor, user, statement_id, { + 'state':'cancel', + }, context=context) def draft_workflow(self, cursor, user, ids, context=None): workflow_service = LocalService('workflow') for statement in self.browse(cursor, user, ids, context=context): workflow_service.trg_create(user, self._name, statement.id, cursor) - self.write( - cursor, user, statement.id, - {'state': 'draft',}) + self.write(cursor, user, statement.id, { + 'state': 'draft', + }, context=context) return True Statement() @@ -114,22 +121,19 @@ Statement() class Line(OSV): 'Bank Statement Line' - _name = 'statement.statement.line' + _name = 'account.statement.line' _description = __doc__ - statement = fields.Many2One( - 'statement.statement', 'Statement', required=True, ondelete='CASCADE') + statement = fields.Many2One('account.statement', 'Statement', + required=True, ondelete='CASCADE') date = fields.Date('Date', required=True) - amount = fields.Numeric( - 'Amount', digits=(16,2), required=True, + amount = fields.Numeric('Amount', digits=(16,2), required=True, on_change=['amount', 'party', 'account']) - party = fields.Many2One( - 'relationship.party', 'Party', on_change=['amount', 'party']) - account = fields.Many2One( - 'account.account', 'Account', required=True) - description = fields.Char('Description', size=None) - move = fields.Many2One( - 'account.move', 'Account Move', readonly=True) + party = fields.Many2One('relationship.party', 'Party', + on_change=['amount', 'party']) + account = fields.Many2One('account.account', 'Account', required=True) + description = fields.Char('Description') + move = fields.Many2One('account.move', 'Account Move', readonly=True) def __init__(self): super(Line, self).__init__() @@ -139,8 +143,9 @@ class Line(OSV): }) def on_change_party(self, cursor, user, ids, value, context=None): + res = {} if not (value.get('party') and value.get('amount')): - return {} + return res party_obj = self.pool.get('relationship.party') account_obj = self.pool.get('account.account') party = party_obj.browse(cursor, user, value['party'], context=context) @@ -148,25 +153,28 @@ class Line(OSV): account = party.account_receivable else: account = party.account_payable - return {'account': account_obj.name_get( - cursor, user, account.id, context=context)[0]} + res['account'] = account_obj.name_get(cursor, user, account.id, + context=context)[0] + return res def on_change_amount(self, cursor, user, ids, value, context=None): + res = {} if not (value.get('party') and value.get('amount')): - return {} + return res party_obj = self.pool.get('relationship.party') account_obj = self.pool.get('account.account') party = party_obj.browse(cursor, user, value['party'], context=context) if value.get('account') and value['account'] not in ( party.account_receivable.id, party.account_payable.id): # The user has entered a non-default value, we keep it. - return {} + return res if value['amount'] > Decimal("0.0"): account = party.account_receivable else: account = party.account_payable - return {'account': account_obj.name_get( - cursor, user, account.id, context=context)[0]} + res['account'] = account_obj.name_get(cursor, user, account.id, + context=context)[0] + return res def create_move(self, cursor, user, line, context=None): move_obj = self.pool.get('account.move') @@ -176,8 +184,7 @@ class Line(OSV): context=context) move_lines = self.get_move_lines(cursor, user, line, context=context) - move_id = move_obj.create( - cursor, user, { + move_id = move_obj.create(cursor, user, { 'name': line.date, 'period': period_id, 'journal': line.statement.journal.journal.id, @@ -194,8 +201,8 @@ class Line(OSV): def delete_move(self, cursor, user, lines, context=None): move_obj = self.pool.get('account.move') - move_obj.delete( - cursor, user, [l.move.id for l in lines], context=context) + move_obj.delete(cursor, user, [l.move.id for l in lines], + context=context) def get_move_lines(self, cursor, user, statement_line, context=None): currency_obj = self.pool.get('currency.currency') @@ -213,15 +220,15 @@ class Line(OSV): second_currency = None vals = [] - vals.append( - {'name': statement_line.date, - 'debit': amount < zero and -amount or zero, - 'credit': amount >= zero and amount or zero, - 'account': statement_line.account.id, - 'party': statement_line.party and statement_line.party.id, - 'second_currency': second_currency, - 'amount_second_currency': amount_second_currency, - }) + vals.append({ + 'name': statement_line.date, + 'debit': amount < zero and -amount or zero, + 'credit': amount >= zero and amount or zero, + 'account': statement_line.account.id, + 'party': statement_line.party and statement_line.party.id, + 'second_currency': second_currency, + 'amount_second_currency': amount_second_currency, + }) journal = statement_line.statement.journal.journal if statement_line.amount >= zero: @@ -231,15 +238,15 @@ class Line(OSV): if not account: self.raise_user_error(cursor, 'debit_credit_account_bank_journal', context=context) - vals.append( - {'name': statement_line.date, - 'debit': amount >= zero and amount or zero, - 'credit': amount < zero and -amount or zero, - 'account': account.id, - 'party': statement_line.party and statement_line.party.id, - 'second_currency': second_currency, - 'amount_second_currency': amount_second_currency, - }) + vals.append({ + 'name': statement_line.date, + 'debit': amount >= zero and amount or zero, + 'credit': amount < zero and -amount or zero, + 'account': account.id, + 'party': statement_line.party and statement_line.party.id, + 'second_currency': second_currency, + 'amount_second_currency': amount_second_currency, + }) return vals Line() diff --git a/statement.xml b/statement.xml index 3284100241..8a78ceca8d 100644 --- a/statement.xml +++ b/statement.xml @@ -10,7 +10,7 @@ - statement.statement + account.statement form - statement.statement + account.statement tree Draft Statements - statement.statement + account.statement form [('state', '=', 'draft')] @@ -91,7 +91,7 @@ Validated Statement - statement.statement + account.statement form [('state', '=', 'validated')] @@ -110,7 +110,7 @@ Posted Statements - statement.statement + account.statement form [('state', '=', 'posted')] @@ -129,7 +129,7 @@ All Statement - statement.statement + account.statement form @@ -146,7 +146,7 @@ action="act_statement_form" id="menu_statement_form"/> - statement.statement.line + account.statement.line form tree + @@ -186,7 +186,7 @@ Statement - statement.statement + account.statement True @@ -234,7 +234,7 @@ - + @@ -242,7 +242,7 @@ - + @@ -250,7 +250,7 @@ - + @@ -259,7 +259,7 @@ - + @@ -267,7 +267,7 @@ - + @@ -275,7 +275,7 @@ - +