From f745388f378ca94c95c644be101b7ee5b51fa80c Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 12 Jan 2016 20:09:55 +0100 Subject: [PATCH] On partner form view, 2 buttons for journal items: one for payable (seen if supplier = True) and one for receivable (seen if customer=True) --- account_usability/account.py | 34 ++++++++++++++++++------------ account_usability/account_view.xml | 16 +++++++++++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/account_usability/account.py b/account_usability/account.py index c8345c7..a69fe76 100644 --- a/account_usability/account.py +++ b/account_usability/account.py @@ -99,21 +99,23 @@ class ResPartner(models.Model): _inherit = 'res.partner' @api.multi - def show_partner_receivable_or_payable_account(self): + def show_receivable_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')) + account_id = self.property_account_receivable.id + return self.common_show_account(self.ids[0], account_id) + + @api.multi + def show_payable_account(self): + self.ensure_one() + account_id = self.property_account_payable.id + return self.common_show_account(self.ids[0], account_id) + + def common_show_account(self, partner_id, account_id): 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_partner_id': [partner_id], + 'default_partner_id': partner_id, 'search_default_account_id': account_id, } return action @@ -124,10 +126,14 @@ class ResPartner(models.Model): 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))]) + ('account_id', '=', partner.property_account_receivable.id)]) + partner.payable_journal_item_count = amlo.search_count([ + ('partner_id', '=', partner.id), + ('account_id', '=', partner.property_account_payable.id)]) journal_item_count = fields.Integer( compute='_compute_journal_item_count', string="Journal Items", readonly=True) + payable_journal_item_count = fields.Integer( + compute='_compute_journal_item_count', + string="Payable Journal Items", readonly=True) diff --git a/account_usability/account_view.xml b/account_usability/account_view.xml index 418c60b..ff22cdb 100644 --- a/account_usability/account_view.xml +++ b/account_usability/account_view.xml @@ -111,17 +111,27 @@ - usability.res.partner.journal.items.button res.partner + + + + Receivable Account +