| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from datetime import datetime |
| 4 |
import odoo |
| 5 |
from odoo.addons.mail.tests.common import mail_new_test_user |
| 6 |
from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon |
| 7 |
|
| 8 |
@odoo.tests.tagged('post_install', '-at_install') |
| 9 |
class TestPoSController(TestPointOfSaleHttpCommon): |
| 10 |
def test_qr_code_receipt(self): |
| 11 |
"""This test make sure that no user is created when a partner is set on the PoS order. |
| 12 |
It also makes sure that the invoice is correctly created. |
| 13 |
""" |
| 14 |
self.authenticate(None, None) |
| 15 |
self.new_partner = self.env['res.partner'].create({ |
| 16 |
'name': 'AAA Partner', |
| 17 |
'zip': '12345', |
| 18 |
'state_id': self.env.ref('base.state_us_1').id, |
| 19 |
'country_id': self.env.ref('base.us').id, |
| 20 |
}) |
| 21 |
self.product1 = self.env['product.product'].create({ |
| 22 |
'name': 'Test Product 1', |
| 23 |
'is_storable': True, |
| 24 |
'list_price': 10.0, |
| 25 |
'taxes_id': False, |
| 26 |
}) |
| 27 |
self.main_pos_config.open_ui() |
| 28 |
self.pos_order = self.env['pos.order'].create({ |
| 29 |
'company_id': self.env.company.id, |
| 30 |
'session_id': self.main_pos_config.current_session_id.id, |
| 31 |
'partner_id': self.new_partner.id, |
| 32 |
'access_token': '1234567890', |
| 33 |
'lines': [(0, 0, { |
| 34 |
'name': "OL/0001", |
| 35 |
'product_id': self.product1.id, |
| 36 |
'price_unit': 10, |
| 37 |
'discount': 0.0, |
| 38 |
'qty': 1.0, |
| 39 |
'tax_ids': False, |
| 40 |
'price_subtotal': 10, |
| 41 |
'price_subtotal_incl': 10, |
| 42 |
})], |
| 43 |
'amount_tax': 10, |
| 44 |
'amount_total': 10, |
| 45 |
'amount_paid': 10.0, |
| 46 |
'amount_return': 10.0, |
| 47 |
}) |
| 48 |
self.main_pos_config.current_session_id.close_session_from_ui() |
| 49 |
get_invoice_data = { |
| 50 |
'access_token': self.pos_order.access_token, |
| 51 |
'name': self.new_partner.name, |
| 52 |
'email': "[email protected]", |
| 53 |
'company_name': self.new_partner.company_name, |
| 54 |
'vat': self.new_partner.vat, |
| 55 |
'street': "Test street", |
| 56 |
'city': "Test City", |
| 57 |
'zipcode': self.new_partner.zip, |
| 58 |
'country_id': self.new_partner.country_id.id, |
| 59 |
'state_id': self.new_partner.state_id.id, |
| 60 |
'phone': "123456789", |
| 61 |
'csrf_token': odoo.http.Request.csrf_token(self) |
| 62 |
} |
| 63 |
self.url_open(f'/pos/ticket/validate?access_token={self.pos_order.access_token}', data=get_invoice_data) |
| 64 |
self.assertEqual(self.env['res.partner'].sudo().search_count([('name', '=', 'AAA Partner')]), 1) |
| 65 |
self.assertTrue(self.pos_order.is_invoiced, "The pos order should have an invoice") |
| 66 |
self.assertTrue(len(self.pos_order.pos_reference) >= 12, "The pos reference should not be less than 12 characters") |
| 67 |
|
| 68 |
def test_qr_code_receipt_user_connected(self): |
| 69 |
"""This test make sure that when the user is already connected he correctly gets redirected to the invoice.""" |
| 70 |
self.partner_1 = self.env['res.partner'].create({ |
| 71 |
'name': 'Valid Lelitre', |
| 72 |
'email': '[email protected]', |
| 73 |
}) |
| 74 |
self.partner_1_user = mail_new_test_user( |
| 75 |
self.env, |
| 76 |
name=self.partner_1.name, |
| 77 |
login='partner_1', |
| 78 |
email=self.partner_1.email, |
| 79 |
groups='base.group_portal', |
| 80 |
) |
| 81 |
self.authenticate('partner_1', 'partner_1') |
| 82 |
|
| 83 |
self.product1 = self.env['product.product'].create({ |
| 84 |
'name': 'Test Product 1', |
| 85 |
'is_storable': True, |
| 86 |
'list_price': 10.0, |
| 87 |
'taxes_id': False, |
| 88 |
}) |
| 89 |
self.main_pos_config.open_ui() |
| 90 |
self.pos_order = self.env['pos.order'].create({ |
| 91 |
'session_id': self.main_pos_config.current_session_id.id, |
| 92 |
'company_id': self.env.company.id, |
| 93 |
'access_token': '1234567890', |
| 94 |
'lines': [(0, 0, { |
| 95 |
'name': "OL/0001", |
| 96 |
'product_id': self.product1.id, |
| 97 |
'price_unit': 10, |
| 98 |
'discount': 0.0, |
| 99 |
'qty': 1.0, |
| 100 |
'tax_ids': False, |
| 101 |
'price_subtotal': 10, |
| 102 |
'price_subtotal_incl': 10, |
| 103 |
})], |
| 104 |
'amount_tax': 10, |
| 105 |
'amount_total': 10, |
| 106 |
'amount_paid': 10.0, |
| 107 |
'amount_return': 10.0, |
| 108 |
}) |
| 109 |
self.main_pos_config.current_session_id.close_session_from_ui() |
| 110 |
res = self.url_open(f'/pos/ticket/validate?access_token={self.pos_order.access_token}', timeout=30000) |
| 111 |
self.assertTrue(self.pos_order.is_invoiced, "The pos order should have an invoice") |
| 112 |
self.assertTrue("my/invoices" in res.url) |
| 113 |
|
| 114 |
def test_qr_code_receipt_user_not_connected(self): |
| 115 |
"""This test make sure that when the user is not connected (public user). Order should invoiced with public user data.""" |
| 116 |
|
| 117 |
self.product1 = self.env['product.product'].create({ |
| 118 |
'name': 'Test Product 1', |
| 119 |
'is_storable': True, |
| 120 |
'list_price': 10.0, |
| 121 |
'taxes_id': False, |
| 122 |
}) |
| 123 |
self.main_pos_config.open_ui() |
| 124 |
self.pos_order = self.env['pos.order'].create({ |
| 125 |
'session_id': self.main_pos_config.current_session_id.id, |
| 126 |
'company_id': self.env.company.id, |
| 127 |
'access_token': '1234567890', |
| 128 |
'lines': [(0, 0, { |
| 129 |
'name': "Test Product 1", |
| 130 |
'product_id': self.product1.id, |
| 131 |
'price_unit': 10, |
| 132 |
'tax_ids': False, |
| 133 |
'price_subtotal': 10, |
| 134 |
'price_subtotal_incl': 10, |
| 135 |
})], |
| 136 |
'amount_tax': 10, |
| 137 |
'amount_total': 10, |
| 138 |
'amount_paid': 10.0, |
| 139 |
'amount_return': 10.0, |
| 140 |
'pos_reference': '2500-002-00002', |
| 141 |
'ticket_code': 'inPoS', |
| 142 |
'date_order': datetime.today(), |
| 143 |
}) |
| 144 |
context_make_payment = {"active_ids": [self.pos_order.id], "active_id": self.pos_order.id} |
| 145 |
self.pos_make_payment = self.env['pos.make.payment'].with_context(context_make_payment).create({ |
| 146 |
'amount': 10.0, |
| 147 |
'payment_method_id': self.main_pos_config.payment_method_ids[0].id, |
| 148 |
}) |
| 149 |
context_payment = {'active_id': self.pos_order.id} |
| 150 |
self.pos_make_payment.with_context(context_payment).check() |
| 151 |
self.main_pos_config.current_session_id.close_session_from_ui() |
| 152 |
self.start_tour('/pos/ticket', 'invoicePoSOrderWithSelfInvocing', login=None) |
| 153 |
self.assertTrue(self.pos_order.account_move, "The pos order should have an invoice after self invoicing") |
| 154 |
|
| 155 |
def test_qr_code_receipt_user_updated(self): |
| 156 |
"""This test make sure that when the user is already connected he correctly gets redirected to the invoice.""" |
| 157 |
self.authenticate(None, None) |
| 158 |
self.partner_1 = self.env['res.partner'].create({ |
| 159 |
'name': 'Valid Lelitre', |
| 160 |
'email': '[email protected]', |
| 161 |
}) |
| 162 |
|
| 163 |
self.product1 = self.env['product.product'].create({ |
| 164 |
'name': 'Test Product 1', |
| 165 |
'is_storable': True, |
| 166 |
'list_price': 10.0, |
| 167 |
'taxes_id': False, |
| 168 |
}) |
| 169 |
self.main_pos_config.open_ui() |
| 170 |
self.pos_order = self.env['pos.order'].create({ |
| 171 |
'session_id': self.main_pos_config.current_session_id.id, |
| 172 |
'company_id': self.env.company.id, |
| 173 |
'partner_id': self.partner_1.id, |
| 174 |
'access_token': '1234567890', |
| 175 |
'lines': [(0, 0, { |
| 176 |
'name': "OL/0001", |
| 177 |
'product_id': self.product1.id, |
| 178 |
'price_unit': 10, |
| 179 |
'discount': 0.0, |
| 180 |
'qty': 1.0, |
| 181 |
'tax_ids': False, |
| 182 |
'price_subtotal': 10, |
| 183 |
'price_subtotal_incl': 10, |
| 184 |
})], |
| 185 |
'amount_tax': 10, |
| 186 |
'amount_total': 10, |
| 187 |
'amount_paid': 10.0, |
| 188 |
'amount_return': 10.0, |
| 189 |
}) |
| 190 |
self.main_pos_config.current_session_id.close_session_from_ui() |
| 191 |
get_invoice_data = { |
| 192 |
'access_token': self.pos_order.access_token, |
| 193 |
'name': 'New Name', |
| 194 |
'email': "[email protected]", |
| 195 |
'vat': 'VAT_TEST_NUMBER_123', |
| 196 |
'street': "Test street", |
| 197 |
'city': "Test City", |
| 198 |
'zipcode': '12345', |
| 199 |
'country_id': self.company.country_id.id, |
| 200 |
'phone': "123456789", |
| 201 |
'state_id': self.env['res.country.state'].search([], limit=1).id, |
| 202 |
'csrf_token': odoo.http.Request.csrf_token(self) |
| 203 |
} |
| 204 |
self.url_open(f'/pos/ticket/validate?access_token={self.pos_order.access_token}', data=get_invoice_data, timeout=30000) |
| 205 |
self.assertEqual(self.partner_1.vat, 'VAT_TEST_NUMBER_123') |
| 206 |
self.assertEqual(self.partner_1.name, 'New Name') |
| 207 |
self.assertEqual(self.partner_1.zip, '12345') |