trytond-patches/issue4950_sale.diff
Sergi Almacellas Abellana dcd029f1a5 Add patch for issue4950
2015-09-04 16:33:20 +02:00

115 lines
3.8 KiB
Diff

diff -r f9ff7d1399d1 stock.py
--- a/trytond/trytond/modules/sale/stock.py Fri Sep 04 16:30:54 2015 +0200
+++ b/trytond/trytond/modules/sale/stock.py Fri Sep 04 16:31:35 2015 +0200
@@ -1,5 +1,6 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
+from itertools import ifilter
from sql.operators import Concat
from trytond.model import Workflow, ModelView, fields
@@ -60,6 +61,35 @@
return super(ShipmentOut, cls).draft(shipments)
+ def get_origins(self, name):
+ return ', '.join(set(ifilter(None, (m.origin_name
+ for m in self.outgoing_moves))))
+
+ @classmethod
+ def _sync_inventory_to_outgoing_grouping_key(cls, move, type):
+ pool = Pool()
+ Move = pool.get('stock.move')
+ key = super(ShipmentOut,
+ cls)._sync_inventory_to_outgoing_grouping_key(move, type)
+ if type == 'outgoing':
+ key = tuple([key, move.origin])
+ if (type == 'inventory' and move.origin and
+ isinstance(move.origin, Move)):
+ key = tuple([key, move.origin.origin])
+ return key
+
+ def _get_outgoing_move(self, move):
+ new_move = super(ShipmentOut, self)._get_outgoing_move(move)
+ if new_move:
+ new_move.origin = move
+ return new_move
+
+ def _get_inventory_move(self, move):
+ new_move = super(ShipmentOut, self)._get_inventory_move(move)
+ if new_move:
+ new_move.origin = move
+ return new_move
+
class ShipmentOutReturn:
__name__ = 'stock.shipment.out.return'
@@ -146,6 +176,7 @@
@classmethod
def _get_origin(cls):
models = super(Move, cls)._get_origin()
+ models.append('stock.move')
models.append('sale.line')
return models
diff -r f9ff7d1399d1 tests/scenario_sale.rst
--- a/trytond/trytond/modules/sale/tests/scenario_sale.rst Fri Sep 04 16:30:54 2015 +0200
+++ b/trytond/trytond/modules/sale/tests/scenario_sale.rst Fri Sep 04 16:31:35 2015 +0200
@@ -771,3 +771,57 @@
5.0
>>> stock_move.state
u'draft'
+
+Create a sale with the same products with diferent price to be invoiced on
+shipment and check correctly invoiced::
+
+ >>> sale = Sale()
+ >>> sale.party = customer
+ >>> sale.payment_term = payment_term
+ >>> sale.invoice_method = 'shipment'
+ >>> line = sale.lines.new()
+ >>> line.product = product
+ >>> line.quantity = 10.0
+ >>> line = sale.lines.new()
+ >>> line.product = product
+ >>> line.quantity = 10.0
+ >>> line.unit_price = Decimal('9.0000')
+ >>> sale.click('quote')
+ >>> sale.click('confirm')
+ >>> sale.click('process')
+ >>> shipment, = sale.shipments
+ >>> config.user = stock_user.id
+ >>> for move in shipment.inventory_moves:
+ ... move.quantity = 5.0
+ >>> shipment.click('assign_try')
+ True
+ >>> shipment.click('pack')
+ >>> shipment.click('done')
+ >>> config.user = sale_user.id
+ >>> sale.reload()
+ >>> invoice, = sale.invoices
+ >>> _, shipment, = sale.shipments
+ >>> invoice.untaxed_amount
+ Decimal('95.00')
+ >>> first_line, second_line = sorted(invoice.lines,
+ ... key=lambda a: a.unit_price)
+ >>> first_line.unit_price
+ Decimal('9.0000')
+ >>> second_line.unit_price
+ Decimal('10.0000')
+ >>> config.user = stock_user.id
+ >>> shipment.click('assign_try')
+ True
+ >>> shipment.click('pack')
+ >>> shipment.click('done')
+ >>> config.user = sale_user.id
+ >>> sale.reload()
+ >>> _, invoice = sale.invoices
+ >>> invoice.untaxed_amount
+ Decimal('95.00')
+ >>> first_line, second_line = sorted(invoice.lines,
+ ... key=lambda a: a.unit_price)
+ >>> first_line.unit_price
+ Decimal('9.0000')
+ >>> second_line.unit_price
+ Decimal('10.0000')