Add direct access to account.move form from account.move.line tree view
Show code on name_get of journal add direct search on code
This commit is contained in:
@@ -82,14 +82,34 @@ class AccountJournal(models.Model):
|
||||
_inherit = 'account.journal'
|
||||
|
||||
@api.multi
|
||||
@api.depends(
|
||||
'name', 'currency_id', 'company_id', 'company_id.currency_id', 'code')
|
||||
def name_get(self):
|
||||
res = []
|
||||
if self._context.get('journal_show_code_only'):
|
||||
res = []
|
||||
for record in self:
|
||||
res.append((record.id, record.code))
|
||||
for journal in self:
|
||||
res.append((journal.id, journal.code))
|
||||
return res
|
||||
else:
|
||||
return super(AccountJournal, self).name_get()
|
||||
for journal in self:
|
||||
currency = journal.currency_id or journal.company_id.currency_id
|
||||
name = "[%s] %s (%s)" % (journal.code, journal.name, currency.name)
|
||||
res.append((journal.id, name))
|
||||
return res
|
||||
|
||||
# Also search on start of 'code', not only on 'name'
|
||||
@api.model
|
||||
def name_search(
|
||||
self, name='', args=None, operator='ilike', limit=80):
|
||||
if args is None:
|
||||
args = []
|
||||
if name:
|
||||
jrls = self.search(
|
||||
[('code', '=ilike', name + '%')] + args, limit=limit)
|
||||
if jrls:
|
||||
return jrls.name_get()
|
||||
return super(AccountJournal, self).name_search(
|
||||
name=name, args=args, operator=operator, limit=limit)
|
||||
|
||||
|
||||
class AccountAccount(models.Model):
|
||||
@@ -128,6 +148,16 @@ class AccountAnalyticAccount(models.Model):
|
||||
'exists in the same company!')]
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
default_move_line_name = fields.Char(string='Default Label',
|
||||
states={'posted': [('readonly', True)]})
|
||||
# By default, we can still modify "ref" when account move is posted
|
||||
# which seems a bit lazy for me...
|
||||
ref = fields.Char(states={'posted': [('readonly', True)]})
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
|
||||
@@ -170,6 +200,19 @@ class AccountMoveLine(models.Model):
|
||||
else:
|
||||
self.credit = amount_company_currency
|
||||
|
||||
@api.multi
|
||||
def show_account_move_form(self):
|
||||
self.ensure_one()
|
||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||
'account', 'action_move_line_form')
|
||||
action.update({
|
||||
'res_id': self.move_id.id,
|
||||
'view_id': False,
|
||||
'views': False,
|
||||
'view_mode': 'form,tree',
|
||||
})
|
||||
return action
|
||||
|
||||
|
||||
class AccountBankStatement(models.Model):
|
||||
_inherit = 'account.bank.statement'
|
||||
|
||||
@@ -176,6 +176,12 @@ module -->
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="ref" position="after">
|
||||
<field name="default_move_line_name"/>
|
||||
</field>
|
||||
<xpath expr="//field[@name='line_ids']" position="attributes">
|
||||
<attribute name="context">{'line_ids': line_ids, 'journal_id': journal_id, 'default_name': default_move_line_name}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='line_ids']/tree/field[@name='date_maturity']" position="after">
|
||||
<field name="full_reconcile_id"/>
|
||||
</xpath>
|
||||
@@ -224,6 +230,9 @@ module -->
|
||||
<field name="credit" position="after">
|
||||
<field name="full_reconcile_id"/>
|
||||
</field>
|
||||
<field name="date_maturity" position="after">
|
||||
<button name="show_account_move_form" type="object" icon="fa-arrows-h" string="Show Journal Entry"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user