Modularize the selection of the partner to invoice when invoicing from the picking.
With this modification, all the parameters of the invoice are correct even when the goods are delivered to a third party company i.e. when the partner who receives the goods (picking.address_id.partner_id) is not to partner who ordered the goods (picking.sale_id.partner_id). bzr revid: alexis@via.ecp.fr-20120105160845-c6wk08k7v7i64zyl
This commit is contained in:
@@ -48,6 +48,11 @@ class stock_picking(osv.osv):
|
||||
else:
|
||||
return super(stock_picking, self).get_currency_id(cursor, user, picking)
|
||||
|
||||
def _get_partner_to_invoice(self, cr, uid, picking, context=None):
|
||||
if picking.sale_id:
|
||||
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
|
||||
@@ -195,4 +200,4 @@ class stock_picking(osv.osv):
|
||||
})
|
||||
return result
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -874,6 +874,13 @@ class stock_picking(osv.osv):
|
||||
def get_currency_id(self, cr, uid, picking):
|
||||
return False
|
||||
|
||||
def _get_partner_to_invoice(self, cr, uid, picking, context=None):
|
||||
""" Gets the partner that will be invoiced
|
||||
Note that this function is inherited in the sale module
|
||||
@return: partner object
|
||||
"""
|
||||
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
|
||||
@@ -1030,7 +1037,7 @@ class stock_picking(osv.osv):
|
||||
for picking in self.browse(cr, uid, ids, context=context):
|
||||
if picking.invoice_state != '2binvoiced':
|
||||
continue
|
||||
partner = picking.address_id and picking.address_id.partner_id
|
||||
partner = self._get_partner_to_invoice(cr, uid, picking, context=context)
|
||||
if not partner:
|
||||
raise osv.except_osv(_('Error, no partner !'),
|
||||
_('Please put a partner on the picking list if you want to generate invoice.'))
|
||||
|
||||
Reference in New Issue
Block a user