Debian Codegraph @

addons/sale_mrp/tests/test_sale_mrp_report.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo.fields import Command
4 from odoo.tests import tagged
5 from odoo.tools import html2plaintext
6
7 from odoo.addons.sale.tests.common import TestSaleCommon
8
9
10 @tagged('post_install', '-at_install')
11 class TestSaleMrpInvoices(TestSaleCommon):
12
13 @classmethod
14 def setUpClass(cls):
15 super().setUpClass()
16
17 cls.product_by_lot = cls.env['product.product'].create({
18 'name': 'Product By Lot',
19 'is_storable': True,
20 'tracking': 'lot',
21 })
22 cls.warehouse = cls.env['stock.warehouse'].search([('company_id', '=', cls.env.company.id)], limit=1)
23 cls.stock_location = cls.warehouse.lot_stock_id
24 cls.lot = cls.env['stock.lot'].create({
25 'name': 'LOT0001',
26 'product_id': cls.product_by_lot.id,
27 })
28 cls.env['stock.quant']._update_available_quantity(cls.product_by_lot, cls.stock_location, 10, lot_id=cls.lot)
29
30 cls.tracked_kit = cls.env['product.product'].create({
31 'name': 'Simple Kit',
32 'type': 'consu',
33 })
34 cls.env['mrp.bom'].create({
35 'product_tmpl_id': cls.tracked_kit.product_tmpl_id.id,
36 'type': 'phantom',
37 'bom_line_ids': [(0, 0, {
38 'product_id': cls.product_by_lot.id,
39 'product_qty': 1,
40 })]
41 })
42
43 def test_deliver_and_invoice_tracked_components(self):
44 """
45 Suppose the lots are printed on the invoices.
46 The user sells a kit that has one tracked component.
47 The lot of the delivered component should be on the invoice.
48 """
49 display_lots = self.env.ref('stock_account.group_lot_on_invoice')
50 display_uom = self.env.ref('uom.group_uom')
51 self.env.user.write({'group_ids': [(4, display_lots.id), (4, display_uom.id)]})
52
53 so = self.env['sale.order'].create({
54 'partner_id': self.partner.id,
55 'order_line': [
56 (0, 0, {'name': self.tracked_kit.name, 'product_id': self.tracked_kit.id, 'product_uom_qty': 1}),
57 ],
58 })
59 so.action_confirm()
60
61 so.picking_ids.button_validate()
62
63 invoice = so._create_invoices()
64 invoice.action_post()
65
66 html = self.env['ir.actions.report']._render_qweb_html(
67 'account.report_invoice_with_payments', invoice.ids)[0]
68 text = html2plaintext(html.decode())
69 self.assertRegex(text, r'Product By Lot\n1.00Units\nLOT0001', "There should be a line that specifies 1 x LOT0001")
70
71 def test_report_forecast_for_mto_procure_method(self):
72 """
73 Check that mto moves are not reported as taking from stock in the forecast report
74 """
75 mto_route = self.env.ref('stock.route_warehouse0_mto')
76 mto_route.active = True
77 manufacturing_route = self.env.ref('mrp.route_warehouse0_manufacture')
78 product = self.env['product.product'].create({
79 'name': 'SuperProduct',
80 'is_storable': True,
81 'route_ids': [Command.set((mto_route + manufacturing_route).ids)]
82 })
83
84 product.bom_ids = [Command.create({
85 'product_id': product.id,
86 'product_tmpl_id': product.product_tmpl_id.id,
87 'product_uom_id': product.uom_id.id,
88 'bom_line_ids': [Command.create({
89 'product_id': self.product_by_lot.id,
90 'product_qty': 1,
91 })]
92 })]
93 warehouse = self.warehouse
94 # make 2 so: so_1 can be fulfilled and so_2 requires a replenishment
95 self.env['stock.quant']._update_available_quantity(product, warehouse.lot_stock_id, 10.0)
96 so_1, so_2 = self.env['sale.order'].create([
97 {
98 'partner_id': self.partner_a.id,
99 'order_line': [Command.create({
100 'name': product.name,
101 'product_id': product.id,
102 'product_uom_qty': 8.0,
103 'price_unit': product.list_price,
104 })]
105 },
106 {
107 'partner_id': self.partner_a.id,
108 'order_line': [Command.create({
109 'name': product.name,
110 'product_id': product.id,
111 'product_uom_qty': 7.0,
112 'price_unit': product.list_price,
113 })]
114 },
115
116 ])
117 (so_1 | so_2).action_confirm()
118 report_lines = self.env['stock.forecasted_product_product'].with_context(warehouse=warehouse.id).get_report_values(docids=product.ids)['docs']['lines']
119 self.assertEqual(len(report_lines), 3)
120 so_1_line = report_lines[0]
121 self.assertEqual(
122 [so_1_line['quantity'], so_1_line['move_out']['id'], so_1_line['replenishment_filled']],
123 [8.0, so_1.picking_ids.move_ids.id, True]
124 )
125 so_2_line = report_lines[1]
126 self.assertEqual(
127 [so_2_line['quantity'], so_2_line['move_out']['id'], so_2_line['replenishment_filled']],
128 [7.0, so_2.picking_ids.move_ids.id, True]
129 )
130 replenisment_line = report_lines[2]
131 self.assertEqual(
132 [replenisment_line['document_in'], replenisment_line['document_out'], replenisment_line['quantity'], replenisment_line['move_out'], replenisment_line['replenishment_filled']],
133 [False, False, 10.0, None, True]
134 )