Make field_names optional in Model.default_get
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -85,10 +85,10 @@ Class methods:
|
||||
<model-ir.model.field>`.
|
||||
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_<field name>()``.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user