diff --git a/web_x2m_defaults_from_previous/README.rst b/web_x2m_defaults_from_previous/README.rst new file mode 100644 index 00000000..46cad23e --- /dev/null +++ b/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 +`_. 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 `_. + +Contributors +------------ + +* Holger Brunn + +Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list `_ or the `appropriate specialized mailinglist `_ 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. diff --git a/web_x2m_defaults_from_previous/__init__.py b/web_x2m_defaults_from_previous/__init__.py new file mode 100644 index 00000000..fa85807b --- /dev/null +++ b/web_x2m_defaults_from_previous/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# © 2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/web_x2m_defaults_from_previous/__openerp__.py b/web_x2m_defaults_from_previous/__openerp__.py new file mode 100644 index 00000000..5d5a6a48 --- /dev/null +++ b/web_x2m_defaults_from_previous/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2016 Therp BV +# 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', + ], +} diff --git a/web_x2m_defaults_from_previous/demo/ir_ui_view.xml b/web_x2m_defaults_from_previous/demo/ir_ui_view.xml new file mode 100644 index 00000000..f0c49d82 --- /dev/null +++ b/web_x2m_defaults_from_previous/demo/ir_ui_view.xml @@ -0,0 +1,14 @@ + + + + + res.groups + + + + {'web_x2m_defaults_from_previous': ['model_id', 'name']} + + + + + diff --git a/web_x2m_defaults_from_previous/static/description/icon.png b/web_x2m_defaults_from_previous/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_x2m_defaults_from_previous/static/description/icon.png differ diff --git a/web_x2m_defaults_from_previous/static/src/js/web_x2m_defaults_from_previous.js b/web_x2m_defaults_from_previous/static/src/js/web_x2m_defaults_from_previous.js new file mode 100644 index 00000000..2924e474 --- /dev/null +++ b/web_x2m_defaults_from_previous/static/src/js/web_x2m_defaults_from_previous.js @@ -0,0 +1,41 @@ +//-*- coding: utf-8 -*- +//© 2016 Therp BV +//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; + }, + }); +}; diff --git a/web_x2m_defaults_from_previous/views/templates.xml b/web_x2m_defaults_from_previous/views/templates.xml new file mode 100644 index 00000000..748e3201 --- /dev/null +++ b/web_x2m_defaults_from_previous/views/templates.xml @@ -0,0 +1,10 @@ + + + + + +