Add test on context of company multivalue target fields
issue10067 review333851026
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add test on context of company multivalue target fields
|
||||
* Use report header for CompanyReport
|
||||
|
||||
Version 5.8.0 - 2020-11-02
|
||||
|
||||
@@ -55,6 +55,10 @@ class Employee(ModelSQL, ModelView):
|
||||
'Employee'
|
||||
__name__ = 'company.employee'
|
||||
party = fields.Many2One('party.party', 'Party', required=True,
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
},
|
||||
depends=['company'],
|
||||
help="The party which represents the employee.")
|
||||
company = fields.Many2One('company.company', 'Company', required=True,
|
||||
help="The company to which the employee belongs.")
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond import backend
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.tools.multivalue import migrate_property
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
@@ -39,6 +40,13 @@ class Party(CompanyMultiValueMixin, metaclass=PoolMeta):
|
||||
class PartyLang(CompanyValueMixin, metaclass=PoolMeta):
|
||||
__name__ = 'party.party.lang'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.party.context['company'] = Eval('company', -1)
|
||||
if 'company' not in cls.party.depends:
|
||||
cls.party.depends.append('company')
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
exist = backend.TableHandler.table_exist(cls._table)
|
||||
|
||||
+3
-3
@@ -4,12 +4,12 @@
|
||||
try:
|
||||
from trytond.modules.company.tests.test_company import (
|
||||
suite, create_company, set_company, create_employee,
|
||||
PartyCompanyCheckEraseMixin)
|
||||
PartyCompanyCheckEraseMixin, CompanyMultiValueTestMixin)
|
||||
except ImportError:
|
||||
from .test_company import (
|
||||
suite, create_company, set_company, create_employee,
|
||||
PartyCompanyCheckEraseMixin)
|
||||
PartyCompanyCheckEraseMixin, CompanyMultiValueTestMixin)
|
||||
|
||||
__all__ = [
|
||||
'suite', 'create_company', 'set_company', 'create_employee',
|
||||
'PartyCompanyCheckEraseMixin']
|
||||
'PartyCompanyCheckEraseMixin', 'CompanyMultiValueTestMixin']
|
||||
|
||||
+39
-2
@@ -6,11 +6,13 @@ from contextlib import contextmanager
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.pool import Pool, isregisteredby
|
||||
|
||||
from trytond.modules.currency.tests import create_currency, add_currency_rate
|
||||
from trytond.modules.party.tests import PartyCheckEraseMixin
|
||||
|
||||
from ..model import CompanyMultiValueMixin
|
||||
|
||||
|
||||
def create_company(name='Dunder Mifflin', currency=None):
|
||||
pool = Pool()
|
||||
@@ -63,7 +65,42 @@ class PartyCompanyCheckEraseMixin(PartyCheckEraseMixin):
|
||||
return super().setup_check_erase_party()
|
||||
|
||||
|
||||
class CompanyTestCase(PartyCompanyCheckEraseMixin, ModuleTestCase):
|
||||
class CompanyMultiValueTestMixin:
|
||||
|
||||
@with_transaction()
|
||||
def test_company_multivalue_context(self):
|
||||
"Test context of company multivalue target"
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
for mname, model in pool.iterobject():
|
||||
if (not isregisteredby(model, self.module)
|
||||
or issubclass(model, Company)):
|
||||
continue
|
||||
company = None
|
||||
for fname, field in model._fields.items():
|
||||
if (field._type == 'many2one'
|
||||
and issubclass(field.get_target(), Company)):
|
||||
company = fname
|
||||
break
|
||||
else:
|
||||
continue
|
||||
for fname, field in model._fields.items():
|
||||
if not hasattr(field, 'get_target'):
|
||||
continue
|
||||
Target = field.get_target()
|
||||
if not issubclass(Target, CompanyMultiValueMixin):
|
||||
continue
|
||||
if company in model._fields:
|
||||
self.assertIn(
|
||||
'company', list(field.context.keys()),
|
||||
msg="Missing '%s' value as company "
|
||||
'in "%s"."%s" context' % (
|
||||
company, mname, fname))
|
||||
|
||||
|
||||
class CompanyTestCase(
|
||||
PartyCompanyCheckEraseMixin, CompanyMultiValueTestMixin,
|
||||
ModuleTestCase):
|
||||
'Test Company module'
|
||||
module = 'company'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user