Browse Source

[ADD] web_x2m_defaults_from_previous

pull/510/head
Holger Brunn 8 years ago
parent
commit
fd0b874438
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 63
      web_x2m_defaults_from_previous/README.rst
  2. 3
      web_x2m_defaults_from_previous/__init__.py
  3. 20
      web_x2m_defaults_from_previous/__openerp__.py
  4. 14
      web_x2m_defaults_from_previous/demo/ir_ui_view.xml
  5. BIN
      web_x2m_defaults_from_previous/static/description/icon.png
  6. 41
      web_x2m_defaults_from_previous/static/src/js/web_x2m_defaults_from_previous.js
  7. 10
      web_x2m_defaults_from_previous/views/templates.xml

63
web_x2m_defaults_from_previous/README.rst

@ -0,0 +1,63 @@
.. 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
===============
x2many defaults
===============
This module was written to allow you to use the previous line's input as defaults for the next line you add.
Usage
=====
#. on a x2many field, say ``options="{'web_x2m_defaults_from_previous': ['field1', 'field2']}"``
#. after the first line of input, succeeding lines will have the last input's values as default
#. demo data adds this for the ACL list field in the groups form
.. 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/8.0
Known issues / Roadmap
======================
* many2many fields are not yet supported
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 smashing it by providing a 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
------------
* Holger Brunn <hbrunn@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.
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_x2m_defaults_from_previous/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

20
web_x2m_defaults_from_previous/__openerp__.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "x2many defaults",
"version": "8.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Hidden/Dependency",
"summary": "Use previous input as default for next line",
"depends": [
'web',
],
"demo": [
"demo/ir_ui_view.xml",
],
"data": [
'views/templates.xml',
],
}

14
web_x2m_defaults_from_previous/demo/ir_ui_view.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_groups_form" model="ir.ui.view">
<field name="model">res.groups</field>
<field name="inherit_id" ref="base.view_groups_form" />
<field name="arch" type="xml">
<field name="model_access" position="attributes">
<attribute name="options">{'web_x2m_defaults_from_previous': ['model_id', 'name']}</attribute>
</field>
</field>
</record>
</data>
</openerp>

BIN
web_x2m_defaults_from_previous/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

41
web_x2m_defaults_from_previous/static/src/js/web_x2m_defaults_from_previous.js

@ -0,0 +1,41 @@
//-*- coding: utf-8 -*-
//© 2016 Therp BV <http://therp.nl>
//License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
openerp.web_x2m_defaults_from_previous = function(instance)
{
instance.web.form.FieldOne2Many.include({
build_context: function()
{
var self = this,
default_fields =
this.options.web_x2m_defaults_from_previous || [],
extra_context = {},
result = this._super.apply(this, arguments);
if(!this.dataset.cache || !this.dataset.cache.length)
{
return result;
}
_.each(default_fields, function(field_name)
{
var value = self.dataset.cache[
self.views[0].embedded_view.arch.attrs.editable == 'top' ?
0 :
self.dataset.cache.length - 1
].values[field_name];
if(_.isArray(value))
{
value = value[0];
}
extra_context[
_.str.sprintf('default_%s', field_name)
] = value;
});
if(!_.isEmpty(extra_context))
{
result.add(extra_context);
}
return result;
},
});
};

10
web_x2m_defaults_from_previous/views/templates.xml

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