Browse Source

Merge 4110ec06a6 into ad79aa45cf

pull/517/merge
Leonardo Donelli 5 years ago
committed by GitHub
parent
commit
8567f4d1cf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 86
      web_customisable_date_format/README.rst
  2. 3
      web_customisable_date_format/__init__.py
  3. 18
      web_customisable_date_format/__manifest__.py
  4. 26
      web_customisable_date_format/static/src/js/formats.js
  5. 10
      web_customisable_date_format/templates/web.xml

86
web_customisable_date_format/README.rst

@ -0,0 +1,86 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
========================
Customisable date format
========================
This module adds the possibility to specify a rendering format
for date and datetime fields, using MomentJS tokens.
Configuration
=============
No configuration necessary.
Usage
=====
To use this module, first of all add it in the dependencies of your module, then:
* In list view columns, use the ``date_format="<momentjs tokens>"`` attribute
on a date or datetime field, example::
<field name="start_date" date_format="DD - dddd"/>
* In form fields, use the ``options`` attributes::
<field name="start_date" options="{'date_format': 'DD - dddd'}"/>
You can find here the `list of valid MomentJS tokens <http://momentjs.com/docs/#/displaying/format/>`_.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/162/10.0-web_widget_date_format
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example
Known issues / Roadmap
======================
* Add support for datetime columns in tree views
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/web/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Leonardo Donelli @ MONKSoftware <donelli@webmonks.it>
Funders
-------
The development of this module has been financially supported by:
* MONK Software
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

3
web_customisable_date_format/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016- Leonardo Donelli (donelli at monksoftware it)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

18
web_customisable_date_format/__manifest__.py

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# © 2016- Leonardo Donelli (donelli at monksoftware it)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Customisable date format',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'category': 'Web',
'author': 'MONK Software',
'summary': 'Date field widget with custom',
'website': 'https://www.monksoftware.it',
'depends': ['web'],
'data': [
'templates/web.xml',
],
'installable': True,
}

26
web_customisable_date_format/static/src/js/formats.js

@ -0,0 +1,26 @@
// © 2016- Leonardo Donelli (donelli at monksoftware it)
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
odoo.define('web_customisable_date_format.formats', function(require) {
'use strict';
var time = require('web.time');
var formats = require('web.formats');
var original_format_value = formats.format_value;
var new_format_value = function(value, descriptor, value_if_empty) {
// in list view columns, format is passed in the date_format attribute
if (descriptor.date_format) {
var v = moment(time.auto_str_to_date(value));
return v.format(descriptor.date_format);
}
// in form view fields, format is passed in the 'date_format' key of the options attribute
if (descriptor.options && descriptor.options.date_format) {
var v = moment(time.auto_str_to_date(value));
return v.format(descriptor.options.date_format);
}
return original_format_value.apply(this, arguments);
};
formats.format_value = new_format_value;
});

10
web_customisable_date_format/templates/web.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" name="web_customisable_date_format backend assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_customisable_date_format/static/src/js/formats.js"></script>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save