Merge lp:~unifield-team/unifield-server/us-1335 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 4163
Proposed branch: lp:~unifield-team/unifield-server/us-1335
Merge into: lp:unifield-server
Diff against target: 698 lines (+429/-6) (has conflicts)
15 files modified
bin/addons/account/project/wizard/account_analytic_chart.py (+1/-0)
bin/addons/account/wizard/account_chart.py (+1/-0)
bin/addons/account/wizard/account_report_common.py (+2/-0)
bin/addons/account/wizard/account_report_common_view.xml (+7/-0)
bin/addons/account/wizard/account_report_partner_ledger_view.xml (+1/-1)
bin/addons/account_override/wizard/account_chart.py (+2/-0)
bin/addons/account_override/wizard/account_chart.xml (+8/-1)
bin/addons/analytic_distribution/wizard/account_analytic_chart.py (+2/-0)
bin/addons/analytic_distribution/wizard/account_analytic_chart_view.xml (+7/-0)
bin/addons/finance/wizard/account_report_partner_balance_tree.py (+4/-0)
bin/addons/finance/wizard/account_report_partner_balance_tree_view.xml (+1/-1)
bin/addons/msf_profile/i18n/fr_MF.po (+143/-3)
bin/addons/resource/__init__.py (+1/-0)
bin/addons/resource/wizard_template.py (+238/-0)
bin/addons/resource/wizard_template_view.xml (+11/-0)
Text conflict in bin/addons/msf_profile/i18n/fr_MF.po
To merge this branch: bzr merge lp:~unifield-team/unifield-server/us-1335
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+314719@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/account/project/wizard/account_analytic_chart.py'
2--- bin/addons/account/project/wizard/account_analytic_chart.py 2013-11-19 16:30:17 +0000
3+++ bin/addons/account/project/wizard/account_analytic_chart.py 2017-01-13 15:45:43 +0000
4@@ -21,6 +21,7 @@
5 from osv import osv, fields
6
7 class account_analytic_chart(osv.osv_memory):
8+ _inherit = "wizard.template.form" # to be able to store the wizard values
9 _name = 'account.analytic.chart'
10 _description = 'Account Analytic Chart'
11
12
13=== modified file 'bin/addons/account/wizard/account_chart.py'
14--- bin/addons/account/wizard/account_chart.py 2016-06-06 13:49:06 +0000
15+++ bin/addons/account/wizard/account_chart.py 2017-01-13 15:45:43 +0000
16@@ -25,6 +25,7 @@
17 """
18 For Chart of Accounts
19 """
20+ _inherit = "wizard.template.form" # to be able to store the wizard values
21 _name = "account.chart"
22 _description = "Account chart"
23 _columns = {
24
25=== modified file 'bin/addons/account/wizard/account_report_common.py'
26--- bin/addons/account/wizard/account_report_common.py 2016-03-23 14:52:23 +0000
27+++ bin/addons/account/wizard/account_report_common.py 2017-01-13 15:45:43 +0000
28@@ -26,6 +26,7 @@
29 from tools.translate import _
30
31 class account_common_report(osv.osv_memory):
32+ _inherit = "wizard.template.form" # to be able to store the wizard values
33 _name = "account.common.report"
34 _description = "Account Common Report"
35
36@@ -168,6 +169,7 @@
37 if context is None:
38 context = {}
39 data = {}
40+ data['keep_open'] = 1
41 data['ids'] = context.get('active_ids', [])
42 data['model'] = context.get('active_model', 'ir.ui.menu')
43 data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'fiscalyear_id', 'journal_ids', 'period_from', 'period_to', 'filter', 'chart_account_id', 'target_move'])[0]
44
45=== modified file 'bin/addons/account/wizard/account_report_common_view.xml'
46--- bin/addons/account/wizard/account_report_common_view.xml 2016-03-18 10:13:01 +0000
47+++ bin/addons/account/wizard/account_report_common_view.xml 2017-01-13 15:45:43 +0000
48@@ -1,4 +1,9 @@
49 <?xml version="1.0" encoding="utf-8"?>
50+
51+<!DOCTYPE WIZARD [
52+ <!ENTITY wizard_template SYSTEM "../../resource/wizard_template_view.xml">
53+]>
54+
55 <openerp>
56 <data>
57
58@@ -33,6 +38,8 @@
59 <button icon="gtk-cancel" special="cancel" string="Cancel" colspan="2"/>
60 <button icon="gtk-print" name="check_report" string="Print" type="object" colspan="2" default_focus="1" />
61 </group>
62+ <!-- to be able to store the wizard values -->
63+ &wizard_template;
64 </form>
65 </field>
66 </record>
67
68=== modified file 'bin/addons/account/wizard/account_report_partner_ledger_view.xml'
69--- bin/addons/account/wizard/account_report_partner_ledger_view.xml 2014-10-31 10:25:05 +0000
70+++ bin/addons/account/wizard/account_report_partner_ledger_view.xml 2017-01-13 15:45:43 +0000
71@@ -31,7 +31,7 @@
72 <field name="res_model">account.partner.ledger</field>
73 <field name="type">ir.actions.act_window</field>
74 <field name="view_type">form</field>
75- <field name="view_mode">tree,form</field>
76+ <field name="view_mode">form</field>
77 <field name="view_id" ref="account_partner_ledger_view"/>
78 <field name="context">{'record_id':active_id}</field>
79 <field name="target">new</field>
80
81=== modified file 'bin/addons/account_override/wizard/account_chart.py'
82--- bin/addons/account_override/wizard/account_chart.py 2016-06-08 09:08:11 +0000
83+++ bin/addons/account_override/wizard/account_chart.py 2017-01-13 15:45:43 +0000
84@@ -259,6 +259,7 @@
85 if not is_flat_view:
86 domain_tuples_str.insert(0, "('parent_id','=',False)")
87 result['domain'] = "[%s]" % (', '.join(domain_tuples_str), )
88+ result['keep_open'] = 1
89 return result
90
91 def button_export(self, cr, uid, ids, context=None):
92@@ -320,6 +321,7 @@
93 'currency': currency_name,
94 'wiz_fields': wiz_fields,
95 'target_filename': "Balance by account_%s_%s" % (instance_code, strftime('%Y%m%d')),
96+ 'keep_open': 1,
97 } # context permit balance to be processed regarding context's elements
98 # filename
99 return {
100
101=== modified file 'bin/addons/account_override/wizard/account_chart.xml'
102--- bin/addons/account_override/wizard/account_chart.xml 2016-06-02 12:58:02 +0000
103+++ bin/addons/account_override/wizard/account_chart.xml 2017-01-13 15:45:43 +0000
104@@ -1,4 +1,9 @@
105 <?xml version="1.0" encoding="utf-8"?>
106+
107+<!DOCTYPE WIZARD [
108+ <!ENTITY wizard_template SYSTEM "../../resource/wizard_template_view.xml">
109+]>
110+
111 <openerp>
112 <data>
113
114@@ -46,6 +51,8 @@
115 <label string="" colspan="1"/>
116 <button icon="gtk-print" string="Export" name="button_export" type="object" colspan="1"/>
117 </group>
118+ <!-- to be able to store the wizard values -->
119+ &wizard_template;
120 </xpath>
121 </data>
122 </field>
123@@ -59,7 +66,7 @@
124 <field name="name">Balance by account</field>
125 <field name="res_model">account.chart</field>
126 <field name="view_type">form</field>
127- <field name="view_mode">tree,form</field>
128+ <field name="view_mode">form</field>
129 <field name="view_id" ref="view_account_chart_activable"/>
130 <field name="target">new</field>
131 <field name="help">Display your company chart of accounts per fiscal year and filter by period. Have a complete tree view of all journal items per account code by clicking on an account.</field>
132
133=== modified file 'bin/addons/analytic_distribution/wizard/account_analytic_chart.py'
134--- bin/addons/analytic_distribution/wizard/account_analytic_chart.py 2016-06-06 14:38:02 +0000
135+++ bin/addons/analytic_distribution/wizard/account_analytic_chart.py 2017-01-13 15:45:43 +0000
136@@ -165,6 +165,7 @@
137 tree_view_id = tree_view_id and tree_view_id[1] or False
138 result['view_id'] = [tree_view_id]
139 result['views'] = [(tree_view_id, 'tree')]
140+ result['keep_open'] = 1
141 return result
142
143 def button_export(self, cr, uid, ids, context=None):
144@@ -229,6 +230,7 @@
145 'currency': currency_name,
146 'wiz_fields': wiz_fields,
147 'target_filename': "Balance by analytic account_%s_%s" % (instance_code, strftime('%Y%m%d')),
148+ 'keep_open': 1,
149 } # context permit balance to be processed regarding context's elements
150 return {
151 'type': 'ir.actions.report.xml',
152
153=== modified file 'bin/addons/analytic_distribution/wizard/account_analytic_chart_view.xml'
154--- bin/addons/analytic_distribution/wizard/account_analytic_chart_view.xml 2016-04-26 12:59:10 +0000
155+++ bin/addons/analytic_distribution/wizard/account_analytic_chart_view.xml 2017-01-13 15:45:43 +0000
156@@ -1,4 +1,9 @@
157 <?xml version="1.0" encoding="utf-8"?>
158+
159+<!DOCTYPE WIZARD [
160+ <!ENTITY wizard_template SYSTEM "../../resource/wizard_template_view.xml">
161+]>
162+
163 <openerp>
164 <data>
165
166@@ -42,6 +47,8 @@
167 <label string="" colspan="1"/>
168 <button icon="gtk-print" string="Export" name="button_export" type="object" colspan="1"/>
169 </group>
170+ <!-- to be able to store the wizard values -->
171+ &wizard_template;
172 </xpath>
173 </data>
174 </field>
175
176=== modified file 'bin/addons/finance/wizard/account_report_partner_balance_tree.py'
177--- bin/addons/finance/wizard/account_report_partner_balance_tree.py 2016-09-08 14:20:36 +0000
178+++ bin/addons/finance/wizard/account_report_partner_balance_tree.py 2017-01-13 15:45:43 +0000
179@@ -331,6 +331,7 @@
180 _inherit = 'account.common.partner.report'
181 _name = 'wizard.account.partner.balance.tree'
182 _description = 'Print Account Partner Balance View'
183+
184 _columns = {
185 'display_partner': fields.selection([('non-zero_balance',
186 'With balance is not equal to 0'),
187@@ -367,6 +368,7 @@
188 context = {}
189
190 data = {}
191+ data['keep_open'] = 1
192 data['ids'] = context.get('active_ids', [])
193 data['model'] = context.get('active_model', 'ir.ui.menu')
194 data['build_ts'] = datetime.datetime.now().strftime(self.pool.get('date.tools').get_db_datetime_format(cr, uid, context=context))
195@@ -403,6 +405,7 @@
196 'res_model': 'account.partner.balance.tree',
197 'view_type': 'form',
198 'view_mode': 'tree,form',
199+ 'keep_open': 1,
200 'ref': 'view_account_partner_balance_tree',
201 'domain': [
202 ('uid', '=', uid),
203@@ -442,6 +445,7 @@
204 context=context)
205 return {}
206
207+
208 wizard_account_partner_balance_tree()
209
210 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
211
212=== modified file 'bin/addons/finance/wizard/account_report_partner_balance_tree_view.xml'
213--- bin/addons/finance/wizard/account_report_partner_balance_tree_view.xml 2016-02-22 16:17:00 +0000
214+++ bin/addons/finance/wizard/account_report_partner_balance_tree_view.xml 2017-01-13 15:45:43 +0000
215@@ -144,7 +144,7 @@
216 <field name="res_model">wizard.account.partner.balance.tree</field>
217 <field name="type">ir.actions.act_window</field>
218 <field name="view_type">form</field>
219- <field name="view_mode">tree,form</field>
220+ <field name="view_mode">form</field>
221 <field name="view_id" ref="wizard_account_report_partner_balance_tree_view"/>
222 <field name="context">{'record_id':active_id,'search_default_groupby_payable_receivable':'1'}</field>
223 <field name="target">new</field>
224
225=== modified file 'bin/addons/msf_profile/i18n/fr_MF.po'
226--- bin/addons/msf_profile/i18n/fr_MF.po 2017-01-02 08:52:42 +0000
227+++ bin/addons/msf_profile/i18n/fr_MF.po 2017-01-13 15:45:43 +0000
228@@ -9118,7 +9118,7 @@
229 msgid "Process Components to Consume"
230 msgstr "Traiter les composants à consommer"
231
232-#. modules: account_override, delete_button, specific_rules
233+#. modules: account_override, delete_button, specific_rules, account, analytic_distribution
234 #: view:account.move:0
235 #: view:purchase.order:0
236 #: view:sale.order:0
237@@ -9126,6 +9126,9 @@
238 #: view:tender:0
239 #: view:stock.production.lot:0
240 #: view:real.average.consumption:0
241+#: view:account.common.report:0
242+#: view:account.chart:0
243+#: view:account.analytic.chart:0
244 msgid "Delete"
245 msgstr "Supprimer"
246
247@@ -35134,7 +35137,7 @@
248 msgid "Reference of the document that produced this picking."
249 msgstr "Référence du document à l'origine de l'opération de Piquage."
250
251-#. modules: delivery_mechanism, tender_flow, analytic_distribution_supply, product_nomenclature, account_voucher, register_accounting, return_claim, sync_client, res_currency_tables, supplier_catalogue, import_data, stock_batch_recall, account_activable, stock, product, reason_types_moves, account_payment, consumption_calculation, purchase_override, specific_rules, kit, base, account_period_closing_level, account_subscription, msf_cross_docking, purchase, account, msf_outgoing, procurement_auto, sale, msf_config_locations, sourcing
252+#. modules: delivery_mechanism, tender_flow, analytic_distribution_supply, product_nomenclature, account_voucher, register_accounting, return_claim, sync_client, res_currency_tables, supplier_catalogue, import_data, stock_batch_recall, account_activable, stock, product, reason_types_moves, account_payment, consumption_calculation, purchase_override, specific_rules, kit, base, account_period_closing_level, account_subscription, msf_cross_docking, purchase, account, msf_outgoing, procurement_auto, sale, msf_config_locations, sourcing, resource
253 #: code:addons/account/account.py:509
254 #: code:addons/account/account.py:511
255 #: code:addons/account/account.py:832
256@@ -35241,6 +35244,7 @@
257 #: code:addons/tender_flow/tender_flow.py:349
258 #: code:addons/tender_flow/tender_flow.py:481
259 #: code:addons/tender_flow/tender_flow.py:914
260+#: code:addons/resource/wizard_template.py:0
261 #, python-format
262 msgid "Error !"
263 msgstr "Erreur !"
264@@ -62786,8 +62790,11 @@
265 msgid "Tracking a move"
266 msgstr "Suivi d'un mouvement"
267
268-#. module: base
269+#. modules: base, account_override, account, analytic_distribution
270 #: view:base.language.install:0
271+#: view:account.common.report:0
272+#: view:account.chart:0
273+#: view:account.analytic.chart:0
274 msgid "Load"
275 msgstr "Charger"
276
277@@ -75758,6 +75765,136 @@
278 msgid "There is no stopped products to report"
279 msgstr "Il n'y a aucun produit stoppé à afficher"
280
281+#. module: resource
282+#: sql_constraint:wizard.template:0
283+msgid "This template name already exists for this wizard. Please choose another name."
284+msgstr "Ce nom de modèle existe déjà pour cet assistant. Veuillez choisir un autre nom."
285+
286+#. module: resource
287+#: model:ir.model,name:resource.model_wizard_template_form
288+msgid "Wizard Template Form"
289+msgstr "Formulaire de Modèle d'Assistant"
290+
291+#. modules: resource, account_override, account, analytic_distribution
292+#: model:ir.model,name:resource.model_wizard_template
293+#: view:account.common.report:0
294+#: view:account.chart:0
295+#: view:account.analytic.chart:0
296+msgid "Wizard Template"
297+msgstr "Modèle d'Assistant"
298+
299+#. modules: account_override, account, analytic_distribution
300+#: view:account.common.report:0
301+#: view:account.chart:0
302+#: view:account.analytic.chart:0
303+msgid "Save new template"
304+msgstr "Enregistrer nouveau modèle"
305+
306+#. module: resource
307+#: code:addons/resource/wizard_template.py:60
308+#, python-format
309+msgid "You have to choose a template name."
310+msgstr "Vous devez choisir un nom de modèle."
311+
312+#. module: resource
313+#: code:addons/resource/wizard_template.py:91
314+#, python-format
315+msgid "You have to choose a template to load."
316+msgstr "Vous devez choisir un modèle à charger."
317+
318+#. module: resource
319+#: code:addons/resource/wizard_template.py:158
320+#, python-format
321+msgid "You have to choose a template to replace."
322+msgstr "Vous devez choisir un modèle à remplacer."
323+
324+#. module: resource
325+#: code:addons/resource/wizard_template.py:140
326+#, python-format
327+msgid "You have to choose a template to delete."
328+msgstr "Vous devez choisir un modèle à supprimer."
329+
330+#. modules: account_override, account, analytic_distribution
331+#: view:account.common.report:0
332+#: view:account.chart:0
333+#: view:account.analytic.chart:0
334+msgid "Select an existing template"
335+msgstr "Sélectionnez un modèle existant"
336+
337+#. modules: account_override, account, analytic_distribution
338+#: view:account.common.report:0
339+#: view:account.chart:0
340+#: view:account.analytic.chart:0
341+msgid "or Choose a new template name"
342+msgstr "ou Choisissez un nouveau nom de modèle"
343+
344+#. modules: account_override, account, finance, analytic_distribution
345+#: field:account.aged.trial.balance,saved_templates:0
346+#: field:account.balance.report,saved_templates:0
347+#: field:account.bs.report,saved_templates:0
348+#: field:account.central.journal,saved_templates:0
349+#: field:account.common.account.report,saved_templates:0
350+#: field:account.common.journal.report,saved_templates:0
351+#: field:account.common.partner.report,saved_templates:0
352+#: field:account.common.report,saved_templates:0
353+#: field:account.general.journal,saved_templates:0
354+#: field:account.partner.balance,saved_templates:0
355+#: field:account.partner.ledger,saved_templates:0
356+#: field:account.pl.report,saved_templates:0
357+#: field:account.print.journal,saved_templates:0
358+#: field:account.report.general.ledger,saved_templates:0
359+#: field:account.vat.declaration,saved_templates:0
360+#: field:account.chart,saved_templates:0
361+#: field:account.analytic.chart,saved_templates:0
362+#: field:wizard.account.partner.balance.tree,saved_templates:0
363+#: field:wizard.template.form,saved_templates:0
364+msgid "Saved templates"
365+msgstr "Modèles enregistrés"
366+
367+#. modules: account_override, account, finance, analytic_distribution
368+#: field:account.aged.trial.balance,template_name:0
369+#: field:account.balance.report,template_name:0
370+#: field:account.bs.report,template_name:0
371+#: field:account.central.journal,template_name:0
372+#: field:account.common.account.report,template_name:0
373+#: field:account.common.journal.report,template_name:0
374+#: field:account.common.partner.report,template_name:0
375+#: field:account.common.report,template_name:0
376+#: field:account.general.journal,template_name:0
377+#: field:account.partner.balance,template_name:0
378+#: field:account.partner.ledger,template_name:0
379+#: field:account.pl.report,template_name:0
380+#: field:account.print.journal,template_name:0
381+#: field:account.report.general.ledger,template_name:0
382+#: field:account.vat.declaration,template_name:0
383+#: field:account.chart,template_name:0
384+#: field:account.analytic.chart,template_name:0
385+#: field:wizard.account.partner.balance.tree,template_name:0
386+#: field:wizard.template,name:0
387+#: field:wizard.template.form,template_name:0
388+msgid "Template name"
389+msgstr "Nom de modèle"
390+
391+#. modules: account_override, account, analytic_distribution
392+#: view:account.common.report:0
393+#: view:account.chart:0
394+#: view:account.analytic.chart:0
395+msgid "Replace"
396+msgstr "Remplacer"
397+
398+#. modules: account_override, account, analytic_distribution
399+#: view:account.common.report:0
400+#: view:account.chart:0
401+#: view:account.analytic.chart:0
402+#: view:account.report.general.ledger:0
403+#: view:account.balance.report:0
404+#: view:account.pl.report:0
405+#: view:account.bs.report:0
406+#: view:account.partner.ledger:0
407+#: view:wizard.account.partner.balance.tree:0
408+msgid "Do you really want to delete the selected template?"
409+msgstr "Voulez-vous vraiment supprimer le modèle sélectionné ?"
410+
411 #. module: msf_doc_import
412 #: code:addons/msf_doc_import/check_line.py:626
413 #: code:addons/msf_doc_import/check_line.py:628
414@@ -75813,6 +75950,7 @@
415 #: help:res.partner,locally_created:0
416 msgid "Partner Created on this instance"
417 msgstr "Partenaire créé sur cette instance"
418+<<<<<<< TREE
419
420 #. module: account_reconciliation
421 #: code:addons/account_reconciliation/wizard/account_reconcile.py:207
422@@ -75854,3 +75992,5 @@
423 #, python-format
424 msgid "Wrong total: %.2f, instead of: %.2f"
425 msgstr "Total erroné : %.2f, au lieu de : %.2f"
426+=======
427+>>>>>>> MERGE-SOURCE
428
429=== modified file 'bin/addons/resource/__init__.py'
430--- bin/addons/resource/__init__.py 2011-01-14 00:11:01 +0000
431+++ bin/addons/resource/__init__.py 2017-01-13 15:45:43 +0000
432@@ -21,6 +21,7 @@
433
434 import resource
435 import faces
436+import wizard_template
437
438
439 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
440
441=== added file 'bin/addons/resource/wizard_template.py'
442--- bin/addons/resource/wizard_template.py 1970-01-01 00:00:00 +0000
443+++ bin/addons/resource/wizard_template.py 2017-01-13 15:45:43 +0000
444@@ -0,0 +1,238 @@
445+#-*- coding:utf-8 -*-
446+##############################################################################
447+#
448+# OpenERP, Open Source Management Solution
449+# Copyright (C) 2016 TeMPO Consulting, MSF. All Rights Reserved
450+#
451+# This program is free software: you can redistribute it and/or modify
452+# it under the terms of the GNU Affero General Public License as
453+# published by the Free Software Foundation, either version 3 of the
454+# License, or (at your option) any later version.
455+#
456+# This program is distributed in the hope that it will be useful,
457+# but WITHOUT ANY WARRANTY; without even the implied warranty of
458+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
459+# GNU Affero General Public License for more details.
460+#
461+# You should have received a copy of the GNU Affero General Public License
462+# along with this program. If not, see <http://www.gnu.org/licenses/>.
463+#
464+##############################################################################
465+
466+from osv import fields, osv
467+from tools.translate import _
468+
469+
470+class wizard_template(osv.osv):
471+ """
472+ Used to store the values from a wizard in order to reload them later
473+ """
474+
475+ _name = 'wizard.template'
476+ _description = 'Wizard Template'
477+
478+ _columns = {
479+ 'name': fields.char('Template name', size=128, required=True, select=1),
480+ 'user_id': fields.many2one('res.users', string='User', ondelete='cascade', required=True),
481+ 'wizard_name': fields.char('Wizard name', size=256, required=True),
482+ 'values': fields.text('Values', help='Values from the wizard, stored as a dictionary'),
483+ }
484+
485+ _sql_constraints = [
486+ ('name_user_id_wizard_name_uniq', 'UNIQUE(name, user_id, wizard_name)',
487+ 'This template name already exists for this wizard. Please choose another name.')
488+ ]
489+
490+ def save_template(self, cr, uid, ids, wizard_name, context=None):
491+ """
492+ Store all the fields values of the wizard in parameter.
493+ :param wizard_name: String, name of the wizard model (ex: 'wizard.account.partner.balance.tree')
494+ """
495+ if context is None:
496+ context = {}
497+ # object corresponding to the current wizard
498+ wizard_obj = self.pool.get(wizard_name)
499+ # get a dictionary with ALL fields values
500+ data = ids and wizard_obj.read(cr, uid, ids[0], context=context)
501+ if data:
502+ template_name = data['template_name']
503+ if not template_name:
504+ raise osv.except_osv(_('Error !'), _('You have to choose a template name.'))
505+ # don't keep the id, and the values of the fields related to the wizard template itself
506+ del data['template_name']
507+ if 'id' in data:
508+ del data['id']
509+ if 'saved_templates' in data:
510+ del data['saved_templates']
511+ if 'display_load_button' in data:
512+ del data['display_load_button']
513+ # create a new wizard_template to store the values
514+ vals = {'name': template_name,
515+ 'user_id': uid,
516+ 'wizard_name': wizard_obj._name,
517+ 'values': data,
518+ }
519+ self.create(cr, uid, vals, context=context)
520+ return True
521+
522+ def load_template(self, cr, uid, ids, wizard_name, context=None):
523+ """
524+ Load the values in the fields of the wizard in parameter, according to the template selected.
525+ :param wizard_name: String, name of the wizard model (ex: 'wizard.account.partner.balance.tree')
526+ """
527+ if context is None:
528+ context = {}
529+ # object corresponding to the current wizard
530+ wizard_obj = self.pool.get(wizard_name)
531+ # we get the selected template
532+ data = ids and wizard_obj.read(cr, uid, ids[0], ['saved_templates'], context=context)
533+ selected_template_id = data and data['saved_templates']
534+ if not selected_template_id:
535+ raise osv.except_osv(_('Error !'), _('You have to choose a template to load.'))
536+ # we get the values from the template as a String and convert them back to a dictionary
537+ vals = self.browse(cr, uid, selected_template_id, context=context).values
538+ try:
539+ vals = eval(vals)
540+ # we put the value of the selected template in the "Saved templates" selection field
541+ vals.update({'saved_templates': selected_template_id})
542+ # we put the "display_load_button" field to False,
543+ # so as to hide the load button and to show instead the options for the template loaded (delete...)
544+ if 'display_load_button':
545+ vals.update({'display_load_button': False})
546+ except SyntaxError:
547+ vals = {}
548+ # we "format" the many2many fields values to make them look like [(6, 0, [1, 2])]
549+ for i in vals:
550+ if type(vals[i]) == list:
551+ vals[i] = [(6, 0, vals[i])]
552+ # we set the data in a new wizard and display it
553+ new_id = wizard_obj.create(cr, uid, vals, context=context)
554+ if context.get('active_model') == 'ir.ui.menu' and context.get('active_id'):
555+ action = self.pool.get('ir.ui.menu').read(cr, uid, context.get('active_id'), ['action'], context=context)['action']
556+ model, res_id = action.split(',')
557+ ret = self.pool.get(model).read(cr, uid, [res_id],
558+ ['type', 'res_model', 'view_id', 'search_view_id', 'view_mode', 'view_ids', 'name', 'views', 'view_type'],
559+ context=context)[0]
560+ ret.update({'context': context, 'res_id': new_id, 'target': 'new'})
561+ return ret
562+ return {
563+ 'type': 'ir.actions.act_window',
564+ 'res_model': wizard_name,
565+ 'view_type': 'form',
566+ 'context': context,
567+ 'res_id': new_id,
568+ 'target': 'new',
569+ }
570+
571+ def delete_template(self, cr, uid, ids, wizard_name, context=None):
572+ """
573+ Delete the template selected in the "saved_templates_field" of the "wizard_name"
574+ :param wizard_name: String, name of the wizard model (ex: 'wizard.account.partner.balance.tree')
575+ """
576+ if context is None:
577+ context = {}
578+ # object corresponding to the current wizard
579+ wizard_obj = self.pool.get(wizard_name)
580+ # get the selected template
581+ data = ids and wizard_obj.read(cr, uid, ids[0], ['saved_templates'], context=context)
582+ selected_template_id = data and data['saved_templates']
583+ if not selected_template_id:
584+ raise osv.except_osv(_('Error !'), _('You have to choose a template to delete.'))
585+ # delete the template
586+ self.unlink(cr, uid, selected_template_id, context=context)
587+ # close the wizard
588+ return {'type': 'ir.actions.act_window_close'}
589+
590+ def edit_template(self, cr, uid, ids, wizard_name, context=None):
591+ """
592+ Edit the values of the fields stored in the selected template.
593+ :param wizard_name: String, name of the wizard model (ex: 'wizard.account.partner.balance.tree')
594+ """
595+ if context is None:
596+ context = {}
597+ # object corresponding to the current wizard
598+ wizard_obj = self.pool.get(wizard_name)
599+ # get a dictionary containing ALL fields values of the selected template
600+ data = ids and wizard_obj.read(cr, uid, ids[0], context=context)
601+ if data:
602+ selected_template_id = data['saved_templates']
603+ if not selected_template_id:
604+ raise osv.except_osv(_('Error !'), _('You have to choose a template to replace.'))
605+ # don't keep the id, and the values of the fields related to the wizard template itself
606+ if 'template_name' in data:
607+ del data['template_name']
608+ if 'id' in data:
609+ del data['id']
610+ del data['saved_templates']
611+ if 'display_load_button' in data:
612+ del data['display_load_button']
613+ # update the existing record with the new values
614+ vals = {'values': data}
615+ return self.write(cr, uid, selected_template_id, vals, context=context)
616+ return True
617+
618+wizard_template()
619+
620+
621+class wizard_template_form(osv.osv_memory):
622+ """
623+ Used to build the part of form that should be added to the wizards to use the "wizard template" functionality
624+ """
625+
626+ _name = 'wizard.template.form'
627+ _description = 'Wizard Template Form'
628+
629+ def _get_templates(self, cr, uid, context):
630+ """
631+ Return the recorded templates for the wizard in parameter and the current user,
632+ as a list of tuples with key (wizard template id) and value (template name), ordered by template name.
633+ Ex: [(4, 'a template'), (2, 'other template')]
634+ """
635+ if context is None:
636+ context = {}
637+ wizard_template_obj = self.pool.get('wizard.template')
638+ template_ids = wizard_template_obj.search(cr, uid, [('wizard_name', '=', self._name), ('user_id', '=', uid)],
639+ context=context, order='name') or []
640+ templates = template_ids and wizard_template_obj.browse(cr, uid, template_ids,
641+ fields_to_fetch=['name'], context=context) or []
642+ names = [(t.id, t.name) for t in templates]
643+ return names
644+
645+ _columns = {
646+ 'template_name': fields.char('Template name', size=128),
647+ 'saved_templates': fields.selection(_get_templates, string='Saved templates'),
648+ 'display_load_button': fields.boolean(),
649+ }
650+
651+ _defaults = {
652+ 'display_load_button': True,
653+ }
654+
655+ def save_template(self, cr, buid, ids, context=None):
656+ uid = hasattr(buid, 'realUid') and buid.realUid or buid
657+ return self.pool.get('wizard.template').save_template(cr, uid, ids, wizard_name=self._name, context=context)
658+
659+ def load_template(self, cr, buid, ids, context=None):
660+ uid = hasattr(buid, 'realUid') and buid.realUid or buid
661+ return self.pool.get('wizard.template').load_template(cr, uid, ids, wizard_name=self._name, context=context)
662+
663+ def delete_template(self, cr, buid, ids, context=None):
664+ uid = hasattr(buid, 'realUid') and buid.realUid or buid
665+ return self.pool.get('wizard.template').delete_template(cr, uid, ids, wizard_name=self._name, context=context)
666+
667+ def edit_template(self, cr, buid, ids, context=None):
668+ uid = hasattr(buid, 'realUid') and buid.realUid or buid
669+ return self.pool.get('wizard.template').edit_template(cr, uid, ids, wizard_name=self._name, context=context)
670+
671+ def onchange_saved_templates(self, cr, uid, ids, context=None):
672+ """
673+ Whenever a new template is selected, display the "load" button
674+ (and don't display the other options for the template, such as "delete"...)
675+ """
676+ res = {}
677+ res['value'] = {'display_load_button': True}
678+ return res
679+
680+wizard_template_form()
681+
682+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
683
684=== added file 'bin/addons/resource/wizard_template_view.xml'
685--- bin/addons/resource/wizard_template_view.xml 1970-01-01 00:00:00 +0000
686+++ bin/addons/resource/wizard_template_view.xml 2017-01-13 15:45:43 +0000
687@@ -0,0 +1,11 @@
688+<separator string="Wizard Template" colspan="4"/>
689+<group col="5" colspan="4">
690+ <field name="display_load_button" invisible="1" />
691+ <field name="saved_templates" on_change="onchange_saved_templates()" string="Select an existing template" />
692+ <button icon="gtk-save" name="load_template" string="Load" type="object" attrs="{'invisible': [('display_load_button', '=', False)]}" />
693+ <button icon="gtk-edit" name="edit_template" string="Replace" type="object" attrs="{'invisible': [('display_load_button', '=', True)]}" />
694+ <button icon="gtk-cancel" name="delete_template" string="Delete" type="object" attrs="{'invisible': [('display_load_button', '=', True)]}"
695+ confirm="Do you really want to delete the selected template?"/>
696+ <field name="template_name" colspan="2" string="or Choose a new template name" />
697+ <button icon="gtk-floppy" name="save_template" string="Save new template" type="object" colspan="3" />
698+</group>

Subscribers

People subscribed via source and target branches

to all changes: