Ejemplo n.º 1
0
    def test_2_related_related(self):
        """ test a related field referring to a related field """
        # add a related field on a related field on res.partner
        # and simulate a _inherits_reload() to populate _all_columns.
        old_columns = self.partner._columns
        old_all_columns = self.partner._all_columns
        self.partner._columns = dict(old_columns)
        self.partner._all_columns = dict(old_all_columns)
        self.partner._columns.update({
            'single_related_company_id':
            fields.related('company_id', type='many2one', obj='res.company'),
            'related_related_company_id':
            fields.related('single_related_company_id',
                           type='many2one',
                           obj='res.company'),
        })
        self.partner._all_columns.update({
            'single_related_company_id':
            fields.column_info(
                'single_related_company_id',
                self.partner._columns['single_related_company_id'], None, None,
                None),
            'related_related_company_id':
            fields.column_info(
                'related_related_company_id',
                self.partner._columns['related_related_company_id'], None,
                None, None)
        })

        self.do_test_company_field('related_related_company_id')

        # restore res.partner fields
        self.partner._columns = old_columns
        self.partner._all_columns = old_all_columns
Ejemplo n.º 2
0
    def test_1_single_related(self):
        """ test a related field with a single indirection like fields.related('foo') """
        # add a related field test_related_company_id on res.partner
        # and simulate a _inherits_reload() to populate _all_columns.
        old_columns = self.partner._columns
        old_all_columns = self.partner._all_columns
        self.partner._columns = dict(old_columns)
        self.partner._all_columns = dict(old_all_columns)
        self.partner._columns.update({
            'single_related_company_id':
            fields.related('company_id', type='many2one', obj='res.company'),
        })
        self.partner._all_columns.update({
            'single_related_company_id':
            fields.column_info(
                'single_related_company_id',
                self.partner._columns['single_related_company_id'], None, None,
                None)
        })

        self.do_test_company_field('single_related_company_id')

        # restore res.partner fields
        self.partner._columns = old_columns
        self.partner._all_columns = old_all_columns
Ejemplo n.º 3
0
    def test_2_related_related(self):
        """ test a related field referring to a related field """
        # add a related field on a related field on res.partner
        # and simulate a _inherits_reload() to populate _all_columns.
        old_columns = self.partner._columns
        old_all_columns = self.partner._all_columns
        self.partner._columns = dict(old_columns)
        self.partner._all_columns = dict(old_all_columns)
        self.partner._columns.update({
            'single_related_company_id': fields.related('company_id', type='many2one', obj='res.company'),
            'related_related_company_id': fields.related('single_related_company_id', type='many2one', obj='res.company'),
        })
        self.partner._all_columns.update({
            'single_related_company_id': fields.column_info('single_related_company_id', self.partner._columns['single_related_company_id'], None, None, None),
            'related_related_company_id': fields.column_info('related_related_company_id', self.partner._columns['related_related_company_id'], None, None, None)
        })

        self.do_test_company_field('related_related_company_id')

        # restore res.partner fields
        self.partner._columns = old_columns
        self.partner._all_columns = old_all_columns
Ejemplo n.º 4
0
    def test_1_property_multicompany(self):
        cr, uid = self.cr, self.uid

        parent_company_id = self.imd.get_object_reference(cr, uid, 'base', 'main_company')[1]
        country_be = self.imd.get_object_reference(cr, uid, 'base', 'be')[1]
        country_fr = self.imd.get_object_reference(cr, uid, 'base', 'fr')[1]
        group_partner_manager = self.imd.get_object_reference(cr, uid, 'base', 'group_partner_manager')[1]
        group_multi_company = self.imd.get_object_reference(cr, uid, 'base', 'group_multi_company')[1]

        sub_company = self.company.create(cr, uid, {'name': 'MegaCorp', 'parent_id': parent_company_id})
        alice = self.user.create(cr, uid, {'name': 'Alice',
            'login':'******',
            'email':'*****@*****.**',
            'company_id':parent_company_id,
            'company_ids':[(6, 0, [parent_company_id, sub_company])],
            'country_id':country_be,
            'groups_id': [(6, 0, [group_partner_manager, group_multi_company])]
        })
        bob = self.user.create(cr, uid, {'name': 'Bob',
            'login':'******',
            'email':'*****@*****.**',
            'company_id':sub_company,
            'company_ids':[(6, 0, [parent_company_id, sub_company])],
            'country_id':country_fr,
            'groups_id': [(6, 0, [group_partner_manager, group_multi_company])]
        })
        
        self.partner._columns = dict(self.partner._columns)
        self.partner._columns.update({
            'property_country': fields.property('res.country', type='many2one', relation="res.country", string="Country by company", view_load=True),
        })
        self.partner._all_columns.update({
            'property_country': fields.column_info('property_country', self.partner._columns['property_country'], None, None, None),
        })
        self.partner._field_create(cr)

        partner_id = self.partner.create(cr, alice, {
            'name': 'An International Partner',
            'email': '*****@*****.**',
            'company_id': parent_company_id,
        })
        self.partner.write(cr, bob, [partner_id], {'property_country': country_fr})
        self.assertEqual(self.partner.browse(cr, bob, partner_id).property_country.id, country_fr, "Bob does not see the value he has set on the property field")

        self.partner.write(cr, alice, [partner_id], {'property_country': country_be})
        self.assertEqual(self.partner.browse(cr, alice, partner_id).property_country.id, country_be, "Alice does not see the value he has set on the property field")
        self.assertEqual(self.partner.browse(cr, bob, partner_id).property_country.id, country_fr, "Changes made by Alice have overwritten Bob's value")
Ejemplo n.º 5
0
    def test_1_property_multicompany(self):
        cr, uid = self.cr, self.uid

        parent_company_id = self.imd.get_object_reference(cr, uid, 'base', 'main_company')[1]
        country_be = self.imd.get_object_reference(cr, uid, 'base', 'be')[1]
        country_fr = self.imd.get_object_reference(cr, uid, 'base', 'fr')[1]
        group_partner_manager = self.imd.get_object_reference(cr, uid, 'base', 'group_partner_manager')[1]
        group_multi_company = self.imd.get_object_reference(cr, uid, 'base', 'group_multi_company')[1]

        sub_company = self.company.create(cr, uid, {'name': 'MegaCorp', 'parent_id': parent_company_id})
        alice = self.user.create(cr, uid, {'name': 'Alice',
            'login':'******',
            'email':'*****@*****.**',
            'company_id':parent_company_id,
            'company_ids':[(6, 0, [parent_company_id, sub_company])],
            'country_id':country_be,
            'groups_id': [(6, 0, [group_partner_manager, group_multi_company])]
        })
        bob = self.user.create(cr, uid, {'name': 'Bob',
            'login':'******',
            'email':'*****@*****.**',
            'company_id':sub_company,
            'company_ids':[(6, 0, [parent_company_id, sub_company])],
            'country_id':country_fr,
            'groups_id': [(6, 0, [group_partner_manager, group_multi_company])]
        })
        
        self.partner._columns = dict(self.partner._columns)
        self.partner._columns.update({
            'property_country': fields.property(type='many2one', relation="res.country", string="Country by company"),
        })
        self.partner._all_columns.update({
            'property_country': fields.column_info('property_country', self.partner._columns['property_country'], None, None, None),
        })
        self.partner._field_create(cr)

        partner_id = self.partner.create(cr, alice, {
            'name': 'An International Partner',
            'email': '*****@*****.**',
            'company_id': parent_company_id,
        })
        self.partner.write(cr, bob, [partner_id], {'property_country': country_fr})
        self.assertEqual(self.partner.browse(cr, bob, partner_id).property_country.id, country_fr, "Bob does not see the value he has set on the property field")

        self.partner.write(cr, alice, [partner_id], {'property_country': country_be})
        self.assertEqual(self.partner.browse(cr, alice, partner_id).property_country.id, country_be, "Alice does not see the value he has set on the property field")
        self.assertEqual(self.partner.browse(cr, bob, partner_id).property_country.id, country_fr, "Changes made by Alice have overwritten Bob's value")
Ejemplo n.º 6
0
    def test_1_single_related(self):
        """ test a related field with a single indirection like fields.related('foo') """
        # add a related field test_related_company_id on res.partner
        # and simulate a _inherits_reload() to populate _all_columns.
        old_columns = self.partner._columns
        old_all_columns = self.partner._all_columns
        self.partner._columns = dict(old_columns)
        self.partner._all_columns = dict(old_all_columns)
        self.partner._columns.update({
            'single_related_company_id': fields.related('company_id', type='many2one', obj='res.company'),
        })
        self.partner._all_columns.update({
            'single_related_company_id': fields.column_info('single_related_company_id', self.partner._columns['single_related_company_id'], None, None, None)
        })

        self.do_test_company_field('single_related_company_id')

        # restore res.partner fields
        self.partner._columns = old_columns
        self.partner._all_columns = old_all_columns