diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-09-13 18:07:59 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-09-13 18:07:59 +0200 |
| commit | 6c948c36bbf72dd896e0bff03aa7fbddadcbb0cd (patch) | |
| tree | f8620905c011735d8a3c340c46d1417a54a75972 /odoo/tools | |
| parent | 48503fcf08eac6fed12e080d4f501f9bbc8d257d (diff) | |
| parent | 197474e5b9ad43ab2d587a98136a1a809ce9a2e7 (diff) | |
[MERGE] forward port branch saas-12.5 up to 197474e5b9a
Diffstat (limited to 'odoo/tools')
| -rw-r--r-- | odoo/tools/mail.py | 2 | ||||
| -rw-r--r-- | odoo/tools/misc.py | 25 | ||||
| -rw-r--r-- | odoo/tools/sql.py | 8 | ||||
| -rw-r--r-- | odoo/tools/template_inheritance.py | 7 | ||||
| -rw-r--r-- | odoo/tools/translate.py | 38 |
5 files changed, 54 insertions, 26 deletions
diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index b32934101e8..50ccd6b0375 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -58,7 +58,7 @@ safe_attrs = clean.defs.safe_attrs | frozenset( ['style', 'data-o-mail-quote', # quote detection 'data-oe-model', 'data-oe-id', 'data-oe-field', 'data-oe-type', 'data-oe-expression', 'data-oe-translation-id', 'data-oe-nodeid', - 'data-publish', 'data-id', 'data-res_id', 'data-member_id', 'data-view-id' + 'data-publish', 'data-id', 'data-res_id', 'data-interval', 'data-member_id', 'data-scroll-background-ratio', 'data-view-id', ]) diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index 7e069d22a77..356e08db371 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -1225,6 +1225,25 @@ def format_date(env, value, lang_code=False, date_format=False): return babel.dates.format_date(value, format=date_format, locale=locale) +def parse_date(env, value, lang_code=False): + ''' + Parse the date from a given format. If it is not a valid format for the + localization, return the original string. + + :param env: an environment. + :param string value: the date to parse. + :param string lang_code: the lang code, if not specified it is extracted from the + environment context. + :return: date object from the localized string + :rtype: datetime.date + ''' + lang = env['res.lang']._lang_get(lang_code or env.context.get('lang') or 'en_US') + locale = babel.Locale.parse(lang.code) + try: + return babel.dates.parse_date(value, locale=locale) + except: + return value + def format_datetime(env, value, tz=False, dt_format='medium', lang_code=False): """ Formats the datetime in a given format. @@ -1249,8 +1268,10 @@ def format_datetime(env, value, tz=False, dt_format='medium', lang_code=False): except Exception: localized_datetime = utc_datetime - lang = env['res.lang']._lang_get(lang_code or env.context.get('lang') or 'en_US') - locale = babel.Locale.parse(lang.code) + lang_code = lang_code or env.context.get('lang') or 'en_US' + lang = env['res.lang']._lang_get(lang_code) + + locale = babel.Locale.parse(lang.code or lang_code) # lang can be inactive, so `lang`is empty if not dt_format: date_format = posix_to_ldml(lang.date_format, locale=locale) time_format = posix_to_ldml(lang.time_format, locale=locale) diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py index a805202a019..30cebe3bcd0 100644 --- a/odoo/tools/sql.py +++ b/odoo/tools/sql.py @@ -88,7 +88,7 @@ def rename_column(cr, tablename, columnname1, columnname2): def convert_column(cr, tablename, columnname, columntype): """ Convert the column to the given type. """ try: - with cr.savepoint(): + with cr.savepoint(flush=False): cr.execute('ALTER TABLE "{}" ALTER COLUMN "{}" TYPE {}'.format(tablename, columnname, columntype), log_exceptions=False) except psycopg2.NotSupportedError: @@ -106,7 +106,7 @@ def set_not_null(cr, tablename, columnname): """ Add a NOT NULL constraint on the given column. """ query = 'ALTER TABLE "{}" ALTER COLUMN "{}" SET NOT NULL'.format(tablename, columnname) try: - with cr.savepoint(): + with cr.savepoint(flush=False): cr.execute(query) _schema.debug("Table %r: column %r: added constraint NOT NULL", tablename, columnname) except Exception: @@ -135,7 +135,7 @@ def add_constraint(cr, tablename, constraintname, definition): query1 = 'ALTER TABLE "{}" ADD CONSTRAINT "{}" {}'.format(tablename, constraintname, definition) query2 = 'COMMENT ON CONSTRAINT "{}" ON "{}" IS %s'.format(constraintname, tablename) try: - with cr.savepoint(): + with cr.savepoint(flush=False): cr.execute(query1) cr.execute(query2, (definition,)) _schema.debug("Table %r: added constraint %r as %s", tablename, constraintname, definition) @@ -147,7 +147,7 @@ def add_constraint(cr, tablename, constraintname, definition): def drop_constraint(cr, tablename, constraintname): """ drop the given constraint. """ try: - with cr.savepoint(): + with cr.savepoint(flush=False): cr.execute('ALTER TABLE "{}" DROP CONSTRAINT "{}"'.format(tablename, constraintname)) _schema.debug("Table %r: dropped constraint %r", tablename, constraintname) except Exception: diff --git a/odoo/tools/template_inheritance.py b/odoo/tools/template_inheritance.py index 347e022d87b..7f84f97d225 100644 --- a/odoo/tools/template_inheritance.py +++ b/odoo/tools/template_inheritance.py @@ -74,7 +74,7 @@ def locate_node(arch, spec): return None -def apply_inheritance_specs(source, specs_tree, inherit_branding=False): +def apply_inheritance_specs(source, specs_tree, inherit_branding=False, pre_locate=lambda s: True): """ Apply an inheriting view (a descendant of the base view) Apply to a source architecture all the spec nodes (i.e. nodes @@ -82,6 +82,9 @@ def apply_inheritance_specs(source, specs_tree, inherit_branding=False): architecture) given by an inheriting view. :param Element source: a parent architecture to modify + :param pre_locate: function that is executed before locating a node. + This function receives an arch as argument. + This is required by studio to properly handle group_ids. :return: a modified source where the specs are applied :rtype: Element """ @@ -99,6 +102,7 @@ def apply_inheritance_specs(source, specs_tree, inherit_branding=False): _("Invalid specification for moved nodes: '%s'") % etree.tostring(spec) ) + pre_locate(spec) to_extract = locate_node(source, spec) if to_extract is not None: remove_element(to_extract) @@ -116,6 +120,7 @@ def apply_inheritance_specs(source, specs_tree, inherit_branding=False): if spec.tag == 'data': specs += [c for c in spec] continue + pre_locate(spec) node = locate_node(source, spec) if node is not None: pos = spec.get('position', 'inside') diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 1577fa2bb48..39edaee9423 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -603,7 +603,7 @@ class PoFileReader: translation = entry.msgstr found_code_occurrence = False for occurrence, line_number in entry.occurrences: - match = re.match(r'(model|model_terms):([\w.]+),([\w]+):(\w+)\.(\w+)', occurrence) + match = re.match(r'(model|model_terms):([\w.]+),([\w]+):(\w+)\.([\w-]+)', occurrence) if match: type, model_name, field_name, module, xmlid = match.groups() yield { @@ -632,7 +632,7 @@ class PoFileReader: 'src': source, 'value': translation, 'comments': comments, - 'res_id': int(line_number), + 'res_id': int(line_number or 0), 'module': module, } continue @@ -890,6 +890,21 @@ def trans_generate(lang, modules, cr): tnx = (module, source, name, id, type, tuple(comments or ())) to_translate.add(tnx) + def translatable_model(record): + if not record._translate: + return False + + if record._name == 'ir.model.fields.selection': + record = record.field_id + if record._name == 'ir.model.fields': + field_name = record.name + field_model = env.get(record.model) + if (field_model is None or not field_model._translate or + field_name not in field_model._fields): + return False + + return True + query = 'SELECT min(name), model, res_id, module FROM ir_model_data' if 'all_installed' in modules: @@ -914,25 +929,12 @@ def trans_generate(lang, modules, cr): continue record = env[model].browse(res_id) - if not record._translate: - # explicitly disabled - continue - if not record.exists(): _logger.warning(u"Unable to find object %r with id %d", model, res_id) - continue + return False - if model==u'ir.model.fields': - try: - field_name = record.name - except AttributeError as exc: - _logger.error(u"name error in %s: %s", xml_name, str(exc)) - continue - field_model = env.get(record.model) - if (field_model is None or not field_model._translate or - field_name not in field_model._fields): - continue - field = field_model._fields[field_name] + if not translatable_model(record): + continue for field_name, field in record._fields.items(): if field.translate: |
