Fix get_move_done computation for returns

The quantity of the line may be negative, so the absolute value must be used.
The scenario update does not catch this case because it is a complex case that
can not be achieved with the default methods. But it adds various states
checks.

issue6440
review39311002
This commit is contained in:
Cédric Krier
2017-04-19 10:29:30 +02:00
parent 4627feb3b9
commit 1d152d9dc5
2 changed files with 89 additions and 22 deletions
+18 -15
View File
@@ -1119,26 +1119,29 @@ class SaleLine(sequence_ordered(), ModelSQL, ModelView):
return self.unit.digits
return 2
def get_move_done(self, name):
Uom = Pool().get('product.uom')
done = True
@property
def _move_remaining_quantity(self):
"Compute the remaining quantity to ship"
pool = Pool()
Uom = pool.get('product.uom')
if self.type != 'line' or not self.product:
return True
return
if self.product.type == 'service':
return True
return
skip_ids = set(x.id for x in self.moves_ignored)
skip_ids.update(x.id for x in self.moves_recreated)
quantity = self.quantity
quantity = abs(self.quantity)
for move in self.moves:
if move.state != 'done' \
and move.id not in skip_ids:
done = False
break
quantity -= Uom.compute_qty(move.uom, move.quantity, self.unit)
if done:
if self.unit.round(quantity) > 0.0:
done = False
return done
if move.state == 'done' or move.id in skip_ids:
quantity -= Uom.compute_qty(move.uom, move.quantity, self.unit)
return quantity
def get_move_done(self, name):
quantity = self._move_remaining_quantity
if quantity is None:
return True
else:
return self.unit.round(quantity) <= 0
def get_move_exception(self, name):
skip_ids = set(x.id for x in self.moves_ignored)
+71 -7
View File
@@ -184,6 +184,10 @@ Sale 5 products::
(Decimal('50.00'), Decimal('5.00'), Decimal('55.00'))
>>> sale.state
u'processing'
>>> sale.shipment_state
u'waiting'
>>> sale.invoice_state
u'waiting'
>>> len(sale.shipments), len(sale.shipment_returns), len(sale.invoices)
(1, 0, 1)
>>> invoice, = sale.invoices
@@ -255,6 +259,10 @@ Sale 5 products with an invoice method 'on shipment'::
>>> sale.click('process')
>>> sale.state
u'processing'
>>> sale.shipment_state
u'waiting'
>>> sale.invoice_state
u'none'
>>> sale.reload()
>>> len(sale.shipments), len(sale.shipment_returns), len(sale.invoices)
(1, 0, 0)
@@ -281,6 +289,8 @@ Open customer invoice::
>>> config.user = sale_user.id
>>> sale.reload()
>>> sale.invoice_state
u'waiting'
>>> invoice, = sale.invoices
>>> config.user = account_user.id
>>> Invoice = Model.get('account.invoice')
@@ -325,6 +335,10 @@ Sale 5 products with shipment method 'on invoice'::
>>> sale.click('process')
>>> sale.state
u'processing'
>>> sale.shipment_state
u'none'
>>> sale.invoice_state
u'waiting'
>>> len(sale.shipments), len(sale.shipment_returns), len(sale.invoices)
(0, 0, 1)
@@ -420,27 +434,41 @@ Create a Return::
>>> return_.click('process')
>>> return_.state
u'processing'
>>> return_.reload()
>>> return_.shipment_state
u'waiting'
>>> return_.invoice_state
u'none'
>>> (len(return_.shipments), len(return_.shipment_returns),
... len(return_.invoices))
(0, 1, 0)
Check Return Shipments::
Receive Return Shipment for 3 products::
>>> config.user = sale_user.id
>>> ship_return, = return_.shipment_returns
>>> config.user = stock_user.id
>>> ship_return.click('receive')
>>> move_return, = ship_return.incoming_moves
>>> move_return.product.rec_name
u'product'
>>> move_return.quantity
4.0
>>> move_return.quantity = 3
>>> ship_return.click('receive')
Open customer credit note::
Check Return::
>>> config.user = sale_user.id
>>> return_.reload()
>>> return_.shipment_state
u'waiting'
>>> return_.invoice_state
u'waiting'
>>> (len(return_.shipments), len(return_.shipment_returns),
... len(return_.invoices))
(0, 2, 1)
Open customer credit note::
>>> credit_note, = return_.invoices
>>> config.user = account_user.id
>>> credit_note = Invoice(credit_note.id)
@@ -449,9 +477,34 @@ Open customer credit note::
>>> len(credit_note.lines)
1
>>> sum(l.quantity for l in credit_note.lines)
-4.0
-3.0
>>> credit_note.click('post')
Receive Remaining Return Shipment::
>>> config.user = sale_user.id
>>> return_.reload()
>>> _, ship_return = return_.shipment_returns
>>> config.user = stock_user.id
>>> move_return, = ship_return.incoming_moves
>>> move_return.product.rec_name
u'product'
>>> move_return.quantity
1.0
>>> ship_return.click('receive')
Check Return::
>>> config.user = sale_user.id
>>> return_.reload()
>>> return_.shipment_state
u'sent'
>>> return_.invoice_state
u'waiting'
>>> (len(return_.shipments), len(return_.shipment_returns),
... len(return_.invoices))
(0, 2, 2)
Mixing return and sale::
>>> config.user = sale_user.id
@@ -476,7 +529,10 @@ Mixing return and sale::
>>> mix.click('process')
>>> mix.state
u'processing'
>>> mix.reload()
>>> mix.shipment_state
u'waiting'
>>> mix.invoice_state
u'waiting'
>>> len(mix.shipments), len(mix.shipment_returns), len(mix.invoices)
(1, 1, 1)
@@ -541,6 +597,10 @@ Mixing stuff with an invoice method 'on shipment'::
>>> mix.click('process')
>>> mix.state
u'processing'
>>> mix.shipment_state
u'waiting'
>>> mix.invoice_state
u'none'
>>> len(mix.shipments), len(mix.shipment_returns), len(mix.invoices)
(1, 1, 0)
@@ -580,6 +640,10 @@ Sale services::
>>> service_sale.click('process')
>>> service_sale.state
u'processing'
>>> service_sale.shipment_state
u'none'
>>> service_sale.invoice_state
u'waiting'
>>> service_invoice, = service_sale.invoices
Pay the service invoice::
@@ -664,7 +728,7 @@ to invoices::
>>> stock_move.state
u'done'
Create a sale to be sent on invoice partialy and check correctly linked to
Create a sale to be sent on invoice partially and check correctly linked to
invoices::
>>> sale = Sale()