From 08461c439b3b05f67e809a4aaff23c3a6d950345 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 14 Nov 2017 16:38:31 +0100 Subject: [PATCH] [IMP] product_margin: formify tests --- .../tests/test_product_margin.py | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/addons/product_margin/tests/test_product_margin.py b/addons/product_margin/tests/test_product_margin.py index c67ffd5eb2f..9cc292dd82d 100644 --- a/addons/product_margin/tests/test_product_margin.py +++ b/addons/product_margin/tests/test_product_margin.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import tools -from odoo.tests import common +from odoo.tests import common, Form from odoo.modules.module import get_resource_path @@ -9,24 +9,17 @@ class TestProductMargin(common.TransactionCase): def create_account_invoice(self, invoice_type, partner, product, quantity=0.0, price_unit=0.0): """ Create an invoice as in a view by triggering its onchange methods""" - default_get_vals = self.env['account.invoice'].default_get(list(self.env['account.invoice'].fields_get())) - account_invoice = self.env['account.invoice'].new(default_get_vals) - account_invoice.type = invoice_type - account_invoice._onchange_journal_id() - account_invoice.partner_id = partner.id - account_invoice._onchange_partner_id() - account_invoice.invoice_line_ids = [(0, 0, { - 'quantity': quantity, - 'product_id': product.id, - 'uom_id': self.ref('product.product_uom_unit'), - 'invoice_id': account_invoice, # This value is required for '_onchange_product_id' to work correctly - })] - account_invoice.invoice_line_ids._onchange_product_id() - account_invoice.invoice_line_ids.price_unit = price_unit - account_invoice._onchange_invoice_line_ids() - vals = account_invoice._convert_to_write(account_invoice._cache) - account_invoice = self.env['account.invoice'].create(vals) - account_invoice.action_invoice_open() + + invoice_form = Form(self.env['account.invoice'].with_context(type=invoice_type)) + invoice_form.partner_id = partner + with invoice_form.invoice_line_ids.new() as line: + line.product_id = product + line.quantity = quantity + line.price_unit = price_unit + + invoice = invoice_form.save() + invoice.action_invoice_open() + return invoice def test_product_margin(self): ''' In order to test the product_margin module '''