Use account as first name for object and fix some guidelines
This commit is contained in:
+2
-3
@@ -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)
|
||||
|
||||
+5
-5
@@ -3,7 +3,7 @@
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="statement_journal_view_form">
|
||||
<field name="model">statement.journal</field>
|
||||
<field name="model">account.statement.journal</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
@@ -21,7 +21,7 @@
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="statement_journal_view_tree">
|
||||
<field name="model">statement.journal</field>
|
||||
<field name="model">account.statement.journal</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
<record model="ir.action.act_window" id="act_statement_journal_form">
|
||||
<field name="name">Statement Journals</field>
|
||||
<field name="res_model">statement.journal</field>
|
||||
<field name="res_model">account.statement.journal</field>
|
||||
<field name="view_type">form</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_statement_journal_form_view1">
|
||||
@@ -58,14 +58,14 @@
|
||||
action="act_statement_journal_form" id="menu_statement_journal_form"/>
|
||||
|
||||
<record model="ir.model.access" id="access_statement_journal">
|
||||
<field name="model" search="[('model', '=', 'statement.journal')]"/>
|
||||
<field name="model" search="[('model', '=', 'account.statement.journal')]"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_statement_journal_admin">
|
||||
<field name="model" search="[('model', '=', 'statement.journal')]"/>
|
||||
<field name="model" search="[('model', '=', 'account.statement.journal')]"/>
|
||||
<field name="group" ref="account.group_account_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
|
||||
+89
-82
@@ -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()
|
||||
|
||||
+15
-15
@@ -10,7 +10,7 @@
|
||||
<menuitem name="Statements" parent="account.menu_account_configuration"
|
||||
id="menu_statement_configuration" sequence="70"/>
|
||||
<record model="ir.ui.view" id="statement_view_form">
|
||||
<field name="model">statement.statement</field>
|
||||
<field name="model">account.statement</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
@@ -54,7 +54,7 @@
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="statement_view_tree">
|
||||
<field name="model">statement.statement</field>
|
||||
<field name="model">account.statement</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
@@ -72,7 +72,7 @@
|
||||
</record>
|
||||
<record model="ir.action.act_window" id="act_draft_statement_form">
|
||||
<field name="name">Draft Statements</field>
|
||||
<field name="res_model">statement.statement</field>
|
||||
<field name="res_model">account.statement</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="domain">[('state', '=', 'draft')]</field>
|
||||
</record>
|
||||
@@ -91,7 +91,7 @@
|
||||
|
||||
<record model="ir.action.act_window" id="act_validated_statement_form">
|
||||
<field name="name">Validated Statement</field>
|
||||
<field name="res_model">statement.statement</field>
|
||||
<field name="res_model">account.statement</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="domain">[('state', '=', 'validated')]</field>
|
||||
</record>
|
||||
@@ -110,7 +110,7 @@
|
||||
|
||||
<record model="ir.action.act_window" id="act_posted_statement_form">
|
||||
<field name="name">Posted Statements</field>
|
||||
<field name="res_model">statement.statement</field>
|
||||
<field name="res_model">account.statement</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="domain">[('state', '=', 'posted')]</field>
|
||||
</record>
|
||||
@@ -129,7 +129,7 @@
|
||||
|
||||
<record model="ir.action.act_window" id="act_statement_form">
|
||||
<field name="name">All Statement</field>
|
||||
<field name="res_model">statement.statement</field>
|
||||
<field name="res_model">account.statement</field>
|
||||
<field name="view_type">form</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_statement_form_view1">
|
||||
@@ -146,7 +146,7 @@
|
||||
action="act_statement_form" id="menu_statement_form"/>
|
||||
|
||||
<record model="ir.ui.view" id="statement_line_view_form">
|
||||
<field name="model">statement.statement.line</field>
|
||||
<field name="model">account.statement.line</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
@@ -172,7 +172,7 @@
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<tree string="Bank Statement Lines">
|
||||
<tree string="Statement Lines">
|
||||
<field name="date"/>
|
||||
<field name="amount"/>
|
||||
<field name="party"/>
|
||||
@@ -186,7 +186,7 @@
|
||||
<!-- Statement workflow -->
|
||||
<record model="workflow" id="wkf_statement">
|
||||
<field name="name">Statement</field>
|
||||
<field name="osv">statement.statement</field>
|
||||
<field name="osv">account.statement</field>
|
||||
<field name="on_create">True</field>
|
||||
</record>
|
||||
<record model="workflow.activity" id="statement_act_draft">
|
||||
@@ -234,7 +234,7 @@
|
||||
</record>
|
||||
|
||||
<record model="ir.model.access" id="access_statement_account_admin">
|
||||
<field name="model" search="[('model', '=', 'statement.statement')]"/>
|
||||
<field name="model" search="[('model', '=', 'account.statement')]"/>
|
||||
<field name="group" ref="account.group_account_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
@@ -242,7 +242,7 @@
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_statement_account">
|
||||
<field name="model" search="[('model', '=', 'statement.statement')]"/>
|
||||
<field name="model" search="[('model', '=', 'account.statement')]"/>
|
||||
<field name="group" ref="account.group_account"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
@@ -250,7 +250,7 @@
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_statement_statement">
|
||||
<field name="model" search="[('model', '=', 'statement.statement')]"/>
|
||||
<field name="model" search="[('model', '=', 'account.statement')]"/>
|
||||
<field name="group" ref="group_statement"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
@@ -259,7 +259,7 @@
|
||||
</record>
|
||||
|
||||
<record model="ir.model.access" id="access_statement_line_account_admin">
|
||||
<field name="model" search="[('model', '=', 'statement.statement.line')]"/>
|
||||
<field name="model" search="[('model', '=', 'account.statement.line')]"/>
|
||||
<field name="group" ref="account.group_account_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
@@ -267,7 +267,7 @@
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_statement_line_account">
|
||||
<field name="model" search="[('model', '=', 'statement.statement.line')]"/>
|
||||
<field name="model" search="[('model', '=', 'account.statement.line')]"/>
|
||||
<field name="group" ref="account.group_account"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
@@ -275,7 +275,7 @@
|
||||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_statement_line_statement">
|
||||
<field name="model" search="[('model', '=', 'statement.statement.line')]"/>
|
||||
<field name="model" search="[('model', '=', 'account.statement.line')]"/>
|
||||
<field name="group" ref="group_statement"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
|
||||
Reference in New Issue
Block a user