- avoid using sale objects in stock_account module
- check the purchase side
This commit is contained in:
Nicolas Seinlet 2014-08-08 14:15:13 +02:00 committed by Josse Colpaert
parent 2bd1ec9e6b
commit c2b7bca486
3 changed files with 29 additions and 8 deletions

View File

@ -83,6 +83,14 @@ class stock_move(osv.osv):
class stock_picking(osv.osv):
_inherit = 'stock.picking'
def _get_partner_to_invoice(self, cr, uid, picking, context=None):
""" Inherit the original function of the 'stock' module
We select the partner of the purchase order as the partner of the invoice
"""
if picking.move_lines and picking.move_lines[0] and picking.move_lines[0].purchase_line_id:
return picking.move_lines[0].purchase_line_id.order_id.partner_id and picking.move_lines[0].purchase_line_id.order_id.partner_id.id
return super(stock_picking, self)._get_partner_to_invoice(cr, uid, picking, context=context)
def _get_to_invoice(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):

View File

@ -396,6 +396,17 @@ class stock_location_route(osv.osv):
class stock_picking(osv.osv):
_inherit = "stock.picking"
def _get_partner_to_invoice(self, cr, uid, picking, context=None):
""" Inherit the original function of the 'stock' module
We select the partner of the sales order as the partner of the customer invoice
"""
saleorder_ids = self.pool['sale.order'].search(cr, uid, [('procurement_group_id' ,'=', picking.group_id.id)], context=context)
saleorders = self.pool['sale.order'].browse(cr, uid, saleorder_ids, context=context)
if saleorders and saleorders[0]:
saleorder = saleorders[0]
return saleorder.partner_invoice_id.id
return super(stock_picking, self)._get_partner_to_invoice(cr, uid, picking, context=context)
def _get_sale_id(self, cr, uid, ids, name, args, context=None):
sale_obj = self.pool.get("sale.order")
res = {}

View File

@ -190,6 +190,14 @@ class stock_picking(osv.osv):
invoice_obj = self.pool.get('account.invoice')
return invoice_obj.create(cr, uid, vals, context=context)
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 and purchase modules
@param picking: object of the picking for which we are selecting the partner to invoice
@return: object of the partner to invoice
"""
return picking.partner_id and picking.partner_id.id
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.
@param journal_id: Id of journal
@ -197,20 +205,14 @@ class stock_picking(osv.osv):
@param type: Type invoice to be created
@return: Ids of created invoices for the pickings
"""
saleorder_model = self.pool['sale.order']
context = context or {}
todo = {}
for picking in self.browse(cr, uid, ids, context=context):
partner = self._get_partner_to_invoice(cr, uid, picking, context)
#grouping is based on the invoiced partner
if group:
saleorder_ids = saleorder_model.search(cr, uid, [('procurement_group_id' ,'=', picking.group_id.id)], context=context)
saleorders = saleorder_model.browse(cr, uid, saleorder_ids, context=context)
if saleorders and saleorders[0]:
saleorder = saleorders[0]
key = "%s" % saleorder.partner_invoice_id.id
else:
key = "Pick %s" % picking.id
key = partner
else:
key = picking.id
for move in picking.move_lines: