Browse Source
[9.0][FIX] contract: Invoice supplier form view from contract link (#84)
[9.0][FIX] contract: Invoice supplier form view from contract link (#84)
* [9.0][FIX] contract: Invoice supplier form from contract link * [9.0][IMP] contract: Smart button in partner * [9.0][IMP] contract: Search partner contract with child_of operator * [9.0][IMP] contract: Remove commented line * [9.0][IMP] contract: Filter by "partner" and "Partner and dependents"pull/79/merge
Carlos Dauden
7 years ago
committed by
Rafael Blasco
6 changed files with 97 additions and 8 deletions
-
3contract/__openerp__.py
-
1contract/models/__init__.py
-
44contract/models/res_partner.py
-
8contract/tests/test_contract.py
-
18contract/views/contract.xml
-
31contract/views/res_partner_view.xml
@ -0,0 +1,44 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 Carlos Dauden <carlos.dauden@tecnativa.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp import api, fields, models |
|||
|
|||
|
|||
class ResPartner(models.Model): |
|||
_inherit = 'res.partner' |
|||
|
|||
contract_count = fields.Integer( |
|||
compute='_compute_contract_count', |
|||
string='# of Contracts', |
|||
) |
|||
contract_ids = fields.One2many( |
|||
comodel_name='account.analytic.account', |
|||
inverse_name='partner_id', |
|||
string='Contracts', |
|||
) |
|||
|
|||
@api.multi |
|||
@api.depends('contract_ids') |
|||
def _compute_contract_count(self): |
|||
contract_data = self.env['account.analytic.account'].read_group( |
|||
domain=[('partner_id', 'child_of', self.ids), |
|||
('recurring_invoices', '=', True)], |
|||
fields=['partner_id'], |
|||
groupby=['partner_id']) |
|||
# read to keep the child/parent relation while aggregating the |
|||
# read_group result in the loop |
|||
partner_child_ids = self.read(['child_ids']) |
|||
mapped_data = dict([ |
|||
(m['partner_id'][0], m['partner_id_count']) for m in contract_data |
|||
]) |
|||
for partner in self: |
|||
# let's obtain the partner id and all its child ids from the read |
|||
# up there |
|||
partner_ids = filter( |
|||
lambda r: r['id'] == partner.id, partner_child_ids)[0] |
|||
partner_ids = ([partner_ids.get('id')] + |
|||
partner_ids.get('child_ids')) |
|||
# then we can sum for all the partner's child |
|||
partner.contract_count = sum( |
|||
mapped_data.get(child, 0) for child in partner_ids) |
@ -0,0 +1,31 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
|
|||
<record id="act_res_partner_2_contract" model="ir.actions.act_window"> |
|||
<field name="name">Contracts</field> |
|||
<field name="res_model">account.analytic.account</field> |
|||
<field name="view_type">form</field> |
|||
<field name="view_mode">tree,form</field> |
|||
<field name="context">{ |
|||
'search_default_partner_id': active_id, |
|||
'search_default_recurring_invoices': 1}</field> |
|||
<field name="groups_id" eval="[(4, ref('base.group_sale_salesman'))]"/> |
|||
</record> |
|||
|
|||
<record id="view_partner_form" model="ir.ui.view"> |
|||
<field name="name">res.partner.view.contract</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="inherit_id" ref="base.view_partner_form" /> |
|||
<field name="groups_id" eval="[(4, ref('base.group_sale_salesman'))]"/> |
|||
<field name="arch" type="xml"> |
|||
<div name="button_box" position="inside"> |
|||
<button class="oe_stat_button" type="action" name="%(contract.act_res_partner_2_contract)d" |
|||
attrs="{'invisible': [('customer', '=', False)]}" |
|||
icon="fa-file-o"> |
|||
<field string="Contracts" name="contract_count" widget="statinfo"/> |
|||
</button> |
|||
</div> |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue