On partner form view, 2 buttons for journal items: one for payable (seen if supplier = True) and one for receivable (seen if customer=True)

This commit is contained in:
Alexis de Lattre
2016-01-12 20:09:55 +01:00
parent ad0e2f43c4
commit f745388f37
2 changed files with 33 additions and 17 deletions

View File

@@ -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)