| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
|
| 4 |
import inspect |
| 5 |
import logging |
| 6 |
import base64 |
| 7 |
import io |
| 8 |
|
| 9 |
from PIL import Image |
| 10 |
from contextlib import contextmanager |
| 11 |
from unittest.mock import patch |
| 12 |
from unittest import skip |
| 13 |
from odoo import Command, api |
| 14 |
|
| 15 |
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT |
| 16 |
from odoo.tests import tagged, loaded_demo_data |
| 17 |
from odoo.addons.account.tests.common import TestTaxCommon, AccountTestInvoicingHttpCommon |
| 18 |
from odoo.addons.point_of_sale.tests.common_setup_methods import setup_product_combo_items |
| 19 |
from datetime import date, timedelta |
| 20 |
from odoo.addons.point_of_sale.tests.common import archive_products |
| 21 |
from odoo.exceptions import UserError |
| 22 |
from freezegun import freeze_time |
| 23 |
|
| 24 |
_logger = logging.getLogger(__name__) |
| 25 |
|
| 26 |
|
| 27 |
def _create_image(color: int | str = 0, dims=(1920, 1080), format='JPEG'): |
| 28 |
f = io.BytesIO() |
| 29 |
Image.new('RGB', dims, color).save(f, format) |
| 30 |
f.seek(0) |
| 31 |
return base64.b64encode(f.read()) |
| 32 |
|
| 33 |
|
| 34 |
class TestPointOfSaleHttpCommon(AccountTestInvoicingHttpCommon): |
| 35 |
|
| 36 |
@classmethod |
| 37 |
def _get_main_company(cls): |
| 38 |
return cls.company_data['company'] |
| 39 |
|
| 40 |
def _get_url(self, pos_config=None): |
| 41 |
pos_config = pos_config or self.main_pos_config |
| 42 |
return f"/pos/ui/{pos_config.id}" |
| 43 |
|
| 44 |
def get_method_additional_tags(self, test_method): |
| 45 |
additional_tags = super().get_method_additional_tags(test_method) |
| 46 |
method_source = inspect.getsource(test_method) |
| 47 |
if "self.start_pos_tour" in method_source: |
| 48 |
additional_tags.append("is_tour") |
| 49 |
return additional_tags |
| 50 |
|
| 51 |
def start_pos_tour(self, tour_name, login="pos_user", **kwargs): |
| 52 |
self.start_tour(self._get_url(pos_config=kwargs.get('pos_config')), tour_name, login=login, **kwargs) |
| 53 |
|
| 54 |
@contextmanager |
| 55 |
def with_new_session(self, config=None, user=None): |
| 56 |
config = config or self.main_pos_config |
| 57 |
user = user or self.pos_user |
| 58 |
config.with_user(user).open_ui() |
| 59 |
session = config.current_session_id |
| 60 |
yield session |
| 61 |
session.post_closing_cash_details(0) |
| 62 |
session.close_session_from_ui() |
| 63 |
|
| 64 |
@classmethod |
| 65 |
def setUpClass(cls): |
| 66 |
super().setUpClass() |
| 67 |
|
| 68 |
env = cls.env |
| 69 |
cls.env.user.group_ids += env.ref('point_of_sale.group_pos_manager') |
| 70 |
journal_obj = env['account.journal'] |
| 71 |
account_obj = env['account.account'] |
| 72 |
main_company = cls._get_main_company() |
| 73 |
|
| 74 |
cls.account_receivable = account_obj.create({'code': 'X1012', |
| 75 |
'name': 'Account Receivable - Test', |
| 76 |
'account_type': 'asset_receivable', |
| 77 |
'reconcile': True}) |
| 78 |
env.company.account_default_pos_receivable_account_id = cls.account_receivable |
| 79 |
env['ir.default'].set('res.partner', 'property_account_receivable_id', cls.account_receivable.id, company_id=main_company.id) |
| 80 |
# Pricelists are set below, do not take demo data into account |
| 81 |
env['res.partner'].sudo().invalidate_model(['property_product_pricelist', 'specific_property_product_pricelist']) |
| 82 |
# remove the all specific values for all companies only for test |
| 83 |
env.cr.execute('UPDATE res_partner SET specific_property_product_pricelist = NULL') |
| 84 |
|
| 85 |
# Create user. |
| 86 |
cls.pos_user = cls.env['res.users'].create({ |
| 87 |
'name': 'A simple PoS man!', |
| 88 |
'login': 'pos_user', |
| 89 |
'password': 'pos_user', |
| 90 |
'group_ids': [ |
| 91 |
(4, cls.env.ref('base.group_user').id), |
| 92 |
(4, cls.env.ref('point_of_sale.group_pos_user').id), |
| 93 |
(4, cls.env.ref('stock.group_stock_user').id), |
| 94 |
], |
| 95 |
'tz': 'America/New_York', |
| 96 |
}) |
| 97 |
cls.pos_admin = cls.env['res.users'].create({ |
| 98 |
'name': 'A powerful PoS man!', |
| 99 |
'login': 'pos_admin', |
| 100 |
'password': 'pos_admin', |
| 101 |
'group_ids': [ |
| 102 |
(4, cls.env.ref('point_of_sale.group_pos_manager').id), |
| 103 |
], |
| 104 |
'tz': 'America/New_York', |
| 105 |
}) |
| 106 |
|
| 107 |
cls.pos_user.partner_id.email = '[email protected]' |
| 108 |
cls.pos_admin.partner_id.email = '[email protected]' |
| 109 |
|
| 110 |
cls.bank_journal = journal_obj.create({ |
| 111 |
'name': 'Bank Test', |
| 112 |
'type': 'bank', |
| 113 |
'company_id': main_company.id, |
| 114 |
'code': 'BNK', |
| 115 |
'sequence': 10, |
| 116 |
}) |
| 117 |
|
| 118 |
cls.bank_payment_method = env['pos.payment.method'].create({ |
| 119 |
'name': 'Bank', |
| 120 |
'journal_id': cls.bank_journal.id, |
| 121 |
'outstanding_account_id': cls.inbound_payment_method_line.payment_account_id.id, |
| 122 |
}) |
| 123 |
env['pos.config'].search([]).unlink() |
| 124 |
cls.main_pos_config = env['pos.config'].create({ |
| 125 |
'name': 'Shop', |
| 126 |
'module_pos_restaurant': False, |
| 127 |
}) |
| 128 |
|
| 129 |
env['res.partner'].create({ |
| 130 |
'name': 'Acme Corporation', |
| 131 |
}) |
| 132 |
|
| 133 |
cash_journal = journal_obj.create({ |
| 134 |
'name': 'Cash Test', |
| 135 |
'type': 'cash', |
| 136 |
'company_id': main_company.id, |
| 137 |
'code': 'CSH', |
| 138 |
'sequence': 10, |
| 139 |
}) |
| 140 |
|
| 141 |
archive_products(env) |
| 142 |
|
| 143 |
cls.tip = env.ref('point_of_sale.product_product_tip') |
| 144 |
|
| 145 |
cls.pos_desk_misc_test = env['pos.category'].create({ |
| 146 |
'name': 'Misc test', |
| 147 |
}) |
| 148 |
cls.pos_cat_chair_test = env['pos.category'].create({ |
| 149 |
'name': 'Chair test', |
| 150 |
}) |
| 151 |
cls.pos_cat_desk_test = env['pos.category'].create({ |
| 152 |
'name': 'Desk test', |
| 153 |
}) |
| 154 |
|
| 155 |
# test an extra price on an attribute |
| 156 |
cls.whiteboard_pen = env['product.template'].create({ |
| 157 |
'name': 'Whiteboard Pen', |
| 158 |
'available_in_pos': True, |
| 159 |
'list_price': 1.20, |
| 160 |
'taxes_id': False, |
| 161 |
'weight': 0.01, |
| 162 |
'to_weight': True, |
| 163 |
'pos_categ_ids': [(4, cls.pos_desk_misc_test.id)], |
| 164 |
}) |
| 165 |
cls.wall_shelf = env['product.template'].create({ |
| 166 |
'name': 'Wall Shelf Unit', |
| 167 |
'available_in_pos': True, |
| 168 |
'list_price': 1.98, |
| 169 |
'taxes_id': False, |
| 170 |
'barcode': '2100005000000', |
| 171 |
}) |
| 172 |
cls.small_shelf = env['product.template'].create({ |
| 173 |
'name': 'Small Shelf', |
| 174 |
'available_in_pos': True, |
| 175 |
'list_price': 2.83, |
| 176 |
'taxes_id': False, |
| 177 |
}) |
| 178 |
cls.magnetic_board = env['product.template'].create({ |
| 179 |
'name': 'Magnetic Board', |
| 180 |
'available_in_pos': True, |
| 181 |
'list_price': 1.98, |
| 182 |
'taxes_id': False, |
| 183 |
'barcode': '2305000000004', |
| 184 |
}) |
| 185 |
cls.monitor_stand = env['product.template'].create({ |
| 186 |
'name': 'Monitor Stand', |
| 187 |
'available_in_pos': True, |
| 188 |
'list_price': 3.19, |
| 189 |
'taxes_id': False, |
| 190 |
'barcode': '0123456789', # No pattern in barcode nomenclature |
| 191 |
}) |
| 192 |
cls.desk_pad = env['product.template'].create({ |
| 193 |
'name': 'Desk Pad', |
| 194 |
'available_in_pos': True, |
| 195 |
'list_price': 1.98, |
| 196 |
'taxes_id': False, |
| 197 |
'pos_categ_ids': [(4, cls.pos_cat_desk_test.id)], |
| 198 |
}) |
| 199 |
cls.letter_tray = env['product.template'].create({ |
| 200 |
'name': 'Letter Tray', |
| 201 |
'available_in_pos': True, |
| 202 |
'list_price': 4.80, |
| 203 |
'taxes_id': False, |
| 204 |
'categ_id': env.ref('product.product_category_services').id, |
| 205 |
'pos_categ_ids': [(4, cls.pos_cat_chair_test.id)], |
| 206 |
}) |
| 207 |
cls.desk_organizer = env['product.template'].create({ |
| 208 |
'name': 'Desk Organizer', |
| 209 |
'available_in_pos': True, |
| 210 |
'list_price': 5.10, |
| 211 |
'taxes_id': False, |
| 212 |
'barcode': '2300002000007', |
| 213 |
}) |
| 214 |
cls.configurable_chair = env['product.template'].create({ |
| 215 |
'name': 'Configurable Chair', |
| 216 |
'available_in_pos': True, |
| 217 |
'list_price': 10, |
| 218 |
'taxes_id': False, |
| 219 |
}) |
| 220 |
|
| 221 |
attribute = env['product.attribute'].create({ |
| 222 |
'name': 'add 2', |
| 223 |
}) |
| 224 |
attribute_value = env['product.attribute.value'].create({ |
| 225 |
'name': 'add 2', |
| 226 |
'attribute_id': attribute.id, |
| 227 |
}) |
| 228 |
line = env['product.template.attribute.line'].create({ |
| 229 |
'product_tmpl_id': cls.whiteboard_pen.id, |
| 230 |
'attribute_id': attribute.id, |
| 231 |
'value_ids': [(6, 0, attribute_value.ids)] |
| 232 |
}) |
| 233 |
line.product_template_value_ids[0].price_extra = 2 |
| 234 |
|
| 235 |
cls.chair_color_attribute = env['product.attribute'].create({ |
| 236 |
'name': 'Color', |
| 237 |
'display_type': 'color', |
| 238 |
'create_variant': 'no_variant', |
| 239 |
}) |
| 240 |
cls.chair_color_red = env['product.attribute.value'].create({ |
| 241 |
'name': 'Red', |
| 242 |
'attribute_id': cls.chair_color_attribute.id, |
| 243 |
'html_color': '#ff0000', |
| 244 |
}) |
| 245 |
chair_color_blue = env['product.attribute.value'].create({ |
| 246 |
'name': 'Blue', |
| 247 |
'attribute_id': cls.chair_color_attribute.id, |
| 248 |
'html_color': '#0000ff', |
| 249 |
}) |
| 250 |
chair_color_line = env['product.template.attribute.line'].create({ |
| 251 |
'product_tmpl_id': cls.configurable_chair.id, |
| 252 |
'attribute_id': cls.chair_color_attribute.id, |
| 253 |
'value_ids': [(6, 0, [cls.chair_color_red.id, chair_color_blue.id])] |
| 254 |
}) |
| 255 |
chair_color_line.product_template_value_ids[0].price_extra = 1 |
| 256 |
|
| 257 |
chair_legs_attribute = env['product.attribute'].create({ |
| 258 |
'name': 'Chair Legs', |
| 259 |
'display_type': 'select', |
| 260 |
'create_variant': 'no_variant', |
| 261 |
}) |
| 262 |
chair_legs_metal = env['product.attribute.value'].create({ |
| 263 |
'name': 'Metal', |
| 264 |
'attribute_id': chair_legs_attribute.id, |
| 265 |
}) |
| 266 |
chair_legs_wood = env['product.attribute.value'].create({ |
| 267 |
'name': 'Wood', |
| 268 |
'attribute_id': chair_legs_attribute.id, |
| 269 |
}) |
| 270 |
env['product.template.attribute.line'].create({ |
| 271 |
'product_tmpl_id': cls.configurable_chair.id, |
| 272 |
'attribute_id': chair_legs_attribute.id, |
| 273 |
'value_ids': [(6, 0, [chair_legs_metal.id, chair_legs_wood.id])] |
| 274 |
}) |
| 275 |
|
| 276 |
cls.chair_fabrics_attribute = env['product.attribute'].create({ |
| 277 |
'name': 'Fabrics', |
| 278 |
'display_type': 'radio', |
| 279 |
'create_variant': 'no_variant', |
| 280 |
}) |
| 281 |
chair_fabrics_leather = env['product.attribute.value'].create({ |
| 282 |
'name': 'Leather', |
| 283 |
'attribute_id': cls.chair_fabrics_attribute.id, |
| 284 |
}) |
| 285 |
cls.chair_fabrics_wool = env['product.attribute.value'].create({ |
| 286 |
'name': 'wool', |
| 287 |
'attribute_id': cls.chair_fabrics_attribute.id, |
| 288 |
}) |
| 289 |
cls.chair_fabrics_other = env['product.attribute.value'].create({ |
| 290 |
'name': 'Other', |
| 291 |
'attribute_id': cls.chair_fabrics_attribute.id, |
| 292 |
'is_custom': True, |
| 293 |
}) |
| 294 |
env['product.template.attribute.line'].create({ |
| 295 |
'product_tmpl_id': cls.configurable_chair.id, |
| 296 |
'attribute_id': cls.chair_fabrics_attribute.id, |
| 297 |
'value_ids': [(6, 0, [chair_fabrics_leather.id, cls.chair_fabrics_wool.id, cls.chair_fabrics_other.id])] |
| 298 |
}) |
| 299 |
chair_color_line.product_template_value_ids[1].is_custom = True |
| 300 |
|
| 301 |
cls.chair_addons_attribute = env['product.attribute'].create({ |
| 302 |
'name': 'Add-ons', |
| 303 |
'display_type': 'multi', |
| 304 |
'create_variant': 'no_variant', |
| 305 |
}) |
| 306 |
cls.chair_addon_cushion = env['product.attribute.value'].create({ |
| 307 |
'name': 'Cushion', |
| 308 |
'attribute_id': cls.chair_addons_attribute.id, |
| 309 |
}) |
| 310 |
cls.chair_addon_cupholder = env['product.attribute.value'].create({ |
| 311 |
'name': 'Cup Holder', |
| 312 |
'attribute_id': cls.chair_addons_attribute.id, |
| 313 |
}) |
| 314 |
cls.chair_addon_headrest = env['product.attribute.value'].create({ |
| 315 |
'name': 'Headrest', |
| 316 |
'attribute_id': cls.chair_addons_attribute.id, |
| 317 |
}) |
| 318 |
env['product.template.attribute.line'].create({ |
| 319 |
'product_tmpl_id': cls.configurable_chair.id, |
| 320 |
'attribute_id': cls.chair_addons_attribute.id, |
| 321 |
'value_ids': [(6, 0, [cls.chair_addon_cushion.id, cls.chair_addon_cupholder.id, cls.chair_addon_headrest.id])] |
| 322 |
}) |
| 323 |
|
| 324 |
fixed_pricelist = env['product.pricelist'].create({ |
| 325 |
'name': 'Fixed', |
| 326 |
'item_ids': [(0, 0, { |
| 327 |
'compute_price': 'fixed', |
| 328 |
'fixed_price': 1, |
| 329 |
}), (0, 0, { |
| 330 |
'compute_price': 'fixed', |
| 331 |
'fixed_price': 2, |
| 332 |
'applied_on': '0_product_variant', |
| 333 |
'product_id': cls.wall_shelf.product_variant_id.id, |
| 334 |
}), (0, 0, { |
| 335 |
'compute_price': 'fixed', |
| 336 |
'fixed_price': 13.95, # test for issues like in 7f260ab517ebde634fc274e928eb062463f0d88f |
| 337 |
'applied_on': '0_product_variant', |
| 338 |
'product_id': cls.small_shelf.product_variant_id.id, |
| 339 |
})], |
| 340 |
}) |
| 341 |
|
| 342 |
env['product.pricelist'].create({ |
| 343 |
'name': 'Percentage', |
| 344 |
'item_ids': [(0, 0, { |
| 345 |
'compute_price': 'percentage', |
| 346 |
'percent_price': 100, |
| 347 |
'applied_on': '0_product_variant', |
| 348 |
'product_id': cls.wall_shelf.product_variant_id.id, |
| 349 |
}), (0, 0, { |
| 350 |
'compute_price': 'percentage', |
| 351 |
'percent_price': 99, |
| 352 |
'applied_on': '0_product_variant', |
| 353 |
'product_id': cls.small_shelf.product_variant_id.id, |
| 354 |
}), (0, 0, { |
| 355 |
'compute_price': 'percentage', |
| 356 |
'percent_price': 0, |
| 357 |
'applied_on': '0_product_variant', |
| 358 |
'product_id': cls.magnetic_board.product_variant_id.id, |
| 359 |
})], |
| 360 |
}) |
| 361 |
|
| 362 |
env['product.pricelist'].create({ |
| 363 |
'name': 'Formula', |
| 364 |
'item_ids': [(0, 0, { |
| 365 |
'compute_price': 'formula', |
| 366 |
'price_discount': 6, |
| 367 |
'price_surcharge': 5, |
| 368 |
'applied_on': '0_product_variant', |
| 369 |
'product_id': cls.wall_shelf.product_variant_id.id, |
| 370 |
}), (0, 0, { |
| 371 |
# .99 prices |
| 372 |
'compute_price': 'formula', |
| 373 |
'price_surcharge': -0.01, |
| 374 |
'price_round': 1, |
| 375 |
'applied_on': '0_product_variant', |
| 376 |
'product_id': cls.small_shelf.product_variant_id.id, |
| 377 |
}), (0, 0, { |
| 378 |
'compute_price': 'formula', |
| 379 |
'price_min_margin': 10, |
| 380 |
'price_max_margin': 100, |
| 381 |
'applied_on': '0_product_variant', |
| 382 |
'product_id': cls.magnetic_board.product_variant_id.id, |
| 383 |
}), (0, 0, { |
| 384 |
'compute_price': 'formula', |
| 385 |
'price_surcharge': 10, |
| 386 |
'price_max_margin': 5, |
| 387 |
'applied_on': '0_product_variant', |
| 388 |
'product_id': cls.monitor_stand.product_variant_id.id, |
| 389 |
}), (0, 0, { |
| 390 |
'compute_price': 'formula', |
| 391 |
'price_discount': -100, |
| 392 |
'price_min_margin': 5, |
| 393 |
'price_max_margin': 20, |
| 394 |
'applied_on': '0_product_variant', |
| 395 |
'product_id': cls.desk_pad.product_variant_id.id, |
| 396 |
})], |
| 397 |
}) |
| 398 |
|
| 399 |
env['product.pricelist'].create({ |
| 400 |
'name': 'min_quantity ordering', |
| 401 |
'item_ids': [(0, 0, { |
| 402 |
'compute_price': 'fixed', |
| 403 |
'fixed_price': 1, |
| 404 |
'applied_on': '0_product_variant', |
| 405 |
'min_quantity': 2, |
| 406 |
'product_id': cls.wall_shelf.product_variant_id.id, |
| 407 |
}), (0, 0, { |
| 408 |
'compute_price': 'fixed', |
| 409 |
'fixed_price': 2, |
| 410 |
'applied_on': '0_product_variant', |
| 411 |
'min_quantity': 1, |
| 412 |
'product_id': cls.wall_shelf.product_variant_id.id, |
| 413 |
}), (0, 0, { |
| 414 |
'compute_price': 'fixed', |
| 415 |
'fixed_price': 1, |
| 416 |
'applied_on': '0_product_variant', |
| 417 |
'min_quantity': 5, |
| 418 |
'product_id': cls.monitor_stand.product_variant_id.id, |
| 419 |
})], |
| 420 |
}) |
| 421 |
|
| 422 |
env['product.pricelist'].create({ |
| 423 |
'name': 'Product template', |
| 424 |
'item_ids': [(0, 0, { |
| 425 |
'compute_price': 'fixed', |
| 426 |
'fixed_price': 1, |
| 427 |
'applied_on': '1_product', |
| 428 |
'product_tmpl_id': cls.wall_shelf.id, |
| 429 |
}), (0, 0, { |
| 430 |
'compute_price': 'fixed', |
| 431 |
'fixed_price': 2, |
| 432 |
})], |
| 433 |
}) |
| 434 |
|
| 435 |
product_category_3 = env['product.category'].create({ |
| 436 |
'name': 'Services', |
| 437 |
'parent_id': env.ref('product.product_category_services').id, |
| 438 |
}) |
| 439 |
|
| 440 |
env['product.pricelist'].create({ |
| 441 |
# no category has precedence over category |
| 442 |
'name': 'Category vs no category', |
| 443 |
'item_ids': [(0, 0, { |
| 444 |
'compute_price': 'fixed', |
| 445 |
'fixed_price': 1, |
| 446 |
'applied_on': '2_product_category', |
| 447 |
'categ_id': product_category_3.id, |
| 448 |
}), (0, 0, { |
| 449 |
'compute_price': 'fixed', |
| 450 |
'fixed_price': 2, |
| 451 |
})], |
| 452 |
}) |
| 453 |
|
| 454 |
env['product.pricelist'].create({ |
| 455 |
'name': 'Category', |
| 456 |
'item_ids': [(0, 0, { |
| 457 |
'compute_price': 'fixed', |
| 458 |
'fixed_price': 2, |
| 459 |
'applied_on': '2_product_category', |
| 460 |
'categ_id': env.ref('product.product_category_services').id, |
| 461 |
}), (0, 0, { |
| 462 |
'compute_price': 'fixed', |
| 463 |
'fixed_price': 1, |
| 464 |
'applied_on': '2_product_category', |
| 465 |
'categ_id': product_category_3.id, |
| 466 |
})], |
| 467 |
}) |
| 468 |
|
| 469 |
today = date.today() |
| 470 |
one_week_ago = today - timedelta(weeks=1) |
| 471 |
two_weeks_ago = today - timedelta(weeks=2) |
| 472 |
one_week_from_now = today + timedelta(weeks=1) |
| 473 |
two_weeks_from_now = today + timedelta(weeks=2) |
| 474 |
|
| 475 |
public_pricelist = env['product.pricelist'].create({ |
| 476 |
'name': 'Public Pricelist', |
| 477 |
}) |
| 478 |
|
| 479 |
env['product.pricelist'].create({ |
| 480 |
'name': 'Dates', |
| 481 |
'item_ids': [(0, 0, { |
| 482 |
'compute_price': 'fixed', |
| 483 |
'fixed_price': 1, |
| 484 |
'date_start': two_weeks_ago.strftime(DEFAULT_SERVER_DATE_FORMAT), |
| 485 |
'date_end': one_week_ago.strftime(DEFAULT_SERVER_DATE_FORMAT), |
| 486 |
}), (0, 0, { |
| 487 |
'compute_price': 'fixed', |
| 488 |
'fixed_price': 2, |
| 489 |
'date_start': today.strftime(DEFAULT_SERVER_DATE_FORMAT), |
| 490 |
'date_end': one_week_from_now.strftime(DEFAULT_SERVER_DATE_FORMAT), |
| 491 |
}), (0, 0, { |
| 492 |
'compute_price': 'fixed', |
| 493 |
'fixed_price': 3, |
| 494 |
'date_start': one_week_from_now.strftime(DEFAULT_SERVER_DATE_FORMAT), |
| 495 |
'date_end': two_weeks_from_now.strftime(DEFAULT_SERVER_DATE_FORMAT), |
| 496 |
})], |
| 497 |
}) |
| 498 |
|
| 499 |
cost_base_pricelist = env['product.pricelist'].create({ |
| 500 |
'name': 'Cost base', |
| 501 |
'item_ids': [(0, 0, { |
| 502 |
'base': 'standard_price', |
| 503 |
'compute_price': 'percentage', |
| 504 |
'percent_price': 55, |
| 505 |
})], |
| 506 |
}) |
| 507 |
|
| 508 |
pricelist_base_pricelist = env['product.pricelist'].create({ |
| 509 |
'name': 'Pricelist base', |
| 510 |
'item_ids': [(0, 0, { |
| 511 |
'base': 'pricelist', |
| 512 |
'base_pricelist_id': cost_base_pricelist.id, |
| 513 |
'compute_price': 'percentage', |
| 514 |
'percent_price': 15, |
| 515 |
})], |
| 516 |
}) |
| 517 |
|
| 518 |
env['product.pricelist'].create({ |
| 519 |
'name': 'Pricelist base 2', |
| 520 |
'item_ids': [(0, 0, { |
| 521 |
'base': 'pricelist', |
| 522 |
'base_pricelist_id': pricelist_base_pricelist.id, |
| 523 |
'compute_price': 'percentage', |
| 524 |
'percent_price': 3, |
| 525 |
})], |
| 526 |
}) |
| 527 |
|
| 528 |
env['product.pricelist'].create({ |
| 529 |
'name': 'Pricelist base rounding', |
| 530 |
'item_ids': [(0, 0, { |
| 531 |
'base': 'pricelist', |
| 532 |
'base_pricelist_id': fixed_pricelist.id, |
| 533 |
'compute_price': 'percentage', |
| 534 |
'percent_price': 0.01, |
| 535 |
})], |
| 536 |
}) |
| 537 |
|
| 538 |
excluded_pricelist = env['product.pricelist'].create({ |
| 539 |
'name': 'Not loaded' |
| 540 |
}) |
| 541 |
res_partner_18 = env['res.partner'].create({ |
| 542 |
'name': 'Lumber Inc', |
| 543 |
'is_company': True, |
| 544 |
}) |
| 545 |
res_partner_18.property_product_pricelist = excluded_pricelist |
| 546 |
|
| 547 |
test_sale_journal = journal_obj.create({'name': 'Sales Journal - Test', |
| 548 |
'code': 'TSJ', |
| 549 |
'type': 'sale', |
| 550 |
'company_id': main_company.id}) |
| 551 |
|
| 552 |
all_pricelists = env['product.pricelist'].search([ |
| 553 |
('id', '!=', excluded_pricelist.id), |
| 554 |
'|', ('company_id', '=', main_company.id), ('company_id', '=', False) |
| 555 |
]) |
| 556 |
all_pricelists.write(dict(currency_id=main_company.currency_id.id)) |
| 557 |
|
| 558 |
FP_POS_2M = env['account.fiscal.position'].create({ |
| 559 |
'name': "FP-POS-2M", |
| 560 |
}) |
| 561 |
|
| 562 |
src_tax = env['account.tax'].create({'name': "SRC", 'amount': 10}) |
| 563 |
env['account.tax'].create({'name': "DST", 'amount': 5, 'fiscal_position_ids': [Command.link(FP_POS_2M.id)], 'original_tax_ids': [Command.link(src_tax.id)]}) |
| 564 |
env['account.tax'].create({'name': "DST2", 'amount': 10, 'fiscal_position_ids': [Command.link(FP_POS_2M.id)], 'original_tax_ids': [Command.link(src_tax.id)]}) |
| 565 |
|
| 566 |
cls.letter_tray.taxes_id = [(6, 0, [src_tax.id])] |
| 567 |
|
| 568 |
cls.main_pos_config.write({ |
| 569 |
'tax_regime_selection': True, |
| 570 |
'fiscal_position_ids': FP_POS_2M, |
| 571 |
'journal_id': test_sale_journal.id, |
| 572 |
'invoice_journal_id': test_sale_journal.id, |
| 573 |
'payment_method_ids': [(0, 0, { 'name': 'Cash', |
| 574 |
'journal_id': cash_journal.id, |
| 575 |
'receivable_account_id': cls.account_receivable.id, |
| 576 |
})], |
| 577 |
'use_pricelist': True, |
| 578 |
'pricelist_id': public_pricelist.id, |
| 579 |
'available_pricelist_ids': [(4, pricelist.id) for pricelist in all_pricelists], |
| 580 |
}) |
| 581 |
|
| 582 |
cls.printer = cls.env['pos.printer'].create({ |
| 583 |
'name': 'Printer', |
| 584 |
'printer_type': 'epson_epos', |
| 585 |
'epson_printer_ip': '0.0.0.0', |
| 586 |
}) |
| 587 |
|
| 588 |
# Set customers |
| 589 |
# Unlink some data partners that makes the test crash |
| 590 |
for xmlid in [ |
| 591 |
"l10n_us_hr_payroll.res_partner_taxation_va", |
| 592 |
"l10n_us_hr_payroll.res_partner_revenue_dc", |
| 593 |
"l10n_us_hr_payroll.res_partner_pfl_dc", |
| 594 |
"l10n_us_hr_payroll.res_partner_revenue_or", |
| 595 |
"l10n_us_hr_payroll.res_partner_dcbs_or", |
| 596 |
"l10n_us_hr_payroll.res_partner_employment_or", |
| 597 |
"l10n_us_hr_payroll.res_partner_revenue_nc", |
| 598 |
"l10n_us_hr_payroll.res_partner_state_tax_commission_id", |
| 599 |
"l10n_us_hr_payroll.res_partner_department_taxes_vt", |
| 600 |
"l10n_us_hr_payroll.res_partner_department_revenue_il", |
| 601 |
"l10n_us_hr_payroll.res_partner_department_revenue_az", |
| 602 |
]: |
| 603 |
partner = cls.env.ref(xmlid, raise_if_not_found=False) |
| 604 |
if partner: |
| 605 |
partner.unlink() |
| 606 |
|
| 607 |
partners = cls.env['res.partner'].create([ |
| 608 |
{'name': 'Partner Test 1'}, |
| 609 |
{'name': 'Partner Test 2'}, |
| 610 |
{'name': 'Partner Test 3'}, |
| 611 |
{ |
| 612 |
'name': 'Partner Full', |
| 613 |
'email': '[email protected]', |
| 614 |
'street': '77 Santa Barbara Rd', |
| 615 |
'city': 'Pleasant Hill', |
| 616 |
'state_id': cls.env.ref('base.state_us_5').id, |
| 617 |
'zip': '94523', |
| 618 |
'country_id': cls.env.ref('base.us').id, |
| 619 |
} |
| 620 |
]) |
| 621 |
cls.partner_test_1 = partners[0] |
| 622 |
cls.partner_test_2 = partners[1] |
| 623 |
cls.partner_test_3 = partners[2] |
| 624 |
cls.partner_full = partners[3] |
| 625 |
|
| 626 |
# Change the default sale pricelist of customers, |
| 627 |
# so the js tests can expect deterministically this pricelist when selecting a customer. |
| 628 |
# bad hack only for test |
| 629 |
env['ir.default'].set("res.partner", "specific_property_product_pricelist", public_pricelist.id, company_id=main_company.id) |
| 630 |
|
| 631 |
|
| 632 |
@tagged('post_install', '-at_install') |
| 633 |
class TestUi(TestPointOfSaleHttpCommon): |
| 634 |
def test_01_pos_basic_order(self): |
| 635 |
self.start_pos_tour('pos_pricelist') |
| 636 |
|
| 637 |
def test_pos_basic_order_02_decimal_order_quantity(self): |
| 638 |
self.start_pos_tour('pos_basic_order_02_decimal_order_quantity') |
| 639 |
|
| 640 |
def test_pos_basic_order_03_tax_position(self): |
| 641 |
self.start_pos_tour('pos_basic_order_03_tax_position') |
| 642 |
|
| 643 |
def test_floating_order_tour(self): |
| 644 |
self.start_pos_tour('FloatingOrderTour') |
| 645 |
|
| 646 |
def test_product_screen_tour(self): |
| 647 |
self.whiteboard_pen.write({ |
| 648 |
'is_favorite': True |
| 649 |
}) |
| 650 |
self.start_pos_tour('ProductScreenTour') |
| 651 |
|
| 652 |
def test_payment_screen_tour(self): |
| 653 |
self.start_pos_tour('PaymentScreenTour') |
| 654 |
|
| 655 |
def test_receipt_screen_tour(self): |
| 656 |
self.tip.write({ |
| 657 |
'taxes_id': False |
| 658 |
}) |
| 659 |
self.main_pos_config.write({ |
| 660 |
'iface_tipproduct': True, |
| 661 |
'tip_product_id': self.tip.id, |
| 662 |
'ship_later': True |
| 663 |
}) |
| 664 |
self.start_pos_tour('ReceiptScreenTour') |
| 665 |
for order in self.env['pos.order'].search([]): |
| 666 |
self.assertEqual(order.state, 'paid', "Validated order has payment of " + str(order.amount_paid) + " and total of " + str(order.amount_total)) |
| 667 |
|
| 668 |
# check if email from ReceiptScreenTour is properly sent |
| 669 |
email_count = self.env['mail.mail'].search_count([('email_to', '=', '[email protected]')]) |
| 670 |
self.assertEqual(email_count, 1) |
| 671 |
|
| 672 |
@skip('Temporary to fast merge new valuation') |
| 673 |
def test_02_pos_with_invoiced(self): |
| 674 |
self.pos_user.write({ |
| 675 |
'group_ids': [ |
| 676 |
(4, self.env.ref('account.group_account_invoice').id), |
| 677 |
] |
| 678 |
}) |
| 679 |
|
| 680 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 681 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'ChromeTour', login="pos_user") |
| 682 |
n_invoiced = self.env['pos.order'].search_count([('account_move', '!=', False)]) |
| 683 |
n_paid = self.env['pos.order'].search_count([('state', '=', 'paid')]) |
| 684 |
self.assertEqual(n_invoiced, 1, 'There should be 1 invoiced order.') |
| 685 |
self.assertEqual(n_paid, 2, 'There should be 2 paid order.') |
| 686 |
last_order = self.env['pos.order'].search([], limit=1, order="id desc") |
| 687 |
self.assertEqual(last_order.lines[0].price_subtotal, 30.0) |
| 688 |
self.assertEqual(last_order.lines[0].price_subtotal_incl, 30.0) |
| 689 |
# Check if session name contains config name as prefix |
| 690 |
self.assertEqual(self.main_pos_config.name in last_order.session_id.name, True) |
| 691 |
|
| 692 |
def test_03_pos_with_lots(self): |
| 693 |
|
| 694 |
# open a session, the /pos/ui controller will redirect to it |
| 695 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 696 |
|
| 697 |
self.monitor_stand.tracking = 'lot' |
| 698 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_03_pos_with_lots', login="pos_user") |
| 699 |
|
| 700 |
def test_04_product_configurator(self): |
| 701 |
# Making one attribute inactive to verify that it doesn't show |
| 702 |
configurable_product = self.env['product.product'].search([('name', '=', 'Configurable Chair'), ('available_in_pos', '=', 'True')], limit=1) |
| 703 |
fabrics_line = configurable_product.attribute_line_ids[2] |
| 704 |
fabrics_line.product_template_value_ids[1].ptav_active = False |
| 705 |
self.pos_user.write({ |
| 706 |
'group_ids': [ |
| 707 |
(4, self.env.ref('stock.group_stock_manager').id), |
| 708 |
] |
| 709 |
}) |
| 710 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 711 |
self.start_pos_tour('ProductConfiguratorTour') |
| 712 |
|
| 713 |
def test_optional_product(self): |
| 714 |
# optional product in pos |
| 715 |
image = _create_image(color="orange") |
| 716 |
|
| 717 |
self.small_shelf.write({'image_1920': image}) |
| 718 |
|
| 719 |
self.desk_pad.write({'pos_optional_product_ids': [ |
| 720 |
Command.set([ self.small_shelf.id ]) |
| 721 |
]}) |
| 722 |
|
| 723 |
self.letter_tray.write({ |
| 724 |
'pos_optional_product_ids': [Command.set([self.configurable_chair.id])], |
| 725 |
'barcode': 'lettertray' |
| 726 |
}) |
| 727 |
# Case 1: Images ON → images must be visible in optional product dialog |
| 728 |
self.main_pos_config.show_product_images = True |
| 729 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 730 |
self.start_pos_tour('test_optional_product') |
| 731 |
|
| 732 |
# Case 2: Images OFF → product images should not be shown |
| 733 |
self.main_pos_config.show_product_images = False |
| 734 |
self.start_pos_tour('test_optional_product_image_not_display') |
| 735 |
|
| 736 |
@skip('Temporary to fast merge new valuation') |
| 737 |
def test_05_ticket_screen(self): |
| 738 |
self.pos_user.write({ |
| 739 |
'group_ids': [ |
| 740 |
(4, self.env.ref('account.group_account_invoice').id), |
| 741 |
] |
| 742 |
}) |
| 743 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 744 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'TicketScreenTour', login="pos_user") |
| 745 |
|
| 746 |
def test_product_information_screen_admin(self): |
| 747 |
'''Consider this test method to contain a test tour with miscellaneous tests/checks that require admin access. |
| 748 |
''' |
| 749 |
self.product_a.available_in_pos = True |
| 750 |
self.pos_admin.write({ |
| 751 |
'group_ids': [Command.link(self.env.ref('base.group_system').id)], |
| 752 |
}) |
| 753 |
self.main_pos_config.write({ |
| 754 |
'is_margins_costs_accessible_to_every_user': True, |
| 755 |
}) |
| 756 |
self.assertFalse(self.product_a.is_storable) |
| 757 |
self.main_pos_config.with_user(self.pos_admin).open_ui() |
| 758 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'CheckProductInformation', login="pos_admin") |
| 759 |
|
| 760 |
def test_fixed_tax_negative_qty(self): |
| 761 |
""" Assert the negative amount of a negative-quantity orderline |
| 762 |
with zero-amount product with fixed tax. |
| 763 |
""" |
| 764 |
|
| 765 |
# setup the zero-amount product |
| 766 |
tax_received_account = self.env['account.account'].create({ |
| 767 |
'name': 'TAX_BASE', |
| 768 |
'code': 'TBASE', |
| 769 |
'account_type': 'asset_current', |
| 770 |
}) |
| 771 |
fixed_tax = self.env['account.tax'].create({ |
| 772 |
'name': 'fixed amount tax', |
| 773 |
'amount_type': 'fixed', |
| 774 |
'amount': 1, |
| 775 |
'invoice_repartition_line_ids': [ |
| 776 |
(0, 0, {'repartition_type': 'base'}), |
| 777 |
(0, 0, { |
| 778 |
'repartition_type': 'tax', |
| 779 |
'account_id': tax_received_account.id, |
| 780 |
}), |
| 781 |
], |
| 782 |
'price_include_override': 'tax_excluded', |
| 783 |
}) |
| 784 |
zero_amount_product = self.env['product.product'].create({ |
| 785 |
'name': 'Zero Amount Product', |
| 786 |
'available_in_pos': True, |
| 787 |
'list_price': 0, |
| 788 |
'taxes_id': [(6, 0, [fixed_tax.id])], |
| 789 |
'categ_id': self.env.ref('product.product_category_services').id, |
| 790 |
}) |
| 791 |
|
| 792 |
# Make an order with the zero-amount product from the frontend. |
| 793 |
# We need to do this because of the fix in the "compute_all" port. |
| 794 |
self.main_pos_config.write({'iface_tax_included': 'total'}) |
| 795 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 796 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'FixedTaxNegativeQty', login="pos_user") |
| 797 |
pos_session = self.main_pos_config.current_session_id |
| 798 |
|
| 799 |
# Close the session and check the session journal entry. |
| 800 |
pos_session.action_pos_session_validate() |
| 801 |
|
| 802 |
lines = pos_session.move_id.line_ids.sorted('balance') |
| 803 |
|
| 804 |
# order in the tour is paid using the bank payment method. |
| 805 |
bank_pm = self.main_pos_config.payment_method_ids.filtered(lambda pm: pm.name == 'Bank') |
| 806 |
|
| 807 |
self.assertEqual(lines[0].account_id, bank_pm.receivable_account_id or self.env.company.account_default_pos_receivable_account_id) |
| 808 |
self.assertAlmostEqual(lines[0].balance, -1) |
| 809 |
self.assertEqual(lines[1].account_id, self.env.company.income_account_id) |
| 810 |
self.assertAlmostEqual(lines[1].balance, 0) |
| 811 |
self.assertEqual(lines[2].account_id, tax_received_account) |
| 812 |
self.assertAlmostEqual(lines[2].balance, 1) |
| 813 |
|
| 814 |
def test_change_without_cash_method(self): |
| 815 |
#create bank payment method |
| 816 |
bank_pm = self.env['pos.payment.method'].create({ |
| 817 |
'name': 'Bank', |
| 818 |
'receivable_account_id': self.env.company.account_default_pos_receivable_account_id.id, |
| 819 |
'is_cash_count': False, |
| 820 |
'split_transactions': False, |
| 821 |
'company_id': self.env.company.id, |
| 822 |
}) |
| 823 |
self.main_pos_config.write({'payment_method_ids': [(6, 0, bank_pm.ids)], 'ship_later': True}) |
| 824 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 825 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PaymentScreenTour2', login="pos_user") |
| 826 |
|
| 827 |
def test_rounding_up(self): |
| 828 |
rouding_method = self.env['account.cash.rounding'].create({ |
| 829 |
'name': 'Rounding up', |
| 830 |
'rounding': 0.05, |
| 831 |
'rounding_method': 'UP', |
| 832 |
}) |
| 833 |
|
| 834 |
self.env['product.product'].create({ |
| 835 |
'name': 'Product Test', |
| 836 |
'available_in_pos': True, |
| 837 |
'list_price': 1.96, |
| 838 |
'taxes_id': False, |
| 839 |
}) |
| 840 |
|
| 841 |
self.main_pos_config.write({ |
| 842 |
'rounding_method': rouding_method.id, |
| 843 |
'cash_rounding': True, |
| 844 |
'only_round_cash_method': True, |
| 845 |
}) |
| 846 |
|
| 847 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 848 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PaymentScreenRoundingUp', login="pos_user") |
| 849 |
|
| 850 |
def test_rounding_down(self): |
| 851 |
rouding_method = self.env['account.cash.rounding'].create({ |
| 852 |
'name': 'Rounding down', |
| 853 |
'rounding': 0.05, |
| 854 |
'rounding_method': 'DOWN', |
| 855 |
}) |
| 856 |
|
| 857 |
self.env['product.product'].create({ |
| 858 |
'name': 'Product Test', |
| 859 |
'available_in_pos': True, |
| 860 |
'list_price': 1.98, |
| 861 |
'taxes_id': False, |
| 862 |
}) |
| 863 |
|
| 864 |
self.main_pos_config.write({ |
| 865 |
'rounding_method': rouding_method.id, |
| 866 |
'cash_rounding': True, |
| 867 |
'only_round_cash_method': True, |
| 868 |
}) |
| 869 |
|
| 870 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 871 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PaymentScreenRoundingDown', login="pos_user") |
| 872 |
self.env["pos.order"].search([('state', '=', 'draft')]).write({'state': 'cancel'}) |
| 873 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PaymentScreenTotalDueWithOverPayment', login="pos_user") |
| 874 |
|
| 875 |
def test_pos_closing_cash_details(self): |
| 876 |
"""Test cash difference *loss* at closing. |
| 877 |
""" |
| 878 |
self.main_pos_config.open_ui() |
| 879 |
current_session = self.main_pos_config.current_session_id |
| 880 |
current_session.post_closing_cash_details(0) |
| 881 |
current_session.close_session_from_ui() |
| 882 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 883 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'CashClosingDetails', login="pos_user") |
| 884 |
self.assertEqual(self.main_pos_config.last_session_closing_cash, 50.0) |
| 885 |
cash_diff_line = self.env['account.bank.statement.line'].search([ |
| 886 |
('payment_ref', 'ilike', 'Cash difference observed during the counting (Loss)') |
| 887 |
]) |
| 888 |
self.assertAlmostEqual(cash_diff_line.amount, -1.00) |
| 889 |
|
| 890 |
def test_cash_payments_should_reflect_on_next_opening(self): |
| 891 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 892 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'OrderPaidInCash', login="pos_user") |
| 893 |
self.assertEqual(self.main_pos_config.last_session_closing_cash, 25.0) |
| 894 |
|
| 895 |
def test_pos_session_statistics_display(self): |
| 896 |
"""Test that POS session statistics are properly displayed in the UI.""" |
| 897 |
# For testing `opening_cash` and `paid_orders` in dashboard |
| 898 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 899 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'SessionStatisticsDisplay', login="pos_user") |
| 900 |
|
| 901 |
# For testing `draft_orders` |
| 902 |
self.env['pos.order'].create({ |
| 903 |
'config_id': self.main_pos_config.id, |
| 904 |
'session_id': self.main_pos_config.current_session_id.id, |
| 905 |
'company_id': self.main_pos_config.company_id.id, |
| 906 |
'amount_total': 10.0, |
| 907 |
'amount_paid': 10.0, |
| 908 |
'amount_tax': 0.0, |
| 909 |
'amount_return': 0.0, |
| 910 |
'to_invoice': False, |
| 911 |
'partner_id': False, |
| 912 |
'pricelist_id': self.main_pos_config.pricelist_id.id, |
| 913 |
'pos_reference': '1000-004-00001', |
| 914 |
'name': 'Order 1001', |
| 915 |
'state': 'draft', |
| 916 |
'lines': [(0, 0, { |
| 917 |
'product_id': self.desk_pad.product_variant_id.id, |
| 918 |
'price_unit': 10.00, |
| 919 |
'discount': 0, |
| 920 |
'qty': 1, |
| 921 |
'tax_ids': False, |
| 922 |
'price_subtotal': 10.00, |
| 923 |
'price_subtotal_incl': 10.00, |
| 924 |
})], |
| 925 |
}) |
| 926 |
|
| 927 |
dashboard_statistics = self.main_pos_config.statistics_for_current_session |
| 928 |
|
| 929 |
self.assertTrue(dashboard_statistics['date']['is_started']) |
| 930 |
self.assertEqual(dashboard_statistics['cash']['raw_opening_cash'], 100.0) |
| 931 |
self.assertEqual(dashboard_statistics['orders']['paid']['amount'], 45.0) |
| 932 |
self.assertEqual(dashboard_statistics['orders']['paid']['count'], 2) |
| 933 |
self.assertEqual(dashboard_statistics['orders']['draft']['amount'], 10.0) |
| 934 |
self.assertEqual(dashboard_statistics['orders']['draft']['count'], 1) |
| 935 |
|
| 936 |
def test_tax_control_button_visiblity(self): |
| 937 |
self.main_pos_config.write({ |
| 938 |
'tax_regime_selection': False, |
| 939 |
}) |
| 940 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 941 |
self.start_pos_tour('test_tax_control_button_visiblity') |
| 942 |
|
| 943 |
def test_fiscal_position_no_tax(self): |
| 944 |
#create a tax of 15% with price included |
| 945 |
tax = self.env['account.tax'].create({ |
| 946 |
'name': 'Tax 15%', |
| 947 |
'amount': 15, |
| 948 |
'price_include_override': 'tax_included', |
| 949 |
'amount_type': 'percent', |
| 950 |
'type_tax_use': 'sale', |
| 951 |
}) |
| 952 |
|
| 953 |
#create a product with the tax |
| 954 |
self.product = self.env['product.product'].create({ |
| 955 |
'name': 'Test Product', |
| 956 |
'taxes_id': [(6, 0, [tax.id])], |
| 957 |
'list_price': 100, |
| 958 |
'available_in_pos': True, |
| 959 |
}) |
| 960 |
|
| 961 |
#create a fiscal position that map the tax to no tax |
| 962 |
fiscal_position = self.env['account.fiscal.position'].create({ |
| 963 |
'name': 'No Tax', |
| 964 |
}) |
| 965 |
|
| 966 |
pricelist = self.env['product.pricelist'].create({ |
| 967 |
'name': 'Test Pricelist', |
| 968 |
}) |
| 969 |
|
| 970 |
self.main_pos_config.write({ |
| 971 |
'tax_regime_selection': True, |
| 972 |
'fiscal_position_ids': [(6, 0, [fiscal_position.id])], |
| 973 |
'available_pricelist_ids': [(6, 0, [pricelist.id])], |
| 974 |
'pricelist_id': pricelist.id, |
| 975 |
}) |
| 976 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 977 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'FiscalPositionNoTax', login="pos_user") |
| 978 |
|
| 979 |
def test_fiscal_position_inclusive_and_exclusive_tax(self): |
| 980 |
""" Test the mapping of fiscal position for both Tax Inclusive ans Tax Exclusive""" |
| 981 |
# create a fiscal position that map the tax |
| 982 |
fiscal_position_1 = self.env['account.fiscal.position'].create({ |
| 983 |
'name': 'Incl. to Incl.', |
| 984 |
}) |
| 985 |
fiscal_position_2 = self.env['account.fiscal.position'].create({ |
| 986 |
'name': 'Incl. to Excl.', |
| 987 |
}) |
| 988 |
fiscal_position_3 = self.env['account.fiscal.position'].create({ |
| 989 |
'name': 'Excl. to Excl.', |
| 990 |
}) |
| 991 |
fiscal_position_4 = self.env['account.fiscal.position'].create({ |
| 992 |
'name': 'Excl. to Incl.', |
| 993 |
}) |
| 994 |
|
| 995 |
# create a tax with price included |
| 996 |
tax_inclusive_1 = self.env['account.tax'].create({ |
| 997 |
'name': 'Tax incl.20%', |
| 998 |
'amount': 20, |
| 999 |
'price_include_override': 'tax_included', |
| 1000 |
'amount_type': 'percent', |
| 1001 |
'type_tax_use': 'sale', |
| 1002 |
}) |
| 1003 |
tax_exclusive_1 = self.env['account.tax'].create({ |
| 1004 |
'name': 'Tax excl.20%', |
| 1005 |
'amount': 20, |
| 1006 |
'price_include_override': 'tax_excluded', |
| 1007 |
'amount_type': 'percent', |
| 1008 |
'type_tax_use': 'sale', |
| 1009 |
}) |
| 1010 |
self.env['account.tax'].create({ |
| 1011 |
'name': 'Tax incl.10%', |
| 1012 |
'amount': 10, |
| 1013 |
'price_include_override': 'tax_included', |
| 1014 |
'amount_type': 'percent', |
| 1015 |
'type_tax_use': 'sale', |
| 1016 |
'fiscal_position_ids': [Command.set((fiscal_position_1 | fiscal_position_4).ids)], |
| 1017 |
'original_tax_ids': [Command.set((tax_inclusive_1 | tax_exclusive_1).ids)], |
| 1018 |
}) |
| 1019 |
self.env['account.tax'].create({ |
| 1020 |
'name': 'Tax excl.10%', |
| 1021 |
'amount': 10, |
| 1022 |
'price_include_override': 'tax_excluded', |
| 1023 |
'amount_type': 'percent', |
| 1024 |
'type_tax_use': 'sale', |
| 1025 |
'fiscal_position_ids': [Command.set((fiscal_position_2 | fiscal_position_3).ids)], |
| 1026 |
'original_tax_ids': [Command.set((tax_inclusive_1 | tax_exclusive_1).ids)], |
| 1027 |
}) |
| 1028 |
self.test_product_1 = self.env['product.product'].create({ |
| 1029 |
'name': 'Test Product 1', |
| 1030 |
'available_in_pos': True, |
| 1031 |
'list_price': 100, |
| 1032 |
'taxes_id': [(6, 0, [tax_inclusive_1.id])], |
| 1033 |
}) |
| 1034 |
|
| 1035 |
self.test_product_2 = self.env['product.product'].create({ |
| 1036 |
'name': 'Test Product 2', |
| 1037 |
'available_in_pos': True, |
| 1038 |
'list_price': 100, |
| 1039 |
'taxes_id': [(6, 0, [tax_exclusive_1.id])], |
| 1040 |
}) |
| 1041 |
|
| 1042 |
# add the fiscal position to the PoS |
| 1043 |
self.main_pos_config.write({ |
| 1044 |
'tax_regime_selection': True, |
| 1045 |
'fiscal_position_ids': [(6, 0, [ |
| 1046 |
fiscal_position_1.id, |
| 1047 |
fiscal_position_2.id, |
| 1048 |
fiscal_position_3.id, |
| 1049 |
fiscal_position_4.id, |
| 1050 |
])], |
| 1051 |
}) |
| 1052 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1053 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'FiscalPositionIncl', login="pos_user") |
| 1054 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'FiscalPositionExcl', login="pos_user") |
| 1055 |
|
| 1056 |
def test_06_pos_discount_display_with_multiple_pricelist(self): |
| 1057 |
""" Test the discount display on the POS screen when multiple pricelists are used.""" |
| 1058 |
test_product = self.env['product.template'].create({ |
| 1059 |
'name': 'Test Product', |
| 1060 |
'available_in_pos': True, |
| 1061 |
'list_price': 10, |
| 1062 |
'taxes_id': False, |
| 1063 |
}) |
| 1064 |
|
| 1065 |
base_pricelist = self.env['product.pricelist'].create({ |
| 1066 |
'name': 'base_pricelist', |
| 1067 |
}) |
| 1068 |
|
| 1069 |
self.env['product.pricelist.item'].create({ |
| 1070 |
'pricelist_id': base_pricelist.id, |
| 1071 |
'product_tmpl_id': test_product.id, |
| 1072 |
'compute_price': 'percentage', |
| 1073 |
'applied_on': '1_product', |
| 1074 |
'percent_price': 30, |
| 1075 |
}) |
| 1076 |
|
| 1077 |
special_pricelist = self.env['product.pricelist'].create({ |
| 1078 |
'name': 'special_pricelist', |
| 1079 |
}) |
| 1080 |
self.env['product.pricelist.item'].create({ |
| 1081 |
'pricelist_id': special_pricelist.id, |
| 1082 |
'base': 'pricelist', |
| 1083 |
'base_pricelist_id': base_pricelist.id, |
| 1084 |
'compute_price': 'percentage', |
| 1085 |
'applied_on': '3_global', |
| 1086 |
'percent_price': 10, |
| 1087 |
}) |
| 1088 |
|
| 1089 |
self.main_pos_config.write({ |
| 1090 |
'pricelist_id': base_pricelist.id, |
| 1091 |
'available_pricelist_ids': [(6, 0, [base_pricelist.id, special_pricelist.id])], |
| 1092 |
}) |
| 1093 |
|
| 1094 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1095 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'ReceiptScreenDiscountWithPricelistTour', login="pos_user") |
| 1096 |
|
| 1097 |
def test_07_product_combo(self): |
| 1098 |
self.env['decimal.precision'].search([('name', '=', 'Product Price')]).digits = 4 |
| 1099 |
setup_product_combo_items(self) |
| 1100 |
combo_product_sofa = self.env["product.template"].create( |
| 1101 |
{ |
| 1102 |
"name": "Combo product Sofa", |
| 1103 |
"is_storable": True, |
| 1104 |
"available_in_pos": True, |
| 1105 |
"list_price": 40, |
| 1106 |
} |
| 1107 |
) |
| 1108 |
sofa_size_attribute = self.env['product.attribute'].create({ |
| 1109 |
'name': 'Size', |
| 1110 |
'display_type': 'radio', |
| 1111 |
'create_variant': 'always', |
| 1112 |
}) |
| 1113 |
sofa_color_attribute = self.env['product.attribute'].create({ |
| 1114 |
'name': 'Color', |
| 1115 |
'display_type': 'radio', |
| 1116 |
'create_variant': 'always', |
| 1117 |
}) |
| 1118 |
sofa_size_L = self.env['product.attribute.value'].create({ |
| 1119 |
'name': 'L', |
| 1120 |
'attribute_id': sofa_size_attribute.id, |
| 1121 |
}) |
| 1122 |
sofa_size_M = self.env['product.attribute.value'].create({ |
| 1123 |
'name': 'M', |
| 1124 |
'attribute_id': sofa_size_attribute.id, |
| 1125 |
}) |
| 1126 |
sofa_color_red = self.env['product.attribute.value'].create({ |
| 1127 |
'name': 'red', |
| 1128 |
'attribute_id': sofa_color_attribute.id, |
| 1129 |
}) |
| 1130 |
sofa_color_blue = self.env['product.attribute.value'].create({ |
| 1131 |
'name': 'blue', |
| 1132 |
'attribute_id': sofa_color_attribute.id, |
| 1133 |
}) |
| 1134 |
|
| 1135 |
product_attribute_size = self.env['product.template.attribute.line'].create({ |
| 1136 |
'product_tmpl_id': combo_product_sofa.id, |
| 1137 |
'attribute_id': sofa_size_attribute.id, |
| 1138 |
'value_ids': [Command.set([sofa_size_M.id, sofa_size_L.id])], |
| 1139 |
|
| 1140 |
}) |
| 1141 |
self.env['product.template.attribute.line'].create({ |
| 1142 |
'product_tmpl_id': combo_product_sofa.id, |
| 1143 |
'attribute_id': sofa_color_attribute.id, |
| 1144 |
'value_ids': [Command.set([sofa_color_red.id, sofa_color_blue.id])], |
| 1145 |
|
| 1146 |
}) |
| 1147 |
product_attribute_size.product_template_value_ids[0].price_extra = 50 |
| 1148 |
product_attribute_size.product_template_value_ids[1].price_extra = 100 |
| 1149 |
self.sofa_combo = self.env["product.combo"].create( |
| 1150 |
{ |
| 1151 |
"name": "Chairs Combo", |
| 1152 |
"combo_item_ids": [ |
| 1153 |
Command.create({ |
| 1154 |
"product_id": combo_product_sofa.product_variant_ids[0].id, |
| 1155 |
"extra_price": 5, |
| 1156 |
}), |
| 1157 |
Command.create({ |
| 1158 |
"product_id": combo_product_sofa.product_variant_ids[1].id, |
| 1159 |
"extra_price": 10, |
| 1160 |
}), |
| 1161 |
], |
| 1162 |
}, |
| 1163 |
) |
| 1164 |
self.sofa_combo = self.env["product.product"].create( |
| 1165 |
{ |
| 1166 |
"available_in_pos": True, |
| 1167 |
"list_price": 20, |
| 1168 |
"name": "Sofa Combo", |
| 1169 |
"type": "combo", |
| 1170 |
"uom_id": self.env.ref("uom.product_uom_unit").id, |
| 1171 |
"combo_ids": [ |
| 1172 |
Command.set([self.sofa_combo.id]), |
| 1173 |
], |
| 1174 |
}, |
| 1175 |
) |
| 1176 |
self.office_combo.write({ |
| 1177 |
'lst_price': 50, |
| 1178 |
'barcode': 'SuperCombo', |
| 1179 |
}) |
| 1180 |
|
| 1181 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1182 |
self.start_pos_tour('ProductComboPriceTaxIncludedTour') |
| 1183 |
order = self.env['pos.order'].search([]) |
| 1184 |
self.assertEqual(len(order.lines), 4, "There should be 4 order lines - 1 combo parent and 3 combo lines") |
| 1185 |
# check that the combo lines are correctly linked to each other |
| 1186 |
parent_line_id = self.env['pos.order.line'].search([('product_id.name', '=', 'Office Combo'), ('order_id', '=', order.id)]) |
| 1187 |
combo_line_ids = self.env['pos.order.line'].search([('product_id.name', '!=', 'Office Combo'), ('order_id', '=', order.id)]) |
| 1188 |
self.assertEqual(parent_line_id.combo_line_ids, combo_line_ids, "The combo parent should have 3 combo lines") |
| 1189 |
self.assertEqual(order.lines[1].price_unit, 10.33) |
| 1190 |
self.assertEqual(order.lines[2].price_unit, 18.67) |
| 1191 |
self.assertEqual(order.lines[3].price_unit, 30.00) |
| 1192 |
# In the future we might want to test also if: |
| 1193 |
# - the combo lines are correctly stored in and restored from local storage |
| 1194 |
# - the combo lines are correctly shared between the pos configs ( in cross ordering ) |
| 1195 |
|
| 1196 |
def test_07_product_combo_max_free_qty(self): |
| 1197 |
""" Test the max free quantity of a product combo.""" |
| 1198 |
setup_product_combo_items(self) |
| 1199 |
self.office_combo.combo_ids[0].write({ |
| 1200 |
'qty_free': 2, |
| 1201 |
'qty_max': 2, |
| 1202 |
}) |
| 1203 |
self.office_combo.combo_ids[1].write({ |
| 1204 |
'qty_free': 2, |
| 1205 |
'qty_max': 5, |
| 1206 |
}) |
| 1207 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1208 |
self.start_pos_tour('ProductComboMaxFreeQtyTour') |
| 1209 |
|
| 1210 |
def test_line_configurators(self): |
| 1211 |
setup_product_combo_items(self) |
| 1212 |
self.env['product.combo.item'].create({ |
| 1213 |
'combo_id': self.desks_combo.id, |
| 1214 |
'product_id': self.configurable_chair.product_variant_id.id, |
| 1215 |
'extra_price': 0, |
| 1216 |
}) |
| 1217 |
|
| 1218 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1219 |
self.start_pos_tour('test_line_configurators_product') |
| 1220 |
self.start_pos_tour('test_line_configurators_combo') |
| 1221 |
|
| 1222 |
def test_07_pos_barcodes_scan(self): |
| 1223 |
barcode_rule = self.env.ref("point_of_sale.barcode_rule_client") |
| 1224 |
barcode_rule.pattern = barcode_rule.pattern + "|234" |
| 1225 |
# should in theory be changed in the JS code to `|^234` |
| 1226 |
# If not, it will fail as it will mistakenly match with the product barcode "0123456789" |
| 1227 |
|
| 1228 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1229 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'BarcodeScanningTour', login="pos_user") |
| 1230 |
|
| 1231 |
def test_08_show_tax_excluded(self): |
| 1232 |
# define a tax included tax record |
| 1233 |
tax = self.env['account.tax'].create({ |
| 1234 |
'name': 'Tax 10% Included', |
| 1235 |
'amount_type': 'percent', |
| 1236 |
'amount': 10, |
| 1237 |
'price_include_override': 'tax_included', |
| 1238 |
}) |
| 1239 |
|
| 1240 |
# define a product record with the tax |
| 1241 |
self.env['product.product'].create({ |
| 1242 |
'name': 'Test Product', |
| 1243 |
'list_price': 110, |
| 1244 |
'taxes_id': [(6, 0, [tax.id])], |
| 1245 |
'available_in_pos': True, |
| 1246 |
}) |
| 1247 |
|
| 1248 |
# set Tax-Excluded Price |
| 1249 |
self.main_pos_config.write({ |
| 1250 |
'iface_tax_included': 'subtotal' |
| 1251 |
}) |
| 1252 |
|
| 1253 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1254 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'ShowTaxExcludedTour', login="pos_user") |
| 1255 |
|
| 1256 |
def test_chrome_without_cash_move_permission(self): |
| 1257 |
self.env.user.write({'group_ids': [ |
| 1258 |
Command.set( |
| 1259 |
[ |
| 1260 |
self.env.ref('base.group_user').id, |
| 1261 |
self.env.ref('point_of_sale.group_pos_user').id, |
| 1262 |
] |
| 1263 |
) |
| 1264 |
]}) |
| 1265 |
self.main_pos_config.open_ui() |
| 1266 |
self.start_pos_tour('chrome_without_cash_move_permission', login="accountman") |
| 1267 |
|
| 1268 |
def test_09_pos_barcodes_scan_product_packaging(self): |
| 1269 |
pack_of_10 = self.env['uom.uom'].create({ |
| 1270 |
'name': 'Pack of 10', |
| 1271 |
'relative_factor': 10, |
| 1272 |
'relative_uom_id': self.env.ref('uom.product_uom_unit').id, |
| 1273 |
'is_pos_groupable': True, |
| 1274 |
}) |
| 1275 |
product = self.env['product.product'].create({ |
| 1276 |
'name': 'Packaging Product', |
| 1277 |
'available_in_pos': True, |
| 1278 |
'list_price': 10, |
| 1279 |
'taxes_id': False, |
| 1280 |
'barcode': '12345601', |
| 1281 |
'uom_ids': [Command.link(pack_of_10.id)], |
| 1282 |
}) |
| 1283 |
self.env['product.uom'].create({ |
| 1284 |
'barcode': '12345610', |
| 1285 |
'product_id': product.id, |
| 1286 |
'uom_id': pack_of_10.id, |
| 1287 |
}) |
| 1288 |
|
| 1289 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1290 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'BarcodeScanningProductPackagingTour', login="pos_user") |
| 1291 |
|
| 1292 |
def test_GS1_pos_barcodes_scan(self): |
| 1293 |
barcodes_gs1_nomenclature = self.env.ref("barcodes_gs1_nomenclature.default_gs1_nomenclature") |
| 1294 |
default_nomenclature_id = self.env.ref("barcodes.default_barcode_nomenclature") |
| 1295 |
self.main_pos_config.company_id.write({ |
| 1296 |
'nomenclature_id': barcodes_gs1_nomenclature.id |
| 1297 |
}) |
| 1298 |
self.main_pos_config.write({ |
| 1299 |
'fallback_nomenclature_id': default_nomenclature_id |
| 1300 |
}) |
| 1301 |
self.env['product.product'].create({ |
| 1302 |
'name': 'Product 1', |
| 1303 |
'available_in_pos': True, |
| 1304 |
'list_price': 10, |
| 1305 |
'taxes_id': False, |
| 1306 |
'barcode': '08431673020125', |
| 1307 |
}) |
| 1308 |
|
| 1309 |
self.env['product.product'].create({ |
| 1310 |
'name': 'Product 2', |
| 1311 |
'available_in_pos': True, |
| 1312 |
'list_price': 10, |
| 1313 |
'taxes_id': False, |
| 1314 |
'barcode': '08431673020126', |
| 1315 |
}) |
| 1316 |
|
| 1317 |
# 3760171283370 can be parsed with GS1 rules but it's not GS1 |
| 1318 |
self.env['product.product'].create({ |
| 1319 |
'name': 'Product 3', |
| 1320 |
'available_in_pos': True, |
| 1321 |
'list_price': 10, |
| 1322 |
'taxes_id': False, |
| 1323 |
'barcode': '3760171283370', |
| 1324 |
}) |
| 1325 |
|
| 1326 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1327 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'GS1BarcodeScanningTour', login="pos_user") |
| 1328 |
|
| 1329 |
def test_refund_order_with_fp_tax_included(self): |
| 1330 |
# create a fiscal position |
| 1331 |
self.fiscal_position = self.env['account.fiscal.position'].create({ |
| 1332 |
'name': 'No Tax', |
| 1333 |
}) |
| 1334 |
#create a tax of 15% tax included |
| 1335 |
self.tax1 = self.env['account.tax'].create({ |
| 1336 |
'name': 'Tax 1', |
| 1337 |
'amount': 15, |
| 1338 |
'amount_type': 'percent', |
| 1339 |
'type_tax_use': 'sale', |
| 1340 |
'price_include_override': 'tax_included', |
| 1341 |
}) |
| 1342 |
#create a tax of 0% |
| 1343 |
self.tax2 = self.env['account.tax'].create({ |
| 1344 |
'name': 'Tax 2', |
| 1345 |
'amount': 0, |
| 1346 |
'amount_type': 'percent', |
| 1347 |
'type_tax_use': 'sale', |
| 1348 |
'price_include_override': 'tax_included', |
| 1349 |
'fiscal_position_ids': self.fiscal_position, |
| 1350 |
'original_tax_ids': self.tax1, |
| 1351 |
}) |
| 1352 |
|
| 1353 |
self.product_test = self.env['product.product'].create({ |
| 1354 |
'name': 'Product Test', |
| 1355 |
'is_storable': True, |
| 1356 |
'available_in_pos': True, |
| 1357 |
'list_price': 100, |
| 1358 |
'taxes_id': [(6, 0, self.tax1.ids)], |
| 1359 |
}) |
| 1360 |
|
| 1361 |
#add the fiscal position to the PoS |
| 1362 |
self.main_pos_config.write({ |
| 1363 |
'fiscal_position_ids': [(4, self.fiscal_position.id)], |
| 1364 |
'tax_regime_selection': True, |
| 1365 |
}) |
| 1366 |
|
| 1367 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1368 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'FiscalPositionNoTaxRefund', login="pos_user") |
| 1369 |
order = self.env['pos.order'].search([]) |
| 1370 |
self.assertTrue(order[0].name == order[1].name + " REFUND") |
| 1371 |
|
| 1372 |
def test_customer_display_popup(self): |
| 1373 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'customer_display_shows_qr_popup', login="pos_user") |
| 1374 |
|
| 1375 |
def test_lot_refund(self): |
| 1376 |
|
| 1377 |
self.product1 = self.env['product.product'].create({ |
| 1378 |
'name': 'Product A', |
| 1379 |
'is_storable': True, |
| 1380 |
'tracking': 'serial', |
| 1381 |
'available_in_pos': True, |
| 1382 |
}) |
| 1383 |
|
| 1384 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1385 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'LotRefundTour', login="pos_user") |
| 1386 |
|
| 1387 |
def test_receipt_tracking_method(self): |
| 1388 |
self.product_a = self.env['product.product'].create({ |
| 1389 |
'name': 'Product A', |
| 1390 |
'is_storable': True, |
| 1391 |
'tracking': 'lot', |
| 1392 |
'available_in_pos': True, |
| 1393 |
}) |
| 1394 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1395 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'ReceiptTrackingMethodTour', login="pos_user") |
| 1396 |
|
| 1397 |
def test_printed_receipt_tour(self): |
| 1398 |
self.main_pos_config.write({ |
| 1399 |
'basic_receipt': True, |
| 1400 |
}) |
| 1401 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1402 |
self.start_pos_tour("point_of_sale.test_printed_receipt_tour") |
| 1403 |
|
| 1404 |
def test_limited_product_pricelist_loading(self): |
| 1405 |
self.env['ir.config_parameter'].sudo().set_param('point_of_sale.limited_product_count', '1') |
| 1406 |
|
| 1407 |
limited_category = self.env['pos.category'].create({ |
| 1408 |
'name': 'Limited Category', |
| 1409 |
}) |
| 1410 |
product_1 = self.env['product.product'].create({ |
| 1411 |
'name': 'Test Product 1', |
| 1412 |
'list_price': 100, |
| 1413 |
'barcode': '0100100', |
| 1414 |
'taxes_id': False, |
| 1415 |
'pos_categ_ids': [(4, limited_category.id)], |
| 1416 |
'available_in_pos': True, |
| 1417 |
}) |
| 1418 |
|
| 1419 |
color_attribute = self.env['product.attribute'].create({ |
| 1420 |
'name': 'Color', |
| 1421 |
'sequence': 4, |
| 1422 |
'value_ids': [(0, 0, { |
| 1423 |
'name': 'White', |
| 1424 |
'sequence': 1, |
| 1425 |
}), (0, 0, { |
| 1426 |
'name': 'Red', |
| 1427 |
'sequence': 2, |
| 1428 |
'default_extra_price': 50, |
| 1429 |
})], |
| 1430 |
}) |
| 1431 |
|
| 1432 |
product_2_template = self.env['product.template'].create({ |
| 1433 |
'name': 'Test Product 2', |
| 1434 |
'list_price': 200, |
| 1435 |
'taxes_id': False, |
| 1436 |
'available_in_pos': True, |
| 1437 |
'pos_categ_ids': [(4, limited_category.id)], |
| 1438 |
'tracking': 'lot', |
| 1439 |
'attribute_line_ids': [(0, 0, { |
| 1440 |
'attribute_id': color_attribute.id, |
| 1441 |
'value_ids': [(6, 0, color_attribute.value_ids.ids)] |
| 1442 |
})], |
| 1443 |
}) |
| 1444 |
|
| 1445 |
# Check that two product variant are created |
| 1446 |
self.assertEqual(product_2_template.product_variant_count, 2) |
| 1447 |
product_2_template.product_variant_ids[0].write({'barcode': '0100201'}) |
| 1448 |
product_2_template.product_variant_ids[1].write({'barcode': '0100202'}) |
| 1449 |
|
| 1450 |
self.env['product.product'].create({ |
| 1451 |
'name': 'Test Product 3', |
| 1452 |
'list_price': 300, |
| 1453 |
'barcode': '0100300', |
| 1454 |
'taxes_id': False, |
| 1455 |
'pos_categ_ids': [(4, limited_category.id)], |
| 1456 |
'available_in_pos': True, |
| 1457 |
}) |
| 1458 |
|
| 1459 |
pricelist_item = self.env['product.pricelist.item'].create([{ |
| 1460 |
'applied_on': '3_global', |
| 1461 |
'fixed_price': 50, |
| 1462 |
}, { |
| 1463 |
'applied_on': '1_product', |
| 1464 |
'product_tmpl_id': product_2_template.id, |
| 1465 |
'fixed_price': 100, |
| 1466 |
}, { |
| 1467 |
'applied_on': '0_product_variant', |
| 1468 |
'product_id': product_1.id, |
| 1469 |
'fixed_price': 80, |
| 1470 |
'min_quantity': 1, |
| 1471 |
}, { |
| 1472 |
'applied_on': '0_product_variant', |
| 1473 |
'product_id': product_1.id, |
| 1474 |
'fixed_price': 70, |
| 1475 |
'min_quantity': 2, |
| 1476 |
}, { |
| 1477 |
'applied_on': '0_product_variant', |
| 1478 |
'product_id': product_2_template.product_variant_ids[1].id, |
| 1479 |
'fixed_price': 120, |
| 1480 |
}]) |
| 1481 |
self.main_pos_config.write({ |
| 1482 |
'iface_available_categ_ids': [], |
| 1483 |
'limit_categories': True, |
| 1484 |
}) |
| 1485 |
self.main_pos_config.pricelist_id.write({'item_ids': [(6, 0, pricelist_item.ids)]}) |
| 1486 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1487 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'limitedProductPricelistLoading', login="pos_user") |
| 1488 |
|
| 1489 |
def test_restricted_categories_combo_product(self): |
| 1490 |
""" |
| 1491 |
Ensure combo choices product are always loaded if parent is in allowed categories, even when restricted categories are configured: |
| 1492 |
- These combo choices should be visible when configuring the parent combo product but not be visible as product that we can directly sell inside POS |
| 1493 |
- These combo choices should appear on the preparation ticket changes |
| 1494 |
""" |
| 1495 |
pos_restricted_categ = self.env["pos.category"].create({ |
| 1496 |
"name": "Restricted product", |
| 1497 |
}) |
| 1498 |
pos_other_categ = self.env["pos.category"].create({ |
| 1499 |
"name": "Other products", |
| 1500 |
}) |
| 1501 |
self.env['pos.printer'].create({ |
| 1502 |
'name': 'Printer', |
| 1503 |
'printer_type': 'epson_epos', |
| 1504 |
'epson_printer_ip': '0.0.0.0', |
| 1505 |
'product_categories_ids': [Command.set(self.env['pos.category'].search([]).ids)], |
| 1506 |
}) |
| 1507 |
|
| 1508 |
self.main_pos_config.write({ |
| 1509 |
'is_order_printer': True, |
| 1510 |
'printer_ids': [Command.set(self.env['pos.printer'].search([]).ids)], |
| 1511 |
}) |
| 1512 |
self.main_pos_config.write({ |
| 1513 |
"limit_categories": True, |
| 1514 |
"iface_available_categ_ids": [(6, 0, [pos_restricted_categ.id])], |
| 1515 |
}) |
| 1516 |
setup_product_combo_items(self) |
| 1517 |
self.office_combo.pos_categ_ids = [(6, 0, [pos_restricted_categ.id])] |
| 1518 |
self.office_combo.combo_ids = [(6, 0, [self.desks_combo.id])] |
| 1519 |
self.desks_combo.combo_item_ids[0].product_id.pos_categ_ids = [(6, 0, [pos_restricted_categ.id])] |
| 1520 |
self.desks_combo.combo_item_ids[1].product_id.pos_categ_ids = [(6, 0, [pos_other_categ.id])] |
| 1521 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1522 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_restricted_categories_combo_product', login="pos_user") |
| 1523 |
|
| 1524 |
def test_printer_restricts_to_allowed_categories_for_combo(self): |
| 1525 |
setup_product_combo_items(self) |
| 1526 |
self.printer.write({ |
| 1527 |
'product_categories_ids': [Command.set(self.env['pos.category'].search([('name', '=', 'Category 2')]).ids)], |
| 1528 |
}) |
| 1529 |
self.office_combo.write({ |
| 1530 |
'pos_categ_ids': [Command.set(self.env['pos.category'].search([('name', '=', 'Category 1')]).ids)], |
| 1531 |
}) |
| 1532 |
self.main_pos_config.write({ |
| 1533 |
'is_order_printer': True, |
| 1534 |
'printer_ids': [Command.set(self.printer.ids)], |
| 1535 |
}) |
| 1536 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1537 |
self.start_pos_tour('test_printer_restricts_to_allowed_categories_for_combo', login="pos_user") |
| 1538 |
|
| 1539 |
def test_printer_not_linked_to_any_combo_category(self): |
| 1540 |
setup_product_combo_items(self) |
| 1541 |
new_category = self.env['pos.category'].create({ |
| 1542 |
'name': 'New Category', |
| 1543 |
}) |
| 1544 |
self.wall_shelf.write({ |
| 1545 |
'pos_categ_ids': [Command.set(new_category.ids)], |
| 1546 |
}) |
| 1547 |
self.printer.write({ |
| 1548 |
'product_categories_ids': [Command.set(new_category.ids)], |
| 1549 |
}) |
| 1550 |
self.main_pos_config.write({ |
| 1551 |
'is_order_printer': True, |
| 1552 |
'printer_ids': [Command.set(self.printer.ids)], |
| 1553 |
}) |
| 1554 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1555 |
self.start_pos_tour('test_printer_not_linked_to_any_combo_category', login="pos_user") |
| 1556 |
|
| 1557 |
def test_multi_product_options(self): |
| 1558 |
self.pos_user.write({ |
| 1559 |
'group_ids': [ |
| 1560 |
(4, self.env.ref('stock.group_stock_manager').id), |
| 1561 |
] |
| 1562 |
}) |
| 1563 |
product_a = self.env['product.product'].create({ |
| 1564 |
'name': 'Product A', |
| 1565 |
'available_in_pos': True, |
| 1566 |
'list_price': 10, |
| 1567 |
'taxes_id': False, |
| 1568 |
}) |
| 1569 |
|
| 1570 |
chair_multi_attribute = self.env['product.attribute'].create({ |
| 1571 |
'name': 'Multi', |
| 1572 |
'display_type': 'multi', |
| 1573 |
'create_variant': 'no_variant', |
| 1574 |
}) |
| 1575 |
chair_multi_value_1 = self.env['product.attribute.value'].create({ |
| 1576 |
'name': 'Value 1', |
| 1577 |
'attribute_id': chair_multi_attribute.id, |
| 1578 |
}) |
| 1579 |
chair_multi_value_2 = self.env['product.attribute.value'].create({ |
| 1580 |
'name': 'Value 2', |
| 1581 |
'attribute_id': chair_multi_attribute.id, |
| 1582 |
}) |
| 1583 |
self.chair_multi_line = self.env['product.template.attribute.line'].create({ |
| 1584 |
'product_tmpl_id': product_a.product_tmpl_id.id, |
| 1585 |
'attribute_id': chair_multi_attribute.id, |
| 1586 |
'value_ids': [(6, 0, [chair_multi_value_1.id, chair_multi_value_2.id])] |
| 1587 |
}) |
| 1588 |
|
| 1589 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1590 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'MultiProductOptionsTour', login="pos_user") |
| 1591 |
|
| 1592 |
def test_translate_product_name(self): |
| 1593 |
self.env['res.lang']._activate_lang('fr_FR') |
| 1594 |
self.pos_user.write({'lang': 'fr_FR'}) |
| 1595 |
|
| 1596 |
product = self.env['product.product'].create({ |
| 1597 |
'name': 'Test Product', |
| 1598 |
'list_price': 100, |
| 1599 |
'taxes_id': False, |
| 1600 |
'available_in_pos': True, |
| 1601 |
}) |
| 1602 |
product.update_field_translations('name', {'fr_FR': 'Testez le produit'}) |
| 1603 |
|
| 1604 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1605 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'TranslateProductNameTour', login="pos_user") |
| 1606 |
|
| 1607 |
def test_properly_display_price(self): |
| 1608 |
"""Make sure that when the decimal separator is a comma, the shown orderline price is correct. |
| 1609 |
""" |
| 1610 |
lang = self.env['res.lang'].search([('code', '=', self.pos_user.lang)]) |
| 1611 |
lang.write({'thousands_sep': '.', 'decimal_point': ','}) |
| 1612 |
|
| 1613 |
self.env['product.product'].create({ |
| 1614 |
'name': 'Test Product', |
| 1615 |
'list_price': 1_453.53, |
| 1616 |
'taxes_id': False, |
| 1617 |
'available_in_pos': True, |
| 1618 |
}) |
| 1619 |
|
| 1620 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1621 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, "DecimalCommaOrderlinePrice", login="pos_user") |
| 1622 |
|
| 1623 |
def test_res_partner_scan_barcode(self): |
| 1624 |
# default Customer Barcodes pattern is '042' |
| 1625 |
self.env['res.partner'].create({ |
| 1626 |
'name': 'John Doe', |
| 1627 |
'barcode': '0421234567890', |
| 1628 |
}) |
| 1629 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1630 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'BarcodeScanPartnerTour', login="pos_user") |
| 1631 |
|
| 1632 |
def test_allow_order_modification_after_validation_error(self): |
| 1633 |
""" |
| 1634 |
User error as a result of validation should block the order. |
| 1635 |
Taking action by order modification should be allowed. |
| 1636 |
""" |
| 1637 |
|
| 1638 |
self.env['product.product'].create({ |
| 1639 |
'name': 'Test Product', |
| 1640 |
'list_price': 10.00, |
| 1641 |
'taxes_id': False, |
| 1642 |
'available_in_pos': True, |
| 1643 |
}) |
| 1644 |
|
| 1645 |
def sync_from_ui_patch(*_args, **_kwargs): |
| 1646 |
raise UserError('Test Error') |
| 1647 |
|
| 1648 |
with patch.object(self.env.registry.models['pos.order'], "sync_from_ui", sync_from_ui_patch): |
| 1649 |
# If there is problem in the tour, remove the log catcher to debug. |
| 1650 |
with self.assertLogs(level="WARNING") as log_catcher: |
| 1651 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1652 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'OrderModificationAfterValidationError', login="pos_user") |
| 1653 |
|
| 1654 |
warning_outputs = [o for o in log_catcher.output if 'WARNING' in o] |
| 1655 |
self.assertEqual(len(warning_outputs), 1, "Exactly one warning should be logged") |
| 1656 |
|
| 1657 |
def test_customer_display(self): |
| 1658 |
self.start_tour(f"/pos_customer_display/{self.main_pos_config.id}/{self.main_pos_config.access_token}", 'CustomerDisplayTour', login="pos_user") |
| 1659 |
|
| 1660 |
def test_customer_display_scroll(self): |
| 1661 |
self.start_tour(f"/pos_customer_display/{self.main_pos_config.id}/{self.main_pos_config.access_token}", 'CustomerDisplayTourScroll', login="pos_user") |
| 1662 |
|
| 1663 |
def test_customer_display_with_qr(self): |
| 1664 |
self.start_tour(f"/pos_customer_display/{self.main_pos_config.id}/{self.main_pos_config.access_token}", 'CustomerDisplayTourWithQr', login="pos_user") |
| 1665 |
|
| 1666 |
def test_order_refund_flow(self): |
| 1667 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1668 |
self.start_pos_tour('test_order_refund_flow') |
| 1669 |
|
| 1670 |
def test_refund_few_quantities(self): |
| 1671 |
""" Test to check that refund works with quantities of less than 0.5 """ |
| 1672 |
self.env['product.product'].create({ |
| 1673 |
'name': 'Sugar', |
| 1674 |
'list_price': 3, |
| 1675 |
'taxes_id': False, |
| 1676 |
'available_in_pos': True, |
| 1677 |
'uom_id': self.env.ref('uom.product_uom_kgm').id, |
| 1678 |
}) |
| 1679 |
|
| 1680 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1681 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'RefundFewQuantities', login="pos_user") |
| 1682 |
|
| 1683 |
def test_refund_multiple_products_amounts_compliance(self): |
| 1684 |
test_product = self.env['product.product'].create({ |
| 1685 |
'name': 'Test Product', |
| 1686 |
'list_price': 10.00, |
| 1687 |
'taxes_id': False, |
| 1688 |
'available_in_pos': True, |
| 1689 |
}) |
| 1690 |
|
| 1691 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1692 |
current_session = self.main_pos_config.current_session_id |
| 1693 |
|
| 1694 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'refund_multiple_products_amounts_compliance', login="pos_user") |
| 1695 |
|
| 1696 |
refund_order = current_session.order_ids.filtered(lambda order: order.is_refund) |
| 1697 |
self.assertEqual(refund_order.lines[0].price_subtotal, 2 * test_product.list_price) |
| 1698 |
total_cash_payment = sum(current_session.mapped('order_ids.payment_ids').filtered( |
| 1699 |
lambda payment: payment.payment_method_id.type == 'cash').mapped('amount') |
| 1700 |
) |
| 1701 |
current_session.post_closing_cash_details(total_cash_payment) |
| 1702 |
current_session.close_session_from_ui() |
| 1703 |
self.assertEqual(current_session.state, 'closed') |
| 1704 |
report_refund_order, report_order = self.env['report.pos.order'].sudo().search([('order_id', 'in', current_session.order_ids.ids)]) |
| 1705 |
self.assertEqual(report_order.margin, 20.0) |
| 1706 |
self.assertEqual(report_refund_order.margin, -20.0) |
| 1707 |
|
| 1708 |
def test_product_combo_price(self): |
| 1709 |
""" Check that the combo has the expected price """ |
| 1710 |
self.desk_organizer.product_variant_id.write({"lst_price": 7}) |
| 1711 |
self.desk_pad.product_variant_id.write({"lst_price": 2.5}) |
| 1712 |
self.whiteboard_pen.product_variant_id.write({"lst_price": 1.5}) |
| 1713 |
|
| 1714 |
combos = self.env["product.combo"].create([ |
| 1715 |
{ |
| 1716 |
"name": product.name, |
| 1717 |
"combo_item_ids": [ |
| 1718 |
Command.create({ |
| 1719 |
"product_id": product.id, "extra_price": 0 |
| 1720 |
}) |
| 1721 |
] |
| 1722 |
} |
| 1723 |
for product in (self.desk_organizer.product_variant_id, self.desk_pad.product_variant_id, self.whiteboard_pen.product_variant_id) |
| 1724 |
]) |
| 1725 |
|
| 1726 |
self.env["product.product"].create( |
| 1727 |
{ |
| 1728 |
"available_in_pos": True, |
| 1729 |
"list_price": 7, |
| 1730 |
"standard_price": 10, |
| 1731 |
"name": "Desk Combo", |
| 1732 |
"type": "combo", |
| 1733 |
"taxes_id": False, |
| 1734 |
"combo_ids": [ |
| 1735 |
(6, 0, [combo.id for combo in combos]) |
| 1736 |
], |
| 1737 |
} |
| 1738 |
) |
| 1739 |
|
| 1740 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1741 |
self.start_tour(f"/pos/ui/{self.main_pos_config.id}", 'ProductComboPriceCheckTour', login="pos_user") |
| 1742 |
order = self.env['pos.order'].search([], limit=1) |
| 1743 |
self.assertEqual(order.lines.filtered(lambda l: l.product_id.type == 'combo').margin, 0) |
| 1744 |
self.assertEqual(order.lines.filtered(lambda l: l.product_id.type == 'combo').margin_percent, 0) |
| 1745 |
|
| 1746 |
def test_customer_display_as_public(self): |
| 1747 |
self.main_pos_config.customer_display_bg_img = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGNgYGAAAAAEAAH2FzhVAAAAAElFTkSuQmCC' |
| 1748 |
response = self.url_open(f"/web/image/pos.config/{self.main_pos_config.id}/customer_display_bg_img") |
| 1749 |
self.assertEqual(response.status_code, 200) |
| 1750 |
self.assertTrue('Shop.png' in response.headers['Content-Disposition']) |
| 1751 |
|
| 1752 |
def test_customer_all_fields_displayed(self): |
| 1753 |
""" |
| 1754 |
Verify that all the field of a partner can be displayed in the partner list. |
| 1755 |
Also verify that all these fields can be searched. |
| 1756 |
""" |
| 1757 |
self.env["res.partner"].create({ |
| 1758 |
"name": "John Doe", |
| 1759 |
"street": "1 street of astreet", |
| 1760 |
"city": "Acity", |
| 1761 |
"state_id": self.env.ref("base.state_us_30").id, # Ohio |
| 1762 |
"country_id": self.env.ref("base.us").id, |
| 1763 |
"zip": "26432685463", |
| 1764 |
"phone": "9898989899", |
| 1765 |
"email": "[email protected]" |
| 1766 |
}) |
| 1767 |
|
| 1768 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1769 |
self.start_pos_tour('PosCustomerAllFieldsDisplayed') |
| 1770 |
|
| 1771 |
def test_product_combo_change_fp(self): |
| 1772 |
""" |
| 1773 |
Verify than when the fiscal position is changed, |
| 1774 |
the price of the combo doesn't change and taxes are well taken into account |
| 1775 |
""" |
| 1776 |
fiscal_position = self.env['account.fiscal.position'].create({ |
| 1777 |
'name': 'test fp', |
| 1778 |
}) |
| 1779 |
|
| 1780 |
tax_1 = self.env['account.tax'].create({ |
| 1781 |
'name': 'Tax 10%', |
| 1782 |
'amount': 10, |
| 1783 |
'price_include_override': 'tax_included', |
| 1784 |
'amount_type': 'percent', |
| 1785 |
'type_tax_use': 'sale', |
| 1786 |
}) |
| 1787 |
|
| 1788 |
self.env['account.tax'].create({ |
| 1789 |
'name': 'Tax 5%', |
| 1790 |
'amount': 5, |
| 1791 |
'price_include_override': 'tax_included', |
| 1792 |
'amount_type': 'percent', |
| 1793 |
'type_tax_use': 'sale', |
| 1794 |
'fiscal_position_ids': [Command.link(fiscal_position.id)], |
| 1795 |
'original_tax_ids': [Command.link(tax_1.id)], |
| 1796 |
}) |
| 1797 |
|
| 1798 |
setup_product_combo_items(self) |
| 1799 |
self.office_combo.write({'list_price': 50, 'taxes_id': [(6, 0, [tax_1.id])]}) |
| 1800 |
for combo in self.office_combo.combo_ids: # Set the tax to all the products of the combo |
| 1801 |
for item in combo.combo_item_ids: |
| 1802 |
item.product_id.taxes_id = [(6, 0, [tax_1.id])] |
| 1803 |
|
| 1804 |
self.main_pos_config.write({ |
| 1805 |
'tax_regime_selection': True, |
| 1806 |
'fiscal_position_ids': [(6, 0, [fiscal_position.id])], |
| 1807 |
}) |
| 1808 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1809 |
self.start_tour(f"/pos/ui/{self.main_pos_config.id}", 'ProductComboChangeFP', login="pos_user") |
| 1810 |
|
| 1811 |
def test_product_combo_change_pricelist(self): |
| 1812 |
""" |
| 1813 |
Verify than when we change the pricelist, the combo price is updated |
| 1814 |
""" |
| 1815 |
setup_product_combo_items(self) |
| 1816 |
|
| 1817 |
sale_10_pl = self.env['product.pricelist'].create({ |
| 1818 |
'name': 'sale 10%', |
| 1819 |
}) |
| 1820 |
self.env['product.pricelist.item'].create({ |
| 1821 |
'pricelist_id': sale_10_pl.id, |
| 1822 |
'compute_price': 'percentage', |
| 1823 |
'applied_on': '3_global', |
| 1824 |
'percent_price': 10, |
| 1825 |
}) |
| 1826 |
|
| 1827 |
self.main_pos_config.write({ |
| 1828 |
'available_pricelist_ids': [(4, sale_10_pl.id)], |
| 1829 |
}) |
| 1830 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1831 |
self.start_tour(f"/pos/ui?config_id={self.main_pos_config.id}", 'ProductComboChangePricelist', login="pos_user") |
| 1832 |
|
| 1833 |
def test_product_combo_discount(self): |
| 1834 |
""" |
| 1835 |
Verify that the combo product applies the correct discount and updates prices accordingly |
| 1836 |
""" |
| 1837 |
setup_product_combo_items(self) |
| 1838 |
self.office_combo.write({'list_price': 100}) |
| 1839 |
self.office_combo.combo_ids.combo_item_ids.product_id.taxes_id = False |
| 1840 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1841 |
self.start_tour( |
| 1842 |
f"/pos/ui?config_id={self.main_pos_config.id}", |
| 1843 |
'ProductComboDiscountTour', |
| 1844 |
login="pos_user", |
| 1845 |
) |
| 1846 |
|
| 1847 |
def test_combo_item_image_display(self): |
| 1848 |
""" when `show_product_images` is enabled, verify combo item product images should appear in the POS UI. When disabled, the UI should not display |
| 1849 |
the product image for combo items. |
| 1850 |
""" |
| 1851 |
|
| 1852 |
setup_product_combo_items(self) |
| 1853 |
image = _create_image(color="orange") |
| 1854 |
|
| 1855 |
for combo in self.office_combo.combo_ids: |
| 1856 |
for item in combo.combo_item_ids: |
| 1857 |
item.product_id.image_1920 = image |
| 1858 |
|
| 1859 |
# Case 1: Images ON → images must be visible in combo items |
| 1860 |
self.main_pos_config.show_product_images = True |
| 1861 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1862 |
self.start_tour(f"/pos/ui?config_id={self.main_pos_config.id}", 'test_combo_item_image_display', login="pos_user") |
| 1863 |
|
| 1864 |
# Case 2: Images OFF → product images should not be shown |
| 1865 |
self.main_pos_config.show_product_images = False |
| 1866 |
self.start_tour(f"/pos/ui?config_id={self.main_pos_config.id}", 'test_combo_item_image_not_display', login="pos_user") |
| 1867 |
|
| 1868 |
def test_product_categories_order(self): |
| 1869 |
""" Verify that the order of categories doesnt change in the frontend """ |
| 1870 |
self.env['pos.category'].search([]).write({'sequence': 100}) |
| 1871 |
aaa_catg = self.env['pos.category'].create({ |
| 1872 |
'name': 'AAA', |
| 1873 |
'parent_id': False, |
| 1874 |
'sequence': 1, |
| 1875 |
}) |
| 1876 |
aac_catg = self.env['pos.category'].create({ |
| 1877 |
'name': 'AAC', |
| 1878 |
'parent_id': False, |
| 1879 |
'sequence': 3, |
| 1880 |
}) |
| 1881 |
parentA = self.env['pos.category'].create({ |
| 1882 |
'name': 'AAB', |
| 1883 |
'parent_id': False, |
| 1884 |
'sequence': 2, |
| 1885 |
}) |
| 1886 |
parentB = self.env['pos.category'].create({ |
| 1887 |
'name': 'AAX', |
| 1888 |
'parent_id': parentA.id, |
| 1889 |
}) |
| 1890 |
aay_catg = self.env['pos.category'].create({ |
| 1891 |
'name': 'AAY', |
| 1892 |
'parent_id': parentB.id, |
| 1893 |
}) |
| 1894 |
# Add a product that belongs to both parent and child categories. |
| 1895 |
# It's presence is checked during the tour to make sure app doesn't crash. |
| 1896 |
self.env['product.product'].create({ |
| 1897 |
'name': 'Product in AAB and AAX', |
| 1898 |
'pos_categ_ids': [(6, 0, [parentA.id, parentB.id])], |
| 1899 |
'available_in_pos': True, |
| 1900 |
}) |
| 1901 |
self.env['product.product'].create([ |
| 1902 |
{ |
| 1903 |
'name': 'Product in AAA Catg', |
| 1904 |
'pos_categ_ids': [(6, 0, [aaa_catg.id])], |
| 1905 |
'available_in_pos': True, |
| 1906 |
}, |
| 1907 |
{ |
| 1908 |
'name': 'Product in AAC Catg', |
| 1909 |
'pos_categ_ids': [(6, 0, [aac_catg.id])], |
| 1910 |
'available_in_pos': True, |
| 1911 |
}, |
| 1912 |
{ |
| 1913 |
'name': 'Product in AAY Catg', |
| 1914 |
'pos_categ_ids': [(6, 0, [aay_catg.id])], |
| 1915 |
'available_in_pos': True, |
| 1916 |
}, |
| 1917 |
]) |
| 1918 |
self.main_pos_config.with_user(self.pos_admin).open_ui() |
| 1919 |
self.start_tour(f"/pos/ui/{self.main_pos_config.id}", 'PosCategoriesOrder', login="pos_admin") |
| 1920 |
|
| 1921 |
def test_product_with_dynamic_attributes(self): |
| 1922 |
dynamic_attribute = self.env['product.attribute'].create({ |
| 1923 |
'name': 'Dynamic Attribute', |
| 1924 |
'create_variant': 'dynamic', |
| 1925 |
}) |
| 1926 |
value_1 = self.env['product.attribute.value'].create({ |
| 1927 |
'name': 'Test 1', |
| 1928 |
'attribute_id': dynamic_attribute.id, |
| 1929 |
}) |
| 1930 |
value_2 = self.env['product.attribute.value'].create({ |
| 1931 |
'name': 'Test 2', |
| 1932 |
'default_extra_price': 10, |
| 1933 |
'attribute_id': dynamic_attribute.id, |
| 1934 |
}) |
| 1935 |
product_template = self.env['product.template'].create({ |
| 1936 |
'name': 'Dynamic Product', |
| 1937 |
'uom_id': self.env.ref('uom.product_uom_unit').id, |
| 1938 |
'is_storable': True, |
| 1939 |
'available_in_pos': True, |
| 1940 |
}) |
| 1941 |
self.env['product.template.attribute.line'].create({ |
| 1942 |
'product_tmpl_id': product_template.id, |
| 1943 |
'attribute_id': dynamic_attribute.id, |
| 1944 |
'value_ids': [Command.set([value_1.id, value_2.id])], |
| 1945 |
}) |
| 1946 |
self.main_pos_config.with_user(self.pos_admin).open_ui() |
| 1947 |
self.start_tour(f"/pos/ui/{self.main_pos_config.id}", 'PosProductWithDynamicAttributes', login="pos_admin") |
| 1948 |
|
| 1949 |
def test_autofill_cash_count(self): |
| 1950 |
"""Make sure that when the decimal separator is a comma, the shown orderline price is correct. |
| 1951 |
""" |
| 1952 |
lang = self.env['res.lang'].search([('code', '=', self.pos_user.lang)]) |
| 1953 |
lang.write({'thousands_sep': '.', 'decimal_point': ','}) |
| 1954 |
self.env["product.product"].create( |
| 1955 |
{ |
| 1956 |
"available_in_pos": True, |
| 1957 |
"list_price": 123456, |
| 1958 |
"name": "Test Expensive", |
| 1959 |
"taxes_id": False |
| 1960 |
} |
| 1961 |
) |
| 1962 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1963 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, "AutofillCashCount", login="pos_user") |
| 1964 |
|
| 1965 |
def test_product_search_2(self): |
| 1966 |
self.env['product.product'].create({ |
| 1967 |
'name': 'Test chair 1', |
| 1968 |
'available_in_pos': True, |
| 1969 |
}) |
| 1970 |
self.env['product.product'].create({ |
| 1971 |
'name': 'Test CHAIR 2', |
| 1972 |
'available_in_pos': True, |
| 1973 |
}) |
| 1974 |
self.env['product.product'].create({ |
| 1975 |
'name': 'Test sofa', |
| 1976 |
'available_in_pos': True, |
| 1977 |
"default_code": "CHAIR_01", |
| 1978 |
}) |
| 1979 |
self.env['product.product'].create({ |
| 1980 |
'name': 'clémentine', |
| 1981 |
'available_in_pos': True, |
| 1982 |
}) |
| 1983 |
self.main_pos_config.open_ui() |
| 1984 |
self.start_tour(f"/pos/ui/{self.main_pos_config.id}", 'SearchProducts', login="pos_user") |
| 1985 |
|
| 1986 |
def test_lot(self): |
| 1987 |
self.product1 = self.env['product.product'].create({ |
| 1988 |
'name': 'Product A', |
| 1989 |
'is_storable': True, |
| 1990 |
'tracking': 'serial', |
| 1991 |
'available_in_pos': True, |
| 1992 |
}) |
| 1993 |
product2 = self.env['product.product'].create({ |
| 1994 |
'name': 'Product B', |
| 1995 |
'is_storable': True, |
| 1996 |
'tracking': 'lot', |
| 1997 |
'available_in_pos': True, |
| 1998 |
}) |
| 1999 |
self.env['stock.quant'].with_context(inventory_mode=True).create({ |
| 2000 |
'product_id': product2.id, |
| 2001 |
'inventory_quantity': 1, |
| 2002 |
'location_id': self.env.user._get_default_warehouse_id().lot_stock_id.id, |
| 2003 |
'lot_id': self.env['stock.lot'].create({'name': '1001', 'product_id': product2.id}).id, |
| 2004 |
}).sudo().action_apply_inventory() |
| 2005 |
|
| 2006 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2007 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'LotTour', login="pos_user") |
| 2008 |
two_last_orders = self.env['pos.order'].search([], order='id desc', limit=2) |
| 2009 |
order_lot_id = [lot_id.lot_name for lot_id in two_last_orders[1].lines.pack_lot_ids] |
| 2010 |
refund_lot_id = [lot_id.lot_name for lot_id in two_last_orders[0].lines.pack_lot_ids] |
| 2011 |
self.assertEqual(order_lot_id, refund_lot_id, "In the refund we should find the same lot as in the original order") |
| 2012 |
self.assertEqual(two_last_orders[0].state, 'paid') |
| 2013 |
self.assertEqual(two_last_orders[1].state, 'paid') |
| 2014 |
self.main_pos_config.current_session_id.order_ids.filtered( |
| 2015 |
lambda o: o.state != 'paid').state = 'cancel' |
| 2016 |
|
| 2017 |
self.main_pos_config.current_session_id.action_pos_session_closing_control() |
| 2018 |
self.assertEqual( |
| 2019 |
two_last_orders[0].picking_ids.move_line_ids.owner_id.id, |
| 2020 |
two_last_orders[1].picking_ids.move_line_ids.owner_id.id, |
| 2021 |
"The owner of the refund is not the same as the owner of the original order") |
| 2022 |
|
| 2023 |
def test_only_existing_lots(self): |
| 2024 |
product = self.env['product.product'].create({ |
| 2025 |
'name': 'Product with existing lots', |
| 2026 |
'is_storable': True, |
| 2027 |
'tracking': 'lot', |
| 2028 |
'available_in_pos': True, |
| 2029 |
}) |
| 2030 |
self.env['stock.quant'].with_context(inventory_mode=True).create([{ |
| 2031 |
'product_id': product.id, |
| 2032 |
'inventory_quantity': 1, |
| 2033 |
'location_id': self.env.user._get_default_warehouse_id().lot_stock_id.id, |
| 2034 |
'lot_id': self.env['stock.lot'].create({'name': '1001', 'product_id': product.id}).id, |
| 2035 |
}, { |
| 2036 |
'product_id': product.id, |
| 2037 |
'inventory_quantity': 1, |
| 2038 |
'location_id': self.env.user._get_default_warehouse_id().lot_stock_id.id, |
| 2039 |
'lot_id': self.env['stock.lot'].create({'name': '1002', 'product_id': product.id}).id, |
| 2040 |
}]).sudo().action_apply_inventory() |
| 2041 |
|
| 2042 |
self.main_pos_config.picking_type_id.write({ |
| 2043 |
"use_create_lots": False, |
| 2044 |
"use_existing_lots": True, |
| 2045 |
}) |
| 2046 |
|
| 2047 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2048 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_only_existing_lots', login="pos_user") |
| 2049 |
|
| 2050 |
def test_order_with_existing_serial(self): |
| 2051 |
product = self.env['product.product'].create({ |
| 2052 |
'name': 'Serial Product', |
| 2053 |
'is_storable': True, |
| 2054 |
'tracking': 'serial', |
| 2055 |
'available_in_pos': True, |
| 2056 |
}) |
| 2057 |
for sn in ["SN1", "SN2"]: |
| 2058 |
self.env['stock.quant'].create({ |
| 2059 |
'product_id': product.id, |
| 2060 |
'inventory_quantity': 1, |
| 2061 |
'location_id': self.env.user._get_default_warehouse_id().lot_stock_id.id, |
| 2062 |
'lot_id': self.env['stock.lot'].create({'name': sn, 'product_id': product.id}).id, |
| 2063 |
}).sudo().action_apply_inventory() |
| 2064 |
self.env['stock.picking.type'].search([('name', '=', 'PoS Orders')]).use_create_lots = False |
| 2065 |
|
| 2066 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2067 |
self.start_pos_tour("test_order_with_existing_serial") |
| 2068 |
|
| 2069 |
def test_product_search(self): |
| 2070 |
"""Verify that the product search works correctly""" |
| 2071 |
product_with_variant = self.env['product.template'].create({ |
| 2072 |
'name': 'Product with Variant', |
| 2073 |
'available_in_pos': True, |
| 2074 |
'list_price': 10, |
| 2075 |
'taxes_id': False, |
| 2076 |
'barcode': '1234567', |
| 2077 |
}) |
| 2078 |
|
| 2079 |
color_attribute = self.env['product.attribute'].create({ |
| 2080 |
'name': 'Color always', |
| 2081 |
'create_variant': 'always', |
| 2082 |
'value_ids': [(0, 0, { |
| 2083 |
'name': 'Red', |
| 2084 |
'sequence': 1, |
| 2085 |
}), (0, 0, { |
| 2086 |
'name': 'Blue', |
| 2087 |
'sequence': 2, |
| 2088 |
})], |
| 2089 |
}) |
| 2090 |
|
| 2091 |
self.env['product.template.attribute.line'].create({ |
| 2092 |
'product_tmpl_id': product_with_variant.id, |
| 2093 |
'attribute_id': color_attribute.id, |
| 2094 |
'value_ids': [(6, 0, color_attribute.value_ids.ids)] |
| 2095 |
}) |
| 2096 |
product_with_variant.product_variant_ids[0].write({ |
| 2097 |
"barcode": "variant_barcode_1", |
| 2098 |
"default_code": "VARIANT_1" |
| 2099 |
}) |
| 2100 |
product_with_variant.product_variant_ids[1].write({ |
| 2101 |
"barcode": "variant_barcode_2", |
| 2102 |
"default_code": "VARIANT_2" |
| 2103 |
}) |
| 2104 |
|
| 2105 |
self.env['product.product'].create([ |
| 2106 |
{ |
| 2107 |
'name': 'Test Product 1', |
| 2108 |
'list_price': 100, |
| 2109 |
'taxes_id': False, |
| 2110 |
'available_in_pos': True, |
| 2111 |
'barcode': '1234567890123', |
| 2112 |
'default_code': 'TESTPROD1', |
| 2113 |
}, |
| 2114 |
{ |
| 2115 |
'name': 'Test Product 2', |
| 2116 |
'list_price': 100, |
| 2117 |
'taxes_id': False, |
| 2118 |
'available_in_pos': True, |
| 2119 |
'barcode': '1234567890124', |
| 2120 |
'default_code': 'TESTPROD2', |
| 2121 |
}, |
| 2122 |
{ |
| 2123 |
'name': 'Apple', |
| 2124 |
'list_price': 100, |
| 2125 |
'taxes_id': False, |
| 2126 |
'available_in_pos': True, |
| 2127 |
}, |
| 2128 |
{ |
| 2129 |
'name': 'galaxy', |
| 2130 |
'list_price': 100, |
| 2131 |
'taxes_id': False, |
| 2132 |
'available_in_pos': True, |
| 2133 |
}, |
| 2134 |
{ |
| 2135 |
'name': '1234567890123', |
| 2136 |
'list_price': 100, |
| 2137 |
'taxes_id': False, |
| 2138 |
'available_in_pos': True, |
| 2139 |
}, |
| 2140 |
]) |
| 2141 |
|
| 2142 |
att_color = self.env['product.attribute'].create({'name': 'Color', 'sequence': 1}) |
| 2143 |
|
| 2144 |
att_color_values = self.env['product.attribute.value'].create([ |
| 2145 |
{'name': 'galaxy variant', 'attribute_id': att_color.id, 'sequence': 1}, |
| 2146 |
{'name': 'blue', 'attribute_id': att_color.id, 'sequence': 2}, |
| 2147 |
]) |
| 2148 |
|
| 2149 |
self.env['product.template'].create({ |
| 2150 |
'name': 'Test Product variant', |
| 2151 |
'attribute_line_ids': [ |
| 2152 |
Command.create({ |
| 2153 |
'attribute_id': att_color.id, |
| 2154 |
'value_ids': [Command.set(att_color_values.mapped('id'))], |
| 2155 |
}), |
| 2156 |
], |
| 2157 |
'available_in_pos': True, |
| 2158 |
}) |
| 2159 |
|
| 2160 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2161 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'ProductSearchTour', login="pos_user") |
| 2162 |
|
| 2163 |
def test_customer_popup(self): |
| 2164 |
"""Verify that the customer popup search & inifnite scroll work properly""" |
| 2165 |
self.env["res.partner"].create([{"name": "Z partner to search"}, {"name": "Z partner to scroll"}]) |
| 2166 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2167 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'CustomerPopupTour', login="pos_user") |
| 2168 |
|
| 2169 |
def test_pricelist_multi_items_different_qty_thresholds(self): |
| 2170 |
""" Having multiple pricelist items for the same product tmpl with ascending `min_quantity` |
| 2171 |
values, prefer the "latest available"- that is, the one with greater `min_quantity`. |
| 2172 |
""" |
| 2173 |
product = self.env['product.product'].create({ |
| 2174 |
'name': 'tpmcapi product', |
| 2175 |
'list_price': 1.0, |
| 2176 |
'available_in_pos': True, |
| 2177 |
'taxes_id': False, |
| 2178 |
}) |
| 2179 |
self.main_pos_config.pricelist_id.write({ |
| 2180 |
'item_ids': [Command.create({ |
| 2181 |
'display_applied_on': '1_product', |
| 2182 |
'product_tmpl_id': product.product_tmpl_id.id, |
| 2183 |
'compute_price': 'fixed', |
| 2184 |
'fixed_price': 10.0, |
| 2185 |
'min_quantity': 3, |
| 2186 |
}), Command.create({ |
| 2187 |
'display_applied_on': '1_product', |
| 2188 |
'product_tmpl_id': product.product_tmpl_id.id, |
| 2189 |
'compute_price': 'fixed', |
| 2190 |
'fixed_price': 20.0, |
| 2191 |
'min_quantity': 2, |
| 2192 |
})], |
| 2193 |
}) |
| 2194 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2195 |
self.start_tour( |
| 2196 |
f'/pos/ui/{self.main_pos_config.id}', |
| 2197 |
'test_pricelist_multi_items_different_qty_thresholds', |
| 2198 |
login='pos_user' |
| 2199 |
) |
| 2200 |
|
| 2201 |
def test_tracking_number_closing_session(self): |
| 2202 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2203 |
self.start_tour(f"/pos/ui/{self.main_pos_config.id}", 'test_tracking_number_closing_session', login="pos_user") |
| 2204 |
|
| 2205 |
# Change should be given in cash |
| 2206 |
cash_payment_method = self.main_pos_config.payment_method_ids.filtered(lambda p: p.is_cash_count) |
| 2207 |
last_order = self.main_pos_config.current_session_id.order_ids[-1] |
| 2208 |
self.assertRecordValues(last_order.payment_ids.sorted(), [ |
| 2209 |
{'amount': -18.02, 'payment_method_id': cash_payment_method.id, 'is_change': True}, |
| 2210 |
{'amount': 20.0, 'payment_method_id': self.bank_payment_method.id, 'is_change': False}, |
| 2211 |
]) |
| 2212 |
|
| 2213 |
# References should not have gaps |
| 2214 |
references = self.env['pos.order'].search([], order="pos_reference").mapped("pos_reference") |
| 2215 |
for i in range(len(references) - 1): |
| 2216 |
self.assertEqual(int(references[i + 1].split('-')[-1]), int(references[i].split('-')[-1]) + 1, "There is a gap in the pos references") |
| 2217 |
|
| 2218 |
def test_reload_page_before_payment_with_customer_account(self): |
| 2219 |
self.customer_account_payment_method = self.env['pos.payment.method'].create({ |
| 2220 |
'name': 'Customer Account', |
| 2221 |
'split_transactions': True, |
| 2222 |
}) |
| 2223 |
self.main_pos_config.write({'payment_method_ids': [(6, 0, self.customer_account_payment_method.ids)]}) |
| 2224 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2225 |
self.start_tour( |
| 2226 |
f'/pos/ui/{self.main_pos_config.id}', |
| 2227 |
'test_reload_page_before_payment_with_customer_account', |
| 2228 |
login='pos_user' |
| 2229 |
) |
| 2230 |
|
| 2231 |
def test_product_card_qty_precision(self): |
| 2232 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2233 |
self.start_tour(f"/pos/ui/{self.main_pos_config.id}", 'ProductCardUoMPrecision', login="pos_user") |
| 2234 |
|
| 2235 |
@freeze_time("2025-06-15 11:09") |
| 2236 |
def test_cash_in_out(self): |
| 2237 |
self.pos_user.write({ |
| 2238 |
'group_ids': [ |
| 2239 |
(4, self.env.ref('account.group_account_basic').id), |
| 2240 |
] |
| 2241 |
}) |
| 2242 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2243 |
self.start_tour(f"/pos/ui/{self.main_pos_config.id}", 'test_cash_in_out', login="pos_user") |
| 2244 |
|
| 2245 |
self.assertEqual(len(self.main_pos_config.current_session_id.statement_line_ids), 1, "There should be one cash in/out statement line") |
| 2246 |
self.assertEqual(self.main_pos_config.current_session_id.statement_line_ids[0].amount, -5, "The cash in/out amount should be -5") |
| 2247 |
|
| 2248 |
def test_reuse_empty_floating_order(self): |
| 2249 |
""" Verify that after a payment, POS should reuse an existing empty floating order if available, instead of always creating new ones """ |
| 2250 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2251 |
self.start_tour(f"/pos/ui?config_id={self.main_pos_config.id}", 'test_reuse_empty_floating_order', login="pos_user") |
| 2252 |
|
| 2253 |
def test_add_multiple_serials_at_once(self): |
| 2254 |
self.product_a = self.env['product.product'].create({ |
| 2255 |
'name': 'Product A', |
| 2256 |
'is_storable': True, |
| 2257 |
'tracking': 'serial', |
| 2258 |
'available_in_pos': True, |
| 2259 |
}) |
| 2260 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2261 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, "AddMultipleSerialsAtOnce", login="pos_user") |
| 2262 |
|
| 2263 |
def test_order_and_invoice_amounts(self): |
| 2264 |
payment_term = self.env['account.payment.term'].create({ |
| 2265 |
'name': "early_payment_term", |
| 2266 |
'discount_percentage': 10, |
| 2267 |
'discount_days': 10, |
| 2268 |
'early_discount': True, |
| 2269 |
'early_pay_discount_computation': 'mixed', |
| 2270 |
'line_ids': [Command.create({ |
| 2271 |
'value': 'percent', |
| 2272 |
'nb_days': 0, |
| 2273 |
'value_amount': 100, |
| 2274 |
})] |
| 2275 |
}) |
| 2276 |
self.partner_test_1.property_payment_term_id = payment_term.id |
| 2277 |
|
| 2278 |
tax = self.env['account.tax'].create({ |
| 2279 |
'name': 'Tax 10%', |
| 2280 |
'amount': 10, |
| 2281 |
'amount_type': 'percent', |
| 2282 |
'type_tax_use': 'sale', |
| 2283 |
}) |
| 2284 |
self.env['product.product'].create({ |
| 2285 |
'name': 'Product Test', |
| 2286 |
'available_in_pos': True, |
| 2287 |
'list_price': 1000, |
| 2288 |
'taxes_id': [(6, 0, [tax.id])], |
| 2289 |
}) |
| 2290 |
|
| 2291 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2292 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PaymentScreenInvoiceOrder', login="pos_user") |
| 2293 |
|
| 2294 |
order = self.env['pos.order'].search([('partner_id', '=', self.partner_test_1.id)], limit=1) |
| 2295 |
self.assertTrue(order) |
| 2296 |
|
| 2297 |
self.assertEqual(order.partner_id, self.partner_test_1) |
| 2298 |
|
| 2299 |
invoice = self.env['account.move'].search([('invoice_origin', '=', order.pos_reference)], limit=1) |
| 2300 |
self.assertTrue(invoice) |
| 2301 |
self.assertFalse(invoice.invoice_payment_term_id) |
| 2302 |
|
| 2303 |
self.assertAlmostEqual(order.amount_total, invoice.amount_total, places=2, msg="Order and Invoice amounts do not match.") |
| 2304 |
|
| 2305 |
def test_pricelist_parent_category_rule(self): |
| 2306 |
parent_category = self.env['product.category'].create({ |
| 2307 |
'name': 'Parent Category', |
| 2308 |
}) |
| 2309 |
child_category = self.env['product.category'].create({ |
| 2310 |
'name': 'Child Category', |
| 2311 |
'parent_id': parent_category.id, |
| 2312 |
}) |
| 2313 |
self.env['product.product'].create({ |
| 2314 |
'name': 'Product with child category', |
| 2315 |
'list_price': 100, |
| 2316 |
'taxes_id': False, |
| 2317 |
'available_in_pos': True, |
| 2318 |
'categ_id': child_category.id, |
| 2319 |
}) |
| 2320 |
|
| 2321 |
pricelist = self.env['product.pricelist'].create({ |
| 2322 |
'name': 'Test pricelist on category', |
| 2323 |
'item_ids': [(0, 0, { |
| 2324 |
'compute_price': 'fixed', |
| 2325 |
'fixed_price': 50, |
| 2326 |
'applied_on': '2_product_category', |
| 2327 |
'categ_id': parent_category.id, |
| 2328 |
})], |
| 2329 |
}) |
| 2330 |
|
| 2331 |
self.main_pos_config.write({ |
| 2332 |
'pricelist_id': pricelist.id, |
| 2333 |
'available_pricelist_ids': [(6, 0, [pricelist.id])], |
| 2334 |
}) |
| 2335 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2336 |
self.start_tour(f"/pos/ui?config_id={self.main_pos_config.id}", 'test_pricelist_parent_category_rule', login="pos_user") |
| 2337 |
|
| 2338 |
def test_product_create_update_from_frontend(self): |
| 2339 |
''' This test verifies product creation and updates product details from the POS frontend. ''' |
| 2340 |
self.pos_admin.write({ |
| 2341 |
'group_ids': [Command.link(self.env.ref('base.group_system').id)], |
| 2342 |
}) |
| 2343 |
self.env['pos.category'].search([('id', '!=', self.pos_cat_chair_test.id)]).write({'sequence': 100}) |
| 2344 |
self.pos_cat_chair_test.write({'sequence': 1}) |
| 2345 |
self.main_pos_config.with_user(self.pos_admin).open_ui() |
| 2346 |
self.start_tour('/pos/ui/%d' % self.main_pos_config.id, 'test_product_create_update_from_frontend', login='pos_admin') |
| 2347 |
|
| 2348 |
# In the frontend, a product was created during the tour with the following details: |
| 2349 |
# - Product name: Test Frontend Product |
| 2350 |
# - Barcode: 710535977349 |
| 2351 |
# - List price: 20.0 |
| 2352 |
|
| 2353 |
# Ensure that the original product created in the frontend ('Test Frontend Product') has been edited to ('Test Frontend Product Edited'). |
| 2354 |
frontend_created_product = self.env['product.product'].search_count([('name', '=', 'Test Frontend Product')]) |
| 2355 |
frontend_created_product_edited = self.env['product.product'].search([('name', '=', 'Test Frontend Product Edited')]) |
| 2356 |
|
| 2357 |
self.assertEqual(frontend_created_product, 0) |
| 2358 |
self.assertEqual(frontend_created_product_edited.name, 'Test Frontend Product Edited') |
| 2359 |
self.assertEqual(frontend_created_product_edited.barcode, '710535977348') |
| 2360 |
self.assertEqual(frontend_created_product_edited.list_price, 50.0) |
| 2361 |
|
| 2362 |
def test_one_attribute_value_scan_barcode(self): |
| 2363 |
product = self.env['product.template'].create({ |
| 2364 |
'name': 'Product Test', |
| 2365 |
'available_in_pos': True, |
| 2366 |
'list_price': 10, |
| 2367 |
'taxes_id': False, |
| 2368 |
'barcode': '1234567', |
| 2369 |
}) |
| 2370 |
|
| 2371 |
size_attribute = self.env['product.attribute'].create({ |
| 2372 |
'name': 'Size never', |
| 2373 |
'create_variant': 'no_variant', |
| 2374 |
'value_ids': [(0, 0, { |
| 2375 |
'name': 'Large', |
| 2376 |
})], |
| 2377 |
}) |
| 2378 |
|
| 2379 |
self.env['product.template.attribute.line'].create({ |
| 2380 |
'product_tmpl_id': product.id, |
| 2381 |
'attribute_id': size_attribute.id, |
| 2382 |
'value_ids': [(6, 0, size_attribute.value_ids.ids)] |
| 2383 |
}) |
| 2384 |
|
| 2385 |
color_attribute = self.env['product.attribute'].create({ |
| 2386 |
'name': 'Color always', |
| 2387 |
'create_variant': 'always', |
| 2388 |
'value_ids': [(0, 0, { |
| 2389 |
'name': 'Red', |
| 2390 |
'sequence': 1, |
| 2391 |
}), (0, 0, { |
| 2392 |
'name': 'Blue', |
| 2393 |
'sequence': 2, |
| 2394 |
})], |
| 2395 |
}) |
| 2396 |
|
| 2397 |
self.env['product.template.attribute.line'].create({ |
| 2398 |
'product_tmpl_id': product.id, |
| 2399 |
'attribute_id': color_attribute.id, |
| 2400 |
'value_ids': [(6, 0, color_attribute.value_ids.ids)] |
| 2401 |
}) |
| 2402 |
|
| 2403 |
product.product_variant_ids[0].barcode = '1234567' |
| 2404 |
product.product_variant_ids[1].barcode = '1234568' |
| 2405 |
|
| 2406 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2407 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_one_attribute_value_scan_barcode', login="pos_user") |
| 2408 |
|
| 2409 |
def test_fiscal_position_tax_group_labels(self): |
| 2410 |
fiscal_position = self.env['account.fiscal.position'].create({ |
| 2411 |
'name': 'Fiscal Position Test', |
| 2412 |
}) |
| 2413 |
tax_1 = self.env['account.tax'].create({ |
| 2414 |
'name': 'Tax 15%', |
| 2415 |
'amount': 15, |
| 2416 |
'price_include_override': 'tax_included', |
| 2417 |
'amount_type': 'percent', |
| 2418 |
'type_tax_use': 'sale', |
| 2419 |
}) |
| 2420 |
tax_1.tax_group_id.pos_receipt_label = 'Tax Group 1' |
| 2421 |
|
| 2422 |
tax_2 = self.env['account.tax'].create({ |
| 2423 |
'name': 'Tax 5%', |
| 2424 |
'amount': 5, |
| 2425 |
'price_include_override': 'tax_included', |
| 2426 |
'amount_type': 'percent', |
| 2427 |
'type_tax_use': 'sale', |
| 2428 |
'fiscal_position_ids': [Command.link(fiscal_position.id)], |
| 2429 |
'original_tax_ids': [Command.link(tax_1.id)], |
| 2430 |
}) |
| 2431 |
tax_2.tax_group_id.pos_receipt_label = 'Tax Group 2' |
| 2432 |
|
| 2433 |
self.product = self.env['product.product'].create({ |
| 2434 |
'name': 'Test Product', |
| 2435 |
'taxes_id': [(6, 0, [tax_1.id])], |
| 2436 |
'list_price': 100, |
| 2437 |
'available_in_pos': True, |
| 2438 |
}) |
| 2439 |
|
| 2440 |
self.main_pos_config.write({ |
| 2441 |
'tax_regime_selection': True, |
| 2442 |
'fiscal_position_ids': [(6, 0, [fiscal_position.id])], |
| 2443 |
}) |
| 2444 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2445 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'test_fiscal_position_tax_group_labels', login="pos_user") |
| 2446 |
|
| 2447 |
def test_draft_orders_not_syncing(self): |
| 2448 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2449 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_draft_orders_not_syncing', login="pos_user") |
| 2450 |
n_draft_order = self.env['pos.order'].search_count([('state', '=', 'draft')], limit=1) |
| 2451 |
self.assertEqual(n_draft_order, 0, 'There should be no draft orders created') |
| 2452 |
|
| 2453 |
def test_product_long_press(self): |
| 2454 |
""" Test the long press on product to open the product info """ |
| 2455 |
archive_products(self.env) |
| 2456 |
group_tax = self.env['account.tax'].create({ |
| 2457 |
'name': 'Parent Tax', |
| 2458 |
'amount_type': 'group', |
| 2459 |
'children_tax_ids': [(0, 0, { |
| 2460 |
'name': 'Child Tax 1', |
| 2461 |
'amount': 10, |
| 2462 |
}), (0, 0, { |
| 2463 |
'name': 'Child Tax 2', |
| 2464 |
'amount': 5, |
| 2465 |
})], |
| 2466 |
}) |
| 2467 |
self.env['product.product'].create({ |
| 2468 |
'name': 'Test Product', |
| 2469 |
'list_price': 100, |
| 2470 |
'taxes_id': [(6, 0, [group_tax.id])], |
| 2471 |
'available_in_pos': True, |
| 2472 |
}) |
| 2473 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2474 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'test_product_long_press', login="pos_user") |
| 2475 |
|
| 2476 |
def test_zero_decimal_places_currency(self): |
| 2477 |
zero_decimal_currency = self.env['res.currency'].create({ |
| 2478 |
'name': 'ZeroDecimalCurrency', |
| 2479 |
'symbol': 'ZDC', |
| 2480 |
'rounding': 1.0, |
| 2481 |
'decimal_places': 0, |
| 2482 |
}) |
| 2483 |
|
| 2484 |
self.env.user.company_id.currency_id = zero_decimal_currency |
| 2485 |
self.main_pos_config.available_pricelist_ids.write({'currency_id': zero_decimal_currency.id}) |
| 2486 |
|
| 2487 |
self.env['product.product'].create({ |
| 2488 |
'name': 'Test Product', |
| 2489 |
'list_price': 100, |
| 2490 |
'taxes_id': False, |
| 2491 |
'available_in_pos': True, |
| 2492 |
}) |
| 2493 |
|
| 2494 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2495 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_zero_decimal_places_currency', login="pos_user") |
| 2496 |
|
| 2497 |
def test_barcode_search_attributes_preset(self): |
| 2498 |
product = self.env['product.template'].create({ |
| 2499 |
'name': 'Product with Attributes', |
| 2500 |
'available_in_pos': True, |
| 2501 |
'list_price': 10, |
| 2502 |
'taxes_id': False, |
| 2503 |
}) |
| 2504 |
|
| 2505 |
# Product template to force UI reset (acts as a delay) |
| 2506 |
self.env['product.template'].create({ |
| 2507 |
'name': 'Product without Attributes', |
| 2508 |
'available_in_pos': True, |
| 2509 |
'list_price': 20, |
| 2510 |
'taxes_id': False, |
| 2511 |
'barcode': '987654321', |
| 2512 |
}) |
| 2513 |
|
| 2514 |
attribute_1, attribute_2, attribute_3, attribute_4 = self.env['product.attribute'].create([{ |
| 2515 |
'name': 'Attribute 1', |
| 2516 |
'create_variant': 'always', |
| 2517 |
'display_type': 'radio', |
| 2518 |
'value_ids': [(0, 0, { |
| 2519 |
'name': 'Value 1', |
| 2520 |
}), (0, 0, { |
| 2521 |
'name': 'Value 2', |
| 2522 |
})], |
| 2523 |
}, { |
| 2524 |
'name': 'Attribute 2', |
| 2525 |
'create_variant': 'always', |
| 2526 |
'display_type': 'pills', |
| 2527 |
'value_ids': [(0, 0, { |
| 2528 |
'name': 'Value 3', |
| 2529 |
}), (0, 0, { |
| 2530 |
'name': 'Value 4', |
| 2531 |
})], |
| 2532 |
}, { |
| 2533 |
'name': 'Attribute 3', |
| 2534 |
'create_variant': 'always', |
| 2535 |
'display_type': 'select', |
| 2536 |
'value_ids': [(0, 0, { |
| 2537 |
'name': 'Value 5', |
| 2538 |
}), (0, 0, { |
| 2539 |
'name': 'Value 6', |
| 2540 |
})], |
| 2541 |
}, { |
| 2542 |
'name': 'Attribute 4', |
| 2543 |
'create_variant': 'always', |
| 2544 |
'display_type': 'color', |
| 2545 |
'value_ids': [(0, 0, { |
| 2546 |
'name': 'Value 7', |
| 2547 |
}), (0, 0, { |
| 2548 |
'name': 'Value 8', |
| 2549 |
})], |
| 2550 |
}]) |
| 2551 |
|
| 2552 |
self.env['product.template.attribute.line'].create([{ |
| 2553 |
'product_tmpl_id': product.id, |
| 2554 |
'attribute_id': attribute_1.id, |
| 2555 |
'value_ids': [(6, 0, attribute_1.value_ids.ids)], |
| 2556 |
'sequence': 1, |
| 2557 |
}, { |
| 2558 |
'product_tmpl_id': product.id, |
| 2559 |
'attribute_id': attribute_2.id, |
| 2560 |
'value_ids': [(6, 0, attribute_2.value_ids.ids)], |
| 2561 |
'sequence': 2, |
| 2562 |
}, { |
| 2563 |
'product_tmpl_id': product.id, |
| 2564 |
'attribute_id': attribute_3.id, |
| 2565 |
'value_ids': [(6, 0, attribute_3.value_ids.ids)], |
| 2566 |
'sequence': 3, |
| 2567 |
}, { |
| 2568 |
'product_tmpl_id': product.id, |
| 2569 |
'attribute_id': attribute_4.id, |
| 2570 |
'value_ids': [(6, 0, attribute_4.value_ids.ids)], |
| 2571 |
'sequence': 4, |
| 2572 |
}]) |
| 2573 |
|
| 2574 |
for p in product.product_variant_ids: |
| 2575 |
p.write({ |
| 2576 |
'barcode': f'1234{"".join(p.product_template_attribute_value_ids.mapped(lambda ptav: ptav.name[-1]))}', |
| 2577 |
}) |
| 2578 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2579 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_barcode_search_attributes_preset', login="pos_user") |
| 2580 |
|
| 2581 |
def test_auto_validate_force_done(self): |
| 2582 |
self.main_pos_config.write({ |
| 2583 |
'auto_validate_terminal_payment': True |
| 2584 |
}) |
| 2585 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_auto_validate_force_done', login="pos_user") |
| 2586 |
|
| 2587 |
def test_pos_ui_round_globally(self): |
| 2588 |
self.main_pos_config.company_id.tax_calculation_rounding_method = 'round_globally' |
| 2589 |
tax_16 = self.env['account.tax'].create({ |
| 2590 |
'name': 'Tax 16%', |
| 2591 |
'amount': 16, |
| 2592 |
}) |
| 2593 |
self.env['product.product'].create([{ |
| 2594 |
'name': 'Test Product 1', |
| 2595 |
'list_price': 7051.73, |
| 2596 |
'taxes_id': [(6, 0, [tax_16.id])], |
| 2597 |
'available_in_pos': True, |
| 2598 |
}, { |
| 2599 |
'name': 'Test Product 2', |
| 2600 |
'list_price': 352.59, |
| 2601 |
'taxes_id': [(6, 0, [tax_16.id])], |
| 2602 |
'available_in_pos': True, |
| 2603 |
}]) |
| 2604 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2605 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_pos_ui_round_globally', login="pos_user") |
| 2606 |
|
| 2607 |
pos_session = self.main_pos_config.current_session_id |
| 2608 |
self.assertEqual(pos_session.order_ids[0].payment_ids[0].amount, 7771.01) |
| 2609 |
|
| 2610 |
# Close the session and check the session journal entry. |
| 2611 |
pos_session.action_pos_session_validate() |
| 2612 |
|
| 2613 |
lines = pos_session.move_id.line_ids.sorted('balance') |
| 2614 |
|
| 2615 |
self.assertEqual(len(lines), 5, "There should be 5 lines in the session journal entry") |
| 2616 |
self.assertAlmostEqual(lines[0].balance, -7051.73) |
| 2617 |
self.assertAlmostEqual(lines[1].balance, -1128.28) |
| 2618 |
self.assertAlmostEqual(lines[2].balance, 56.41) |
| 2619 |
self.assertAlmostEqual(lines[3].balance, 352.59) |
| 2620 |
self.assertAlmostEqual(lines[4].balance, 7771.01) |
| 2621 |
|
| 2622 |
def test_ctrl_number_ignored(self): |
| 2623 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_ctrl_number_ignored', login="pos_user") |
| 2624 |
|
| 2625 |
def test_click_all_orders_keep_customer(self): |
| 2626 |
"""Verify that clicking on 'All Orders' keeps the customer selected.""" |
| 2627 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2628 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_click_all_orders_keep_customer', login="pos_user") |
| 2629 |
|
| 2630 |
def test_quantity_package_of_non_basic_unit(self): |
| 2631 |
test_uom_unit = self.env['uom.uom'].create({ |
| 2632 |
"name": "test unit uom", |
| 2633 |
"relative_factor": "1.0", |
| 2634 |
}) |
| 2635 |
pack_of_12_unit = self.env['uom.uom'].create({ |
| 2636 |
'name': 'Pack of 12 unit', |
| 2637 |
'relative_factor': 12, |
| 2638 |
'relative_uom_id': test_uom_unit.id, |
| 2639 |
'is_pos_groupable': True, |
| 2640 |
}) |
| 2641 |
product_cord = self.env['product.product'].create({ |
| 2642 |
'name': 'Cord', |
| 2643 |
'is_storable': True, |
| 2644 |
'available_in_pos': True, |
| 2645 |
'uom_id': test_uom_unit.id, |
| 2646 |
'uom_ids': [pack_of_12_unit.id], |
| 2647 |
'lst_price': 10.0, |
| 2648 |
}) |
| 2649 |
self.env['product.uom'].create({ |
| 2650 |
'barcode': '555555', |
| 2651 |
'product_id': product_cord.id, |
| 2652 |
'uom_id': pack_of_12_unit.id, |
| 2653 |
}) |
| 2654 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2655 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_quantity_package_of_non_basic_unit', login="pos_user") |
| 2656 |
|
| 2657 |
def test_attribute_order(self): |
| 2658 |
product = self.env['product.template'].create({ |
| 2659 |
'name': 'Product Test', |
| 2660 |
'available_in_pos': True, |
| 2661 |
'list_price': 10, |
| 2662 |
'taxes_id': False, |
| 2663 |
}) |
| 2664 |
|
| 2665 |
attribute_3 = self.env['product.attribute'].create({ |
| 2666 |
'name': 'Attribute 3', |
| 2667 |
'create_variant': 'no_variant', |
| 2668 |
'value_ids': [(0, 0, { |
| 2669 |
'name': 'Value 3', |
| 2670 |
}), (0, 0, { |
| 2671 |
'name': 'Value 4', |
| 2672 |
})], |
| 2673 |
}) |
| 2674 |
|
| 2675 |
self.env['product.template.attribute.line'].create({ |
| 2676 |
'product_tmpl_id': product.id, |
| 2677 |
'attribute_id': attribute_3.id, |
| 2678 |
'value_ids': [(6, 0, attribute_3.value_ids.ids)], |
| 2679 |
'sequence': 3, |
| 2680 |
}) |
| 2681 |
|
| 2682 |
attribute_2 = self.env['product.attribute'].create({ |
| 2683 |
'name': 'Attribute 2', |
| 2684 |
'create_variant': 'no_variant', |
| 2685 |
'value_ids': [(0, 0, { |
| 2686 |
'name': 'Value 2', |
| 2687 |
})], |
| 2688 |
}) |
| 2689 |
|
| 2690 |
self.env['product.template.attribute.line'].create({ |
| 2691 |
'product_tmpl_id': product.id, |
| 2692 |
'attribute_id': attribute_2.id, |
| 2693 |
'value_ids': [(6, 0, attribute_2.value_ids.ids)], |
| 2694 |
'sequence': 2, |
| 2695 |
}) |
| 2696 |
|
| 2697 |
attribute_1 = self.env['product.attribute'].create({ |
| 2698 |
'name': 'Attribute 1', |
| 2699 |
'create_variant': 'no_variant', |
| 2700 |
'value_ids': [(0, 0, { |
| 2701 |
'name': 'Value 1', |
| 2702 |
})], |
| 2703 |
}) |
| 2704 |
|
| 2705 |
self.env['product.template.attribute.line'].create({ |
| 2706 |
'product_tmpl_id': product.id, |
| 2707 |
'attribute_id': attribute_1.id, |
| 2708 |
'value_ids': [(6, 0, attribute_1.value_ids.ids)], |
| 2709 |
'sequence': 1, |
| 2710 |
}) |
| 2711 |
|
| 2712 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2713 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_attribute_order', login="pos_user") |
| 2714 |
|
| 2715 |
def test_preset_timing_retail(self): |
| 2716 |
""" |
| 2717 |
Test to set order preset hour inside a tour |
| 2718 |
""" |
| 2719 |
self.preset_dine_in = self.env['pos.preset'].create({ |
| 2720 |
'name': 'Dine in', |
| 2721 |
}) |
| 2722 |
self.preset_delivery = self.env['pos.preset'].create({ |
| 2723 |
'name': 'Delivery', |
| 2724 |
'identification': 'address', |
| 2725 |
}) |
| 2726 |
self.main_pos_config.write({ |
| 2727 |
'use_presets': True, |
| 2728 |
'default_preset_id': self.preset_dine_in.id, |
| 2729 |
'available_preset_ids': [(6, 0, [self.preset_delivery.id])], |
| 2730 |
}) |
| 2731 |
self.pos_user.street = 'Rue de Ramillies' |
| 2732 |
resource_calendar = self.env['resource.calendar'].create({ |
| 2733 |
'name': 'Takeaway', |
| 2734 |
'attendance_ids': [(0, 0, { |
| 2735 |
'name': 'Takeaway', |
| 2736 |
'dayofweek': str(day), |
| 2737 |
'hour_from': 0, |
| 2738 |
'hour_to': 24, |
| 2739 |
'day_period': 'morning', |
| 2740 |
}) for day in range(7)], |
| 2741 |
}) |
| 2742 |
self.preset_delivery.write({ |
| 2743 |
'use_timing': True, |
| 2744 |
'resource_calendar_id': resource_calendar |
| 2745 |
}) |
| 2746 |
self.start_pos_tour('test_preset_timing_retail') |
| 2747 |
|
| 2748 |
def test_pricelists_in_pos(self): |
| 2749 |
pos_limited_category = self.env['pos.category'].create({'name': 'Limited Category'}) |
| 2750 |
pos_category = self.env['pos.category'].create({'name': 'test_pricelists_in_pos'}) |
| 2751 |
product_category = self.env['product.category'].create({'name': 'test_pricelists_in_pos'}) |
| 2752 |
orange_category = self.env['product.category'].create({'name': 'Orange Category'}) |
| 2753 |
|
| 2754 |
def generate_pricelist_items(pricelist, fixed_price, product=None, product_tmpl=None, product_category=None): |
| 2755 |
applied_on = '0_product_variant' if product else '1_product' if product_tmpl else '2_product_category' if product_category else '3_global' |
| 2756 |
return self.env['product.pricelist.item'].create({ |
| 2757 |
'pricelist_id': pricelist.id, |
| 2758 |
'product_id': product.id if product else False, |
| 2759 |
'product_tmpl_id': product_tmpl.id if product_tmpl else False, |
| 2760 |
'categ_id': product_category.id if product_category else False, |
| 2761 |
'compute_price': 'fixed', |
| 2762 |
'applied_on': applied_on, |
| 2763 |
'fixed_price': fixed_price, |
| 2764 |
}) |
| 2765 |
|
| 2766 |
def generate_product_template_with_attributes(name, price, pos_category=None, product_category=None): |
| 2767 |
size_attribute = self.env['product.attribute'].create({ |
| 2768 |
'name': 'Size', |
| 2769 |
'sequence': 4, |
| 2770 |
'value_ids': [(0, 0, { |
| 2771 |
'name': 'BIG', |
| 2772 |
'sequence': 1, |
| 2773 |
}), (0, 0, { |
| 2774 |
'name': 'MEDIUM', |
| 2775 |
'sequence': 2, |
| 2776 |
}), (0, 0, { |
| 2777 |
'name': 'SMALL', |
| 2778 |
'sequence': 3, |
| 2779 |
})], |
| 2780 |
}) |
| 2781 |
|
| 2782 |
product_tmpl = self.env['product.template'].create({ |
| 2783 |
'name': name.capitalize(), |
| 2784 |
'available_in_pos': True, |
| 2785 |
'categ_id': product_category.id if product_category else False, |
| 2786 |
'pos_categ_ids': [(4, pos_category.id)] if pos_category else False, |
| 2787 |
'list_price': price, |
| 2788 |
'taxes_id': False, |
| 2789 |
'attribute_line_ids': [(0, 0, { |
| 2790 |
'attribute_id': size_attribute.id, |
| 2791 |
'value_ids': [(6, 0, size_attribute.value_ids.ids)] |
| 2792 |
})], |
| 2793 |
}) |
| 2794 |
|
| 2795 |
for index, variant in enumerate(product_tmpl.product_variant_ids): |
| 2796 |
variant.write({'barcode': f'{name}_{index}'}) |
| 2797 |
|
| 2798 |
return product_tmpl |
| 2799 |
|
| 2800 |
banana = generate_product_template_with_attributes('banana', 10.00, pos_category) |
| 2801 |
apple = generate_product_template_with_attributes('apple', 5.00, False, product_category) |
| 2802 |
pear = generate_product_template_with_attributes('pear', 2.00) |
| 2803 |
lime = generate_product_template_with_attributes('lime', 1.00) |
| 2804 |
orange = generate_product_template_with_attributes('orange', 3.00, False, orange_category) |
| 2805 |
kiwi = generate_product_template_with_attributes('kiwi', 4.00) |
| 2806 |
|
| 2807 |
test_pricelist = self.env['product.pricelist'].create({ |
| 2808 |
'name': 'Test Pricelist', |
| 2809 |
}) |
| 2810 |
|
| 2811 |
percentage_pricelist = self.env['product.pricelist'].create({ |
| 2812 |
'name': 'Percentage Pricelist', |
| 2813 |
}) |
| 2814 |
|
| 2815 |
generate_pricelist_items(test_pricelist, 20, False, banana) |
| 2816 |
generate_pricelist_items(test_pricelist, 100, banana.product_variant_ids[0]) |
| 2817 |
generate_pricelist_items(test_pricelist, 150, banana.product_variant_ids[1]) |
| 2818 |
generate_pricelist_items(test_pricelist, 500, False, False, product_category) |
| 2819 |
generate_pricelist_items(test_pricelist, 1000, False, False, orange_category) |
| 2820 |
generate_pricelist_items(test_pricelist, 100, apple.product_variant_ids[0]) |
| 2821 |
generate_pricelist_items(test_pricelist, 20, pear.product_variant_ids[0]) |
| 2822 |
generate_pricelist_items(test_pricelist, 40, pear.product_variant_ids[1]) |
| 2823 |
generate_pricelist_items(test_pricelist, 60, pear.product_variant_ids[2]) |
| 2824 |
generate_pricelist_items(test_pricelist, 100, False, lime) |
| 2825 |
generate_pricelist_items(test_pricelist, 200, lime.product_variant_ids[1]) |
| 2826 |
generate_pricelist_items(test_pricelist, 400, lime.product_variant_ids[2]) |
| 2827 |
generate_pricelist_items(test_pricelist, 600, orange.product_variant_ids[1]) |
| 2828 |
generate_pricelist_items(test_pricelist, 500, orange.product_variant_ids[2]) |
| 2829 |
generate_pricelist_items(test_pricelist, 10) |
| 2830 |
generate_pricelist_items(test_pricelist, 20, kiwi.product_variant_ids[0]) |
| 2831 |
|
| 2832 |
self.env['product.pricelist.item'].create({ |
| 2833 |
'pricelist_id': percentage_pricelist.id, |
| 2834 |
'base': 'pricelist', |
| 2835 |
'base_pricelist_id': test_pricelist.id, |
| 2836 |
'compute_price': 'percentage', |
| 2837 |
'percent_price': 50, |
| 2838 |
'applied_on': '3_global', |
| 2839 |
}) |
| 2840 |
|
| 2841 |
self.main_pos_config.write({ |
| 2842 |
"limit_categories": True, |
| 2843 |
"iface_available_categ_ids": [(6, 0, [pos_limited_category.id])], |
| 2844 |
'available_pricelist_ids': [(6, 0, [test_pricelist.id, percentage_pricelist.id])], |
| 2845 |
'pricelist_id': test_pricelist.id, |
| 2846 |
}) |
| 2847 |
|
| 2848 |
load_product_from_pos_stats = {'count': 0, 'items': {}} |
| 2849 |
product_template = self.env.registry.models['product.template'] |
| 2850 |
|
| 2851 |
# Test product exclusion |
| 2852 |
cherry = generate_product_template_with_attributes('cherry', 2.00) |
| 2853 |
color_attribute = self.env['product.attribute'].create({ |
| 2854 |
'name': 'Color', |
| 2855 |
'sequence': 5, |
| 2856 |
'value_ids': [(0, 0, { |
| 2857 |
'name': 'RED', |
| 2858 |
'sequence': 1, |
| 2859 |
}), (0, 0, { |
| 2860 |
'name': 'GREEN', |
| 2861 |
'sequence': 2, |
| 2862 |
}), (0, 0, { |
| 2863 |
'name': 'BLUE', |
| 2864 |
'sequence': 3, |
| 2865 |
})], |
| 2866 |
}) |
| 2867 |
cherry.attribute_line_ids = [(0, 0, { |
| 2868 |
'attribute_id': color_attribute.id, |
| 2869 |
'value_ids': [(6, 0, color_attribute.value_ids.ids)] |
| 2870 |
})] |
| 2871 |
color_attribute = cherry.attribute_line_ids.filtered(lambda l: l.attribute_id.name == 'Color') |
| 2872 |
first_color_value = color_attribute.product_template_value_ids.filtered(lambda v: v.attribute_id.name == 'Color' and v.name == 'RED') |
| 2873 |
first_size_value = cherry.product_variant_ids.product_template_attribute_value_ids.filtered(lambda v: v.attribute_id.name == 'Size' and v.name == 'BIG') |
| 2874 |
first_color_value.exclude_for = [(0, 0, { |
| 2875 |
'product_tmpl_id': cherry.id, |
| 2876 |
'value_ids': first_size_value.ids, |
| 2877 |
'product_template_attribute_value_id': first_size_value.id |
| 2878 |
})] |
| 2879 |
for index, variant in enumerate(cherry.product_variant_ids): |
| 2880 |
variant.write({'barcode': f'cherry_{index}'}) |
| 2881 |
|
| 2882 |
@api.model |
| 2883 |
def load_product_from_pos_patch(self, config_id, domain, offset=0, limit=0): |
| 2884 |
load_product_from_pos_stats['count'] += 1 |
| 2885 |
result = super(product_template, self).load_product_from_pos(config_id, domain, offset, limit) |
| 2886 |
lowered_name = result['product.template'][0]['display_name'].lower() |
| 2887 |
load_product_from_pos_stats['items'][lowered_name] = len(result['product.pricelist.item']) |
| 2888 |
return result |
| 2889 |
|
| 2890 |
with patch.object(product_template, "load_product_from_pos", load_product_from_pos_patch): |
| 2891 |
self.start_pos_tour('test_pricelists_in_pos') |
| 2892 |
|
| 2893 |
# Should load 6 different products, since 6 products were created |
| 2894 |
self.assertEqual(load_product_from_pos_stats['count'], 7) |
| 2895 |
|
| 2896 |
# Length of loaded pricelist items should correspond to the number of items linked |
| 2897 |
# to the product template or product variant |
| 2898 |
# Global rules are loaded at starting of the PoS |
| 2899 |
self.assertEqual(load_product_from_pos_stats['items']['banana'], 3, "Banana should have 3 pricelist items") |
| 2900 |
self.assertEqual(load_product_from_pos_stats['items']['apple'], 1, "Apple should have 1 pricelist item") |
| 2901 |
self.assertEqual(load_product_from_pos_stats['items']['pear'], 3, "Pear should have 3 pricelist items") |
| 2902 |
self.assertEqual(load_product_from_pos_stats['items']['lime'], 3, "Lime should have 3 pricelist items") |
| 2903 |
self.assertEqual(load_product_from_pos_stats['items']['orange'], 2, "Orange should have 2 pricelist items") |
| 2904 |
self.assertEqual(load_product_from_pos_stats['items']['kiwi'], 1, "Kiwi should have 1 pricelist item") |
| 2905 |
|
| 2906 |
def test_available_children_categories(self): |
| 2907 |
parent_categ = self.env['pos.category'].create({ |
| 2908 |
'name': 'Parent Category', |
| 2909 |
}) |
| 2910 |
children_categs = self.env['pos.category'].create([{ |
| 2911 |
'name': 'Child Category 1', |
| 2912 |
'parent_id': parent_categ.id, |
| 2913 |
}, { |
| 2914 |
'name': 'Child Category 2', |
| 2915 |
'parent_id': parent_categ.id, |
| 2916 |
}]) |
| 2917 |
self.env['product.product'].create([{ |
| 2918 |
'name': 'parent product', |
| 2919 |
'pos_categ_ids': [(6, 0, [parent_categ.id])], |
| 2920 |
'available_in_pos': True, |
| 2921 |
}, { |
| 2922 |
'name': 'child product 1', |
| 2923 |
'pos_categ_ids': [(6, 0, [parent_categ.id, children_categs[0].id])], |
| 2924 |
'available_in_pos': True, |
| 2925 |
}, { |
| 2926 |
'name': 'child product 2', |
| 2927 |
'pos_categ_ids': [(6, 0, [parent_categ.id, children_categs[1].id])], |
| 2928 |
'available_in_pos': True, |
| 2929 |
}]) |
| 2930 |
self.main_pos_config.write({ |
| 2931 |
'limit_categories': True, |
| 2932 |
'iface_available_categ_ids': [(6, 0, [parent_categ.id, children_categs[1].id])], |
| 2933 |
}) |
| 2934 |
self.main_pos_config.open_ui() |
| 2935 |
loaded_data = self.main_pos_config.current_session_id.load_data([]) |
| 2936 |
category_id = [category['id'] for category in loaded_data['pos.category']] |
| 2937 |
self.assertNotIn(children_categs[0].id, category_id, "Child category is unavailable and shouldn't appear in the POS") |
| 2938 |
self.assertIn(children_categs[1].id, category_id, "Child category is available and should appear in the POS") |
| 2939 |
|
| 2940 |
def test_pos_order_shipping_date(self): |
| 2941 |
self.env['res.partner'].create({ |
| 2942 |
'name': 'Partner Test with Address', |
| 2943 |
'street': 'test street', |
| 2944 |
'zip': '1234', |
| 2945 |
'city': 'test city', |
| 2946 |
'country_id': self.env.ref('base.us').id |
| 2947 |
}) |
| 2948 |
self.main_pos_config.write({'ship_later': True}) |
| 2949 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2950 |
self.start_tour( |
| 2951 |
f"/pos/ui?config_id={self.main_pos_config.id}", |
| 2952 |
"test_pos_order_shipping_date", |
| 2953 |
login="pos_user", |
| 2954 |
) |
| 2955 |
|
| 2956 |
def test_fast_payment_validation_from_product_screen_without_automatic_receipt_printing(self): |
| 2957 |
self.preset_delivery = self.env['pos.preset'].create({ |
| 2958 |
'name': 'Delivery', |
| 2959 |
'identification': 'address', |
| 2960 |
}) |
| 2961 |
self.main_pos_config.write({ |
| 2962 |
'use_fast_payment': True, |
| 2963 |
'use_presets': True, |
| 2964 |
'fast_payment_method_ids': [(6, 0, self.bank_payment_method.ids)], |
| 2965 |
'default_preset_id': self.preset_delivery.id, |
| 2966 |
'available_preset_ids': [(6, 0, [self.preset_delivery.id])], |
| 2967 |
}) |
| 2968 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2969 |
self.start_pos_tour('test_fast_payment_validation_from_product_screen_without_automatic_receipt_printing') |
| 2970 |
order1 = self.main_pos_config.current_session_id.order_ids[0] |
| 2971 |
order2 = self.main_pos_config.current_session_id.order_ids[1] |
| 2972 |
self.assertEqual(order1.state, 'paid', "The order should be paid after the fast payment validation") |
| 2973 |
self.assertEqual(len(order1.payment_ids), 1, "There should be one payment line used for the fast payment") |
| 2974 |
self.assertEqual(order1.payment_ids.payment_method_id, self.bank_payment_method, "The payment method used should be the bank payment method") |
| 2975 |
self.assertEqual(order2.state, 'paid', "The order should be paid") |
| 2976 |
self.assertEqual(len(order2.payment_ids), 1, "There should be one payment line") |
| 2977 |
self.assertEqual(order2.payment_ids.payment_method_id, self.bank_payment_method, "The payment method used should be the bank payment method") |
| 2978 |
|
| 2979 |
def test_fast_payment_validation_from_product_screen_with_automatic_receipt_printing(self): |
| 2980 |
self.main_pos_config.write({ |
| 2981 |
'use_fast_payment': True, |
| 2982 |
'fast_payment_method_ids': [(6, 0, self.bank_payment_method.ids)], |
| 2983 |
'iface_print_auto': True, |
| 2984 |
'iface_print_skip_screen': True, |
| 2985 |
'other_devices': True, |
| 2986 |
'epson_printer_ip': '127.0.0.1:8069/receipt_receiver', |
| 2987 |
}) |
| 2988 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 2989 |
self.start_pos_tour('test_fast_payment_validation_from_product_screen_with_automatic_receipt_printing') |
| 2990 |
order1 = self.main_pos_config.current_session_id.order_ids[0] |
| 2991 |
order2 = self.main_pos_config.current_session_id.order_ids[1] |
| 2992 |
self.assertEqual(order1.state, 'paid', "The order should be paid after the fast payment validation") |
| 2993 |
self.assertEqual(len(order1.payment_ids), 1, "There should be one payment line used for the fast payment") |
| 2994 |
self.assertEqual(order1.payment_ids.payment_method_id, self.bank_payment_method, "The payment method used should be the bank payment method") |
| 2995 |
self.assertEqual(order2.state, 'paid', "The order should be paid") |
| 2996 |
self.assertEqual(len(order2.payment_ids), 1, "There should be one payment line") |
| 2997 |
self.assertEqual(order2.payment_ids.payment_method_id, self.bank_payment_method, "The payment method used should be the bank payment method") |
| 2998 |
|
| 2999 |
def test_consistent_refund_process_between_frontend_and_backend(self): |
| 3000 |
""" |
| 3001 |
Ensure that the partial refund process is consistent between the frontend and backend. |
| 3002 |
This includes validating the refund order creation, amount, state, and payment processing. |
| 3003 |
""" |
| 3004 |
# Open POS UI with the POS user |
| 3005 |
pricelists = self.env['product.pricelist'].create([ |
| 3006 |
{'name': 'Test Pricelist'}, |
| 3007 |
{'name': 'Percentage Pricelist'}, |
| 3008 |
]) |
| 3009 |
self.main_pos_config.write({ |
| 3010 |
'available_pricelist_ids': [Command.set(pricelists.ids)], |
| 3011 |
'pricelist_id': pricelists[0].id, |
| 3012 |
}) |
| 3013 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3014 |
|
| 3015 |
# Run the POS tour simulating a partial refund |
| 3016 |
self.start_pos_tour('test_consistent_refund_process_between_frontend_and_backend') |
| 3017 |
|
| 3018 |
# Fetch orders created in the current POS session |
| 3019 |
orders = self.env['pos.order'].search([ |
| 3020 |
('session_id', '=', self.main_pos_config.current_session_id.id) |
| 3021 |
]) |
| 3022 |
self.assertEqual(len(orders), 2, "Expected two orders: original and refund.") |
| 3023 |
order, refund_order = orders[0], orders[1] |
| 3024 |
self.assertEqual( |
| 3025 |
refund_order.pricelist_id.id, |
| 3026 |
order.pricelist_id.id, |
| 3027 |
"Refund order pricelist should be the original order's pricelist." |
| 3028 |
) |
| 3029 |
|
| 3030 |
# Perform refund on order and retrieve the resulting draft refund order |
| 3031 |
refund_action = orders[1].refund() |
| 3032 |
refund_order = self.env['pos.order'].browse(refund_action['res_id']) |
| 3033 |
|
| 3034 |
# Validate the refund order is in draft and has correct negative total |
| 3035 |
self.assertEqual(refund_order.state, 'draft', "Refund order should be in draft state.") |
| 3036 |
self.assertEqual(refund_order.amount_total, -4, "Refund order total should be -4.") |
| 3037 |
|
| 3038 |
# Create a payment for the refund using the configured bank method |
| 3039 |
payment_context = { |
| 3040 |
"active_ids": refund_order.ids, |
| 3041 |
"active_id": refund_order.id |
| 3042 |
} |
| 3043 |
refund_payment = self.env['pos.make.payment'].with_context(**payment_context).create({ |
| 3044 |
'amount': refund_order.amount_total, |
| 3045 |
'payment_method_id': self.bank_payment_method.id, |
| 3046 |
}) |
| 3047 |
|
| 3048 |
# Validate and finalize the refund payment |
| 3049 |
refund_payment.with_context(**payment_context).check() |
| 3050 |
self.assertEqual(refund_order.state, 'paid', "Refund order should be marked as paid.") |
| 3051 |
|
| 3052 |
def test_paid_order_with_archived_product_loads(self): |
| 3053 |
""" Test that a paid order with archived products can be loaded in the POS. """ |
| 3054 |
|
| 3055 |
archived_product = self.env['product.product'].create({ |
| 3056 |
'name': 'Archived Product', |
| 3057 |
'available_in_pos': True, |
| 3058 |
'list_price': 10.0, |
| 3059 |
'taxes_id': False, |
| 3060 |
'active': False, # Archived product |
| 3061 |
}) |
| 3062 |
|
| 3063 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3064 |
self.env['pos.order'].create({ |
| 3065 |
'config_id': self.main_pos_config.id, |
| 3066 |
'session_id': self.main_pos_config.current_session_id.id, |
| 3067 |
'company_id': self.main_pos_config.company_id.id, |
| 3068 |
'amount_total': 10.0, |
| 3069 |
'amount_paid': 10.0, |
| 3070 |
'amount_tax': 0.0, |
| 3071 |
'amount_return': 0.0, |
| 3072 |
'to_invoice': False, |
| 3073 |
'partner_id': False, |
| 3074 |
'pricelist_id': self.main_pos_config.pricelist_id.id, |
| 3075 |
'pos_reference': '1000-004-00002', |
| 3076 |
'name': 'Order 0002', |
| 3077 |
'state': 'paid', |
| 3078 |
'lines': [(0, 0, { |
| 3079 |
'name': 'Line 0001', |
| 3080 |
'product_id': archived_product.id, |
| 3081 |
'price_unit': 10.00, |
| 3082 |
'discount': 0, |
| 3083 |
'qty': 1, |
| 3084 |
'tax_ids': False, |
| 3085 |
'price_subtotal': 10.00, |
| 3086 |
'price_subtotal_incl': 10.00, |
| 3087 |
})], |
| 3088 |
}) |
| 3089 |
|
| 3090 |
self.start_tour(f"/pos/ui?config_id={self.main_pos_config.id}", 'test_paid_order_with_archived_product_loads', login="pos_user") |
| 3091 |
|
| 3092 |
def test_delete_line(self): |
| 3093 |
""" Test that deleting a line in the POS through the popup works correctly. """ |
| 3094 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3095 |
self.start_pos_tour('test_delete_line') |
| 3096 |
|
| 3097 |
def test_order_invoice_search(self): |
| 3098 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3099 |
self.pos_user.group_ids = [Command.link(self.env.ref('account.group_account_invoice').id)] |
| 3100 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'test_order_invoice_search', login="pos_user") |
| 3101 |
|
| 3102 |
def test_automatic_receipt_printing(self): |
| 3103 |
self.main_pos_config.write({ |
| 3104 |
'iface_print_auto': True, |
| 3105 |
'iface_print_skip_screen': True, |
| 3106 |
}) |
| 3107 |
|
| 3108 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3109 |
self.start_pos_tour('test_automatic_receipt_printing', login="pos_user") |
| 3110 |
|
| 3111 |
def test_load_pos_demo_data(self): |
| 3112 |
""" Test that the demo data can be loaded by admin but not by user. """ |
| 3113 |
|
| 3114 |
if loaded_demo_data(self.env): |
| 3115 |
self.skipTest('Cannot test with demo data.') |
| 3116 |
|
| 3117 |
# archive existing product records |
| 3118 |
archive_products(self.env) |
| 3119 |
|
| 3120 |
# cannot load by pos user |
| 3121 |
self.start_pos_tour('test_load_pos_demo_data_by_pos_user', login='pos_user') |
| 3122 |
products = self.env['product.template'].search_count([('available_in_pos', '=', True)]) |
| 3123 |
self.assertFalse(products, 'Demo data should not be loaded by user.') |
| 3124 |
|
| 3125 |
# Member role with POS Administrator access |
| 3126 |
self.pos_user.write({'group_ids': [ |
| 3127 |
Command.set( |
| 3128 |
[ |
| 3129 |
self.env.ref('base.group_user').id, |
| 3130 |
self.env.ref('point_of_sale.group_pos_manager').id, |
| 3131 |
self.env.ref('account.group_account_manager').id, |
| 3132 |
] |
| 3133 |
) |
| 3134 |
]}) |
| 3135 |
self.start_pos_tour('test_load_pos_demo_data_with_member_role', login='pos_user') |
| 3136 |
products = self.env['product.template'].search_count([('available_in_pos', '=', True)]) |
| 3137 |
self.assertFalse(products, 'Demo data should not be loaded by user with member role.') |
| 3138 |
|
| 3139 |
def test_combo_variant_mix(self): |
| 3140 |
color_attribute = self.env['product.attribute'].create({ |
| 3141 |
'name': 'Color', |
| 3142 |
'value_ids': [ |
| 3143 |
Command.create({'name': 'Red'}), |
| 3144 |
Command.create({'name': 'Blue'}) |
| 3145 |
], |
| 3146 |
'create_variant': 'no_variant', |
| 3147 |
}) |
| 3148 |
size_attribute = self.env['product.attribute'].create({ |
| 3149 |
'name': 'Size', |
| 3150 |
'value_ids': [ |
| 3151 |
Command.create({'name': 'Small'}), |
| 3152 |
Command.create({'name': 'Large'}) |
| 3153 |
], |
| 3154 |
'create_variant': 'always', |
| 3155 |
}) |
| 3156 |
|
| 3157 |
product_template = self.env['product.template'].create({ |
| 3158 |
'name': 'Test Product', |
| 3159 |
'available_in_pos': True, |
| 3160 |
'list_price': 10, |
| 3161 |
'taxes_id': False, |
| 3162 |
'attribute_line_ids': [ |
| 3163 |
Command.create({ |
| 3164 |
'attribute_id': color_attribute.id, |
| 3165 |
'value_ids': [Command.link(id) for id in color_attribute.value_ids.ids] |
| 3166 |
}), |
| 3167 |
Command.create({ |
| 3168 |
'attribute_id': size_attribute.id, |
| 3169 |
'value_ids': [Command.link(id) for id in size_attribute.value_ids.ids] |
| 3170 |
}) |
| 3171 |
] |
| 3172 |
}) |
| 3173 |
|
| 3174 |
combo = self.env['product.combo'].create({ |
| 3175 |
'name': 'Test Combo', |
| 3176 |
'combo_item_ids': [ |
| 3177 |
Command.create({ |
| 3178 |
'product_id': product_template.product_variant_ids[0].id, |
| 3179 |
'extra_price': 0, |
| 3180 |
}), |
| 3181 |
Command.create({ |
| 3182 |
'product_id': product_template.product_variant_ids[1].id, |
| 3183 |
'extra_price': 0, |
| 3184 |
}), |
| 3185 |
] |
| 3186 |
}) |
| 3187 |
self.env['product.template'].create({ |
| 3188 |
'name': 'Test Product Combo', |
| 3189 |
'available_in_pos': True, |
| 3190 |
'list_price': 20, |
| 3191 |
'taxes_id': False, |
| 3192 |
'type': 'combo', |
| 3193 |
'combo_ids': [Command.link(combo.id)], |
| 3194 |
}) |
| 3195 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_combo_variant_mix', login="pos_user") |
| 3196 |
|
| 3197 |
def test_cross_exclusion_attribute_values(self): |
| 3198 |
""" If you create a product with two attributes and 2 values for each attribute, and you exclude one value of the first attribute with one value of the second attribute |
| 3199 |
and vice versa, you should still be able to select the other values of the attributes. """ |
| 3200 |
self.attribute_1 = self.env['product.attribute'].create({ |
| 3201 |
'name': 'attribute_1', |
| 3202 |
'create_variant': 'no_variant', |
| 3203 |
}) |
| 3204 |
|
| 3205 |
self.attribute_2 = self.env['product.attribute'].create({ |
| 3206 |
'name': 'attribute_2', |
| 3207 |
'create_variant': 'no_variant', |
| 3208 |
}) |
| 3209 |
|
| 3210 |
self.attribute_1_value_1 = self.env['product.attribute.value'].create({ |
| 3211 |
'name': 'attribute_1_value_1', |
| 3212 |
'attribute_id': self.attribute_1.id, |
| 3213 |
}) |
| 3214 |
self.attribute_1_value_2 = self.env['product.attribute.value'].create({ |
| 3215 |
'name': 'attribute_1_value_2', |
| 3216 |
'attribute_id': self.attribute_1.id, |
| 3217 |
}) |
| 3218 |
self.attribute_2_value_1 = self.env['product.attribute.value'].create({ |
| 3219 |
'name': 'attribute_2_value_1', |
| 3220 |
'attribute_id': self.attribute_2.id, |
| 3221 |
}) |
| 3222 |
self.attribute_2_value_2 = self.env['product.attribute.value'].create({ |
| 3223 |
'name': 'attribute_2_value_2', |
| 3224 |
'attribute_id': self.attribute_2.id, |
| 3225 |
}) |
| 3226 |
|
| 3227 |
self.test_product_1 = self.env['product.template'].create({ |
| 3228 |
'name': 'Test Product 1', |
| 3229 |
'available_in_pos': True, |
| 3230 |
'list_price': 10.0, |
| 3231 |
'attribute_line_ids': [ |
| 3232 |
(0, 0, { |
| 3233 |
'attribute_id': self.attribute_1.id, |
| 3234 |
'value_ids': [(6, 0, [self.attribute_1_value_1.id, self.attribute_1_value_2.id])], |
| 3235 |
}), |
| 3236 |
(0, 0, { |
| 3237 |
'attribute_id': self.attribute_2.id, |
| 3238 |
'value_ids': [(6, 0, [self.attribute_2_value_1.id, self.attribute_2_value_2.id])], |
| 3239 |
}), |
| 3240 |
], |
| 3241 |
}) |
| 3242 |
|
| 3243 |
# Test the exclusion of attribute values |
| 3244 |
ptav_1_1 = self.test_product_1.attribute_line_ids.filtered(lambda l: l.attribute_id.id == self.attribute_1.id).product_template_value_ids.filtered(lambda v: v.product_attribute_value_id.id == self.attribute_1_value_1.id) |
| 3245 |
ptav_1_2 = self.test_product_1.attribute_line_ids.filtered(lambda l: l.attribute_id.id == self.attribute_1.id).product_template_value_ids.filtered(lambda v: v.product_attribute_value_id.id == self.attribute_1_value_2.id) |
| 3246 |
ptav_2_2 = self.test_product_1.attribute_line_ids.filtered(lambda l: l.attribute_id.id == self.attribute_2.id).product_template_value_ids.filtered(lambda v: v.product_attribute_value_id.id == self.attribute_2_value_2.id) |
| 3247 |
ptav_2_1 = self.test_product_1.attribute_line_ids.filtered(lambda l: l.attribute_id.id == self.attribute_2.id).product_template_value_ids.filtered(lambda v: v.product_attribute_value_id.id == self.attribute_2_value_1.id) |
| 3248 |
self.env['product.template.attribute.exclusion'].create({ |
| 3249 |
'product_tmpl_id': self.test_product_1.id, |
| 3250 |
'product_template_attribute_value_id': ptav_1_1.id, |
| 3251 |
'value_ids': [Command.set([ptav_2_1.id])], |
| 3252 |
}) |
| 3253 |
|
| 3254 |
self.env['product.template.attribute.exclusion'].create({ |
| 3255 |
'product_tmpl_id': self.test_product_1.id, |
| 3256 |
'product_template_attribute_value_id': ptav_1_2.id, |
| 3257 |
'value_ids': [Command.set([ptav_2_2.id])], |
| 3258 |
}) |
| 3259 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3260 |
self.start_pos_tour('test_cross_exclusion_attribute_values') |
| 3261 |
|
| 3262 |
def test_custom_attribute_alone_displayed(self): |
| 3263 |
""" |
| 3264 |
Tests that if product configurator will be shown if any of the |
| 3265 |
attributes have a free text field, even if there is only one |
| 3266 |
possible selection for every attributes. |
| 3267 |
""" |
| 3268 |
attribute_custom = self.env['product.attribute'].create({ |
| 3269 |
'name': 'Custom', |
| 3270 |
'display_type': 'radio', |
| 3271 |
'create_variant': 'no_variant', |
| 3272 |
}) |
| 3273 |
attribute_value_custom = self.env['product.attribute.value'].create({ |
| 3274 |
'name': 'Custom', |
| 3275 |
'attribute_id': attribute_custom.id, |
| 3276 |
'is_custom': True, |
| 3277 |
}) |
| 3278 |
self.test_product_1 = self.env['product.template'].create({ |
| 3279 |
'name': 'Only Custom', |
| 3280 |
'available_in_pos': True, |
| 3281 |
'list_price': 10.0, |
| 3282 |
'attribute_line_ids': [ |
| 3283 |
Command.create({ |
| 3284 |
'attribute_id': attribute_custom.id, |
| 3285 |
'value_ids': [Command.set([attribute_value_custom.id])], |
| 3286 |
}), |
| 3287 |
], |
| 3288 |
}) |
| 3289 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3290 |
self.start_pos_tour('test_custom_attribute_alone_displayed') |
| 3291 |
|
| 3292 |
def test_preset_customer_selection(self): |
| 3293 |
self.preset_delivery = self.env['pos.preset'].create({ |
| 3294 |
'name': 'Delivery', |
| 3295 |
'identification': 'address', |
| 3296 |
}) |
| 3297 |
self.env['res.partner'].create({ |
| 3298 |
'name': 'Test Partner', |
| 3299 |
'street': '123 Test Street', |
| 3300 |
'city': 'Test City', |
| 3301 |
'zip': '12345', |
| 3302 |
'country_id': self.env['res.country'].search([], limit=1).id, |
| 3303 |
}) |
| 3304 |
self.main_pos_config.write({ |
| 3305 |
'use_presets': True, |
| 3306 |
'default_preset_id': self.preset_delivery.id, |
| 3307 |
'available_preset_ids': [(6, 0, [self.preset_delivery.id])], |
| 3308 |
}) |
| 3309 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3310 |
self.start_pos_tour('test_preset_customer_selection') |
| 3311 |
|
| 3312 |
def test_pos_large_amount_confirmation_dialog(self): |
| 3313 |
"""Test that the Large amount confirmation dialog appears |
| 3314 |
and closes properly after clicking 'OK'.""" |
| 3315 |
self.env['product.product'].create({ |
| 3316 |
'name': 'Overpay Test Product', |
| 3317 |
'list_price': 1.0, |
| 3318 |
'available_in_pos': True, |
| 3319 |
}) |
| 3320 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3321 |
self.start_pos_tour('test_pos_large_amount_confirmation_dialog') |
| 3322 |
|
| 3323 |
def test_product_info_product_inventory(self): |
| 3324 |
""" Test that the product variant inventory info is correctly displayed in the POS. """ |
| 3325 |
size_attribute = self.env['product.attribute'].create({ |
| 3326 |
'name': 'Size', |
| 3327 |
'value_ids': [ |
| 3328 |
Command.create({'name': 'Small'}), |
| 3329 |
Command.create({'name': 'Large'}) |
| 3330 |
], |
| 3331 |
'create_variant': 'always', |
| 3332 |
}) |
| 3333 |
|
| 3334 |
product_template = self.env['product.template'].create({ |
| 3335 |
'name': 'Test Product', |
| 3336 |
'available_in_pos': True, |
| 3337 |
'is_storable': True, |
| 3338 |
'attribute_line_ids': [ |
| 3339 |
Command.create({ |
| 3340 |
'attribute_id': size_attribute.id, |
| 3341 |
'value_ids': [Command.link(id) for id in size_attribute.value_ids.ids] |
| 3342 |
}) |
| 3343 |
] |
| 3344 |
}) |
| 3345 |
|
| 3346 |
for variant in range(len(product_template.product_variant_ids)): |
| 3347 |
self.env['stock.quant']._update_available_quantity(product_template.product_variant_ids[variant], self.main_pos_config.warehouse_id.lot_stock_id, (variant + 1) * 100) |
| 3348 |
product_template.product_variant_ids[variant].write({'barcode': f'product_variant_{variant}'}) |
| 3349 |
|
| 3350 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3351 |
self.start_pos_tour('test_product_info_product_inventory') |
| 3352 |
|
| 3353 |
def test_add_money_button_with_different_decimal_separator(self): |
| 3354 |
""" |
| 3355 |
Tests that the buttons such as +10 or +50 work even in languages such as |
| 3356 |
french that have ',' as a decimal separator. |
| 3357 |
""" |
| 3358 |
lang = self.env['res.lang'].search([('code', '=', self.pos_user.lang)]) |
| 3359 |
lang.write({'thousands_sep': '.', 'decimal_point': ','}) |
| 3360 |
self.start_tour(f"/pos/ui?config_id={self.main_pos_config.id}", 'test_add_money_button_with_different_decimal_separator', login="pos_user") |
| 3361 |
|
| 3362 |
def test_sync_from_ui_one_by_one(self): |
| 3363 |
""" |
| 3364 |
Sync from UI is now syncing orders one by one. |
| 3365 |
sync_from_ui should be called 6 times in this tour (6 orders created). |
| 3366 |
""" |
| 3367 |
|
| 3368 |
pos_order = self.env.registry.models['pos.order'] |
| 3369 |
sync_counter = {'count': 0} |
| 3370 |
|
| 3371 |
@api.model |
| 3372 |
def sync_from_ui_patch(self, orders): |
| 3373 |
sync_counter['count'] += 1 |
| 3374 |
return super(pos_order, self).sync_from_ui(orders) |
| 3375 |
|
| 3376 |
with patch.object(pos_order, "sync_from_ui", sync_from_ui_patch): |
| 3377 |
self.start_pos_tour("test_sync_from_ui_one_by_one", login="pos_user") |
| 3378 |
self.assertEqual(sync_counter['count'], 6) |
| 3379 |
|
| 3380 |
def test_lot_refund_lower_qty(self): |
| 3381 |
product = self.env['product.product'].create({ |
| 3382 |
'name': 'Serial Product', |
| 3383 |
'is_storable': True, |
| 3384 |
'tracking': 'serial', |
| 3385 |
'available_in_pos': True, |
| 3386 |
}) |
| 3387 |
for sn in ["SN1", "SN2"]: |
| 3388 |
self.env['stock.quant'].create({ |
| 3389 |
'product_id': product.id, |
| 3390 |
'inventory_quantity': 1, |
| 3391 |
'location_id': self.env.user._get_default_warehouse_id().lot_stock_id.id, |
| 3392 |
'lot_id': self.env['stock.lot'].create({'name': sn, 'product_id': product.id}).id, |
| 3393 |
}).sudo().action_apply_inventory() |
| 3394 |
self.env['stock.picking.type'].search([('name', '=', 'PoS Orders')]).use_create_lots = False |
| 3395 |
|
| 3396 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3397 |
self.start_pos_tour("test_lot_refund_lower_qty") |
| 3398 |
|
| 3399 |
def test_exclusion_attribute_values(self): |
| 3400 |
chair_fabrics_other_ptav = self.configurable_chair.attribute_line_ids.filtered(lambda l: l.attribute_id.id == self.chair_fabrics_attribute.id).product_template_value_ids.filtered(lambda v: v.product_attribute_value_id.id == self.chair_fabrics_other.id) |
| 3401 |
chair_fabrics_wool_ptav = self.configurable_chair.attribute_line_ids.filtered(lambda l: l.attribute_id.id == self.chair_fabrics_attribute.id).product_template_value_ids.filtered(lambda v: v.product_attribute_value_id.id == self.chair_fabrics_wool.id) |
| 3402 |
chair_color_red_ptav = self.configurable_chair.attribute_line_ids.filtered(lambda l: l.attribute_id.id == self.chair_color_attribute.id).product_template_value_ids.filtered(lambda v: v.product_attribute_value_id.id == self.chair_color_red.id) |
| 3403 |
|
| 3404 |
# Test the exclusion of attribute values |
| 3405 |
self.env['product.template.attribute.exclusion'].create({ |
| 3406 |
'product_tmpl_id': self.configurable_chair.id, |
| 3407 |
'product_template_attribute_value_id': chair_color_red_ptav.id, |
| 3408 |
'value_ids': [Command.set([chair_fabrics_other_ptav.id])], |
| 3409 |
}) |
| 3410 |
|
| 3411 |
# # Test the exclusion of attribute values in the opposite direction |
| 3412 |
self.env['product.template.attribute.exclusion'].create({ |
| 3413 |
'product_tmpl_id': self.configurable_chair.id, |
| 3414 |
'product_template_attribute_value_id': chair_fabrics_wool_ptav.id, |
| 3415 |
'value_ids': [Command.set([chair_color_red_ptav.id])], |
| 3416 |
}) |
| 3417 |
|
| 3418 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3419 |
self.start_pos_tour('test_exclusion_attribute_values') |
| 3420 |
|
| 3421 |
def test_lot_tracking_without_lot_creation(self): |
| 3422 |
pricelist = self.env['product.pricelist'].create({ |
| 3423 |
'name': 'Test Pricelist', |
| 3424 |
}) |
| 3425 |
self.main_pos_config.write({ |
| 3426 |
'available_pricelist_ids': [(6, 0, [pricelist.id])], |
| 3427 |
'pricelist_id': pricelist.id, |
| 3428 |
}) |
| 3429 |
self.main_pos_config.picking_type_id.write({ |
| 3430 |
"use_create_lots": False, |
| 3431 |
"use_existing_lots": False, |
| 3432 |
}) |
| 3433 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 3434 |
self.monitor_stand.tracking = 'lot' |
| 3435 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_lot_tracking_without_lot_creation', login="pos_user") |
| 3436 |
|
| 3437 |
def test_refund_line_keep_attributes(self): |
| 3438 |
""" |
| 3439 |
Tests that when refunding an order that has lines that are variants, the new line keeps |
| 3440 |
this variant and displays it. |
| 3441 |
""" |
| 3442 |
product_test = self.env['product.product'].create({ |
| 3443 |
'name': 'Donut', |
| 3444 |
'list_price': 10, |
| 3445 |
'available_in_pos': True, |
| 3446 |
'taxes_id': False, |
| 3447 |
}) |
| 3448 |
attribute = self.env['product.attribute'].create({ |
| 3449 |
'name': 'Flavor', |
| 3450 |
'create_variant': 'always', |
| 3451 |
}) |
| 3452 |
attribute_value_1 = self.env['product.attribute.value'].create({ |
| 3453 |
'name': 'Sugar', |
| 3454 |
'attribute_id': attribute.id, |
| 3455 |
}) |
| 3456 |
attribute_value_2 = self.env['product.attribute.value'].create({ |
| 3457 |
'name': 'Chocolate', |
| 3458 |
'attribute_id': attribute.id, |
| 3459 |
}) |
| 3460 |
self.env['product.template.attribute.line'].create({ |
| 3461 |
'product_tmpl_id': product_test.product_tmpl_id.id, |
| 3462 |
'attribute_id': attribute.id, |
| 3463 |
'value_ids': [(6, 0, [attribute_value_1.id, attribute_value_2.id])], |
| 3464 |
}) |
| 3465 |
self.start_pos_tour("test_refund_line_keep_attributes") |
| 3466 |
|
| 3467 |
def test_orderline_merge_with_higher_price_precision(self): |
| 3468 |
""" Test that orderline merging works correctly when product price has a higher precision than the currency. """ |
| 3469 |
self.env['decimal.precision'].search([('name', '=', 'Product Price')]).digits = 3 |
| 3470 |
|
| 3471 |
self.env['product.product'].create({ |
| 3472 |
'name': 'High Precision Product', |
| 3473 |
'list_price': 8.245, |
| 3474 |
'taxes_id': False, |
| 3475 |
'available_in_pos': True, |
| 3476 |
}) |
| 3477 |
|
| 3478 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_orderline_merge_with_higher_price_precision', login="pos_user") |
| 3479 |
|
| 3480 |
def test_product_configurator_price(self): |
| 3481 |
""" Test that the product configurator displays the correct price when selecting attributes that impact the price. """ |
| 3482 |
self.env['product.template'].search([('available_in_pos', '=', True)]).active = False |
| 3483 |
tax_10 = self.env['account.tax'].create({ |
| 3484 |
'name': 'Tax 10%', |
| 3485 |
'amount': 10, |
| 3486 |
}) |
| 3487 |
fiscal_position = self.env['account.fiscal.position'].create({ |
| 3488 |
'name': 'Include to Exclude', |
| 3489 |
}) |
| 3490 |
tax_10 = self.env['account.tax'].create({ |
| 3491 |
'name': 'Tax 10 Excluded', |
| 3492 |
'amount': 10, |
| 3493 |
'amount_type': 'percent', |
| 3494 |
'type_tax_use': 'sale', |
| 3495 |
'price_include_override': 'tax_excluded', |
| 3496 |
}) |
| 3497 |
self.env['account.tax'].create({ |
| 3498 |
'name': 'Tax 10 Included', |
| 3499 |
'amount': 10, |
| 3500 |
'amount_type': 'percent', |
| 3501 |
'type_tax_use': 'sale', |
| 3502 |
'price_include_override': 'tax_included', |
| 3503 |
'fiscal_position_ids': fiscal_position, |
| 3504 |
'original_tax_ids': tax_10, |
| 3505 |
}) |
| 3506 |
product = self.env['product.template'].create({ |
| 3507 |
'name': 'Configurable Product', |
| 3508 |
'available_in_pos': True, |
| 3509 |
'list_price': 10.0, |
| 3510 |
'taxes_id': [(6, 0, [tax_10.id])], |
| 3511 |
}) |
| 3512 |
size_attribute = self.env['product.attribute'].create({ |
| 3513 |
'name': 'Size', |
| 3514 |
'create_variant': 'always', |
| 3515 |
}) |
| 3516 |
color_attribute = self.env['product.attribute'].create({ |
| 3517 |
'name': 'Color', |
| 3518 |
'create_variant': 'no_variant', |
| 3519 |
}) |
| 3520 |
small_size_value, large_size_value = self.env['product.attribute.value'].create([{ |
| 3521 |
'name': 'Small', |
| 3522 |
'attribute_id': size_attribute.id, |
| 3523 |
}, { |
| 3524 |
'name': 'Large', |
| 3525 |
'attribute_id': size_attribute.id, |
| 3526 |
}]) |
| 3527 |
red_color_value, blue_color_value = self.env['product.attribute.value'].create([{ |
| 3528 |
'name': 'Red', |
| 3529 |
'attribute_id': color_attribute.id, |
| 3530 |
}, { |
| 3531 |
'name': 'Blue', |
| 3532 |
'attribute_id': color_attribute.id, |
| 3533 |
}]) |
| 3534 |
size_line = self.env['product.template.attribute.line'].create({ |
| 3535 |
'product_tmpl_id': product.id, |
| 3536 |
'attribute_id': size_attribute.id, |
| 3537 |
'value_ids': [(6, 0, [small_size_value.id, large_size_value.id])], |
| 3538 |
}) |
| 3539 |
size_line.product_template_value_ids[1].price_extra = 1 |
| 3540 |
color_line = self.env['product.template.attribute.line'].create({ |
| 3541 |
'product_tmpl_id': product.id, |
| 3542 |
'attribute_id': color_attribute.id, |
| 3543 |
'value_ids': [(6, 0, [red_color_value.id, blue_color_value.id])], |
| 3544 |
}) |
| 3545 |
color_line.product_template_value_ids[0].price_extra = 2 |
| 3546 |
color_line.product_template_value_ids[1].price_extra = 3 |
| 3547 |
|
| 3548 |
pricelist_1, pricelist_2 = self.env['product.pricelist'].create([{ |
| 3549 |
'name': 'Pricelist 1', |
| 3550 |
}, { |
| 3551 |
'name': 'Pricelist 2', |
| 3552 |
'item_ids': [(0, 0, { |
| 3553 |
'applied_on': '1_product', |
| 3554 |
'product_tmpl_id': product.id, |
| 3555 |
'fixed_price': 20.0, |
| 3556 |
})], |
| 3557 |
}]) |
| 3558 |
self.main_pos_config.write({ |
| 3559 |
'available_pricelist_ids': [(6, 0, [pricelist_1.id, pricelist_2.id])], |
| 3560 |
'pricelist_id': pricelist_1.id, |
| 3561 |
'tax_regime_selection': True, |
| 3562 |
'fiscal_position_ids': [(6, 0, [fiscal_position.id])], |
| 3563 |
}) |
| 3564 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_product_configurator_price', login="pos_user") |
| 3565 |
|
| 3566 |
|
| 3567 |
# This class just runs the same tests as above but with mobile emulation |
| 3568 |
class MobileTestUi(TestUi): |
| 3569 |
browser_size = '375x667' |
| 3570 |
touch_enabled = True |
| 3571 |
allow_inherited_tests_method = True |
| 3572 |
|
| 3573 |
|
| 3574 |
class TestTaxCommonPOS(TestPointOfSaleHttpCommon, TestTaxCommon): |
| 3575 |
@classmethod |
| 3576 |
def setUpClass(cls): |
| 3577 |
super().setUpClass() |
| 3578 |
cls.partner_a.name = "AAAAAA" # The POS only load the first 100 partners |
| 3579 |
|
| 3580 |
def create_base_line_product(self, base_line, **kwargs): |
| 3581 |
return self.env['product.product'].create({ |
| 3582 |
**kwargs, |
| 3583 |
'available_in_pos': True, |
| 3584 |
'list_price': base_line['price_unit'], |
| 3585 |
'taxes_id': [Command.set(base_line['tax_ids'].ids)], |
| 3586 |
'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)], |
| 3587 |
}) |
| 3588 |
|
| 3589 |
def ensure_products_on_document(self, document, product_prefix): |
| 3590 |
for i, base_line in enumerate(document['lines'], start=1): |
| 3591 |
base_line['product_id'] = self.create_base_line_product(base_line, name=f'{product_prefix}_{i}') |
| 3592 |
|
| 3593 |
def assert_pos_order_totals(self, order, expected_values): |
| 3594 |
expected_amounts = {} |
| 3595 |
if 'tax_amount_currency' in expected_values: |
| 3596 |
expected_amounts['amount_tax'] = expected_values['tax_amount_currency'] |
| 3597 |
if 'total_amount_currency' in expected_values: |
| 3598 |
expected_amounts['amount_total'] = expected_values['total_amount_currency'] |
| 3599 |
self.assertRecordValues(order, [expected_amounts]) |
| 3600 |
|
| 3601 |
def assert_pos_orders_and_invoices(self, tour, tests_with_orders): |
| 3602 |
if self.main_pos_config.current_session_id: |
| 3603 |
self.main_pos_config.current_session_id.post_closing_cash_details(0) |
| 3604 |
self.main_pos_config.current_session_id.close_session_from_ui() |
| 3605 |
|
| 3606 |
self.start_pos_tour(tour) |
| 3607 |
orders = self.env['pos.order'].search([('session_id', '=', self.main_pos_config.current_session_id.id)], limit=len(tests_with_orders)) |
| 3608 |
for index, (order, (test_code, _document, _soft_checking, _amount_type, _amount, expected_values)) in enumerate(zip(orders, tests_with_orders)): |
| 3609 |
with self.subTest(test_code=test_code, index=index): |
| 3610 |
self.assert_pos_order_totals(order, expected_values) |
| 3611 |
if order.account_move: |
| 3612 |
self.assert_invoice_totals(order.account_move, expected_values) |