[FIX] delivery: shipping invoice line depending on amount total

The delivery module overrode the method _create_invoice_from_picking
to add the shipping costs according to the invoice and the shipping.

The issue is that the method _create_invoice_from_picking creates an empty
invoice, without any line. The lines are added afterwards, using the method
_create_invoice_line_from_vals, within the method _invoice_create_line.
So, after having called _create_invoice_from_picking, the invoice is indeed
created, but without lines, and therefore without the amount total value.
Adding the shipping costs there will thus prevent the shipping costs
based on the total price of the invoice (e.g. free for an order of 500€)

This rev. overrides the method _invoice_create_line instead, as, after
the call to this method, the invoice will be completely set, with all
its lines, and with a correct amount total. The side effect
is that we need to recompute the taxes a second time, using button_compute.

This is not the cleanest way to solve this issue. Indeed, a cleaner patch
would be to change the method _create_invoice_from_picking so it creates
the invoice along with its invoice lines, using the ORM command
(0, _, values) to creates the lines directly within the invoice creation:
invoice['invoice_line'] = [(0, _, values) for values in invoice_lines_vals].

Nevertheless, this is a bigger change, that will probably require API changes,
and therefore should be done in master.

opw-626226
opw-628517
This commit is contained in:
Denis Ledoux 2015-02-20 12:26:31 +01:00
parent 4ed38c2a92
commit 4ad329de55
1 changed files with 14 additions and 7 deletions

View File

@ -119,15 +119,22 @@ class stock_picking(osv.osv):
'invoice_line_tax_id': [(6, 0, taxes_ids)],
}
def _create_invoice_from_picking(self, cr, uid, picking, vals, context=None):
def _invoice_create_line(self, cr, uid, moves, journal_id, inv_type='out_invoice', context=None):
invoice_obj = self.pool.get('account.invoice')
invoice_line_obj = self.pool.get('account.invoice.line')
invoice_id = super(stock_picking, self)._create_invoice_from_picking(cr, uid, picking, vals, context=context)
invoice = invoice_obj.browse(cr, uid, invoice_id, context=context)
invoice_line = self._prepare_shipping_invoice_line(cr, uid, picking, invoice, context=context)
if invoice_line:
invoice_line_obj.create(cr, uid, invoice_line)
return invoice_id
invoice_ids = super(stock_picking, self)._invoice_create_line(cr, uid, moves, journal_id, inv_type=inv_type, context=context)
delivey_invoices = {}
for move in moves:
for invoice in move.picking_id.sale_id.invoice_ids:
if invoice.id in invoice_ids:
delivey_invoices[invoice] = move.picking_id
if delivey_invoices:
for invoice, picking in delivey_invoices.items():
invoice_line = self._prepare_shipping_invoice_line(cr, uid, picking, invoice, context=context)
if invoice_line:
invoice_line_obj.create(cr, uid, invoice_line)
invoice_obj.button_compute(cr, uid, [invoice.id], context=context, set_total=(inv_type in ('in_invoice', 'in_refund')))
return invoice_ids
def _get_default_uom(self, cr, uid, context=None):
uom_categ_id = self.pool.get('ir.model.data').xmlid_to_res_id(cr, uid, 'product.product_uom_categ_kgm')