From 1a10a110188f2b6cee37646635a39a9c3966e418 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 7 Jan 2015 14:43:11 +0100 Subject: [PATCH 1/2] [FIX] sale, sale_crm: propagate sales team for advance & on lines invoices A _prepare method had to be introduced in the wizard for the lines invoicing method --- addons/sale/wizard/sale_line_invoice.py | 46 ++++++++++++++----------- addons/sale_crm/sale_crm.py | 22 ++++++++++++ 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/addons/sale/wizard/sale_line_invoice.py b/addons/sale/wizard/sale_line_invoice.py index 998c66a8a03..9e01786e96e 100644 --- a/addons/sale/wizard/sale_line_invoice.py +++ b/addons/sale/wizard/sale_line_invoice.py @@ -26,6 +26,30 @@ from openerp import netsvc class sale_order_line_make_invoice(osv.osv_memory): _name = "sale.order.line.make.invoice" _description = "Sale OrderLine Make_invoice" + + def _prepare_invoice(self, cr, uid, order, lines, context=None): + a = order.partner_id.property_account_receivable.id + if order.partner_id and order.partner_id.property_payment_term.id: + pay_term = order.partner_id.property_payment_term.id + else: + pay_term = False + return { + 'name': order.client_order_ref or '', + 'origin': order.name, + 'type': 'out_invoice', + 'reference': "P%dSO%d" % (order.partner_id.id, order.id), + 'account_id': a, + 'partner_id': order.partner_invoice_id.id, + 'invoice_line': [(6, 0, lines)], + 'currency_id' : order.pricelist_id.currency_id.id, + 'comment': order.note, + 'payment_term': pay_term, + 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id, + 'user_id': order.user_id and order.user_id.id or False, + 'company_id': order.company_id and order.company_id.id or False, + 'date_invoice': fields.date.today(), + } + def make_invoices(self, cr, uid, ids, context=None): """ @@ -55,27 +79,7 @@ class sale_order_line_make_invoice(osv.osv_memory): @return: """ - a = order.partner_id.property_account_receivable.id - if order.partner_id and order.partner_id.property_payment_term.id: - pay_term = order.partner_id.property_payment_term.id - else: - pay_term = False - inv = { - 'name': order.client_order_ref or '', - 'origin': order.name, - 'type': 'out_invoice', - 'reference': "P%dSO%d" % (order.partner_id.id, order.id), - 'account_id': a, - 'partner_id': order.partner_invoice_id.id, - 'invoice_line': [(6, 0, lines)], - 'currency_id' : order.pricelist_id.currency_id.id, - 'comment': order.note, - 'payment_term': pay_term, - 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id, - 'user_id': order.user_id and order.user_id.id or False, - 'company_id': order.company_id and order.company_id.id or False, - 'date_invoice': fields.date.today(), - } + inv = self._prepare_invoice(cr, uid, order, lines) inv_id = self.pool.get('account.invoice').create(cr, uid, inv) return inv_id diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 4b73c3b25e8..2c967dd4eef 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -60,6 +60,28 @@ class sale_order(osv.osv): return invoice_vals +class sale_advance_payment_inv(osv.osv_memory): + _inherit = 'sale.advance.payment.inv' + + def _prepare_advance_invoice_vals(self, cr, uid, ids, context=None): + result = super(sale_advance_payment_inv, self)._prepare_advance_invoice_vals(cr, uid, ids, context=context) + orders = dict((order.id, order) for order in self.pool['sale.order'].browse(cr, uid, [order_id for order_id, values in result], context=context)) + for order_id, values in result: + if orders.get(order_id) and orders[order_id].section_id: + values['section_id'] = orders[order_id].section_id.id + return result + + +class sale_order_line_make_invoice(osv.osv_memory): + _inherit = "sale.order.line.make.invoice" + + def _prepare_invoice(self, cr, uid, order, lines, context=None): + result = super(sale_order_line_make_invoice, self)._prepare_invoice(cr, uid, order, lines, context=None) + if order.section_id: + result['section_id'] = order.section_id.id + return result + + class sale_crm_lead(osv.Model): _inherit = 'crm.lead' From 69bfc5e1086f6a187c26a19f2e307b6ffce962bf Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 7 Jan 2015 14:48:04 +0100 Subject: [PATCH 2/2] [FIX] sale_crm: typo introduced during rev. 1a10a110188f2b6cee37646635a39a9c3966e418 --- addons/sale_crm/sale_crm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 2c967dd4eef..9dceede9563 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -76,7 +76,7 @@ class sale_order_line_make_invoice(osv.osv_memory): _inherit = "sale.order.line.make.invoice" def _prepare_invoice(self, cr, uid, order, lines, context=None): - result = super(sale_order_line_make_invoice, self)._prepare_invoice(cr, uid, order, lines, context=None) + result = super(sale_order_line_make_invoice, self)._prepare_invoice(cr, uid, order, lines, context=context) if order.section_id: result['section_id'] = order.section_id.id return result