Debian Codegraph @

addons/point_of_sale/tests/test_anglo_saxon.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from unittest import skip
5
6 from odoo import Command
7 from odoo.tests import tagged
8 from odoo.addons.account.tests.common import AccountTestInvoicingCommon
9
10
11 class TestAngloSaxonCommon(AccountTestInvoicingCommon):
12
13 @classmethod
14 def setUpClass(cls):
15 super().setUpClass()
16 cls.env.user.group_ids |= cls.env.ref('point_of_sale.group_pos_manager')
17 cls.PosMakePayment = cls.env['pos.make.payment']
18 cls.PosOrder = cls.env['pos.order']
19 cls.Statement = cls.env['account.bank.statement']
20 cls.company = cls.env.company
21 cls.warehouse = cls.env['stock.warehouse'].search([('company_id', '=', cls.env.company.id)], limit=1)
22 cls.partner = cls.env['res.partner'].create({'name': 'Partner 1'})
23 cls.category = cls.env.ref('product.product_category_services')
24 cls.category = cls.category.copy({'name': 'New category','property_valuation': 'real_time'})
25 cls.account = cls.env['account.account'].create({'name': 'Receivable', 'code': 'RCV00', 'account_type': 'asset_receivable', 'reconcile': True})
26 account_expense = cls.env['account.account'].create({'name': 'Expense', 'code': 'EXP00', 'account_type': 'expense', 'reconcile': True})
27 account_income = cls.env['account.account'].create({'name': 'Income', 'code': 'INC00', 'account_type': 'income', 'reconcile': True})
28 account_valuation = cls.env['account.account'].create({'name': 'Valuation', 'code': 'STV00', 'account_type': 'expense', 'reconcile': True})
29 cls.partner.property_account_receivable_id = cls.account
30 cls.category.property_account_income_categ_id = account_income
31 cls.category.property_account_expense_categ_id = account_expense
32 cls.category.property_stock_valuation_account_id = account_valuation
33 cls.category.property_stock_journal = cls.env['account.journal'].create({'name': 'Stock journal', 'type': 'sale', 'code': 'STK00'})
34 cls.cash_journal = cls.env['account.journal'].create(
35 {'name': 'CASH journal', 'type': 'cash', 'code': 'CSH02'})
36 cls.cash_payment_method = cls.env['pos.payment.method'].create({
37 'name': 'Cash Test',
38 'journal_id': cls.cash_journal.id,
39 })
40 cls.pos_config = cls.env['pos.config'].create({
41 'name': 'New POS config',
42 'payment_method_ids': cls.cash_payment_method,
43 })
44 cls.product = cls.env['product.product'].create({
45 'name': 'New product',
46 'standard_price': 100,
47 'available_in_pos': True,
48 'is_storable': True,
49 })
50 cls.company.anglo_saxon_accounting = True
51 cls.company.point_of_sale_update_stock_quantities = 'real'
52 cls.product.categ_id = cls.category
53 cls.product.property_account_expense_id = account_expense
54 cls.product.property_account_income_id = account_income
55 sale_journal = cls.env['account.journal'].create({'name': 'POS journal', 'type': 'sale', 'code': 'POS00'})
56 cls.pos_config.journal_id = sale_journal
57 cls.cash_journal = cls.env['account.journal'].create({'name': 'CASH journal', 'type': 'cash', 'code': 'CSH00'})
58 cls.sale_journal = cls.env['account.journal'].create({'name': 'SALE journal', 'type': 'sale', 'code': 'INV00'})
59 cls.pos_config.invoice_journal_id = cls.sale_journal
60 cls.cash_payment_method = cls.env['pos.payment.method'].create({
61 'name': 'Cash Test',
62 'journal_id': cls.cash_journal.id,
63 'receivable_account_id': cls.account.id,
64 })
65 cls.pos_config.write({'payment_method_ids': [(6, 0, cls.cash_payment_method.ids)]})
66
67
68 @tagged('post_install', '-at_install')
69 class TestAngloSaxonFlow(TestAngloSaxonCommon):
70
71 @skip('Temporary to fast merge new valuation')
72 def test_create_account_move_line(self):
73 # This test will check that the correct journal entries are created when a product in real time valuation
74 # is sold in a company using anglo-saxon
75 self.pos_config.open_ui()
76 current_session = self.pos_config.current_session_id
77 self.cash_journal.loss_account_id = self.account
78 current_session.set_opening_control(0, None)
79
80 # I create a PoS order with 1 unit of New product at 450 EUR
81 self.pos_order_pos0 = self.PosOrder.create({
82 'company_id': self.company.id,
83 'partner_id': self.partner.id,
84 'pricelist_id': self.company.partner_id.property_product_pricelist.id,
85 'session_id': self.pos_config.current_session_id.id,
86 'lines': [(0, 0, {
87 'name': "OL/0001",
88 'product_id': self.product.id,
89 'price_unit': 450,
90 'discount': 0.0,
91 'qty': 1.0,
92 'price_subtotal': 450,
93 'price_subtotal_incl': 450,
94 })],
95 'amount_total': 450,
96 'amount_tax': 0,
97 'amount_paid': 0,
98 'amount_return': 0,
99 'last_order_preparation_change': '{}'
100 })
101
102 # I make a payment to fully pay the order
103 context_make_payment = {"active_ids": [self.pos_order_pos0.id], "active_id": self.pos_order_pos0.id}
104 self.pos_make_payment_0 = self.PosMakePayment.with_context(context_make_payment).create({
105 'amount': 450.0,
106 'payment_method_id': self.cash_payment_method.id,
107 })
108
109 # I click on the validate button to register the payment.
110 context_payment = {'active_id': self.pos_order_pos0.id}
111 self.pos_make_payment_0.with_context(context_payment).check()
112
113 # I check that the order is marked as paid
114 self.assertEqual(self.pos_order_pos0.state, 'paid', 'Order should be in paid state.')
115 self.assertEqual(self.pos_order_pos0.amount_paid, 450, 'Amount paid for the order should be updated.')
116
117 # I close the current session to generate the journal entries
118 current_session_id = self.pos_config.current_session_id
119 current_session_id.post_closing_cash_details(450.0)
120 current_session_id.close_session_from_ui()
121 self.assertEqual(current_session_id.state, 'closed', 'Check that session is closed')
122
123 # Check if there is account_move in the order.
124 # There shouldn't be because the order is not invoiced.
125 self.assertFalse(self.pos_order_pos0.account_move, 'There should be no invoice in the order.')
126
127 # I test that the generated journal entries are correct.
128 expense_account = self.category.property_account_expense_categ_id
129 valuation_account = self.category.property_stock_valuation_account_id
130 aml = current_session.move_id.line_ids
131 aml_output = aml.filtered(lambda l: l.account_id.id == valuation_account.id)
132 aml_expense = aml.filtered(lambda l: l.account_id.id == expense_account.id)
133 self.assertEqual(aml_output.credit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
134 self.assertEqual(aml_expense.debit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
135
136 def _prepare_pos_order(self):
137 """ Set the cost method of `self.product` as FIFO. Receive 5@5 and 5@1 and
138 create a `pos.order` record selling 7 units @ 450.
139 """
140 # check fifo Costing Method of product.category
141 self.product.categ_id.property_cost_method = 'fifo'
142 self.product.standard_price = 5.0
143 self.env['stock.quant'].with_context(inventory_mode=True).create({
144 'product_id': self.product.id,
145 'inventory_quantity': 5.0,
146 'location_id': self.warehouse.lot_stock_id.id,
147 }).action_apply_inventory()
148 self.product.standard_price = 1.0
149 self.env['stock.quant'].with_context(inventory_mode=True).create({
150 'product_id': self.product.id,
151 'inventory_quantity': 10.0,
152 'location_id': self.warehouse.lot_stock_id.id,
153 }).action_apply_inventory()
154 self.assertEqual(self.product.total_value, 30, "Value should be (5*5 + 5*1) = 30")
155 self.assertEqual(self.product.virtual_available, 10)
156
157
158 self.pos_config.open_ui()
159 pos_session = self.pos_config.current_session_id
160 pos_session.set_opening_control(0, None)
161
162 pos_order_values = {
163 'company_id': self.company.id,
164 'partner_id': self.partner.id,
165 'pricelist_id': self.company.partner_id.property_product_pricelist.id,
166 'session_id': self.pos_config.current_session_id.id,
167 'lines': [(0, 0, {
168 'name': "OL/0001",
169 'product_id': self.product.id,
170 'price_unit': 450,
171 'discount': 0.0,
172 'qty': 7.0,
173 'price_subtotal': 7 * 450,
174 'price_subtotal_incl': 7 * 450,
175 })],
176 'amount_total': 7 * 450,
177 'amount_tax': 0,
178 'amount_paid': 0,
179 'amount_return': 0,
180 'last_order_preparation_change': '{}'
181 }
182
183 return self.PosOrder.create(pos_order_values)
184
185 @skip('Temporary to fast merge new valuation')
186 def test_fifo_valuation_no_invoice(self):
187 """Register a payment and validate a session after selling a fifo
188 product without making an invoice for the customer"""
189 pos_order_pos0 = self._prepare_pos_order()
190 context_make_payment = {"active_ids": [pos_order_pos0.id], "active_id": pos_order_pos0.id}
191 self.pos_make_payment_0 = self.PosMakePayment.with_context(context_make_payment).create({
192 'amount': 7 * 450.0,
193 'payment_method_id': self.cash_payment_method.id,
194 })
195
196 # register the payment
197 context_payment = {'active_id': pos_order_pos0.id}
198 self.pos_make_payment_0.with_context(context_payment).check()
199
200 # validate the session
201 current_session_id = self.pos_config.current_session_id
202 current_session_id.post_closing_cash_details(7 * 450.0)
203 current_session_id.close_session_from_ui()
204
205 # check the anglo saxon move lines
206 # with uninvoiced orders, the account_move field of pos.order is empty.
207 # the accounting lines are in move_id of pos.session.
208 session_move = pos_order_pos0.session_id.move_id
209 line = session_move.line_ids.filtered(lambda l: l.debit and l.account_id == self.category.property_account_expense_categ_id)
210 self.assertEqual(session_move.journal_id, self.pos_config.journal_id)
211 self.assertEqual(line.debit, 27, 'As it is a fifo product, the move\'s value should be 5*5 + 2*1')
212
213 def test_fifo_valuation_with_invoice(self):
214 """Register a payment and validate a session after selling a fifo
215 product and make an invoice for the customer"""
216 pos_order_pos0 = self._prepare_pos_order()
217 context_make_payment = {"active_ids": [pos_order_pos0.id], "active_id": pos_order_pos0.id}
218 self.pos_make_payment_0 = self.PosMakePayment.with_context(context_make_payment).create({
219 'amount': 7 * 450.0,
220 'payment_method_id': self.cash_payment_method.id,
221 })
222
223 # register the payment
224 context_payment = {'active_id': pos_order_pos0.id}
225 self.pos_make_payment_0.with_context(context_payment).check()
226
227 # Create the customer invoice
228 pos_order_pos0.action_pos_order_invoice()
229
230 # check the anglo saxon move lines
231 line = pos_order_pos0.account_move.line_ids.filtered(lambda l: l.debit and l.account_id == self.category.property_account_expense_categ_id)
232 self.assertEqual(pos_order_pos0.account_move.journal_id, self.pos_config.invoice_journal_id)
233 self.assertEqual(line.debit, 27, 'As it is a fifo product, the move\'s value should be 5*5 + 2*1')
234
235 @skip('Temporary to fast merge new valuation')
236 def test_cogs_with_ship_later_no_invoicing(self):
237 # This test will check that the correct journal entries are created when a product in real time valuation
238 # is sold using the ship later option and no invoice is created in a company using anglo-saxon
239 self.pos_config.open_ui()
240 current_session = self.pos_config.current_session_id
241 self.cash_journal.loss_account_id = self.account
242 current_session.set_opening_control(0, None)
243
244 # 2 step delivery method
245 self.warehouse.delivery_steps = 'pick_ship'
246
247 # I create a PoS order with 1 unit of New product at 450 EUR
248 self.pos_order_pos0 = self.PosOrder.create({
249 'company_id': self.company.id,
250 'partner_id': self.partner.id,
251 'pricelist_id': self.company.partner_id.property_product_pricelist.id,
252 'session_id': self.pos_config.current_session_id.id,
253 'to_invoice': False,
254 'shipping_date': '2023-01-01',
255 'lines': [(0, 0, {
256 'name': "OL/0001",
257 'product_id': self.product.id,
258 'price_unit': 450,
259 'discount': 0.0,
260 'qty': 1.0,
261 'price_subtotal': 450,
262 'price_subtotal_incl': 450,
263 })],
264 'amount_total': 450,
265 'amount_tax': 0,
266 'amount_paid': 0,
267 'amount_return': 0,
268 'last_order_preparation_change': '{}'
269 })
270
271 # I make a payment to fully pay the order
272 context_make_payment = {"active_ids": [self.pos_order_pos0.id], "active_id": self.pos_order_pos0.id}
273 self.pos_make_payment_0 = self.PosMakePayment.with_context(context_make_payment).create({
274 'amount': 450.0,
275 'payment_method_id': self.cash_payment_method.id,
276 })
277
278 # I click on the validate button to register the payment.
279 context_payment = {'active_id': self.pos_order_pos0.id}
280 self.pos_make_payment_0.with_context(context_payment).check()
281
282 # I close the current session to generate the journal entries
283 current_session_id = self.pos_config.current_session_id
284 current_session_id.post_closing_cash_details(450.0)
285 current_session_id.close_session_from_ui()
286 self.assertEqual(current_session_id.state, 'closed', 'Check that session is closed')
287
288 self.assertEqual(len(current_session.picking_ids), 1, "There should be 2 pickings")
289 current_session.picking_ids.move_ids.write({'quantity': 1, 'picked': True})
290 current_session.picking_ids.button_validate()
291 self.assertEqual(len(current_session.picking_ids), 2, "There should be 2 pickings")
292 current_session.picking_ids.button_validate()
293
294 # I test that the generated journal entries are correct.
295 account_output = self.category.property_stock_account_output_categ_id
296 expense_account = self.category.property_account_expense_categ_id
297 aml = current_session._get_related_account_moves().line_ids
298 aml_output = aml.filtered(lambda l: l.account_id.id == account_output.id)
299 aml_expense = aml.filtered(lambda l: l.account_id.id == expense_account.id)
300
301 self.assertEqual(len(aml_output), 2, "There should be 2 output account move lines")
302 # 2 moves in POS journal (Pos order + manual entry at delivery)
303 self.assertEqual(len(aml_output.move_id.filtered(lambda l: l.journal_id == self.pos_config.journal_id)), 1)
304 # 1 move in stock journal (delivery from stock layers)
305 self.assertEqual(len(aml_output.move_id.filtered(lambda l: l.journal_id == self.category.property_stock_journal)), 1)
306 #Check the lines created after the picking validation
307 self.assertEqual(aml_output[1].credit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
308 self.assertEqual(aml_output[1].debit, 0.0, "Cost of Good Sold entry missing or mismatching")
309 self.assertEqual(aml_expense[0].debit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
310 self.assertEqual(aml_expense[0].credit, 0.0, "Cost of Good Sold entry missing or mismatching")
311 #Check the lines created by the PoS session
312 self.assertEqual(aml_output[0].debit, 100.0, "Cost of Good Sold entry missing or mismatching")
313 self.assertEqual(aml_output[0].credit, 0.0, "Cost of Good Sold entry missing or mismatching")
314
315 @skip('Temporary to fast merge new valuation')
316 def test_action_pos_order_invoice(self):
317 self.company.point_of_sale_update_stock_quantities = 'closing'
318
319 # Setup a running session, with a paid pos order that is not invoiced
320 self.pos_config.open_ui()
321 current_session = self.pos_config.current_session_id
322 self.pos_order_pos0 = self.PosOrder.create({
323 'company_id': self.company.id,
324 'partner_id': self.partner.id,
325 'session_id': self.pos_config.current_session_id.id,
326 'lines': [(0, 0, {
327 'product_id': self.product.id,
328 'price_unit': 450,
329 'qty': 1.0,
330 'price_subtotal': 450,
331 'price_subtotal_incl': 450,
332 })],
333 'amount_total': 450,
334 'amount_tax': 0,
335 'amount_paid': 0,
336 'amount_return': 0,
337 })
338 context_make_payment = {"active_ids": [self.pos_order_pos0.id], "active_id": self.pos_order_pos0.id}
339 self.pos_make_payment_0 = self.PosMakePayment.with_context(context_make_payment).create({
340 'amount': 450.0,
341 'payment_method_id': self.cash_payment_method.id,
342 })
343 context_payment = {'active_id': self.pos_order_pos0.id}
344 self.pos_make_payment_0.with_context(context_payment).check()
345
346 # Invoice the pos order afterward (session still running)
347 self.pos_order_pos0.action_pos_order_invoice()
348
349 # Check that the stock output journal item from the invoice is reconciled (with its counterpart from the valuation entry)
350 stock_output_account = self.category.property_stock_account_output_categ_id
351 related_amls = current_session._get_related_account_moves().line_ids
352 stock_output_amls = related_amls.filtered_domain([('account_id', '=', stock_output_account.id)])
353
354 self.assertTrue(all(stock_output_amls.mapped('reconciled')))
355
356 def test_action_pos_order_invoice_with_discount(self):
357 """This test make sure that the line containing 'Discoun from' is correctly added to the invoice"""
358
359 # Setup a running session, with a paid pos order that is not invoiced
360 self.pos_config.open_ui()
361 pricelist = self.env['product.pricelist'].create({
362 'name': 'Test Pricelist',
363 'item_ids': [
364 Command.create({
365 'compute_price': 'percentage',
366 'percent_price': '5.0',
367 'min_quantity': 0,
368 'applied_on': '3_global',
369 })
370 ],
371 })
372 self.product.lst_price = 100
373 self.pos_order_pos0 = self.PosOrder.create({
374 'company_id': self.company.id,
375 'partner_id': self.partner.id,
376 'session_id': self.pos_config.current_session_id.id,
377 'pricelist_id': pricelist.id,
378 'lines': [(0, 0, {
379 'product_id': self.product.id,
380 'price_unit': 95,
381 'qty': 1.0,
382 'tax_ids': [(6, 0, self.tax_purchase_a.ids)],
383 'price_subtotal': 90.25,
384 'price_subtotal_incl': 103.79,
385 'discount': 5,
386 })],
387 'amount_total': 103.79,
388 'amount_tax': 13.51,
389 'amount_paid': 0,
390 'amount_return': 0,
391 'to_invoice': True,
392 })
393 context_make_payment = {"active_ids": [self.pos_order_pos0.id], "active_id": self.pos_order_pos0.id}
394 self.pos_make_payment_0 = self.PosMakePayment.with_context(context_make_payment).create({
395 'amount': 450.0,
396 'payment_method_id': self.cash_payment_method.id,
397 })
398 context_payment = {'active_id': self.pos_order_pos0.id}
399 self.pos_make_payment_0.with_context(context_payment).check()
400
401 res = self.pos_order_pos0.action_pos_order_invoice()
402 invoice = self.env['account.move'].browse(res['res_id'])
403 self.assertTrue('Price discount from 100.00 to 95.00' in invoice.invoice_line_ids.filtered(lambda l: l.display_type == "line_note").display_name)
404 product_line = invoice.invoice_line_ids.filtered(lambda l: l.display_type == "product")
405 self.assertEqual(product_line.price_unit, 95) # Only pricelist applies
406 self.assertEqual(product_line.discount, 5) # Disount is reflected
407 self.assertEqual(product_line.price_subtotal, 90.25) # Discount applies on price_unit
408 self.assertEqual(product_line.price_total, 103.79) # Taxes applied with price_total
409
410 @skip('Temporary to fast merge new valuation')
411 def test_cogs_with_ship_later_with_backorder(self):
412 # This test will check that the correct journal entries are created when 2 products are sold
413 # using the ship later option and one of them is processed in a backorder
414 self.pos_config.open_ui()
415 current_session = self.pos_config.current_session_id
416 self.cash_journal.loss_account_id = self.account
417 current_session.set_opening_control(0, None)
418
419 # Create 2 product one with no cost and one with a cost of 20 EUR
420 self.product_2 = self.env['product.product'].create({
421 'name': 'New product 2',
422 'standard_price': 20,
423 'available_in_pos': True,
424 'is_storable': True,
425 'categ_id': self.category.id,
426 })
427
428 self.product_1 = self.env['product.product'].create({
429 'name': 'New product 1',
430 'standard_price': 0,
431 'available_in_pos': True,
432 'is_storable': True,
433 'categ_id': self.category.id,
434 })
435
436 # I create a PoS order with 1 unit of New product at 450 EUR
437 self.pos_order_pos0 = self.PosOrder.create({
438 'company_id': self.company.id,
439 'partner_id': self.partner.id,
440 'pricelist_id': self.company.partner_id.property_product_pricelist.id,
441 'session_id': self.pos_config.current_session_id.id,
442 'to_invoice': False,
443 'shipping_date': '2023-01-01',
444 'lines': [(0, 0, {
445 'name': "OL/0001",
446 'product_id': self.product_1.id,
447 'price_unit': 100,
448 'discount': 0.0,
449 'qty': 1.0,
450 'price_subtotal': 100,
451 'price_subtotal_incl': 100,
452 }), (0, 0, {
453 'name': "OL/0002",
454 'product_id': self.product_2.id,
455 'price_unit': 200,
456 'discount': 0.0,
457 'qty': 1.0,
458 'price_subtotal': 200,
459 'price_subtotal_incl': 200,
460 })],
461 'amount_total': 300,
462 'amount_tax': 0,
463 'amount_paid': 0,
464 'amount_return': 0,
465 'last_order_preparation_change': '{}'
466 })
467
468 # I make a payment to fully pay the order
469 context_make_payment = {"active_ids": [self.pos_order_pos0.id], "active_id": self.pos_order_pos0.id}
470 self.pos_make_payment_0 = self.PosMakePayment.with_context(context_make_payment).create({
471 'amount': 300.0,
472 'payment_method_id': self.cash_payment_method.id,
473 })
474
475 # I click on the validate button to register the payment.
476 context_payment = {'active_id': self.pos_order_pos0.id}
477 self.pos_make_payment_0.with_context(context_payment).check()
478
479 # I close the current session to generate the journal entries
480 current_session_id = self.pos_config.current_session_id
481 current_session_id.post_closing_cash_details(300.0)
482 current_session_id.close_session_from_ui()
483 self.assertEqual(current_session_id.state, 'closed', 'Check that session is closed')
484
485 current_session.picking_ids.move_ids.filtered(lambda m: m.product_id == self.product_2).write({'quantity': 1, 'picked': True})
486 res_dict = current_session.picking_ids.button_validate()
487 self.env['stock.backorder.confirmation'].with_context(res_dict['context']).process()
488
489 # I test that the generated journal entries are correct.
490 out = self.product_1.categ_id.property_stock_account_output_categ_id
491 exp = self.product_1._get_product_accounts()['expense']
492 aml = current_session._get_related_account_moves().line_ids
493 aml_output = aml.filtered(lambda l: l.account_id.id == out.id and l.journal_id == self.pos_config.journal_id)
494 aml_expense = aml.filtered(lambda l: l.account_id.id == exp.id and l.journal_id == self.pos_config.journal_id)
495
496 self.assertEqual(len(aml_expense), 1, "There should be 1 output account move lines")
497 self.assertEqual(aml_expense.debit, 20)
498 self.assertEqual(aml_expense.credit, 0)
499
500 self.assertEqual(len(aml_output), 1, "There should be 1 output account move lines")
501 self.assertEqual(aml_output.debit, 0)
502 self.assertEqual(aml_output.credit, 20)
503
504 backorder_picking = current_session.picking_ids.filtered(lambda p: p.state == 'confirmed')
505 backorder_picking.move_ids.write({'quantity': 1, 'picked': True})
506 backorder_picking.button_validate()
507
508 # As the second item has no cost, the account move line should be the same as before
509 aml = current_session._get_related_account_moves().line_ids
510 aml_output = aml.filtered(lambda l: l.account_id.id == out.id and l.journal_id == self.pos_config.journal_id)
511 aml_expense = aml.filtered(lambda l: l.account_id.id == exp.id and l.journal_id == self.pos_config.journal_id)
512
513 self.assertEqual(len(aml_expense), 1, "There should be 1 output account move lines")
514 self.assertEqual(aml_expense.debit, 20)
515 self.assertEqual(aml_expense.credit, 0)
516
517 self.assertEqual(len(aml_output), 1, "There should be 1 output account move lines")
518 self.assertEqual(aml_output.debit, 0)
519 self.assertEqual(aml_output.credit, 20)
520
521 def test_cogs_multi_products_perpetual(self):
522 """
523 Check that an order with mutliple products that is invoiced
524 in anglo saxon perpetual posts its stock valuation entries
525 """
526 self.category.property_valuation = 'real_time'
527 self.product.write({
528 'categ_id': self.category,
529 'standard_price': 20,
530 'list_price': 100
531 })
532 product2 = self.env['product.product'].create({
533 'name': 'P2',
534 'categ_id': self.category.id,
535 'standard_price': 100,
536 'list_price': 200,
537 'available_in_pos': True,
538 'is_storable': True,
539 })
540
541 self.pos_config.open_ui()
542 pos_session = self.pos_config.current_session_id
543 pos_session.set_opening_control(0, None)
544
545 # create order
546 pos_order_values = {
547 'company_id': self.company.id,
548 'partner_id': self.partner.id,
549 'session_id': self.pos_config.current_session_id.id,
550 'lines': [Command.create({
551 'product_id': self.product.id,
552 'price_unit': 100,
553 'discount': 0.0,
554 'qty': 1.0,
555 'price_subtotal': 100,
556 'price_subtotal_incl': 100,
557 }), Command.create({
558 'product_id': product2.id,
559 'price_unit': 200,
560 'discount': 0.0,
561 'qty': 1.0,
562 'price_subtotal': 200,
563 'price_subtotal_incl': 200,
564 })],
565 'amount_total': 300,
566 'amount_tax': 0,
567 'amount_paid': 0,
568 'amount_return': 0,
569 'last_order_preparation_change': '{}',
570 'to_invoice': True,
571 }
572 pos_order = self.PosOrder.create(pos_order_values)
573
574 # register payment
575 context_make_payment = {"active_ids": [pos_order.id], "active_id": pos_order.id}
576 pos_payment = self.PosMakePayment.with_context(context_make_payment).create({
577 'amount': 300.0,
578 'payment_method_id': self.cash_payment_method.id,
579 })
580 context_payment = {'active_id': pos_order.id}
581 pos_payment.with_context(context_payment).check()
582
583 valuation_account = self.category.property_stock_valuation_account_id
584 valuation_lines = pos_order.account_move.line_ids.filtered(lambda line: line.account_id == valuation_account)
585
586 self.assertRecordValues(valuation_lines.sorted(lambda aml: aml.product_id.id), [
587 {'product_id': self.product.id, 'credit': 20.0},
588 {'product_id': product2.id, 'credit': 100.0},
589 ])