summaryrefslogtreecommitdiff
path: root/addons/sale_stock/tests
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2019-05-29 15:35:09 +0200
committerChristophe Simonis <chs@odoo.com>2019-07-01 13:45:57 +0200
commitbc131c0cfb51c953de8ec41fb820c8c7831eefb5 (patch)
treecb44e2b49989b6c266af808ed9f06083cf981fc6 /addons/sale_stock/tests
parent230bb2a84d44abcf132a6b2dbe50898f6cbef417 (diff)
[MERGE] manual forward port of accounting-pocalypse (beaa30a3d1843de43a45f419bfbc1bfa7613a920)
This commit merges the following models * account.invoice and account.move * account.invoice.line and account.move.line * account.voucher and account.move * account.voucher.line and account.move.line It was the opportunity for a big cleanup of the code, so it also restructures the whole account module, its different models/fields, the tests etc. for a better world and a better code readability. ==== Rationale ==== The rationale of this huge change is that we want journal entries / invoices to be easily edited, and changes reflected in the other model. It's a HUGE feature and very strategic for the fiduciary companies. For example, changing the account of a journal entry needs to be automatically reflected on the related invoice. The same reasoning applies to sale/purchase vouchers. ==== Changes made in features ===== When creating an invoice, you are now creating a journal entry directly. --> The object account.invoice no longer exists. In the same fashion when creating an invoice line, you're now adding journal items directly in the journal entry representing the invoice. If this invoice line has some tax, it may create additional journal items as well. --> The models account.invoice.line & account.invoice.tax no longer exist Identically, when creating a sale/purchase receipt with its lines, you are now creating a journal entry directly and there's no more usability difference between encoding a receipt or an invoice. --> The object account.voucher no longer exists. --> The object account.voucher.line no longer exists. --> The whole account_voucher module no longer exists. Positive side-effects coming from these changes are * draft invoices/bills/sale or purchase receipts now create a draft accounting entry. Validate these objects now simply post its journal entry. That means that draft invoices/bills/sale or purchase receipt can straightforwardly be included in reporting or budgets. * opening a journal entry in form view will now always open the correct view: if it's a sale/purchase journal entry we will have a customer invoice/vendor bill view or a sale/purchase receipt view, whatever the menu we're coming from. * code & business logic simplification. It is also condensed in a single place instead of being partially duplicated on invoices, vouchers and journal entries. There should be no feature loss, except the one allowing to group multiple journal items together based on the same product during the invoice validation. ==== Changes made in models ===== * account.invoice: model removed. Instead, now use account.move with following mapping field (account.invoice) field (account.move) ----------------------- -------------------- name invoice_payment_ref number name reference ref comment narration user_id invoice_user_id amount_ total_company_signed amount_total_signed residual amount_residual state state + invoice_payment_state /!\ selection changed date_invoice invoice_date date_due invoice_date_due sent invoice_sent origin invoice_origin payment_term_id invoice_payment_term_id partner_bank_id invoice_partner_bank_id incoterm_id invoice_incoterm_id vendor_bill_id invoice_vendor_bill_id source_email invoice_source_email vendor_display_name invoice_vendor_display_name invoice_icon invoice_vendor_icon cash_rounding_id invoice_cash_rounding_id sequence_number_next invoice_sequence_number_next sequence_number_next_prefix invoice_sequence_number_next_prefix 'invoices' subset of account.move can be accessed by using the selection field 'type' or one of the many helpers like is_invoice() * account.move: now has a valid state 'cancel' that has to be excluded from all business logic * account.move: field 'amount' renamed into 'amount_total' * account.move: field 'reverse_entry_id' renamed into 'reversed_entry_id' * account.move.line: now has a field 'display_type' that has to be excluded from all business logic, in order to support invoice layouting * account.invoice.line: model removed. Instead, now use account.move.line with following mapping field (account.invoice.line) field (account.move.line) ---------------------------- ------------------------- invoice_id move_id uom_id product_uom_id invoice_line_tax_ids tax_ids account_analytic_id analytic_account_id 'invoice lines' subset of all account.move.line from a journal entry can be accessed by using the boolean field 'exclude_from_invoice_tab' * account.invoice.tax: model removed. Instead, now use account.move.line with following mapping field (account.invoice.tax) field (account.move.line) --------------------------- ------------------------- invoice_id move_id account_analytic_id analytic_account_id amount price_unit base tax_base_amount 'tax lines' subset of all account.move.line from a journal entry can be accessed by using the relational field 'tax_line_id' * account.invoice.confirm: model removed. Instead, now use the 'post()' function of account.move * account.invoice.refund: model removed. Instead, now use account.move.reversal to reverse the entries with the same options as we had for invoices * account.voucher: model removed. Instead, now use account.move of type in ['out_receipt', 'in_receipt] * account.voucher.line: model removed. Instead, now use account.move.line ==== Changes made in functions ==== * on account.move, method _run_post_draft_to_post() renamed into _autopost_draft_entries() * on account.move, method action_account_invoice_payment() renamed into action_invoice_register_payment() * on account.move, method action_invoice_reconcile_to_check() renamed into action_open_matching_suspense_moves() * on account.move, method _get_domain_edition_mode_available() renamed into _get_domain_matching_supsense_moves() * on account.move, method _get_intrastat_country_id() renamed into _get_invoice_intrastat_country_id() * on account.move.line, method _get_domain_for_edition_mode() renamed into _get_suspense_moves_domain() * in account.bank.statement, contextual key 'edition_mode' renamed into 'suspense_moves_mode' Was task 1917430
Diffstat (limited to 'addons/sale_stock/tests')
-rw-r--r--addons/sale_stock/tests/test_anglo_saxon_valuation_reconciliation.py45
-rw-r--r--addons/sale_stock/tests/test_sale_stock.py19
2 files changed, 28 insertions, 36 deletions
diff --git a/addons/sale_stock/tests/test_anglo_saxon_valuation_reconciliation.py b/addons/sale_stock/tests/test_anglo_saxon_valuation_reconciliation.py
index cf444c56bb3..ae913f88d45 100644
--- a/addons/sale_stock/tests/test_anglo_saxon_valuation_reconciliation.py
+++ b/addons/sale_stock/tests/test_anglo_saxon_valuation_reconciliation.py
@@ -47,24 +47,21 @@ class TestValuationReconciliation(ValuationReconciliationTestCase):
rslt.action_confirm()
return rslt
- def _create_invoice_for_so(self, sale_order, product, date):
- rslt = self.env['account.invoice'].create({
+ def _create_invoice_for_so(self, sale_order, product, date, quantity=1.0):
+ rslt = self.env['account.move'].create({
'partner_id': self.test_partner.id,
'currency_id': self.currency_two.id,
- 'name': 'customer invoice',
'type': 'out_invoice',
- 'date_invoice': date,
- 'account_id': self.account_receivable.id,
+ 'invoice_date': date,
'invoice_line_ids': [(0, 0, {
'name': 'test line',
- 'origin': sale_order.name,
'account_id': self.account_income.id,
'price_unit': self.product_price_unit,
- 'quantity': 1.0,
+ 'quantity': quantity,
'discount': 0.0,
- 'uom_id': product.uom_id.id,
+ 'product_uom_id': product.uom_id.id,
'product_id': product.id,
- 'sale_line_ids': [(6, 0, [line.id for line in sale_order.order_line])],
+ 'sale_line_ids': [(6, 0, sale_order.order_line.ids)],
})],
})
@@ -103,7 +100,7 @@ class TestValuationReconciliation(ValuationReconciliationTestCase):
'rate': 9.87366352,
'name': '2018-02-01',
})
- invoice.action_invoice_open()
+ invoice.post()
picking = self.env['stock.picking'].search([('sale_id', '=', sale_order.id)])
self.check_reconciliation(invoice, picking, operation='sale')
@@ -125,7 +122,7 @@ class TestValuationReconciliation(ValuationReconciliationTestCase):
'rate': 0.974784,
'name': '2018-02-01',
})
- invoice.action_invoice_open()
+ invoice.post()
self._process_pickings(sale_order.picking_ids)
@@ -155,13 +152,15 @@ class TestValuationReconciliation(ValuationReconciliationTestCase):
'rate': 9.56564564,
'name': '2018-04-01',
})
- refund_invoice_wiz = self.env['account.invoice.refund'].with_context(active_ids=[invoice.id]).create({
- 'description': 'test_invoice_shipment_refund',
- 'filter_refund': 'cancel',
+ refund_invoice_wiz = self.env['account.move.reversal'].with_context(active_ids=[invoice.id]).create({
+ 'reason': 'test_invoice_shipment_refund',
+ 'refund_method': 'cancel',
})
- refund_invoice_wiz.invoice_refund()
- refund_invoice = self.env['account.invoice'].search([('name', '=', 'test_invoice_shipment_refund')])[0]
- self.assertTrue(invoice.state == refund_invoice.state == 'paid'), "Invoice and refund should both be in 'Paid' state"
+ refund_invoice = self.env['account.move'].browse(refund_invoice_wiz.reverse_moves()['res_id'])
+ self.assertTrue(
+ invoice.invoice_payment_state == refund_invoice.invoice_payment_state == 'paid',
+ "Invoice and refund should both be in 'Paid' state"
+ )
self.check_reconciliation(refund_invoice, return_pick, operation='sale')
def test_multiple_shipments_invoices(self):
@@ -175,28 +174,24 @@ class TestValuationReconciliation(ValuationReconciliationTestCase):
self._process_pickings(sale_order.picking_ids, quantity=2.0)
picking = self.env['stock.picking'].search([('sale_id', '=', sale_order.id)], order="id asc", limit=1)
- invoice = self._create_invoice_for_so(sale_order, test_product, '2018-02-03')
- invoice_line = self.env['account.invoice.line'].search([('invoice_id', '=', invoice.id)])
- invoice_line.quantity = 3
+ invoice = self._create_invoice_for_so(sale_order, test_product, '2018-02-03', quantity=3)
self.env['res.currency.rate'].create({
'currency_id': self.currency_one.id,
'company_id': self.company.id,
'rate': 7.76435463,
'name': '2018-02-01',
})
- invoice.action_invoice_open()
+ invoice.post()
self.check_reconciliation(invoice, picking, full_reconcile=False, operation='sale')
- invoice2 = self._create_invoice_for_so(sale_order, test_product, '2018-03-12')
- invoice_line = self.env['account.invoice.line'].search([('invoice_id', '=', invoice2.id)])
- invoice_line.quantity = 2
+ invoice2 = self._create_invoice_for_so(sale_order, test_product, '2018-03-12', quantity=2)
self.env['res.currency.rate'].create({
'currency_id': self.currency_one.id,
'company_id': self.company.id,
'rate': 13.834739702,
'name': '2018-03-01',
})
- invoice2.action_invoice_open()
+ invoice2.post()
self.check_reconciliation(invoice2, picking, full_reconcile=False, operation='sale')
self.env['res.currency.rate'].create({
diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py
index 9bea6fa8847..47fd2408bd3 100644
--- a/addons/sale_stock/tests/test_sale_stock.py
+++ b/addons/sale_stock/tests/test_sale_stock.py
@@ -13,7 +13,7 @@ class TestSaleStock(TestSale):
Test SO's changes when playing around with stock moves, quants, pack operations, pickings
and whatever other model there is in stock with "invoice on delivery" products
"""
- inv_obj = self.env['account.invoice']
+ inv_obj = self.env['account.move']
self.so = self.env['sale.order'].create({
'partner_id': self.partner.id,
'partner_invoice_id': self.partner.id,
@@ -41,8 +41,7 @@ class TestSaleStock(TestSale):
del_qties_truth = [1.0 if sol.product_id.type in ['product', 'consu'] else 0.0 for sol in self.so.order_line]
self.assertEqual(del_qties, del_qties_truth, 'Sale Stock: delivered quantities are wrong after partial delivery')
# invoice on delivery: only storable products
- inv_id = self.so._create_invoices()
- inv_1 = inv_obj.browse(inv_id)
+ inv_1 = self.so._create_invoices()
self.assertTrue(all([il.product_id.invoice_policy == 'delivery' for il in inv_1.invoice_line_ids]),
'Sale Stock: invoice should only contain "invoice on delivery" products')
@@ -93,7 +92,7 @@ class TestSaleStock(TestSale):
'product_id': self.env.ref('sale.advance_product_0').id,
})
act = adv_wiz.with_context(open_invoices=True).create_invoices()
- inv = self.env['account.invoice'].browse(act['res_id'])
+ inv = self.env['account.move'].browse(act['res_id'])
self.assertEqual(inv.amount_untaxed, self.so.amount_untaxed * 5.0 / 100.0, 'Sale Stock: deposit invoice is wrong')
self.assertEqual(self.so.invoice_status, 'to invoice', 'Sale Stock: so should be to invoice after invoicing deposit')
# invoice on order: everything should be invoiced
@@ -151,12 +150,11 @@ class TestSaleStock(TestSale):
# Check invoice
self.assertEqual(self.so.invoice_status, 'to invoice', 'Sale Stock: so invoice_status should be "to invoice" instead of "%s" before invoicing' % self.so.invoice_status)
- inv_1_id = self.so._create_invoices()
+ self.inv_1 = self.so._create_invoices()
self.assertEqual(self.so.invoice_status, 'invoiced', 'Sale Stock: so invoice_status should be "invoiced" instead of "%s" after invoicing' % self.so.invoice_status)
- self.assertEqual(len(inv_1_id), 1, 'Sale Stock: only one invoice instead of "%s" should be created' % len(inv_1_id))
- self.inv_1 = self.env['account.invoice'].browse(inv_1_id)
+ self.assertEqual(len(self.inv_1), 1, 'Sale Stock: only one invoice instead of "%s" should be created' % len(self.inv_1))
self.assertEqual(self.inv_1.amount_untaxed, self.inv_1.amount_untaxed, 'Sale Stock: amount in SO and invoice should be the same')
- self.inv_1.action_invoice_open()
+ self.inv_1.post()
# Create return picking
stock_return_picking_form = Form(self.env['stock.return.picking']
@@ -226,10 +224,9 @@ class TestSaleStock(TestSale):
# Check invoice
self.assertEqual(self.so.invoice_status, 'to invoice', 'Sale Stock: so invoice_status should be "to invoice" before invoicing')
- inv_1_id = self.so._create_invoices()
+ self.inv_1 = self.so._create_invoices()
self.assertEqual(self.so.invoice_status, 'no', 'Sale Stock: so invoice_status should be "no" after invoicing')
- self.assertEqual(len(inv_1_id), 1, 'Sale Stock: only one invoice should be created')
- self.inv_1 = self.env['account.invoice'].browse(inv_1_id)
+ self.assertEqual(len(self.inv_1), 1, 'Sale Stock: only one invoice should be created')
self.assertEqual(self.inv_1.amount_untaxed, self.inv_1.amount_untaxed, 'Sale Stock: amount in SO and invoice should be the same')
self.so.action_done()