bemade_multiple_billing_contacts: Early development on multiple billing contacts.
This commit is contained in:
parent
3424f7221c
commit
02624877d6
8 changed files with 179 additions and 10 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/
|
||||||
|
|
@ -27,7 +27,10 @@
|
||||||
'author': 'Bemade Inc.',
|
'author': 'Bemade Inc.',
|
||||||
'website': 'https://www.bemade.org',
|
'website': 'https://www.bemade.org',
|
||||||
'license': 'OPL-1',
|
'license': 'OPL-1',
|
||||||
'depends': ['sale', 'account'],
|
'depends': ['sale',
|
||||||
|
'account',
|
||||||
|
'bemade_partner_root_ancestor',
|
||||||
|
],
|
||||||
'data': [],
|
'data': [],
|
||||||
'demo': [],
|
'demo': [],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
|
from . import res_partner
|
||||||
|
from . import sale_order
|
||||||
|
from . import account_move
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
from odoo import models, fields, api
|
||||||
|
|
||||||
|
|
||||||
|
class AccountMove(models.Model):
|
||||||
|
_inherit = 'account.move'
|
||||||
|
|
||||||
|
billing_contacts = fields.Many2many(comodel_name='res.partner',
|
||||||
|
string="Billing Contacts",
|
||||||
|
compute='_compute_billing_contacts',
|
||||||
|
inverse='_inverse_billing_contacts',
|
||||||
|
store=True)
|
||||||
|
|
||||||
|
@api.depends('line_ids.sale_line_ids.order_id', 'partner_id')
|
||||||
|
def _compute_billing_contacts(self):
|
||||||
|
for rec in self:
|
||||||
|
order_id = rec.line_ids and rec.line_ids.mapped('sale_line_ids').mapped('order_id')
|
||||||
|
if order_id and len(order_id) == 1 and order_id.billing_contacts:
|
||||||
|
rec.billing_contacts = order_id.billing_contacts
|
||||||
|
else:
|
||||||
|
rec.billing_contacts = rec.partner_id.billing_contacts
|
||||||
|
|
||||||
|
def _inverse_billing_contacts(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _post(self, soft=True):
|
||||||
|
# Override the original method to subscribe the partner's billing contacts instead of self.partner_id
|
||||||
|
initial_subscribers = self.message_partner_ids.ids
|
||||||
|
final_subscribers = initial_subscribers + self.partner_id.billing_contacts.ids
|
||||||
|
posted = super()._post()
|
||||||
|
self.message_unsubscribe(self.message_partner_ids - initial_subscribers)
|
||||||
|
self.message_subscribe(final_subscribers)
|
||||||
|
return posted
|
||||||
|
|
@ -4,13 +4,17 @@ from odoo import models, fields, api, _, Command
|
||||||
class Partner(models.Model):
|
class Partner(models.Model):
|
||||||
_inherit = 'res.partner'
|
_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',
|
billing_contacts = fields.Many2many(string='Default Billing Contacts',
|
||||||
comodel_name='res.partner',
|
comodel_name='res.partner',
|
||||||
relation='res_partner_billing_contact_rel',
|
compute='_compute_billing_contacts',
|
||||||
column1='billing_contact_id',
|
inverse='_inverse_billing_contacts')
|
||||||
column2='billed_partner_id',
|
|
||||||
domain=_billing_contacts_domain,
|
@api.depends('child_ids.type')
|
||||||
tracking=True)
|
def _compute_billing_contacts(self):
|
||||||
|
for rec in self:
|
||||||
|
rec.billing_contacts = rec.child_ids.filtered(lambda r: r.type == 'invoice')
|
||||||
|
|
||||||
|
@api.depends('billing_contacts')
|
||||||
|
def _inverse_billing_contacts(self):
|
||||||
|
for partner in self.mapped('billing_contacts'):
|
||||||
|
partner.type = 'invoice'
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,16 @@ from odoo import models, fields, api, _, Command
|
||||||
class SaleOrder(models.Model):
|
class SaleOrder(models.Model):
|
||||||
_inherit = 'sale.order'
|
_inherit = 'sale.order'
|
||||||
|
|
||||||
|
billing_contacts = fields.Many2many(comodel_name='res.partner',
|
||||||
|
string='Billing Contacts',
|
||||||
|
compute='_compute_billing_contacts',
|
||||||
|
inverse='_inverse_billing_contacts',
|
||||||
|
store=True)
|
||||||
|
|
||||||
|
@api.depends('partner_id')
|
||||||
|
def _compute_billing_contacts(self):
|
||||||
|
for rec in self:
|
||||||
|
rec.billing_contacts = rec.partner_id.billing_contacts
|
||||||
|
|
||||||
|
def _inverse_billing_contacts(self):
|
||||||
|
pass
|
||||||
|
|
|
||||||
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from . import test_billing_contacts
|
||||||
40
tests/test_billing_contacts.py
Normal file
40
tests/test_billing_contacts.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
from odoo.tests import TransactionCase, tagged
|
||||||
|
|
||||||
|
|
||||||
|
class TestBillingContacts(TransactionCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
partner = cls.env['res.partner'].create
|
||||||
|
cls.parent_co = partner({
|
||||||
|
'name': 'Partner',
|
||||||
|
'company_type': 'company',
|
||||||
|
})
|
||||||
|
cls.billing_contact1 = partner({
|
||||||
|
'name': 'Billing Contact 1',
|
||||||
|
'company_type': 'person',
|
||||||
|
'email': 'billingcontact1@partner.co',
|
||||||
|
'parent_id': cls.parent_co.id,
|
||||||
|
'type': 'invoice',
|
||||||
|
})
|
||||||
|
cls.billing_contact2 = partner({
|
||||||
|
'name': 'Billing Contact 2',
|
||||||
|
'company_type': 'person',
|
||||||
|
'email': 'billingcontact2@partner.co',
|
||||||
|
'parent_id': cls.parent_co.id,
|
||||||
|
'type': 'invoice',
|
||||||
|
})
|
||||||
|
cls.non_billing_contact = partner({
|
||||||
|
'name': 'Non-billing contact',
|
||||||
|
'company_type': 'person',
|
||||||
|
'email': 'not_billing@partner.co',
|
||||||
|
'parent_id': cls.parent_co.id,
|
||||||
|
'type': 'contact',
|
||||||
|
})
|
||||||
|
|
||||||
|
@tagged('-at_install', 'post_install')
|
||||||
|
def test_sale_order_defaults(self):
|
||||||
|
billing_contacts = self.parent_co.billing_contacts
|
||||||
|
self.assertTrue(self.billing_contact1 in self.parent_co.billing_contacts)
|
||||||
|
self.assertTrue(self.billing_contact2 in self.parent_co.billing_contacts)
|
||||||
|
self.assertTrue(self.non_billing_contact not in self.parent_co.billing_contacts)
|
||||||
Loading…
Reference in a new issue