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.

148 lines
6.0 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 openerp.osv import fields, orm
  22. class AccountReportOpenInvoicesWizard(orm.TransientModel):
  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(
  30. "Clearance date",
  31. required=True,
  32. help="""The clearance date is essentially a tool used for debtors
  33. provisionning calculation.
  34. By default, this date is equal to the the end date (ie: 31/12/2011 if you
  35. select fy 2011).
  36. By amending the clearance date, you will be, for instance, able to answer the
  37. question : 'based on my last year end debtors open invoices, which invoices
  38. are still unpaid today (today is my clearance date)?'
  39. """)}
  40. def _check_until_date(self, cr, uid, ids, context=None):
  41. def get_key_id(obj, field):
  42. return obj.get(field) and obj[field][0] or False
  43. obj = self.read(cr, uid, ids[0], [
  44. 'fiscalyear_id', 'period_to', 'date_to', 'until_date'],
  45. context=context)
  46. min_date = self.default_until_date(cr, uid, ids,
  47. get_key_id(obj, 'fiscalyear_id'),
  48. get_key_id(obj, 'period_to'),
  49. obj['date_to'],
  50. context=context)
  51. if min_date and obj['until_date'] < min_date:
  52. return False
  53. return True
  54. _constraints = [
  55. (_check_until_date, 'Clearance date must be the very last date of the \
  56. last period or later.', ['until_date']),
  57. ]
  58. def default_until_date(self, cr, uid, ids, fiscalyear_id=False,
  59. period_id=False, date_to=False, context=None):
  60. res_date = False
  61. # first priority: period or date filters
  62. if period_id:
  63. res_date = self.pool.get('account.period').read(
  64. cr, uid, period_id, ['date_stop'],
  65. context=context)['date_stop']
  66. elif date_to:
  67. res_date = date_to
  68. elif fiscalyear_id:
  69. res_date = self.pool.get('account.fiscalyear').read(
  70. cr, uid, fiscalyear_id, ['date_stop'],
  71. context=context)['date_stop']
  72. return res_date
  73. def onchange_fiscalyear(self, cr, uid, ids, fiscalyear=False,
  74. period_id=False, date_to=False, until_date=False,
  75. context=None):
  76. res = {'value': {}}
  77. res['value']['until_date'] = self.default_until_date(
  78. cr, 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_date_to(self, cr, uid, ids, fiscalyear=False, period_id=False,
  85. date_to=False, until_date=False, context=None):
  86. res = {'value': {}}
  87. res['value']['until_date'] = self.default_until_date(
  88. cr, uid, ids,
  89. fiscalyear_id=fiscalyear,
  90. period_id=period_id,
  91. date_to=date_to,
  92. context=context)
  93. return res
  94. def onchange_period_to(self, cr, uid, ids, fiscalyear=False,
  95. period_id=False, date_to=False, until_date=False,
  96. context=None):
  97. res = {'value': {}}
  98. res['value']['until_date'] = self.default_until_date(
  99. cr, uid, ids,
  100. fiscalyear_id=fiscalyear,
  101. period_id=period_id,
  102. date_to=date_to,
  103. context=context)
  104. return res
  105. def onchange_filter(self, cr, uid, ids, filter='filter_no',
  106. fiscalyear_id=False, context=None):
  107. res = super(AccountReportOpenInvoicesWizard, self).onchange_filter(
  108. cr, uid, ids, filter=filter, fiscalyear_id=fiscalyear_id,
  109. context=context)
  110. if res.get('value', False):
  111. res['value']['until_date'] = self.default_until_date(
  112. cr, uid, ids,
  113. fiscalyear_id=fiscalyear_id,
  114. period_id=res['value'].get('period_to', False),
  115. date_to=res['value'].get('date_to', False),
  116. context=context)
  117. return res
  118. def pre_print_report(self, cr, uid, ids, data, context=None):
  119. data = super(AccountReportOpenInvoicesWizard, self).pre_print_report(
  120. cr, uid, ids, data, context)
  121. vals = self.read(cr, uid, ids,
  122. ['until_date', 'group_by_currency'],
  123. context=context)[0]
  124. data['form'].update(vals)
  125. return data
  126. def _print_report(self, cr, uid, ids, data, context=None):
  127. # we update form with display account value
  128. data = self.pre_print_report(cr, uid, ids, data, context=context)
  129. return {'type': 'ir.actions.report.xml',
  130. 'report_name': 'account.account_report_open_invoices_webkit',
  131. 'datas': data}