From f1ed6465a7a2e3e21698a57c21c97d9c9ff23b61 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 15 Feb 2012 18:09:11 +0100 Subject: [PATCH] [IMP] Restored sale.order._inv_get() method for compatibility Also added missing context guard (all methods that access the context should care for the None case, even if they are currently always called with a context). Improved docstrings to follow doc guidelines. bzr revid: odo@openerp.com-20120215170911-8ekde3lqmkoxztae --- addons/sale/sale.py | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index c7e6ac383a9..3f1c686b8e3 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -393,19 +393,32 @@ class sale_order(osv.osv): def button_dummy(self, cr, uid, ids, context=None): return True + # FIXME: deprecated method, overriders should be using _prepare_invoice() instead. + # can be removed after 6.1. + def _inv_get(self, cr, uid, order, context=None): + return {} + def _prepare_invoice(self, cr, uid, order, lines, context=None): - """ Builds the dict containing the values for the invoice - @param order: order object - @param line: list of invoice line IDs that must be attached to the invoice - @return: dict that will be used to create the invoice object + """Prepare the dict of values to create the new invoice for a + sale order. This method may be overridden to implement custom + invoice generation (making sure to call super() to establish + a clean extension chain). + + :param browse_record order: sale.order record to invoice + :param list(int) line: list of invoice line IDs that must be + attached to the invoice + :return: dict of value to create() the invoice """ + if context is None: + context = {} journal_ids = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'sale'), ('company_id', '=', order.company_id.id)], limit=1) if not journal_ids: raise osv.except_osv(_('Error !'), _('There is no sales journal defined for this company: "%s" (id:%d)') % (order.company_id.name, order.company_id.id)) - return { + + invoice_vals = { 'name': order.client_order_ref or '', 'origin': order.name, 'type': 'out_invoice', @@ -425,6 +438,11 @@ class sale_order(osv.osv): 'user_id': order.user_id and order.user_id.id or False } + # Care for deprecated _inv_get() hook - FIXME: to be removed after 6.1 + invoice_vals.update(self._inv_get(cr, uid, order, context=context)) + + return invoice_vals + def _make_invoice(self, cr, uid, order, lines, context=None): inv_obj = self.pool.get('account.invoice') obj_invoice_line = self.pool.get('account.invoice.line') @@ -980,10 +998,15 @@ class sale_order_line(osv.osv): } def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None): - """ Builds the invoice line dict from a sale order line - @param line: sale order line object - @param account_id: the id of the account to force eventually (the method is used for picking return including service) - @return: dict that will be used to create the invoice line + """Prepare the dict of values to create the new invoice line for a + sale order line. This method may be overridden to implement custom + invoice generation (making sure to call super() to establish + a clean extension chain). + + :param browse_record line: sale.order.line record to invoice + :param int account_id: optional ID of a G/L account to force + (this is used for returning products including service) + :return: dict of values to create() the invoice line """ def _get_line_qty(line):