diff --git a/modules/marketing_campaign/marketing.py b/modules/marketing_campaign/marketing.py index b121795864..db95577106 100644 --- a/modules/marketing_campaign/marketing.py +++ b/modules/marketing_campaign/marketing.py @@ -134,11 +134,12 @@ class MarketingCampaignMixin(Model): yield fname @classmethod - def default_get(cls, fields_names, with_rec_name=True, with_default=True): + def default_get( + cls, fields_names=None, with_rec_name=True, with_default=True): transaction = Transaction() context = transaction.context default = super().default_get( - fields_names, + fields_names=fields_names, with_rec_name=with_rec_name, with_default=with_default) for fname in cls.marketing_campaign_fields(): diff --git a/modules/marketing_campaign/sale_opportunity_reporting.py b/modules/marketing_campaign/sale_opportunity_reporting.py index c5f551c9d6..b1ace51435 100644 --- a/modules/marketing_campaign/sale_opportunity_reporting.py +++ b/modules/marketing_campaign/sale_opportunity_reporting.py @@ -55,11 +55,12 @@ class Context(MarketingCampaignMixin, metaclass=PoolMeta): __name__ = 'sale.opportunity.reporting.context' @classmethod - def default_get(cls, fields_names, with_rec_name=True, with_default=True): + def default_get( + cls, fields_names=None, with_rec_name=True, with_default=True): transaction = Transaction() context = transaction.context default = super().default_get( - fields_names, + fields_names=fields_names, with_rec_name=with_rec_name, with_default=with_default) for fname in cls.marketing_campaign_fields(): diff --git a/modules/marketing_campaign/sale_reporting.py b/modules/marketing_campaign/sale_reporting.py index d2dc88cf6e..9800c10d46 100644 --- a/modules/marketing_campaign/sale_reporting.py +++ b/modules/marketing_campaign/sale_reporting.py @@ -56,11 +56,12 @@ class Context(MarketingCampaignMixin, metaclass=PoolMeta): __name__ = 'sale.reporting.context' @classmethod - def default_get(cls, fields_names, with_rec_name=True, with_default=True): + def default_get( + cls, fields_names=None, with_rec_name=True, with_default=True): transaction = Transaction() context = transaction.context default = super().default_get( - fields_names, + fields_names=fields_names, with_rec_name=with_rec_name, with_default=with_default) for fname in cls.marketing_campaign_fields(): diff --git a/modules/party/party.py b/modules/party/party.py index c12d10eee6..7d1ca47b70 100644 --- a/modules/party/party.py +++ b/modules/party/party.py @@ -390,12 +390,13 @@ class Party( return result @classmethod - def default_get(cls, fields_names, with_rec_name=True, with_default=True): + def default_get( + cls, fields_names=None, with_rec_name=True, with_default=True): pool = Pool() Country = pool.get('country.country') values = super().default_get( - fields_names, + fields_names=fields_names, with_rec_name=with_rec_name, with_default=with_default) eu_vat = get_cc_module('eu', 'vat') diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 366925ebfa..3131395a7c 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Make field_names optional in Model.default_get * Remove check_xml_record from ModelStorage * Always synchronize XML data with database * Convert None as empty string when searching on Char or Text diff --git a/trytond/doc/ref/models.rst b/trytond/doc/ref/models.rst index 72077470ef..7263c80390 100644 --- a/trytond/doc/ref/models.rst +++ b/trytond/doc/ref/models.rst @@ -85,10 +85,10 @@ Class methods: `. See :meth:`trytond.pool.PoolBase.__register__`. -.. classmethod:: Model.default_get(fields_names[[, with_rec_name], with_default]) +.. classmethod:: Model.default_get([fields_names[[, with_rec_name], with_default]]) Return a dictionary with the default values for each field in - ``fields_names``. + ``fields_names`` or all fields if not specified. Default values are defined by the returned value of each class method with the pattern ``default_()``. diff --git a/trytond/trytond/model/model.py b/trytond/trytond/model/model.py index fede417cff..0587b0868d 100644 --- a/trytond/trytond/model/model.py +++ b/trytond/trytond/model/model.py @@ -131,7 +131,8 @@ class Model(URLMixin, PoolBase, metaclass=ModelMeta): Translation.register_fields(cls, module_name) @classmethod - def default_get(cls, fields_names, with_rec_name=True, with_default=True): + def default_get( + cls, fields_names=None, with_rec_name=True, with_default=True): ''' Return a dict with the default values for each field in fields_names. If with_rec_name is True, rec_name will be added. @@ -140,6 +141,9 @@ class Model(URLMixin, PoolBase, metaclass=ModelMeta): values = {} context = Transaction().context + if fields_names is None: + fields_names = cls._fields.keys() + default_rec_name = context.get('default_rec_name') if (default_rec_name and cls._rec_name in cls._fields