bemade_partner_root_ancestor: First working version with unit test.
This commit is contained in:
parent
3135a41ed5
commit
168dc57063
8 changed files with 143 additions and 24 deletions
74
.gitignore
vendored
Normal file
74
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
/.venv
|
||||
/.pytest_cache
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
bin/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
eggs/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
*.eggs
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
||||
# Pycharm
|
||||
.idea
|
||||
|
||||
# Eclipse
|
||||
.settings
|
||||
|
||||
# Visual Studio cache/options directory
|
||||
.vs/
|
||||
.vscode
|
||||
|
||||
# OSX Files
|
||||
.DS_Store
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
|
||||
# Rope
|
||||
.ropeproject
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# Backup files
|
||||
*~
|
||||
*.swp
|
||||
|
||||
# OCA rules
|
||||
!static/lib/
|
||||
|
|
@ -17,17 +17,14 @@
|
|||
# DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
{
|
||||
'name': 'bemade_multiple_billing_contacts',
|
||||
'name': 'Partner Root Ancestor',
|
||||
'version': '15.0.1.0.0',
|
||||
'summary': 'Send invoices to multiple contacts by default.',
|
||||
'description': """By default, newly created invoices add all invoice addresses for the given partner as
|
||||
followers on the invoice. If billing contacts are set manually on the sales order, those billing
|
||||
contacts are added as followers on the invoice instead.""",
|
||||
'category': 'Invoicing Management',
|
||||
'summary': 'Technical module to add the field root_ancestor to res.partner.',
|
||||
'category': 'Generic Modules/Base',
|
||||
'author': 'Bemade Inc.',
|
||||
'website': 'https://www.bemade.org',
|
||||
'license': 'OPL-1',
|
||||
'depends': ['sale', 'account'],
|
||||
'depends': ['base'],
|
||||
'data': [],
|
||||
'demo': [],
|
||||
'installable': True,
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
|
||||
from . import res_partner
|
||||
|
|
|
|||
|
|
@ -4,13 +4,11 @@ from odoo import models, fields, api, _, Command
|
|||
class Partner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
def _billing_contacts_domain(self):
|
||||
self.ensure_one()
|
||||
return [('is_company', '=', False), ('root_ancestor', '=', self.root_ancestor)]
|
||||
billing_contacts = fields.Many2many(string='Default Billing Contacts',
|
||||
comodel_name='res.partner',
|
||||
relation='res_partner_billing_contact_rel',
|
||||
column1='billing_contact_id',
|
||||
column2='billed_partner_id',
|
||||
domain=_billing_contacts_domain,
|
||||
tracking=True)
|
||||
root_ancestor = fields.Many2one(comodel_name='res.partner',
|
||||
string='Root Ancestor',
|
||||
compute='_compute_root_ancestor')
|
||||
|
||||
@api.depends('parent_id')
|
||||
def _compute_root_ancestor(self):
|
||||
for rec in self:
|
||||
rec.root_ancestor = rec.parent_id and rec.parent_id.root_ancestor or rec
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
from odoo import models, fields, api, _, Command
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import test_root_ancestor
|
||||
55
tests/test_root_ancestor.py
Normal file
55
tests/test_root_ancestor.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
from odoo.tests.common import TransactionCase, tagged
|
||||
from odoo import Command
|
||||
|
||||
|
||||
class TestPartnerRootAncestor(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
partner = cls.env['res.partner']
|
||||
cls.common_ancestor = partner.create({
|
||||
'name': 'Parnter name',
|
||||
'company_type': 'company',
|
||||
})
|
||||
cls.first_child = partner.create({
|
||||
'name': 'Child name',
|
||||
'company_type': 'company',
|
||||
'parent_id': cls.common_ancestor.id,
|
||||
})
|
||||
cls.second_child = partner.create({
|
||||
'name': 'Child name',
|
||||
'company_type': 'company',
|
||||
'parent_id': cls.common_ancestor.id,
|
||||
})
|
||||
cls.first_grandchild = partner.create({
|
||||
'name': 'Grandchild name',
|
||||
'company_type': 'person',
|
||||
'parent_id': cls.first_child.id,
|
||||
})
|
||||
cls.second_grandchild = partner.create({
|
||||
'name': 'Grandchild name',
|
||||
'company_type': 'person',
|
||||
'parent_id': cls.second_child.id,
|
||||
})
|
||||
cls.unrelated_partner = partner.create({
|
||||
'name': 'Unrelated partner',
|
||||
})
|
||||
cls.relatives = [cls.common_ancestor, cls.first_child, cls.second_child, cls.first_grandchild,
|
||||
cls.second_grandchild]
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
def testBaseCase(self):
|
||||
for r1 in self.relatives:
|
||||
self.assertFalse(r1.root_ancestor == self.unrelated_partner)
|
||||
for r2 in self.relatives:
|
||||
self.assertTrue(r1.root_ancestor == r2.root_ancestor)
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
def testNewRelative(self):
|
||||
new_relative = self.env['res.partner'].create({
|
||||
'name': 'Whatever',
|
||||
'company_type': 'person',
|
||||
'parent_id': self.second_grandchild.id,
|
||||
})
|
||||
for r1 in self.relatives:
|
||||
self.assertTrue(r1.root_ancestor == new_relative.root_ancestor)
|
||||
Loading…
Reference in a new issue