Skip to content

Commit

Permalink
[FIX] sale, sale_crm: propagate sales team for advance & on lines inv…
Browse files Browse the repository at this point in the history
…oices

A _prepare method had to be introduced in the wizard for the lines invoicing method
  • Loading branch information
beledouxdenis committed Jan 7, 2015
1 parent dbb2a66 commit 1a10a11
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
46 changes: 25 additions & 21 deletions addons/sale/wizard/sale_line_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
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):
"""
Expand Down Expand Up @@ -55,27 +79,7 @@ def make_invoice(order, lines):
@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

Expand Down
22 changes: 22 additions & 0 deletions addons/sale_crm/sale_crm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ def _prepare_invoice(self, cr, uid, order, lines, context=None):
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'

Expand Down

0 comments on commit 1a10a11

Please sign in to comment.