[REF] stock_account: introduced _get_invoice_vals() to ease inheritance of this feature
bzr revid: qdp-launchpad@openerp.com-20140508102505-f4bwpgixezwhkq6h
This commit is contained in:
parent
a029fb22d0
commit
f2ff555432
|
@ -192,7 +192,7 @@ class stock_picking(osv.osv):
|
||||||
invoice_obj = self.pool.get('account.invoice')
|
invoice_obj = self.pool.get('account.invoice')
|
||||||
return invoice_obj.create(cr, uid, vals, context=context)
|
return invoice_obj.create(cr, uid, vals, context=context)
|
||||||
|
|
||||||
def action_invoice_create(self, cr, uid, ids, journal_id=False, group=False, type='out_invoice', context=None):
|
def action_invoice_create(self, cr, uid, ids, journal_id, group=False, type='out_invoice', context=None):
|
||||||
""" Creates invoice based on the invoice state selected for picking.
|
""" Creates invoice based on the invoice state selected for picking.
|
||||||
@param journal_id: Id of journal
|
@param journal_id: Id of journal
|
||||||
@param group: Whether to create a group invoice or not
|
@param group: Whether to create a group invoice or not
|
||||||
|
@ -213,7 +213,31 @@ class stock_picking(osv.osv):
|
||||||
invoices = self._invoice_create_line(cr, uid, moves, journal_id, type, context=context)
|
invoices = self._invoice_create_line(cr, uid, moves, journal_id, type, context=context)
|
||||||
return invoices
|
return invoices
|
||||||
|
|
||||||
def _invoice_create_line(self, cr, uid, moves, journal_id=False, inv_type='out_invoice', context=None):
|
def _get_invoice_vals(self, cr, uid, key, inv_type, journal_id, origin, context=None):
|
||||||
|
if context is None:
|
||||||
|
context = {}
|
||||||
|
partner, currency_id, company_id, user_id = key
|
||||||
|
if inv_type in ('out_invoice', 'out_refund'):
|
||||||
|
account_id = partner.property_account_receivable.id
|
||||||
|
payment_term = partner.property_payment_term.id or False
|
||||||
|
else:
|
||||||
|
account_id = partner.property_account_payable.id
|
||||||
|
payment_term = partner.property_supplier_payment_term.id or False
|
||||||
|
return {
|
||||||
|
'origin': origin,
|
||||||
|
'date_invoice': context.get('date_inv', False),
|
||||||
|
'user_id': user_id,
|
||||||
|
'partner_id': partner.id,
|
||||||
|
'account_id': account_id,
|
||||||
|
'payment_term': payment_term,
|
||||||
|
'type': inv_type,
|
||||||
|
'fiscal_position': partner.property_account_position.id,
|
||||||
|
'company_id': company_id,
|
||||||
|
'currency_id': currency_id,
|
||||||
|
'journal_id': journal_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _invoice_create_line(self, cr, uid, moves, journal_id, inv_type='out_invoice', context=None):
|
||||||
invoice_obj = self.pool.get('account.invoice')
|
invoice_obj = self.pool.get('account.invoice')
|
||||||
move_obj = self.pool.get('stock.move')
|
move_obj = self.pool.get('stock.move')
|
||||||
invoices = {}
|
invoices = {}
|
||||||
|
@ -222,30 +246,11 @@ class stock_picking(osv.osv):
|
||||||
origin = move.picking_id.name
|
origin = move.picking_id.name
|
||||||
partner, user_id, currency_id = move_obj._get_master_data(cr, uid, move, company, context=context)
|
partner, user_id, currency_id = move_obj._get_master_data(cr, uid, move, company, context=context)
|
||||||
|
|
||||||
key = (partner.id, currency_id, company.id, user_id)
|
key = (partner, currency_id, company.id, user_id)
|
||||||
|
|
||||||
if key not in invoices:
|
if key not in invoices:
|
||||||
# Get account and payment terms
|
# Get account and payment terms
|
||||||
if inv_type in ('out_invoice', 'out_refund'):
|
invoice_vals = self._get_invoice_vals(cr, uid, key, inv_type, journal_id, origin, context=context)
|
||||||
account_id = partner.property_account_receivable.id
|
|
||||||
payment_term = partner.property_payment_term.id or False
|
|
||||||
else:
|
|
||||||
account_id = partner.property_account_payable.id
|
|
||||||
payment_term = partner.property_supplier_payment_term.id or False
|
|
||||||
|
|
||||||
invoice_vals = {
|
|
||||||
'origin': origin,
|
|
||||||
'date_invoice': context.get('date_inv', False),
|
|
||||||
'user_id': user_id,
|
|
||||||
'partner_id': partner.id,
|
|
||||||
'account_id': account_id,
|
|
||||||
'payment_term': payment_term,
|
|
||||||
'type': inv_type,
|
|
||||||
'fiscal_position': partner.property_account_position.id,
|
|
||||||
'company_id': company.id,
|
|
||||||
'currency_id': currency_id,
|
|
||||||
'journal_id': journal_id,
|
|
||||||
}
|
|
||||||
invoice_id = self._create_invoice_from_picking(cr, uid, move.picking_id, invoice_vals, context=context)
|
invoice_id = self._create_invoice_from_picking(cr, uid, move.picking_id, invoice_vals, context=context)
|
||||||
invoices[key] = invoice_id
|
invoices[key] = invoice_id
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue