You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
7.4 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com)
  5. #
  6. # Author : Guewen Baconnier (Camptocamp)
  7. #
  8. # WARNING: This program as such is intended to be used by professional
  9. # programmers who take the whole responsability of assessing all potential
  10. # consequences resulting from its eventual inadequacies and bugs
  11. # End users who are looking for a ready-to-use solution with commercial
  12. # garantees and support are strongly adviced to contract a Free Software
  13. # Service Company
  14. #
  15. # This program is Free Software; you can redistribute it and/or
  16. # modify it under the terms of the GNU General Public License
  17. # as published by the Free Software Foundation; either version 2
  18. # of the License, or (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program; if not, write to the Free Software
  27. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  28. #
  29. ##############################################################################
  30. from lxml import etree
  31. from tools.translate import _
  32. from osv import fields, osv
  33. LEVEL_STYLES = 6
  34. DEFAULT_STYLES = {
  35. 'print': [True, True, True, True, True, True],
  36. 'size': [12, 11, 10, 9, 9, 9],
  37. 'bold': [True, True, True, False, False, False],
  38. 'italic': [False, False, False, False, False, False],
  39. 'underline': [False, False, False, False, False, False],
  40. 'uppercase': [True, True, False, False, False, False],
  41. }
  42. class AccountProfitAndLossLedgerWizard(osv.osv_memory):
  43. """Will launch trial balance report and pass required args"""
  44. _inherit = "account.common.balance.report"
  45. _name = "profit.loss.webkit"
  46. _description = "Profit and Loss Report"
  47. _columns = {
  48. 'numbers_display': fields.selection([('normal', 'Normal'), ('round', 'Round (No decimal)'), ('kilo', 'Kilo')], 'Numbers Display', required=True)
  49. }
  50. _defaults = {
  51. 'numbers_display': 'normal',
  52. }
  53. def view_init(self, cr, uid, fields_list, context=None):
  54. """
  55. Creates view dynamically and adding fields at runtime.
  56. @param self: The object pointer.
  57. @param cr: A database cursor
  58. @param uid: ID of the user currently logged in
  59. @param context: A standard dictionary
  60. @return: New arch of view with new columns.
  61. """
  62. res = super(AccountProfitAndLossLedgerWizard, self).view_init(cr, uid, fields_list, context=context)
  63. for index in range(LEVEL_STYLES):
  64. # create columns for each comparison page
  65. self._columns.update({
  66. "level%s_print" % (index,):
  67. fields.boolean('Print'),
  68. "level%s_size" % (index,):
  69. fields.integer('Size', required=True),
  70. "level%s_bold" % (index,):
  71. fields.boolean('Bold'),
  72. "level%s_italic" % (index,):
  73. fields.boolean('Italic'),
  74. "level%s_underline" % (index,):
  75. fields.boolean('Underline'),
  76. "level%s_uppercase" % (index,):
  77. fields.boolean('Uppercase'),
  78. })
  79. return res
  80. def default_get(self, cr, uid, fields, context=None):
  81. """
  82. To get default values for the object.
  83. @param self: The object pointer.
  84. @param cr: A database cursor
  85. @param uid: ID of the user currently logged in
  86. @param fields: List of fields for which we want default values
  87. @param context: A standard dictionary
  88. @return: A dictionary which of fields with values.
  89. """
  90. res = super(AccountProfitAndLossLedgerWizard, self).default_get(cr, uid, fields, context=context)
  91. for key, values in DEFAULT_STYLES.iteritems():
  92. for index in range(LEVEL_STYLES):
  93. field = "level%s_%s" % (index, key)
  94. if not res.get(field, False):
  95. res[field] = values[index]
  96. return res
  97. def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
  98. res = super(AccountProfitAndLossLedgerWizard, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
  99. eview = etree.fromstring(res['arch'])
  100. placeholder = eview.xpath("//group[@name='levels']")
  101. if placeholder:
  102. placeholder = placeholder[0]
  103. for index in range(LEVEL_STYLES):
  104. # add fields
  105. res['fields']["level%s_print" % (index,)] = {'string': "Print", 'type': 'boolean'}
  106. res['fields']["level%s_size" % (index,)] = {'string': "Size", 'type': 'integer', 'required': True}
  107. res['fields']["level%s_bold" % (index,)] = {'string': "Bold", 'type': 'boolean',}
  108. res['fields']["level%s_italic" % (index,)] = {'string': "Italic", 'type': 'boolean',}
  109. res['fields']["level%s_underline" % (index,)] = {'string': "Underline", 'type': 'boolean',}
  110. res['fields']["level%s_uppercase" % (index,)] = {'string': "Uppercase", 'type': 'boolean'}
  111. common_attrs = "{'readonly': [('level%(index)s_print', '=', False)]}" % {'index': index}
  112. group = etree.Element('group', {'name': "group_level_%s" % (index,), 'colspan':'4', 'col': '10'})
  113. group.append(etree.Element('separator', {'string': _('Level %s') % (index+1,), 'colspan':'2'}))
  114. group.append(etree.Element('field', {'name': "level%s_print" % (index,), 'colspan': '8'}))
  115. group.append(etree.Element('field', {'name': "level%s_size" % (index,), 'attrs': common_attrs}))
  116. group.append(etree.Element('field', {'name': "level%s_bold" % (index,), 'attrs': common_attrs}))
  117. group.append(etree.Element('field', {'name': "level%s_italic" % (index,), 'attrs': common_attrs}))
  118. group.append(etree.Element('field', {'name': "level%s_underline" % (index,), 'attrs': common_attrs}))
  119. group.append(etree.Element('field', {'name': "level%s_uppercase" % (index,), 'attrs': common_attrs}))
  120. placeholder.append(group)
  121. res['arch'] = etree.tostring(eview)
  122. return res
  123. def _print_report(self, cursor, uid, ids, data, context=None):
  124. context = context or {}
  125. # we update form with display account value
  126. data = self.pre_print_report(cursor, uid, ids, data, context=context)
  127. fields_to_read = ['numbers_display',]
  128. # comparison fields
  129. for index in range(LEVEL_STYLES):
  130. fields_to_read.extend([
  131. "level%s_print" % (index,),
  132. "level%s_size" % (index,),
  133. "level%s_bold" % (index,),
  134. "level%s_italic" % (index,),
  135. "level%s_underline" % (index,),
  136. "level%s_uppercase" % (index,),
  137. ])
  138. vals = self.read(cursor, uid, ids, fields_to_read,context=context)[0]
  139. data['form'].update(vals)
  140. return {'type': 'ir.actions.report.xml',
  141. 'report_name': 'account.account_report_profit_loss_webkit',
  142. 'datas': data}
  143. AccountProfitAndLossLedgerWizard()