Browse Source

[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
parent
commit
87e0616277
  1. 3
      contract/__openerp__.py
  2. 1
      contract/models/__init__.py
  3. 44
      contract/models/res_partner.py
  4. 8
      contract/tests/test_contract.py
  5. 18
      contract/views/contract.xml
  6. 31
      contract/views/res_partner_view.xml

3
contract/__openerp__.py

@ -6,7 +6,7 @@
{
'name': 'Contracts Management recurring',
'version': '9.0.1.2.1',
'version': '9.0.1.3.0',
'category': 'Contract Management',
'license': 'AGPL-3',
'author': "OpenERP SA,"
@ -22,6 +22,7 @@
'data/contract_template.xml',
'views/contract.xml',
'views/account_invoice_view.xml',
'views/res_partner_view.xml',
],
'installable': True,
}

1
contract/models/__init__.py

@ -4,3 +4,4 @@
from . import contract
from . import invoice
from . import res_partner

44
contract/models/res_partner.py

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

8
contract/tests/test_contract.py

@ -11,7 +11,10 @@ class TestContract(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestContract, cls).setUpClass()
cls.partner = cls.env.ref('base.res_partner_2')
cls.partner = cls.env['res.partner'].create({
'name': 'Partner test',
'customer': True,
})
cls.product = cls.env.ref('product.product_product_2')
cls.product.description_sale = 'Test description sale'
cls.contract = cls.env['account.analytic.account'].create({
@ -42,10 +45,13 @@ class TestContract(SavepointCase):
self.assertIn('uom_id', res['domain'])
self.contract_line.price_unit = 100.0
self.assertEqual(self.partner.contract_count, 1)
self.contract.partner_id = False
with self.assertRaises(ValidationError):
self.contract.recurring_create_invoice()
self.assertEqual(self.partner.contract_count, 0)
self.contract.partner_id = self.partner.id
self.assertEqual(self.partner.contract_count, 1)
new_invoice = self.contract.recurring_create_invoice()
self.assertTrue(new_invoice)

18
contract/views/contract.xml

@ -3,14 +3,16 @@
<data>
<record id="act_recurring_invoices" model="ir.actions.act_window">
<field name="context">{'search_default_contract_id':
[active_id],
'default_contract_id': active_id}
</field>
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_id" ref="account.invoice_tree" />
<field name="search_view_id" ref="account.view_account_invoice_filter"/>
<field name="view_ids"
eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('account.invoice_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('account.invoice_form')})]"/>
<field name="context">{
'search_default_contract_id': [active_id],
'default_contract_id': active_id}
</field>
</record>
<record id="account_analytic_account_recurring_form_form" model="ir.ui.view">
@ -90,6 +92,10 @@
<field name="model">account.analytic.account</field>
<field name="inherit_id" ref="analytic.view_account_analytic_account_search"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="company_id" filter_domain="[('partner_id', 'child_of', self)]"
string="Partner and dependents"/>
</field>
<field name="name" position="after">
<field name="journal_id"/>
<field name="pricelist_id"/>

31
contract/views/res_partner_view.xml

@ -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>
Loading…
Cancel
Save