diff --git a/purchase.py b/purchase.py index 201e3184b4..8b991f5fb5 100644 --- a/purchase.py +++ b/purchase.py @@ -1551,7 +1551,10 @@ class PurchaseLine(sequence_ordered(), ModelSQL, ModelView): def _get_move_invoice_lines(self, move_type): 'Return the invoice lines that should be shipped' - return [l for l in self.invoice_lines if not l.stock_moves] + if self.purchase.invoice_method == 'order': + return [l for l in self.invoice_lines] + else: + return [l for l in self.invoice_lines if not l.stock_moves] def get_rec_name(self, name): if self.product: diff --git a/tests/scenario_purchase.rst b/tests/scenario_purchase.rst index 200cc6ba78..17b9059d6c 100644 --- a/tests/scenario_purchase.rst +++ b/tests/scenario_purchase.rst @@ -548,6 +548,46 @@ linked to invoices:: >>> stock_move.state u'done' +Create a purchase to be invoiced on order, partially send it and check +correctly linked to invoices:: + + >>> purchase = Purchase() + >>> purchase.party = supplier + >>> purchase.payment_term = payment_term + >>> purchase.invoice_method = 'order' + >>> line = purchase.lines.new() + >>> line.product = product + >>> line.quantity = 10.0 + >>> purchase.click('quote') + >>> purchase.click('confirm') + >>> purchase.click('process') + >>> shipment = ShipmentIn() + >>> shipment.supplier = supplier + >>> for move in purchase.moves: + ... incoming_move = Move(id=move.id) + ... incoming_move.quantity = 8.0 + ... shipment.incoming_moves.append(incoming_move) + >>> shipment.save() + >>> for move in shipment.inventory_moves: + ... move.quantity = 8.0 + >>> shipment.click('receive') + >>> shipment.click('done') + >>> purchase.reload() + >>> invoice, = purchase.invoices + >>> invoice_line, = invoice.lines + >>> invoice_line.quantity + 10.0 + >>> draft_stock_move, stock_move = sorted( + ... invoice_line.stock_moves, key=lambda m: m.quantity) + >>> draft_stock_move.quantity + 2.0 + >>> draft_stock_move.state + u'draft' + >>> stock_move.quantity + 8.0 + >>> stock_move.state + u'done' + Deleting a line from a invoice should recreate it:: >>> purchase = Purchase()