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:
@@ -99,21 +99,23 @@ class ResPartner(models.Model):
|
|||||||
_inherit = 'res.partner'
|
_inherit = 'res.partner'
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def show_partner_receivable_or_payable_account(self):
|
def show_receivable_account(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if self.customer and not self.supplier:
|
|
||||||
account_id = self.property_account_receivable.id
|
account_id = self.property_account_receivable.id
|
||||||
elif self.supplier and not self.customer:
|
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
|
account_id = self.property_account_payable.id
|
||||||
else:
|
return self.common_show_account(self.ids[0], account_id)
|
||||||
raise UserError(_(
|
|
||||||
'This shortcut only works for partners that are only '
|
def common_show_account(self, partner_id, account_id):
|
||||||
'customer or only supplier'))
|
|
||||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||||
'account', 'action_account_moves_all_tree')
|
'account', 'action_account_moves_all_tree')
|
||||||
action['context'] = {
|
action['context'] = {
|
||||||
'search_default_partner_id': [self.ids[0]],
|
'search_default_partner_id': [partner_id],
|
||||||
'default_partner_id': self.ids[0],
|
'default_partner_id': partner_id,
|
||||||
'search_default_account_id': account_id,
|
'search_default_account_id': account_id,
|
||||||
}
|
}
|
||||||
return action
|
return action
|
||||||
@@ -124,10 +126,14 @@ class ResPartner(models.Model):
|
|||||||
for partner in self:
|
for partner in self:
|
||||||
partner.journal_item_count = amlo.search_count([
|
partner.journal_item_count = amlo.search_count([
|
||||||
('partner_id', '=', partner.id),
|
('partner_id', '=', partner.id),
|
||||||
('account_id', 'in', (
|
('account_id', '=', partner.property_account_receivable.id)])
|
||||||
partner.property_account_receivable.id,
|
partner.payable_journal_item_count = amlo.search_count([
|
||||||
partner.property_account_payable.id))])
|
('partner_id', '=', partner.id),
|
||||||
|
('account_id', '=', partner.property_account_payable.id)])
|
||||||
|
|
||||||
journal_item_count = fields.Integer(
|
journal_item_count = fields.Integer(
|
||||||
compute='_compute_journal_item_count',
|
compute='_compute_journal_item_count',
|
||||||
string="Journal Items", readonly=True)
|
string="Journal Items", readonly=True)
|
||||||
|
payable_journal_item_count = fields.Integer(
|
||||||
|
compute='_compute_journal_item_count',
|
||||||
|
string="Payable Journal Items", readonly=True)
|
||||||
|
|||||||
@@ -111,17 +111,27 @@
|
|||||||
</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">
|
<record id="partner_view_button_journal_item_count" model="ir.ui.view">
|
||||||
<field name="name">usability.res.partner.journal.items.button</field>
|
<field name="name">usability.res.partner.journal.items.button</field>
|
||||||
<field name="model">res.partner</field>
|
<field name="model">res.partner</field>
|
||||||
<field name="inherit_id" ref="account.partner_view_button_journal_item_count"/>
|
<field name="inherit_id" ref="account.partner_view_button_journal_item_count"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
<button name="%(account.action_account_moves_all_tree)d" position="after">
|
||||||
|
<button name="show_payable_account" type="object"
|
||||||
|
attrs="{'invisible': [('supplier', '=', False)]}"
|
||||||
|
icon="fa-list" class="oe_stat_button">
|
||||||
|
<field string="Payable Account" name="payable_journal_item_count"
|
||||||
|
widget="statinfo"/>
|
||||||
|
</button>
|
||||||
|
</button>
|
||||||
<button name="%(account.action_account_moves_all_tree)d" position="attributes">
|
<button name="%(account.action_account_moves_all_tree)d" position="attributes">
|
||||||
<attribute name="type">object</attribute>
|
<attribute name="type">object</attribute>
|
||||||
<attribute name="name">show_partner_receivable_or_payable_account</attribute>
|
<attribute name="name">show_receivable_account</attribute>
|
||||||
|
<attribute name="attrs">{'invisible': [('customer', '=', False)]}</attribute>
|
||||||
</button>
|
</button>
|
||||||
|
<field name="journal_item_count" position="attributes">
|
||||||
|
<attribute name="string">Receivable Account</attribute>
|
||||||
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user