From d699052b6a33cf650d6961c619b46a7aa0bd4997 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 24 Nov 2015 16:33:59 +0100 Subject: [PATCH] Better "Journal items" shortcut button on partner form view, to go directly to the "account" of the customer or supplier --- account_usability/account.py | 41 +++++++++++++++++++++++++++++- account_usability/account_view.xml | 13 ++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/account_usability/account.py b/account_usability/account.py index 1439203..c8345c7 100644 --- a/account_usability/account.py +++ b/account_usability/account.py @@ -20,7 +20,8 @@ # ############################################################################## -from openerp import models, fields, api +from openerp import models, fields, api, _ +from openerp.exceptions import Warning as UserError class AccountInvoice(models.Model): @@ -92,3 +93,41 @@ class AccountBankStatementLine(models.Model): cr, uid, ids, excluded_ids=excluded_ids, search_reconciliation_proposition=search_rec_prop, context=context) + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.multi + def show_partner_receivable_or_payable_account(self): + self.ensure_one() + if self.customer and not self.supplier: + account_id = self.property_account_receivable.id + elif self.supplier and not self.customer: + account_id = self.property_account_payable.id + else: + raise UserError(_( + 'This shortcut only works for partners that are only ' + 'customer or only supplier')) + action = self.env['ir.actions.act_window'].for_xml_id( + 'account', 'action_account_moves_all_tree') + action['context'] = { + 'search_default_partner_id': [self.ids[0]], + 'default_partner_id': self.ids[0], + 'search_default_account_id': account_id, + } + return action + + @api.multi + def _compute_journal_item_count(self): + amlo = self.env['account.move.line'] + for partner in self: + partner.journal_item_count = amlo.search_count([ + ('partner_id', '=', partner.id), + ('account_id', 'in', ( + partner.property_account_receivable.id, + partner.property_account_payable.id))]) + + journal_item_count = fields.Integer( + compute='_compute_journal_item_count', + string="Journal Items", readonly=True) diff --git a/account_usability/account_view.xml b/account_usability/account_view.xml index 98ec733..418c60b 100644 --- a/account_usability/account_view.xml +++ b/account_usability/account_view.xml @@ -111,6 +111,19 @@ + + + usability.res.partner.journal.items.button + res.partner + + + + +