-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] web_x2m_defaults_from_previous
- Loading branch information
Showing
7 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
|
||
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:[email protected]>`_ 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions
41
web_x2m_defaults_from_previous/static/src/js/web_x2m_defaults_from_previous.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |