Better "Journal items" shortcut button on partner form view, to go directly to the "account" of the customer or supplier
This commit is contained in:
@@ -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):
|
class AccountInvoice(models.Model):
|
||||||
@@ -92,3 +93,41 @@ class AccountBankStatementLine(models.Model):
|
|||||||
cr, uid, ids, excluded_ids=excluded_ids,
|
cr, uid, ids, excluded_ids=excluded_ids,
|
||||||
search_reconciliation_proposition=search_rec_prop,
|
search_reconciliation_proposition=search_rec_prop,
|
||||||
context=context)
|
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)
|
||||||
|
|||||||
@@ -111,6 +111,19 @@
|
|||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!-- On the partner form, when a user clicks on the journal items
|
||||||
|
we wants to see only the account payable or account receivable -->
|
||||||
|
<record id="partner_view_button_journal_item_count" model="ir.ui.view">
|
||||||
|
<field name="name">usability.res.partner.journal.items.button</field>
|
||||||
|
<field name="model">res.partner</field>
|
||||||
|
<field name="inherit_id" ref="account.partner_view_button_journal_item_count"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<button name="%(account.action_account_moves_all_tree)d" position="attributes">
|
||||||
|
<attribute name="type">object</attribute>
|
||||||
|
<attribute name="name">show_partner_receivable_or_payable_account</attribute>
|
||||||
|
</button>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
||||||
|
|||||||
Reference in New Issue
Block a user