[FIX] sale, sale_stock: do not decrease quantity
In case of exception (refund, return of product), we want to let the user decides what needs to be done with the quantity delivered or invoiced.
This commit is contained in:
+2
-5
@@ -421,11 +421,8 @@ class SaleOrderLine(models.Model):
|
||||
for line in self:
|
||||
qty_invoiced = 0.0
|
||||
for invoice_line in line.invoice_lines:
|
||||
if invoice_line.invoice_id.state != 'cancel':
|
||||
if invoice_line.invoice_id.type == 'out_invoice':
|
||||
qty_invoiced += invoice_line.quantity
|
||||
elif invoice_line.invoice_id.type == 'out_refund':
|
||||
qty_invoiced -= invoice_line.quantity
|
||||
if invoice_line.invoice_id.state != 'cancel' and invoice_line.invoice_id.type == 'out_invoice':
|
||||
qty_invoiced += invoice_line.quantity
|
||||
line.qty_invoiced = qty_invoiced
|
||||
|
||||
@api.depends('price_subtotal', 'product_uom_qty')
|
||||
|
||||
@@ -166,8 +166,6 @@ class SaleOrderLine(models.Model):
|
||||
for move in self.procurement_ids.mapped('move_ids').filtered(lambda r: r.state == 'done' and not r.scrapped):
|
||||
if move.location_dest_id.usage == "customer":
|
||||
qty += self.env['product.uom']._compute_qty_obj(move.product_uom, move.product_uom_qty, self.product_uom)
|
||||
elif move.location_id.usage == "customer":
|
||||
qty -= self.env['product.uom']._compute_qty_obj(move.product_uom, move.product_uom_qty, self.product_uom)
|
||||
return qty
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -164,12 +164,4 @@ class TestSaleStock(TestSale):
|
||||
return_pick.do_new_transfer()
|
||||
|
||||
# Check invoice
|
||||
self.assertEqual(self.so.invoice_status, 'to invoice', 'Sale Stock: so invoice_status should be "to invoice" before invoicing')
|
||||
# let's do an invoice with refunds
|
||||
adv_wiz = self.env['sale.advance.payment.inv'].with_context(active_ids=[self.so.id]).create({
|
||||
'advance_payment_method': 'all',
|
||||
})
|
||||
adv_wiz.with_context(open_invoices=True).create_invoices()
|
||||
self.inv_2 = self.so.invoice_ids[1]
|
||||
self.assertEqual(self.so.invoice_status, 'no', 'Sale Stock: so invoice_status should be "no" after invoicing the return')
|
||||
self.assertEqual(self.inv_2.amount_untaxed, self.inv_2.amount_untaxed, 'Sale Stock: amount in SO and invoice should be the same')
|
||||
self.assertEqual(self.so.invoice_status, 'invoiced', 'Sale Stock: so invoice_status should be "invoiced" after picking return')
|
||||
|
||||
Reference in New Issue
Block a user