diff --git a/account_credit_control/__init__.py b/account_credit_control/__init__.py index 27a4fabc2..b195eabad 100644 --- a/account_credit_control/__init__.py +++ b/account_credit_control/__init__.py @@ -26,5 +26,4 @@ from . import partner from . import policy from . import company from . import wizard -from . import report from . import invoice diff --git a/account_credit_control/__openerp__.py b/account_credit_control/__openerp__.py index fa905f236..2cee51f35 100644 --- a/account_credit_control/__openerp__.py +++ b/account_credit_control/__openerp__.py @@ -27,9 +27,10 @@ 'depends': ['base', 'account', 'email_template', - 'report_webkit'], + ], 'website': 'http://www.camptocamp.com', 'data': ["report/report.xml", + "report/report_credit_control_summary.xml", "data.xml", "line_view.xml", "account_view.xml", diff --git a/account_credit_control/data.xml b/account_credit_control/data.xml index 09fc3cced..2ff738563 100644 --- a/account_credit_control/data.xml +++ b/account_credit_control/data.xml @@ -9,9 +9,9 @@ ${object.get_contact_address().lang or 'en_US'} - +
${object.current_policy_level.custom_mail_text} diff --git a/account_credit_control/policy.py b/account_credit_control/policy.py index 59cac0612..5680d8929 100644 --- a/account_credit_control/policy.py +++ b/account_credit_control/policy.py @@ -181,7 +181,7 @@ class CreditControlPolicy(models.Model): different_lines = move_line_obj.browse() if not lines: return different_lines - cr = self._cr + cr = self.env.cr cr.execute("SELECT move_line_id FROM credit_control_line" " WHERE policy_id != %s and move_line_id in %s" " AND manually_overridden IS false", @@ -322,7 +322,7 @@ class CreditControlPolicyLevel(models.Model): move_line_obj = self.env['account.move.line'] if not lines: return move_line_obj.browse() - cr = self._cr + cr = self.env.cr sql = ("SELECT DISTINCT mv_line.id\n" " FROM account_move_line mv_line\n" " WHERE mv_line.id in %(line_ids)s\n" @@ -356,7 +356,7 @@ class CreditControlPolicyLevel(models.Model): move_line_obj = self.env['account.move.line'] if not lines: return move_line_obj.browse() - cr = self._cr + cr = self.env.cr sql = ("SELECT mv_line.id\n" " FROM account_move_line mv_line\n" " JOIN credit_control_line cr_line\n" diff --git a/account_credit_control/report/__init__.py b/account_credit_control/report/__init__.py deleted file mode 100644 index b7e5edadc..000000000 --- a/account_credit_control/report/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import credit_control_summary diff --git a/account_credit_control/report/credit_control_summary.html.mako b/account_credit_control/report/credit_control_summary.html.mako deleted file mode 100644 index 323838aa2..000000000 --- a/account_credit_control/report/credit_control_summary.html.mako +++ /dev/null @@ -1,244 +0,0 @@ -## -*- coding: utf-8 -*- - - - - - - - %for comm in objects : - <% setLang(comm.get_contact_address().lang) %> -
- - <% - add = comm.get_contact_address() - %> - %if comm.partner_id.id == add.id: - - <% address_lines = comm.partner_id.contact_address.split("\n") %> - - %else: - - - <% address_lines = add.contact_address.split("\n")[1:] %> - %endif - %for part in address_lines: - %if part: - - %endif - %endfor -
${comm.partner_id.title and comm.partner_id.title.name or ''} ${comm.partner_id.name }
${comm.partner_id.name or ''}
${add.title and add.title.name or ''} ${add.name}
${part}
-
-
-
-
- -
-
-
-
-
- -

- ${_('Reminder')}: ${comm.current_policy_level.name or '' } -

- -

${_('Dear')},

-

${comm.current_policy_level.custom_text.replace('\n', '
')}

- -
-
-

${_('Summary')}

- - - - - - - - - - -%for line in comm.credit_control_line_ids: - - %if line.invoice_id: - - %else: - - %endif - - - - - - -%endfor -
${_('Invoice number')}${_('Invoice date')}${_('Date due')}${_('Invoiced amount')}${_('Open amount')}${_('Currency')}
${line.invoice_id.number} - %if line.invoice_id.name: -
- ${line.invoice_id.name} - %endif -
${line.move_line_id.name}${line.date_entry}${line.date_due}${line.amount_due}${line.balance_due}${line.currency_id.name or comm.company_id.currency_id.name}
-
-
-<%doc> - -

${_('If you have any question, do not hesitate to contact us.')}

- -

${comm.user_id.name} ${comm.user_id.email and '<%s>'%(comm.user_id.email) or ''}
- ${comm.company_id.name}
- % if comm.company_id.street: - ${comm.company_id.street or ''}
- - % endif - - % if comm.company_id.street2: - ${comm.company_id.street2}
- % endif - % if comm.company_id.city or comm.company_id.zip: - ${comm.company_id.zip or ''} ${comm.company_id.city or ''}
- % endif - % if comm.company_id.country_id: - ${comm.company_id.state_id and ('%s, ' % comm.company_id.state_id.name) or ''} ${comm.company_id.country_id.name or ''}
- % endif - % if comm.company_id.phone: - Phone: ${comm.company_id.phone}
- % endif - % if comm.company_id.website: - ${comm.company_id.website or ''}
- % endif - - -

- %endfor - - - diff --git a/account_credit_control/report/credit_control_summary.py b/account_credit_control/report/credit_control_summary.py deleted file mode 100644 index ffbc65116..000000000 --- a/account_credit_control/report/credit_control_summary.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Nicolas Bessi, Guewen Baconnier -# Copyright 2012 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -import time - -from openerp.report import report_sxw - - -class CreditSummaryReport(report_sxw.rml_parse): - def __init__(self, cr, uid, name, context): - super(CreditSummaryReport, self).__init__(cr, uid, name, - context=context) - self.localcontext.update({ - 'time': time, - 'cr': cr, - 'uid': uid, - }) - -report_sxw.report_sxw( - 'report.credit_control_summary', - 'credit.control.communication', - 'addons/account_credit_control/report/credit_control_summary.html.mako', - parser=CreditSummaryReport -) diff --git a/account_credit_control/report/report.xml b/account_credit_control/report/report.xml index dee64b896..2d24c0862 100644 --- a/account_credit_control/report/report.xml +++ b/account_credit_control/report/report.xml @@ -1,16 +1,15 @@ - - - - + + diff --git a/account_credit_control/report/report_credit_control_summary.xml b/account_credit_control/report/report_credit_control_summary.xml new file mode 100644 index 000000000..da5d38f90 --- /dev/null +++ b/account_credit_control/report/report_credit_control_summary.xml @@ -0,0 +1,78 @@ + + + + + + + + diff --git a/account_credit_control/run.py b/account_credit_control/run.py index 740c811d4..ff2bca35a 100644 --- a/account_credit_control/run.py +++ b/account_credit_control/run.py @@ -144,8 +144,8 @@ class CreditControlRun(models.Model): calls of this method. """ try: - self._cr.execute('SELECT id FROM credit_control_run' - ' LIMIT 1 FOR UPDATE NOWAIT') + self.env.cr.execute('SELECT id FROM credit_control_run' + ' LIMIT 1 FOR UPDATE NOWAIT') except Exception: # In case of exception openerp will do a rollback # for us and free the lock diff --git a/account_credit_control/wizard/credit_control_communication.py b/account_credit_control/wizard/credit_control_communication.py index e988a229b..b2307898a 100644 --- a/account_credit_control/wizard/credit_control_communication.py +++ b/account_credit_control/wizard/credit_control_communication.py @@ -20,7 +20,6 @@ ############################################################################## import logging from openerp import models, fields, api -from openerp import netsvc logger = logging.getLogger('credit.control.line.mailing') @@ -40,10 +39,15 @@ class CreditCommunication(models.TransientModel): current_policy_level = fields.Many2one('credit.control.policy.level', 'Level', required=True) + credit_control_line_ids = fields.Many2many('credit.control.line', rel='comm_credit_rel', string='Credit Lines') + contact_address = fields.Many2one('res.partner', + string='Contact Address', + readonly=True) + @api.model def _get_company(self): company_obj = self.env['res.company'] @@ -57,21 +61,37 @@ class CreditCommunication(models.TransientModel): default=lambda self: self.env.user, string='User') + @api.model + @api.returns('self', lambda value: value.id) + def create(self, vals): + if vals.get('partner_id'): + # the computed field does not work in TransientModel, + # just set a value on creation + partner_id = vals['partner_id'] + vals['contact_address'] = self._get_contact_address(partner_id).id + return super(CreditCommunication, self).create(vals) + @api.multi def get_email(self): """ Return a valid email for customer """ self.ensure_one() - contact = self.get_contact_address() + contact = self.contact_address return contact.email @api.multi @api.returns('res.partner') def get_contact_address(self): + """ Compatibility method, please use the contact_address field """ self.ensure_one() + return self.contact_address + + @api.model + @api.returns('res.partner') + def _get_contact_address(self, partner_id): partner_obj = self.env['res.partner'] - partner = self.partner_id + partner = partner_obj.browse(partner_id) add_ids = partner.address_get(adr_pref=['invoice']) or {} - add_id = add_ids.get('invoice', add_ids.get('default', False)) + add_id = add_ids['invoice'] return partner_obj.browse(add_id) @api.model @@ -89,9 +109,9 @@ class CreditCommunication(models.TransientModel): """ Aggregate credit control line by partner, level, and currency It also generate a communication object per aggregation. """ - if not lines: - return [] comms = self.browse() + if not lines: + return comms sql = ( "SELECT distinct partner_id, policy_level_id, " " credit_control_line.currency_id, " @@ -103,7 +123,7 @@ class CreditCommunication(models.TransientModel): " ORDER by credit_control_policy_level.level, " " credit_control_line.currency_id" ) - cr = self._cr + cr = self.env.cr cr.execute(sql, (tuple(lines.ids), )) res = cr.dictfetchall() for level_assoc in res: @@ -139,7 +159,6 @@ class CreditCommunication(models.TransientModel): template.id, comm.id, context=context) - email_values['body_html'] = email_values['body'] email_values['type'] = 'email' email = email_message_obj.create(email_values) @@ -179,13 +198,8 @@ class CreditCommunication(models.TransientModel): of related policy template """ - return '' - service = netsvc.LocalService('report.credit_control_summary') - cr, uid = self.env.cr, self.env.uid - result, format = service.create(cr, uid, self.ids, {}, {}) - return result - # TODO - # return self.env['report'].get_pdf(self, 'credit_control_summary') + report_name = 'account_credit_control.report_credit_control_summary' + return self.env['report'].get_pdf(self, report_name) @api.multi @api.returns('credit.control.line') diff --git a/account_credit_control/wizard/credit_control_printer.py b/account_credit_control/wizard/credit_control_printer.py index b7c2ba8f2..b5796b271 100644 --- a/account_credit_control/wizard/credit_control_printer.py +++ b/account_credit_control/wizard/credit_control_printer.py @@ -18,7 +18,6 @@ # along with this program. If not, see . # ############################################################################## -import base64 from openerp import models, fields, api, _ @@ -40,9 +39,6 @@ class CreditControlPrinter(models.TransientModel): mark_as_sent = fields.Boolean(string='Mark letter lines as sent', default=True, help="Only letter lines will be marked.") - report_file = fields.Binary(string='Generated Report', readonly=True) - report_name = fields.Char(string='Report name') - state = fields.Char(string='state') line_ids = fields.Many2many('credit.control.line', string='Credit Control Lines', default=_get_line_ids) @@ -67,15 +63,9 @@ class CreditControlPrinter(models.TransientModel): comms = comm_obj._generate_comm_from_credit_lines(lines) - report_content = comms._generate_report() - - self.write({'report_file': base64.b64encode(report_content), - 'report_name': ('credit_control_esr_bvr_%s.pdf' % - fields.datetime.now()), - 'state': 'done'}) - if self.mark_as_sent: comms._mark_credit_line_as_sent() - action = self.get_formview_action()[0] - action['target'] = 'new' - return action + + report_name = 'account_credit_control.report_credit_control_summary' + report_obj = self.env['report'].with_context(active_ids=comms.ids) + return report_obj.get_action(comms, report_name) diff --git a/account_credit_control/wizard/credit_control_printer_view.xml b/account_credit_control/wizard/credit_control_printer_view.xml index 68b67aa31..224e5fc8e 100644 --- a/account_credit_control/wizard/credit_control_printer_view.xml +++ b/account_credit_control/wizard/credit_control_printer_view.xml @@ -11,28 +11,17 @@ + colspan="4"/> - - + + - - - -