[IMP] Make sure there is a link between purchase order invoice and purchase order
This commit is contained in:
parent
bdd8d5a937
commit
eb13d3ee5f
|
@ -55,6 +55,35 @@ class stock_move(osv.osv):
|
|||
})
|
||||
return super(stock_move, self).copy(cr, uid, id, default, context)
|
||||
|
||||
|
||||
def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
|
||||
invoice_line_id = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
|
||||
if move.purchase_line_id:
|
||||
purchase_line = move.purchase_line_id
|
||||
self.pool.get('purchase.order.line').write(cr, uid, [purchase_line.id], {
|
||||
'invoice_lines': [(4, invoice_line_id)]
|
||||
}, context=context)
|
||||
self.pool.get('purchase.order').write(cr, uid, [purchase_line.order_id.id], {
|
||||
'invoice_ids': [(4, invoice_line_vals['invoice_id'])],
|
||||
})
|
||||
return invoice_line_id
|
||||
|
||||
def _get_master_data(self, cr, uid, move, company, context=None):
|
||||
if move.purchase_line_id:
|
||||
purchase_order = move.purchase_line_id.order_id
|
||||
return purchase_order.partner_id, purchase_order.create_uid.id, purchase_order.pricelist_id.currency_id.id
|
||||
super(stock_move, self)._get_master_data(cr, uid, move, company, context=context)
|
||||
|
||||
def _get_invoice_line_vals(self, cr, uid, move, partner, inv_type, context=None):
|
||||
res = super(stock_move, self)._get_invoice_line_vals(cr, uid, move, partner, inv_type, context=context)
|
||||
if move.purchase_line_id:
|
||||
purchase_line = move.purchase_line_id
|
||||
res['invoice_line_tax_id'] = [(6, 0, [x.id for x in purchase_line.taxes_id])]
|
||||
#res['account_analytic_id'] = purc_line.order_id.project_id and sale_line.order_id.project_id.id or False
|
||||
res['price_unit'] = purchase_line.price_unit
|
||||
#res['discount'] = sale_line.discount
|
||||
return res
|
||||
|
||||
class stock_picking(osv.osv):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
|
|
|
@ -388,7 +388,7 @@ class stock_move(osv.osv):
|
|||
return super(stock_move, self).action_cancel(cr, uid, ids, context=context)
|
||||
|
||||
def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
|
||||
invoice_line_id = self.pool.get('account.invoice.line').create(cr, uid, invoice_line_vals, context=context)
|
||||
invoice_line_id = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
|
||||
if move.procurement_id and move.procurement_id.sale_line_id:
|
||||
sale_line = move.procurement_id.sale_line_id
|
||||
self.pool.get('sale.order.line').write(cr, uid, [sale_line.id], {
|
||||
|
|
|
@ -202,7 +202,7 @@ class stock_picking(osv.osv):
|
|||
for picking in self.browse(cr, uid, ids, context=context):
|
||||
key = group and picking.id or True
|
||||
for move in picking.move_lines:
|
||||
if move.procurement_id and (move.procurement_id.invoice_state == '2binvoiced') or move.invoice_state == '2binvoiced':
|
||||
if move.invoice_state == '2binvoiced':
|
||||
if (move.state != 'cancel') and not move.scrapped:
|
||||
todo.setdefault(key, [])
|
||||
todo[key].append(move)
|
||||
|
@ -257,12 +257,7 @@ class stock_picking(osv.osv):
|
|||
invoice_line_vals['origin'] = origin
|
||||
|
||||
move_obj._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
|
||||
|
||||
move_obj.write(cr, uid, move.id, {'invoice_state': 'invoiced'}, context=context)
|
||||
if move.procurement_id:
|
||||
self.pool.get('procurement.order').write(cr, uid, [move.procurement_id.id], {
|
||||
'invoice_state': 'invoiced',
|
||||
}, context=context)
|
||||
|
||||
invoice_obj.button_compute(cr, uid, invoices.values(), context=context, set_total=(inv_type in ('in_invoice', 'in_refund')))
|
||||
return invoices.values()
|
||||
|
|
Loading…
Reference in New Issue