Add _get_partner_to_invoice() to purchase module.
Inheritance of _prepare_invoice() now replaces the functions _get_payment_term() and _get_address_invoice(). I have checked that these two functions are not used elsewere in the addons and extra-addons. bzr revid: alexis@via.ecp.fr-20120105214230-3wetu0v1foyeate3
This commit is contained in:
parent
752186173f
commit
1f9401bf41
|
@ -58,18 +58,23 @@ class stock_picking(osv.osv):
|
|||
'purchase_id': False,
|
||||
}
|
||||
|
||||
def _get_address_invoice(self, cr, uid, picking):
|
||||
""" Gets invoice address of a partner
|
||||
@return {'contact': address, 'invoice': address} for invoice
|
||||
"""
|
||||
res = super(stock_picking, self)._get_address_invoice(cr, uid, picking)
|
||||
def _get_partner_to_invoice(self, cr, uid, picking, context=None):
|
||||
if picking.purchase_id:
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
partner = picking.purchase_id.partner_id or picking.address_id.partner_id
|
||||
data = partner_obj.address_get(cr, uid, [partner.id],
|
||||
['contact', 'invoice'])
|
||||
res.update(data)
|
||||
return res
|
||||
return picking.purchase_id.partner_id
|
||||
return super(stock_picking, self)._get_partner_to_invoice(cr, uid, picking, context=context)
|
||||
|
||||
def _prepare_invoice(self, cr, uid, picking, partner, inv_type, journal_id, context=None):
|
||||
"""Inherit the original function of the 'stock' module in order to override some
|
||||
values if the picking has been generated by a purchase order
|
||||
"""
|
||||
invoice_vals = super(stock_picking, self)._prepare_invoice(cr, uid, picking, partner, inv_type, journal_id, context=context)
|
||||
if picking.purchase_id:
|
||||
invoice_vals['address_contact_id'], invoice_vals['address_invoice_id'] = \
|
||||
self.pool.get('res.partner').address_get(cr, uid, [partner.id],
|
||||
['contact', 'invoice']).values()
|
||||
if picking.purchase_id.fiscal_position:
|
||||
invoice_vals['fiscal_position'] = picking.purchase_id.fiscal_position.id
|
||||
return invoice_vals
|
||||
|
||||
def get_currency_id(self, cursor, user, picking):
|
||||
if picking.purchase_id:
|
||||
|
|
|
@ -53,28 +53,25 @@ class stock_picking(osv.osv):
|
|||
return picking.sale_id.partner_id
|
||||
return super(stock_picking, self)._get_partner_to_invoice(cr, uid, picking, context=context)
|
||||
|
||||
def _get_payment_term(self, cursor, user, picking):
|
||||
if picking.sale_id and picking.sale_id.payment_term:
|
||||
return picking.sale_id.payment_term.id
|
||||
return super(stock_picking, self)._get_payment_term(cursor, user, picking)
|
||||
|
||||
def _get_address_invoice(self, cursor, user, picking):
|
||||
res = {}
|
||||
if picking.sale_id:
|
||||
res['contact'] = picking.sale_id.partner_order_id.id
|
||||
res['invoice'] = picking.sale_id.partner_invoice_id.id
|
||||
return res
|
||||
return super(stock_picking, self)._get_address_invoice(cursor, user, picking)
|
||||
|
||||
def _get_comment_invoice(self, cursor, user, picking):
|
||||
if picking.note or (picking.sale_id and picking.sale_id.note):
|
||||
return picking.note or picking.sale_id.note
|
||||
return super(stock_picking, self)._get_comment_invoice(cursor, user, picking)
|
||||
|
||||
def _prepare_invoice(self, cr, uid, picking, partner, inv_type, journal_id, context=None):
|
||||
"""Inherit the original function of the 'stock' module in order to override some
|
||||
values if the picking has been generated by a sale order
|
||||
"""
|
||||
invoice_vals = super(stock_picking, self)._prepare_invoice(cr, uid, picking, partner, inv_type, journal_id, context=context)
|
||||
if picking.sale_id and picking.sale_id.fiscal_position:
|
||||
invoice_vals['fiscal_position'] = picking.sale_id.fiscal_position.id
|
||||
if picking.sale_id:
|
||||
invoice_vals['address_contact_id'] = picking.sale_id.partner_order_id.id
|
||||
invoice_vals['address_invoice_id'] = picking.sale_id.partner_invoice_id.id
|
||||
if picking.sale_id.fiscal_position:
|
||||
invoice_vals['fiscal_position'] = picking.sale_id.fiscal_position.id
|
||||
if picking.sale_id.payment_term:
|
||||
invoice_vals['payment_term'] = picking.sale_id.payment_term.id
|
||||
if picking.sale_id.user_id:
|
||||
invoice_vals['user_id'] = picking.sale_id.user_id.id
|
||||
return invoice_vals
|
||||
|
||||
def _get_price_unit_invoice(self, cursor, user, move_line, type):
|
||||
|
|
|
@ -881,22 +881,6 @@ class stock_picking(osv.osv):
|
|||
"""
|
||||
return picking.address_id and picking.address_id.partner_id
|
||||
|
||||
def _get_payment_term(self, cr, uid, picking):
|
||||
""" Gets payment term from partner.
|
||||
@return: Payment term
|
||||
"""
|
||||
partner = picking.address_id.partner_id
|
||||
return partner.property_payment_term and partner.property_payment_term.id or False
|
||||
|
||||
def _get_address_invoice(self, cr, uid, picking):
|
||||
""" Gets invoice address of a partner
|
||||
@return {'contact': address, 'invoice': address} for invoice
|
||||
"""
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
partner = picking.address_id.partner_id
|
||||
return partner_obj.address_get(cr, uid, [partner.id],
|
||||
['contact', 'invoice'])
|
||||
|
||||
def _get_comment_invoice(self, cr, uid, picking):
|
||||
"""
|
||||
@return: comment string for invoice
|
||||
|
@ -994,7 +978,8 @@ class stock_picking(osv.osv):
|
|||
else:
|
||||
account_id = partner.property_account_payable.id
|
||||
address_contact_id, address_invoice_id = \
|
||||
self._get_address_invoice(cr, uid, picking).values()
|
||||
self.pool.get('res.partner').address_get(cr, uid, [partner.id],
|
||||
['contact', 'invoice']).values()
|
||||
comment = self._get_comment_invoice(cr, uid, picking)
|
||||
invoice_vals = {
|
||||
'name': picking.name,
|
||||
|
@ -1005,7 +990,8 @@ class stock_picking(osv.osv):
|
|||
'address_invoice_id': address_invoice_id,
|
||||
'address_contact_id': address_contact_id,
|
||||
'comment': comment,
|
||||
'payment_term': self._get_payment_term(cr, uid, picking),
|
||||
'payment_term': partner.property_payment_term and partner.property_payment_term.id
|
||||
or False,
|
||||
'fiscal_position': partner.property_account_position.id,
|
||||
'date_invoice': context.get('date_inv', False),
|
||||
'company_id': picking.company_id.id,
|
||||
|
|
Loading…
Reference in New Issue