Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG][10.0-Issue175-T23296] project_partner_name #180

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions project_partner_name/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ Installation
============

To install this module, you need to:
* have basic modules installed (project)
* Have basic modules installed (project)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/infrastructure-dns/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Bugs are tracked on `GitHub Issues <https://github.com/Elico-Corp/odoo-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback

Credits
=======
Expand All @@ -44,9 +43,10 @@ Maintainer

This module is maintained by Elico Corporation.

Elico Corporation offers consulting services to implement open source
management software in SMEs, with a strong involvement in quality of service.
Elico Corporation offers consulting services to implement open source management
software in SMEs, with a strong involvement in quality of service.

Our headquarters are located in Shanghai with branches in Hong Kong, ShenZhen
and Singapore servicing customers from Greater China, Asia Pacific, Europe,
Americas, etc...
Our headquarters are located in Shanghai and Singapore servicing customers from
Greater China and Asia Pacific.

Contact information: `Sales <[email protected]>`__
2 changes: 1 addition & 1 deletion project_partner_name/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Elico Corp (www.elico-corp.com).
# © 2016-2017 Elico Corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
13 changes: 7 additions & 6 deletions project_partner_name/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# -*- coding: utf-8 -*-
# © 2016 Elico Corp (www.elico-corp.com).
# © 2016-2017 Elico Corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Project Partner Name",
"summary": "Project Partner Name",
"version": "10.0.1.0.0",
'category': 'Project Management',
'website': 'https://www.elico-corp.com',
'support': '[email protected]',
"author": "Elico Corp",
"category": "Project Management",
"website": "https://www.elico-corp.com",
"support": "[email protected]",
"license": "AGPL-3",
"application": False,
"installable": False,
"depends": [
"project",
"account_analytic_parent",
],
"data": [
"views/project_view.xml",
],
"installable": True,
}
6 changes: 3 additions & 3 deletions project_partner_name/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Elico Corp (www.elico-corp.com).
# © 2016-2017 Elico Corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import project_partner_mandatory
from . import analytic_account_id
from . import project_project
from . import analytic_account
56 changes: 56 additions & 0 deletions project_partner_name/models/analytic_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# © 2016-2017 Elico Corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class AnalyticAccount(models.Model):
_inherit = 'account.analytic.account'

def _get_partner_ref(self, project):
partner = project.partner_id
return partner.is_company and partner.ref\
or (partner.parent_id and partner.parent_id.ref or False)

@api.multi
def _get_full_names(self, level):
self.ensure_one()

# Tail recursion function
def iter_parent_ids(elmt, level, full_names):
if level <= 0:
full_names.append('...')
return (None, 0, full_names)
elif elmt.parent_id and not elmt.type == 'template':
full_names.append(elmt.name)
return iter_parent_ids(elmt.parent_id, level - 1, full_names)
else:
full_names.append(elmt.name)
return (None, level - 1, full_names)

(_, _, full_names) = iter_parent_ids(self, level, [])

return full_names

@api.multi
def name_get(self):
res = []
project_obj = self.env['project.project']
for analytic_acc in self:
full_names = analytic_acc._get_full_names(6)
if isinstance(full_names, list) and full_names:
project = project_obj.search(
[('analytic_account_id', '=', analytic_acc.id)], limit=1
)
if project:
partner_ref = self._get_partner_ref(project)
if partner_ref:
full_names[0] = "%s - %s" % (
partner_ref,
full_names[0]
)
full_names.reverse() # order on First Root Last Leaf
res.append((analytic_acc.id, ' / '.join(full_names)))

return res
69 changes: 0 additions & 69 deletions project_partner_name/models/analytic_account_id.py

This file was deleted.

46 changes: 0 additions & 46 deletions project_partner_name/models/project_partner_mandatory.py

This file was deleted.

39 changes: 39 additions & 0 deletions project_partner_name/models/project_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# © 2016-2017 Elico Corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class ProjectProject(models.Model):
_inherit = 'project.project'

def _get_partner_ref(self, project):
partner = project.partner_id
return partner.is_company and partner.ref\
or (partner.parent_id and partner.parent_id.ref or False)

@api.multi
def name_get(self):
result = []
for project in self:
partner_ref = self._get_partner_ref(project)
project_name = partner_ref and '%s - %s' % (
partner_ref, project.name
) or project.name
result.append((project.id, '%s' % (project_name)))
return result

@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
args = args or []
projects = self.browse()
if name:
projects = self.search(
['|', ('partner_id.ref', operator, name),
('partner_id.parent_id.ref', operator, name)] + args,
limit=limit)
if not projects:
projects = self.search([('name', operator, name)] + args,
limit=limit)
return projects.name_get()
5 changes: 5 additions & 0 deletions project_partner_name/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2017 Elico corp (www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from . import test_project_partner_name
35 changes: 35 additions & 0 deletions project_partner_name/tests/test_project_partner_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# © 2017 Elico corp (www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo.tests import common


class TestProjectPartnerName(common.TransactionCase):

def setUp(self):
super(TestProjectPartnerName, self).setUp()
self.project_obj = self.env['project.project']
self.analytic_acc_obj = self.env['account.analytic.account']
self.project1 = self.env.ref('project.project_project_3')
self.partner1 = self.env.ref('base.res_partner_2')
self.partner1.ref = 'ref1'
self.project2 = self.env.ref('project.project_project_5')
self.partner2 = self.env.ref('base.res_partner_address_13')
self.partner2.parent_id.ref = 'ref2'

def test_name_get_search(self):
"""Check namge_get and namge_search of Project / Analytic
Partner Name Ref"""
proj_name1 = self.project1.name
self.assertEqual(self.project1.name_get()[0][1],
self.partner1.ref + ' - ' + proj_name1)
self.assertEqual(self.project2.name_get()[0][1],
self.partner2.parent_id.ref + ' - ' +
self.project2.name)
self.assertEqual(self.project_obj.name_search(proj_name1)[0][1],
self.partner1.ref + ' - ' + proj_name1)
analytic_name = self.analytic_acc_obj.name_search(
self.project1.analytic_account_id.name
)
self.assertEqual(analytic_name[0][1],
self.partner1.ref + ' - ' + proj_name1)
26 changes: 13 additions & 13 deletions project_partner_name/views/project_view.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="edit_project" model="ir.ui.view">
<field name="name">project.project.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<field name="partner_id" position="attributes">
<attribute name="required">1</attribute>
</field>
<odoo>

<record id="edit_project" model="ir.ui.view">
<field name="name">project.project.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<field name="partner_id" position="attributes">
<attribute name="required">1</attribute>
</field>
</record>
</data>
</openerp>
</field>
</record>

</odoo>