[IMP] sale: qty_invoiced computation test

Finetuning of #46133 which refactored qty_invoiced compute for performance reasons,
this commit adds a test to ensure the behavior stays constant w.r.t uom rounding
which was previously done in python and is now done in sql.

closes odoo/odoo#46665

X-original-commit: ce9f13a018b752f47bb455e35737e82247ca3089
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2020-03-02 15:43:25 +00:00
parent b2414b118d
commit eff7885e0d
+61
View File
@@ -264,3 +264,64 @@ class TestSaleToInvoice(TestCommonSaleNoChart):
invoice = sale_order.invoice_ids[0]
self.assertEqual(invoice.line_ids[0].display_type, 'line_section')
def test_qty_invoiced(self):
"""Verify uom rounding is correctly considered during qty_invoiced compute"""
sale_order = self.env['sale.order'].with_context(tracking_disable=True).create({
'partner_id': self.partner_customer_usd.id,
'partner_invoice_id': self.partner_customer_usd.id,
'partner_shipping_id': self.partner_customer_usd.id,
'pricelist_id': self.pricelist_usd.id,
})
SaleOrderLine = self.env['sale.order.line'].with_context(tracking_disable=True)
sol_prod_deliver = SaleOrderLine.create({
'name': self.product_order.name,
'product_id': self.product_order.id,
'product_uom_qty': 5,
'product_uom': self.product_order.uom_id.id,
'price_unit': self.product_order.list_price,
'order_id': sale_order.id,
'tax_id': False,
})
# Confirm the SO
sale_order.action_confirm()
sol_prod_deliver.write({'qty_delivered': 5.0})
# Context
self.context = {
'active_model': 'sale.order',
'active_ids': [sale_order.id],
'active_id': sale_order.id,
'default_journal_id': self.journal_sale.id,
}
# Let's do an invoice with invoiceable lines
invoicing_wizard = self.env['sale.advance.payment.inv'].with_context(self.context).create({
'advance_payment_method': 'delivered'
})
invoicing_wizard.create_invoices()
self.assertEqual(sol_prod_deliver.qty_invoiced, 5.0)
# We would have to change the digits of the field to
# test a greater decimal precision.
quantity = 5.003
move_form = Form(sale_order.invoice_ids)
with move_form.invoice_line_ids.edit(0) as line_form:
line_form.quantity = quantity
move_form.save()
# Default uom rounding to 0.001
qty_invoiced_field = sol_prod_deliver._fields.get('qty_invoiced')
sol_prod_deliver.env.add_to_compute(qty_invoiced_field, sol_prod_deliver)
self.assertEqual(sol_prod_deliver.qty_invoiced, quantity)
# Rounding to 0.01, should be rounded with UP (ceil) rounding_method
# Not floor or half up rounding.
sol_prod_deliver.product_uom.rounding *= 10
sol_prod_deliver.product_uom.flush(['rounding'])
expected_qty = 5.01
qty_invoiced_field = sol_prod_deliver._fields.get('qty_invoiced')
sol_prod_deliver.env.add_to_compute(qty_invoiced_field, sol_prod_deliver)
self.assertEqual(sol_prod_deliver.qty_invoiced, expected_qty)