Browse Source

[IMP] Changes to avoid some data being changed when swapping the parent from the Affiliate.

Created new Affiliate type and set it as default when creating a new affiliate.

(cherry picked from commit 89dfe04)
pull/592/head
BT-mgomez 7 years ago
committed by mara1
parent
commit
a0e8e72599
  1. 4
      partner_affiliate/models/res_partner.py
  2. 1
      partner_affiliate/tests/__init__.py
  3. 89
      partner_affiliate/tests/test_partner_affiliate.py
  4. 2
      partner_affiliate/views/res_partner_view.xml

4
partner_affiliate/models/res_partner.py

@ -3,13 +3,15 @@
# Copyright 2018 brain-tec AG - Raul Martin # Copyright 2018 brain-tec AG - Raul Martin
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo import fields, models, api
class ResPartner(models.Model): class ResPartner(models.Model):
"""Add relation affiliate_ids.""" """Add relation affiliate_ids."""
_inherit = "res.partner" _inherit = "res.partner"
type = fields.Selection(selection_add=[('affiliate', 'Affiliate')])
# force "active_test" domain to bypass _search() override # force "active_test" domain to bypass _search() override
child_ids = fields.One2many('res.partner', 'parent_id', child_ids = fields.One2many('res.partner', 'parent_id',
string='Contacts', string='Contacts',

1
partner_affiliate/tests/__init__.py

@ -0,0 +1 @@
from . import test_partner_affiliate

89
partner_affiliate/tests/test_partner_affiliate.py

@ -0,0 +1,89 @@
from odoo.tests import common
class TestPartnerAffiliate(common.TransactionCase):
def setUp(self):
super(TestPartnerAffiliate, self).setUp()
self.partner_obj = self.env['res.partner']
self.first_parent = self.partner_obj.create({
'name': 'MyFirstParentForTheAffiliate',
'type': 'contact',
'is_company': True,
'street': 'first parent street',
'street2': 'number 99',
'zip': 123,
'city': 'Test City',
})
self.second_parent = self.partner_obj.create({
'name': 'MySecondParentForTheAffiliate',
'type': 'contact',
'is_company': True,
'street': 'second parent street',
'street2': 'number 44',
'zip': 999,
'city': 'Test City',
})
# Check data integrity of the objects when an affiliate is given a new
# parent. So both objects keeps their data.
def test_change_parent_from_a_new_affiliate(self):
new_affiliate = self.partner_obj.create({
'name': 'MyTestAffiliate',
'is_company': True,
'parent_id': self.first_parent.id,
'type': 'affiliate',
'street': 'affiliate street',
'street2': 'number 11',
'zip': 567,
'city': 'Test City',
'email': 'myAffiliate@test.com',
})
# Checks for data integrity in affiliate and his parent.
self.assertTrue(new_affiliate, "The new affiliate have been created.")
self.assertEquals(new_affiliate.type, 'affiliate',
"Check type must be 'affiliate'")
self.assertEquals(new_affiliate.parent_id.id, self.first_parent.id,
"Must be child of the parent defined in the setup")
self.assertEquals(new_affiliate.street, "affiliate street",
"The street have been correctly set.")
self.assertEquals(self.first_parent.street, "first parent street",
"The parent continues with his original street")
# Change the parent of the affiliate for the second one in the set-up.
new_affiliate.parent_id = self.second_parent.id
new_affiliate.onchange_parent_id()
# The parent have been changed. And is not the first one.
self.assertEquals(new_affiliate.parent_id.id, self.second_parent.id)
# The affiliate keeps its data for the street. Not modified.
self.assertEquals(new_affiliate.street, "affiliate street",
"keeps the same street")
# The data for the street of the first parent have not been changed.
self.assertEquals(self.first_parent.street, "first parent street",
"keeps the same street")
# Check that the default value for 'type' defined by default in the view
# is set correctly when a new affiliate is created.
def test_new_affiliate_is_created_with_type_affiliate_by_default(self):
new_affiliate = self.partner_obj.with_context(
{'default_parent_id': self.first_parent.id,
'default_is_company': True,
'default_type': 'affiliate'
}
).create({
'name': 'MyTestAffiliate',
'street': 'affiliate street',
'street2': 'number 11',
'zip': 567,
'city': 'Test City',
'email': 'myAffiliate@test.com',
})
self.assertEquals(new_affiliate.type, 'affiliate')

2
partner_affiliate/views/res_partner_view.xml

@ -14,7 +14,7 @@
<xpath expr='//page[@name="internal_notes"]' position="before"> <xpath expr='//page[@name="internal_notes"]' position="before">
<page string="Affiliates" attrs="{'invisible': [('is_company','=',False)]}"> <page string="Affiliates" attrs="{'invisible': [('is_company','=',False)]}">
<field name="affiliate_ids" <field name="affiliate_ids"
context="{'default_parent_id': active_id, 'default_is_company': True, 'default_type':'other'}" mode="kanban">
context="{'default_parent_id': active_id, 'default_is_company': True, 'default_type':'affiliate'}" mode="kanban">
<kanban> <kanban>
<field name="color"/> <field name="color"/>
<field name="name"/> <field name="name"/>

Loading…
Cancel
Save