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.

126 lines
6.5 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Guewen Baconnier
  5. # Copyright Camptocamp SA 2012
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from osv import fields, osv
  22. class AccountReportOpenInvoicesWizard(osv.osv_memory):
  23. """Will launch partner ledger report and pass required args"""
  24. _inherit = "partners.ledger.webkit"
  25. _name = "open.invoices.webkit"
  26. _description = "Open Invoices Report"
  27. _columns = {
  28. 'group_by_currency':fields.boolean('Group Partner by currency'),
  29. 'until_date': fields.date("Clearance date",
  30. required=True,
  31. help="""The clearance date is essentially a tool used for debtors provisionning calculation.
  32. By default, this date is equal to the the end date (ie: 31/12/2011 if you select fy 2011).
  33. By amending the clearance date, you will be, for instance, able to answer the question : 'based on my last year end debtors open invoices, which invoices are still unpaid today (today is my clearance date)?'
  34. """)}
  35. def _check_until_date(self, cr, uid, ids, context=None):
  36. def get_key_id(obj, field):
  37. return obj.get(field) and obj[field][0] or False
  38. obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'period_to', 'date_to', 'until_date'], context=context)
  39. min_date = self.default_until_date(cr, uid, ids,
  40. get_key_id(obj, 'fiscalyear_id'),
  41. get_key_id(obj, 'period_to'),
  42. obj['date_to'],
  43. context=context)
  44. if min_date and obj['until_date'] < min_date:
  45. return False
  46. return True
  47. _constraints = [
  48. (_check_until_date, 'Clearance date must be the very last date of the last period or later.', ['until_date']),
  49. ]
  50. def default_until_date(self, cursor, uid, ids, fiscalyear_id=False, period_id=False, date_to=False, context=None):
  51. res_date = False
  52. # first priority: period or date filters
  53. if period_id:
  54. res_date = self.pool.get('account.period').read(cursor, uid, period_id, ['date_stop'], context=context)['date_stop']
  55. elif date_to:
  56. res_date = date_to
  57. elif fiscalyear_id:
  58. res_date = self.pool.get('account.fiscalyear').read(cursor, uid, fiscalyear_id, ['date_stop'], context=context)['date_stop']
  59. return res_date
  60. def onchange_fiscalyear(self, cursor, uid, ids, fiscalyear=False, period_id=False, date_to=False, until_date=False, context=None):
  61. res = {'value': {}}
  62. res['value']['until_date'] = self.default_until_date(cursor, uid, ids,
  63. fiscalyear_id=fiscalyear,
  64. period_id=period_id,
  65. date_to=date_to,
  66. context=context)
  67. return res
  68. def onchange_date_to(self, cursor, uid, ids, fiscalyear=False, period_id=False, date_to=False, until_date=False, context=None):
  69. res = {'value': {}}
  70. res['value']['until_date'] = self.default_until_date(cursor, uid, ids,
  71. fiscalyear_id=fiscalyear,
  72. period_id=period_id,
  73. date_to=date_to,
  74. context=context)
  75. return res
  76. def onchange_period_to(self, cursor, uid, ids, fiscalyear=False, period_id=False, date_to=False, until_date=False, context=None):
  77. res = {'value': {}}
  78. res['value']['until_date'] = self.default_until_date(cursor, uid, ids,
  79. fiscalyear_id=fiscalyear,
  80. period_id=period_id,
  81. date_to=date_to,
  82. context=context)
  83. return res
  84. def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None):
  85. res = super(AccountReportOpenInvoicesWizard, self).onchange_filter(cr, uid, ids, filter=filter, fiscalyear_id=fiscalyear_id, context=context)
  86. if res.get('value', False):
  87. res['value']['until_date'] = self.default_until_date(cr, uid, ids,
  88. fiscalyear_id=fiscalyear_id,
  89. period_id=res['value'].get('period_to', False),
  90. date_to=res['value'].get('date_to', False),
  91. context=context)
  92. return res
  93. def pre_print_report(self, cr, uid, ids, data, context=None):
  94. data = super(AccountReportOpenInvoicesWizard, self).pre_print_report(cr, uid, ids, data, context)
  95. if context is None:
  96. context = {}
  97. vals = self.read(cr, uid, ids,
  98. ['until_date', 'group_by_currency'],
  99. context=context)[0]
  100. data['form'].update(vals)
  101. return data
  102. def _print_report(self, cursor, uid, ids, data, context=None):
  103. context = context or {}
  104. # we update form with display account value
  105. data = self.pre_print_report(cursor, uid, ids, data, context=context)
  106. return {'type': 'ir.actions.report.xml',
  107. 'report_name': 'account.account_report_open_invoices_webkit',
  108. 'datas': data}
  109. AccountReportOpenInvoicesWizard()