| 1 |
|
| 2 |
|
| 3 |
from odoo import fields |
| 4 |
from odoo.fields import Command |
| 5 |
from odoo.tests import Form, tagged |
| 6 |
from odoo.tools import format_date |
| 7 |
from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon |
| 8 |
import uuid |
| 9 |
|
| 10 |
|
| 11 |
@tagged('post_install', '-at_install') |
| 12 |
class TestPoSSale(TestPointOfSaleHttpCommon): |
| 13 |
@classmethod |
| 14 |
def get_default_groups(cls): |
| 15 |
groups = super().get_default_groups() |
| 16 |
return groups | cls.quick_ref('sales_team.group_sale_manager') |
| 17 |
|
| 18 |
def test_settle_order_with_kit(self): |
| 19 |
if not self.env["ir.module.module"].search([("name", "=", "mrp"), ("state", "=", "installed")]): |
| 20 |
self.skipTest("mrp module is required for this test") |
| 21 |
|
| 22 |
self.env.user.group_ids |= self.env.ref('mrp.group_mrp_user') |
| 23 |
self.kit = self.env['product.product'].create({ |
| 24 |
'name': 'Pizza Chicken', |
| 25 |
'available_in_pos': True, |
| 26 |
'is_storable': True, |
| 27 |
'lst_price': 10.0, |
| 28 |
}) |
| 29 |
|
| 30 |
self.component_a = self.env['product.product'].create({ |
| 31 |
'name': 'Chicken', |
| 32 |
'is_storable': True, |
| 33 |
'available_in_pos': True, |
| 34 |
'uom_id': self.env.ref('uom.product_uom_gram').id, |
| 35 |
'lst_price': 10.0, |
| 36 |
}) |
| 37 |
self.location = self.env['stock.location'].sudo().create({ |
| 38 |
'name': 'Test location', |
| 39 |
'usage': 'internal', |
| 40 |
}).sudo(False) |
| 41 |
|
| 42 |
self.env['stock.quant']._update_available_quantity(self.component_a, self.location, 100000) |
| 43 |
|
| 44 |
bom_product_form = Form(self.env['mrp.bom'].sudo()) |
| 45 |
if self.env.user._has_group('product.group_product_variant'): |
| 46 |
bom_product_form.product_id = self.kit |
| 47 |
bom_product_form.product_tmpl_id = self.kit.product_tmpl_id |
| 48 |
bom_product_form.product_qty = 1.0 |
| 49 |
bom_product_form.type = 'phantom' |
| 50 |
with bom_product_form.bom_line_ids.new() as bom_line: |
| 51 |
bom_line.product_id = self.component_a |
| 52 |
bom_line.product_qty = 300.0 |
| 53 |
self.bom_a = bom_product_form.save() |
| 54 |
|
| 55 |
sale_order = self.env['sale.order'].sudo().create({ |
| 56 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 57 |
'order_line': [(0, 0, { |
| 58 |
'product_id': self.kit.id, |
| 59 |
'name': self.kit.name, |
| 60 |
'product_uom_qty': 10, |
| 61 |
'price_unit': self.kit.lst_price, |
| 62 |
})], |
| 63 |
}) |
| 64 |
sale_order.action_confirm() |
| 65 |
picking = sale_order.picking_ids |
| 66 |
picking.move_ids.quantity = 300 |
| 67 |
picking.move_ids.picked = True |
| 68 |
Form.from_action(self.env, picking.button_validate()).save().process() |
| 69 |
|
| 70 |
self.assertEqual(sale_order.order_line.qty_delivered, 1) |
| 71 |
|
| 72 |
self.pos_user.write({ |
| 73 |
'group_ids': [ |
| 74 |
(4, self.env.ref('stock.group_stock_user').id), |
| 75 |
(4, self.env.ref('sales_team.group_sale_salesman_all_leads').id), |
| 76 |
(4, self.env.ref('account.group_account_user').id), |
| 77 |
(4, self.env.ref('base.group_system').id), |
| 78 |
] |
| 79 |
}) |
| 80 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 81 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosSettleOrder', login="pos_user") |
| 82 |
|
| 83 |
|
| 84 |
self.assertEqual(sale_order.order_line.qty_delivered, 3) |
| 85 |
self.assertEqual(sale_order.picking_ids[0].move_ids.product_qty, 2100) |
| 86 |
self.assertEqual(sale_order.picking_ids[0].move_ids.quantity, 0) |
| 87 |
self.assertEqual(sale_order.picking_ids[1].move_ids.product_qty, 300) |
| 88 |
self.assertEqual(sale_order.picking_ids[1].move_ids.quantity, 300) |
| 89 |
|
| 90 |
def test_settle_order_with_incompatible_partner(self): |
| 91 |
""" If the partner of the sale order is not compatible with the current pos order, |
| 92 |
then a new pos order should be to settle the newly selected sale order. |
| 93 |
""" |
| 94 |
|
| 95 |
product1 = self.env['product.product'].create({ |
| 96 |
'name': 'product1', |
| 97 |
'available_in_pos': True, |
| 98 |
'is_storable': True, |
| 99 |
'lst_price': 10, |
| 100 |
'taxes_id': [Command.clear()], |
| 101 |
}) |
| 102 |
product2 = self.env['product.product'].create({ |
| 103 |
'name': 'product2', |
| 104 |
'available_in_pos': True, |
| 105 |
'is_storable': True, |
| 106 |
'lst_price': 11, |
| 107 |
'taxes_id': [Command.clear()], |
| 108 |
}) |
| 109 |
partner_1 = self.env['res.partner'].create({'name': 'Test Partner 1'}) |
| 110 |
partner_2 = self.env['res.partner'].create({'name': 'Test Partner 2'}) |
| 111 |
self.env['sale.order'].sudo().create({ |
| 112 |
'partner_id': partner_1.id, |
| 113 |
'partner_shipping_id': partner_2.id, |
| 114 |
'order_line': [(0, 0, {'product_id': product1.id})], |
| 115 |
}) |
| 116 |
self.env['sale.order'].sudo().create({ |
| 117 |
'partner_id': partner_1.id, |
| 118 |
'partner_shipping_id': partner_1.id, |
| 119 |
'order_line': [(0, 0, {'product_id': product2.id})], |
| 120 |
}) |
| 121 |
self.main_pos_config.open_ui() |
| 122 |
self.start_pos_tour('PosSettleOrderIncompatiblePartner', login="accountman") |
| 123 |
|
| 124 |
def test_settle_order_with_different_product(self): |
| 125 |
"""This test create an order and settle it in the PoS. But only one of the product is delivered. |
| 126 |
And we need to make sure the quantity are correctly updated on the sale order. |
| 127 |
""" |
| 128 |
|
| 129 |
product_a = self.env['product.product'].create({ |
| 130 |
'name': 'Product A', |
| 131 |
'available_in_pos': True, |
| 132 |
'is_storable': True, |
| 133 |
'lst_price': 10.0, |
| 134 |
}) |
| 135 |
product_b = self.env['product.product'].create({ |
| 136 |
'name': 'Product B', |
| 137 |
'available_in_pos': True, |
| 138 |
'is_storable': True, |
| 139 |
'lst_price': 10.0, |
| 140 |
}) |
| 141 |
|
| 142 |
sale_order = self.env['sale.order'].sudo().create({ |
| 143 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 144 |
'order_line': [(0, 0, { |
| 145 |
'product_id': product_a.id, |
| 146 |
'name': product_a.name, |
| 147 |
'product_uom_qty': 1, |
| 148 |
'price_unit': product_a.lst_price, |
| 149 |
}), (0, 0, { |
| 150 |
'product_id': product_b.id, |
| 151 |
'name': product_b.name, |
| 152 |
'product_uom_qty': 1, |
| 153 |
'price_unit': product_b.lst_price, |
| 154 |
}), (0, 0, { |
| 155 |
|
| 156 |
'name': 'section line', |
| 157 |
'display_type': 'line_section', |
| 158 |
})], |
| 159 |
}) |
| 160 |
sale_order.action_confirm() |
| 161 |
|
| 162 |
self.assertEqual(sale_order.order_line[0].qty_delivered, 0) |
| 163 |
self.assertEqual(sale_order.order_line[1].qty_delivered, 0) |
| 164 |
|
| 165 |
self.main_pos_config.open_ui() |
| 166 |
self.start_pos_tour('PosSettleOrder2', login="accountman") |
| 167 |
|
| 168 |
sale_order = self.env['sale.order'].browse(sale_order.id) |
| 169 |
self.assertEqual(sale_order.order_line[0].qty_delivered, 1) |
| 170 |
self.assertEqual(sale_order.order_line[1].qty_delivered, 0) |
| 171 |
orderline_product_a = sale_order.order_line.filtered(lambda l: l.product_id.id == product_a.id) |
| 172 |
orderline_product_b = sale_order.order_line.filtered(lambda l: l.product_id.id == product_b.id) |
| 173 |
|
| 174 |
self.assertEqual(orderline_product_a.move_ids.product_uom_qty, 0) |
| 175 |
|
| 176 |
self.assertEqual(orderline_product_b.move_ids.product_uom_qty, 1) |
| 177 |
|
| 178 |
def test_downpayment_refund(self): |
| 179 |
|
| 180 |
sale_order = self.env['sale.order'].sudo().create({ |
| 181 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 182 |
'order_line': [(0, 0, { |
| 183 |
'product_id': self.product_a.id, |
| 184 |
'name': self.product_a.name, |
| 185 |
'product_uom_qty': 1, |
| 186 |
'price_unit': 100, |
| 187 |
})], |
| 188 |
}) |
| 189 |
sale_order.action_confirm() |
| 190 |
|
| 191 |
self.downpayment_product = self.env['product.product'].create({ |
| 192 |
'name': 'Down Payment', |
| 193 |
'available_in_pos': True, |
| 194 |
'type': 'service', |
| 195 |
}) |
| 196 |
self.main_pos_config.write({ |
| 197 |
'down_payment_product_id': self.downpayment_product.id, |
| 198 |
}) |
| 199 |
self.main_pos_config.open_ui() |
| 200 |
self.start_pos_tour('PosRefundDownpayment', login="accountman") |
| 201 |
self.assertEqual(len(sale_order.order_line), 4) |
| 202 |
self.assertEqual(sale_order.order_line[2].qty_invoiced, 1) |
| 203 |
self.assertEqual(sale_order.order_line[3].qty_invoiced, -1) |
| 204 |
|
| 205 |
def test_settle_order_unreserve_order_lines(self): |
| 206 |
|
| 207 |
self.removal_strategy = self.env['product.removal'].search([('method', '=', 'closest')], limit=1) |
| 208 |
self.product_category = self.env['product.category'].create({ |
| 209 |
'name': 'Product Category', |
| 210 |
'removal_strategy_id': self.removal_strategy.id, |
| 211 |
}) |
| 212 |
|
| 213 |
self.product = self.env['product.product'].create({ |
| 214 |
'name': 'Product', |
| 215 |
'available_in_pos': True, |
| 216 |
'is_storable': True, |
| 217 |
'lst_price': 10.0, |
| 218 |
'taxes_id': False, |
| 219 |
'categ_id': self.product_category.id, |
| 220 |
}) |
| 221 |
|
| 222 |
|
| 223 |
self.warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) |
| 224 |
self.shelf_1, self.shelf_2 = self.env['stock.location'].sudo().create([{ |
| 225 |
'name': 'Shelf 1', |
| 226 |
'usage': 'internal', |
| 227 |
'location_id': self.warehouse.lot_stock_id.id, |
| 228 |
}, { |
| 229 |
'name': 'Shelf 2', |
| 230 |
'usage': 'internal', |
| 231 |
'location_id': self.warehouse.lot_stock_id.id, |
| 232 |
}]).sudo(False) |
| 233 |
|
| 234 |
quants = self.env['stock.quant'].with_context(inventory_mode=True).create({ |
| 235 |
'product_id': self.product.id, |
| 236 |
'inventory_quantity': 2, |
| 237 |
'location_id': self.shelf_1.id, |
| 238 |
}) |
| 239 |
quants |= self.env['stock.quant'].with_context(inventory_mode=True).create({ |
| 240 |
'product_id': self.product.id, |
| 241 |
'inventory_quantity': 5, |
| 242 |
'location_id': self.shelf_2.id, |
| 243 |
}) |
| 244 |
quants.action_apply_inventory() |
| 245 |
|
| 246 |
sale_order = self.env['sale.order'].sudo().create({ |
| 247 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 248 |
'order_line': [(0, 0, { |
| 249 |
'product_id': self.product.id, |
| 250 |
'name': self.product.name, |
| 251 |
'product_uom_qty': 4, |
| 252 |
'price_unit': self.product.lst_price, |
| 253 |
})], |
| 254 |
}) |
| 255 |
sale_order.action_confirm() |
| 256 |
|
| 257 |
self.assertEqual(sale_order.order_line.move_ids.move_line_ids[0].quantity, 2) |
| 258 |
self.assertEqual(sale_order.order_line.move_ids.move_line_ids[0].location_id.id, self.shelf_1.id) |
| 259 |
self.assertEqual(sale_order.order_line.move_ids.move_line_ids[1].quantity, 2) |
| 260 |
self.assertEqual(sale_order.order_line.move_ids.move_line_ids[1].location_id.id, self.shelf_2.id) |
| 261 |
|
| 262 |
self.main_pos_config.company_id.write({'point_of_sale_update_stock_quantities': 'real'}) |
| 263 |
self.main_pos_config.open_ui() |
| 264 |
self.start_pos_tour('PosSettleOrderRealTime', login="accountman") |
| 265 |
self.main_pos_config.current_session_id.close_session_from_ui() |
| 266 |
pos_order = self.env['pos.order'].search([], order='id desc', limit=1) |
| 267 |
self.assertEqual(pos_order.picking_ids.move_line_ids[0].quantity, 2) |
| 268 |
self.assertEqual(pos_order.picking_ids.move_line_ids[0].location_id.id, self.shelf_1.id) |
| 269 |
self.assertEqual(pos_order.picking_ids.move_line_ids[1].quantity, 2) |
| 270 |
self.assertEqual(pos_order.picking_ids.move_line_ids[1].location_id.id, self.shelf_2.id) |
| 271 |
self.assertEqual(sale_order.order_line.move_ids.move_lines_count, 0) |
| 272 |
|
| 273 |
def test_settle_order_with_multistep_delivery(self): |
| 274 |
"""This test create an order and settle it in the PoS. It also uses multistep delivery |
| 275 |
and we need to make sure that all the picking are cancelled if the order is fully delivered. |
| 276 |
""" |
| 277 |
|
| 278 |
|
| 279 |
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) |
| 280 |
warehouse.sudo().delivery_steps = 'pick_pack_ship' |
| 281 |
|
| 282 |
product_a = self.env['product.product'].create({ |
| 283 |
'name': 'Product A', |
| 284 |
'available_in_pos': True, |
| 285 |
'is_storable': True, |
| 286 |
'lst_price': 10.0, |
| 287 |
}) |
| 288 |
self.env['stock.quant']._update_available_quantity(product_a, warehouse.lot_stock_id, 1) |
| 289 |
|
| 290 |
|
| 291 |
sale_order = self.env['sale.order'].sudo().create({ |
| 292 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 293 |
'order_line': [(0, 0, { |
| 294 |
'product_id': product_a.id, |
| 295 |
'name': product_a.name, |
| 296 |
'product_uom_qty': 1, |
| 297 |
'price_unit': product_a.lst_price, |
| 298 |
})], |
| 299 |
}) |
| 300 |
sale_order.action_confirm() |
| 301 |
|
| 302 |
self.assertEqual(sale_order.order_line[0].qty_delivered, 0) |
| 303 |
|
| 304 |
self.main_pos_config.open_ui() |
| 305 |
self.start_pos_tour('PosSettleOrder3', login="accountman") |
| 306 |
|
| 307 |
self.assertEqual(sale_order.order_line[0].qty_delivered, 1) |
| 308 |
self.assertEqual(sale_order.picking_ids.mapped('state'), ['cancel']) |
| 309 |
|
| 310 |
def test_pos_not_groupable_product(self): |
| 311 |
|
| 312 |
uom = self.env['uom.uom'].create({ |
| 313 |
'name': 'Test', |
| 314 |
}) |
| 315 |
product_a = self.env['product.product'].create({ |
| 316 |
'name': 'Product A', |
| 317 |
'available_in_pos': True, |
| 318 |
'is_storable': True, |
| 319 |
'lst_price': 10.0, |
| 320 |
'uom_id': uom.id, |
| 321 |
}) |
| 322 |
|
| 323 |
sale_order = self.env['sale.order'].sudo().create({ |
| 324 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 325 |
'order_line': [(0, 0, { |
| 326 |
'product_id': product_a.id, |
| 327 |
'name': product_a.name, |
| 328 |
'product_uom_qty': 3.5, |
| 329 |
'price_unit': 8, |
| 330 |
'discount': 10, |
| 331 |
})], |
| 332 |
}) |
| 333 |
self.assertEqual(sale_order.amount_total, 28.98) |
| 334 |
self.main_pos_config.open_ui() |
| 335 |
self.start_pos_tour('PosSettleOrderNotGroupable', login="accountman") |
| 336 |
|
| 337 |
def test_import_lot_groupable_and_non_groupable(self): |
| 338 |
""" |
| 339 |
Test importing a Sale Order in POS containing both groupable and non-groupable |
| 340 |
lot-tracked products, each with quantities exceeding available lots. |
| 341 |
Ensures the POS correctly handles lot selection and grouping behavior. |
| 342 |
""" |
| 343 |
non_groupable_uom = self.env['uom.uom'].create({ |
| 344 |
'name': 'Non groupable', |
| 345 |
'is_pos_groupable': False, |
| 346 |
}) |
| 347 |
groupable_product, non_groupable_product = self.env['product.product'].create([{ |
| 348 |
'name': name, |
| 349 |
'available_in_pos': True, |
| 350 |
'is_storable': True, |
| 351 |
'lst_price': 10.0, |
| 352 |
'tracking': 'lot', |
| 353 |
'taxes_id': False, |
| 354 |
} for name in ('Groupable Product', 'Non Groupable Product')]) |
| 355 |
non_groupable_product.uom_id = non_groupable_uom.id |
| 356 |
|
| 357 |
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) |
| 358 |
stock_location = warehouse.lot_stock_id |
| 359 |
non_groupable_lot, groupable_lot = self.env['stock.lot'].create([{ |
| 360 |
'name': f'LOT {product.name}', |
| 361 |
'product_id': product.id, |
| 362 |
'company_id': self.env.company.id, |
| 363 |
} for product in (non_groupable_product, groupable_product)]) |
| 364 |
self.env['stock.quant'].with_context(inventory_mode=True).create([{ |
| 365 |
'product_id': lot.product_id.id, |
| 366 |
'inventory_quantity': 2, |
| 367 |
'location_id': stock_location.id, |
| 368 |
'lot_id': lot.id, |
| 369 |
} for lot in (non_groupable_lot, groupable_lot)]).action_apply_inventory() |
| 370 |
|
| 371 |
sale_order = self.env['sale.order'].sudo().create({ |
| 372 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 373 |
'order_line': [ |
| 374 |
Command.create({ |
| 375 |
'product_id': non_groupable_product.id, |
| 376 |
'name': non_groupable_product.name, |
| 377 |
'product_uom_qty': 3, |
| 378 |
}), |
| 379 |
Command.create({ |
| 380 |
'product_id': groupable_product.id, |
| 381 |
'name': groupable_product.name, |
| 382 |
'product_uom_qty': 3, |
| 383 |
}), |
| 384 |
], |
| 385 |
}) |
| 386 |
sale_order.action_confirm() |
| 387 |
self.assertEqual(sale_order.amount_total, 60) |
| 388 |
|
| 389 |
self.main_pos_config.open_ui() |
| 390 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_import_lot_groupable_and_non_groupable', login="accountman") |
| 391 |
|
| 392 |
def test_customer_notes(self): |
| 393 |
"""This test create an order and settle it in the PoS. It also uses multistep delivery |
| 394 |
and we need to make sure that all the picking are cancelled if the order is fully delivered. |
| 395 |
""" |
| 396 |
|
| 397 |
|
| 398 |
sale_order = self.env['sale.order'].sudo().create({ |
| 399 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 400 |
'note': 'Customer note 1', |
| 401 |
'order_line': [(0, 0, { |
| 402 |
'product_id': self.whiteboard_pen.product_variant_id.id, |
| 403 |
'name': self.whiteboard_pen.name, |
| 404 |
'product_uom_qty': 1, |
| 405 |
'price_unit': self.whiteboard_pen.product_variant_id.lst_price, |
| 406 |
}), (0, 0, { |
| 407 |
'name': 'Customer note 2', |
| 408 |
'display_type': 'line_note', |
| 409 |
}), (0, 0, { |
| 410 |
'name': 'Customer note 3', |
| 411 |
'display_type': 'line_note', |
| 412 |
})], |
| 413 |
}) |
| 414 |
|
| 415 |
sale_order.action_confirm() |
| 416 |
|
| 417 |
self.main_pos_config.open_ui() |
| 418 |
self.start_pos_tour('PosSettleOrderWithNote', login="accountman") |
| 419 |
|
| 420 |
def test_order_sales_count(self): |
| 421 |
self.main_pos_config.open_ui() |
| 422 |
current_session = self.main_pos_config.current_session_id |
| 423 |
partner_1 = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 424 |
order = self.env['pos.order'].create({ |
| 425 |
'company_id': self.env.company.id, |
| 426 |
'session_id': current_session.id, |
| 427 |
'partner_id': partner_1.id, |
| 428 |
'pricelist_id': partner_1.property_product_pricelist.id, |
| 429 |
'lines': [(0, 0, { |
| 430 |
'name': "OL/0001", |
| 431 |
'product_id': self.desk_pad.product_variant_id.id, |
| 432 |
'price_unit': self.desk_pad.product_variant_id.lst_price, |
| 433 |
'discount': 0.0, |
| 434 |
'qty': 1.0, |
| 435 |
'tax_ids': [], |
| 436 |
'price_subtotal': self.desk_pad.product_variant_id.lst_price, |
| 437 |
'price_subtotal_incl': self.desk_pad.product_variant_id.lst_price, |
| 438 |
})], |
| 439 |
'amount_total': self.desk_pad.product_variant_id.lst_price, |
| 440 |
'amount_tax': 0.0, |
| 441 |
'amount_paid': 0.0, |
| 442 |
'amount_return': 0.0, |
| 443 |
'last_order_preparation_change': '{}' |
| 444 |
}) |
| 445 |
payment_context = {"active_ids": order.ids, "active_id": order.id} |
| 446 |
order_payment = self.env['pos.make.payment'].with_context(**payment_context).create({ |
| 447 |
'amount': order.amount_total, |
| 448 |
'payment_method_id': current_session.payment_method_ids[0].id, |
| 449 |
}) |
| 450 |
order_payment.with_context(**payment_context).check() |
| 451 |
|
| 452 |
current_session.close_session_from_ui() |
| 453 |
self.env.flush_all() |
| 454 |
self.env.user.group_ids += self.quick_ref('sales_team.group_sale_salesman') |
| 455 |
self.assertEqual(self.desk_pad.sales_count, 1) |
| 456 |
|
| 457 |
def test_untaxed_invoiced_amount(self): |
| 458 |
"""Make sure that orders invoiced in the pos gets their untaxed invoiced |
| 459 |
amount updated accordingly""" |
| 460 |
|
| 461 |
product_a = self.env['product.product'].create({ |
| 462 |
'name': 'Product A', |
| 463 |
'available_in_pos': True, |
| 464 |
'lst_price': 10.0, |
| 465 |
'taxes_id': [], |
| 466 |
}) |
| 467 |
|
| 468 |
product_b = self.env['product.product'].create({ |
| 469 |
'name': 'Product B', |
| 470 |
'available_in_pos': True, |
| 471 |
'lst_price': 5.0, |
| 472 |
'taxes_id': [], |
| 473 |
}) |
| 474 |
|
| 475 |
partner_test = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 476 |
|
| 477 |
sale_order = self.env['sale.order'].sudo().create({ |
| 478 |
'partner_id': partner_test.id, |
| 479 |
'order_line': [(0, 0, { |
| 480 |
'product_id': product_a.id, |
| 481 |
'name': product_a.name, |
| 482 |
'product_uom_qty': 1, |
| 483 |
'price_unit': product_a.lst_price, |
| 484 |
}), (0, 0, { |
| 485 |
'product_id': product_b.id, |
| 486 |
'name': product_b.name, |
| 487 |
'product_uom_qty': 1, |
| 488 |
'price_unit': product_b.lst_price, |
| 489 |
})], |
| 490 |
}) |
| 491 |
sale_order.action_confirm() |
| 492 |
self.main_pos_config.open_ui() |
| 493 |
current_session = self.main_pos_config.current_session_id |
| 494 |
|
| 495 |
pos_order = { |
| 496 |
'amount_paid': 10, |
| 497 |
'amount_return': 0, |
| 498 |
'amount_tax': 0, |
| 499 |
'amount_total': 10, |
| 500 |
'date_order': fields.Datetime.to_string(fields.Datetime.now()), |
| 501 |
'fiscal_position_id': False, |
| 502 |
'to_invoice': True, |
| 503 |
'partner_id': partner_test.id, |
| 504 |
'pricelist_id': self.main_pos_config.available_pricelist_ids[0].id, |
| 505 |
'lines': [[0, |
| 506 |
0, |
| 507 |
{'discount': 0, |
| 508 |
'pack_lot_ids': [], |
| 509 |
'price_unit': 10, |
| 510 |
'product_id': product_a.id, |
| 511 |
'price_subtotal': 10, |
| 512 |
'price_subtotal_incl': 10, |
| 513 |
'sale_order_line_id': sale_order.order_line[0].id, |
| 514 |
'sale_order_origin_id': sale_order.id, |
| 515 |
'qty': 1, |
| 516 |
'tax_ids': []}]], |
| 517 |
'session_id': current_session.id, |
| 518 |
'payment_ids': [[0, |
| 519 |
0, |
| 520 |
{'amount': 10, |
| 521 |
'name': fields.Datetime.now(), |
| 522 |
'payment_method_id': self.main_pos_config.payment_method_ids[0].id}]], |
| 523 |
'user_id': self.env.uid, |
| 524 |
} |
| 525 |
|
| 526 |
self.env['pos.order'].sync_from_ui([pos_order]) |
| 527 |
self.assertEqual(sale_order.order_line[0].untaxed_amount_invoiced, 10, "Untaxed invoiced amount should be 10") |
| 528 |
self.assertEqual(sale_order.order_line[1].untaxed_amount_invoiced, 0, "Untaxed invoiced amount should be 0") |
| 529 |
|
| 530 |
def test_order_does_not_remain_in_list(self): |
| 531 |
"""Verify that a paid order doesn't remain in the orders list""" |
| 532 |
|
| 533 |
|
| 534 |
sale_order = self.env['sale.order'].sudo().create({ |
| 535 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 536 |
'order_line': [(0, 0, { |
| 537 |
'product_id': self.whiteboard_pen.product_variant_id.id, |
| 538 |
'name': self.whiteboard_pen.name, |
| 539 |
'product_uom_qty': 1, |
| 540 |
'price_unit': 100, |
| 541 |
})], |
| 542 |
}) |
| 543 |
|
| 544 |
sale_order.action_confirm() |
| 545 |
|
| 546 |
self.main_pos_config.open_ui() |
| 547 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosOrderDoesNotRemainInList', login="accountman") |
| 548 |
|
| 549 |
def test_settle_draft_order_service_product(self): |
| 550 |
""" |
| 551 |
Checks that, when settling a draft order (quotation), the quantity set on the corresponding |
| 552 |
PoS order, for service products, is set correctly. |
| 553 |
""" |
| 554 |
|
| 555 |
product_a = self.env['product.product'].create({ |
| 556 |
'name': 'Test service product', |
| 557 |
'available_in_pos': True, |
| 558 |
'type': 'service', |
| 559 |
'invoice_policy': 'order', |
| 560 |
'lst_price': 50.0, |
| 561 |
'taxes_id': [], |
| 562 |
}) |
| 563 |
|
| 564 |
partner_test = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 565 |
|
| 566 |
sale_order = self.env['sale.order'].sudo().create({ |
| 567 |
'partner_id': partner_test.id, |
| 568 |
'order_line': [(0, 0, { |
| 569 |
'product_id': product_a.id, |
| 570 |
'name': product_a.name, |
| 571 |
'product_uom_qty': 1, |
| 572 |
'price_unit': product_a.lst_price, |
| 573 |
})], |
| 574 |
}) |
| 575 |
|
| 576 |
self.assertEqual(sale_order.state, 'draft') |
| 577 |
|
| 578 |
self.main_pos_config.open_ui() |
| 579 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosSettleDraftOrder', login="accountman") |
| 580 |
self.assertEqual(sale_order.state, 'sale') |
| 581 |
|
| 582 |
def test_settle_order_change_customer(self): |
| 583 |
""" |
| 584 |
When settling an order, the price set on the sol shouldn't reset to |
| 585 |
the sale price of the product when changing customer. |
| 586 |
""" |
| 587 |
self.product_a.lst_price = 150 |
| 588 |
self.product_a.taxes_id = None |
| 589 |
self.product_a.available_in_pos = True |
| 590 |
self.product_a.name = 'Product A' |
| 591 |
self.env['res.partner'].create({'name': 'A Test Partner AAA'}) |
| 592 |
sale_order = self.env['sale.order'].sudo().create({ |
| 593 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner BBB'}).id, |
| 594 |
'order_line': [(0, 0, { |
| 595 |
'product_id': self.product_a.id, |
| 596 |
'name': self.product_a.name, |
| 597 |
'product_uom_qty': 1, |
| 598 |
'price_unit': 100, |
| 599 |
})], |
| 600 |
}) |
| 601 |
sale_order.action_confirm() |
| 602 |
|
| 603 |
self.main_pos_config.open_ui() |
| 604 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosSettleCustomPrice', login="accountman") |
| 605 |
|
| 606 |
def test_so_with_downpayment(self): |
| 607 |
self.product_a.available_in_pos = True |
| 608 |
so = self.env['sale.order'].sudo().create({ |
| 609 |
'partner_id': self.partner_a.id, |
| 610 |
'order_line': [ |
| 611 |
(0, 0, { |
| 612 |
'name': self.product_a.name, |
| 613 |
'product_id': self.product_a.id, |
| 614 |
'product_uom_qty': 10.0, |
| 615 |
'price_unit': 100, |
| 616 |
'tax_ids': False, |
| 617 |
})], |
| 618 |
}) |
| 619 |
so.action_confirm() |
| 620 |
|
| 621 |
self.env['sale.advance.payment.inv'].sudo().create({ |
| 622 |
'advance_payment_method': 'fixed', |
| 623 |
'fixed_amount': 20, |
| 624 |
'sale_order_ids': so.ids, |
| 625 |
}).create_invoices() |
| 626 |
|
| 627 |
down_payment_invoices = so.invoice_ids |
| 628 |
down_payment_invoices.action_post() |
| 629 |
self.main_pos_config.down_payment_product_id = self.env.ref("pos_sale.default_downpayment_product") |
| 630 |
self.main_pos_config.down_payment_product_id.write({'active': True}) |
| 631 |
self.main_pos_config.open_ui() |
| 632 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PoSSaleOrderWithDownpayment', login="accountman") |
| 633 |
|
| 634 |
def test_downpayment_with_taxed_product(self): |
| 635 |
tax_1 = self.env['account.tax'].create({ |
| 636 |
'name': '10', |
| 637 |
'amount': 10, |
| 638 |
}) |
| 639 |
|
| 640 |
tax_2 = self.env['account.tax'].create({ |
| 641 |
'name': '5 incl', |
| 642 |
'amount': 5, |
| 643 |
'price_include_override': 'tax_included', |
| 644 |
}) |
| 645 |
|
| 646 |
product_a = self.env['product.product'].create({ |
| 647 |
'name': 'Product A', |
| 648 |
'available_in_pos': True, |
| 649 |
'lst_price': 10.0, |
| 650 |
'taxes_id': [tax_1.id], |
| 651 |
}) |
| 652 |
|
| 653 |
product_b = self.env['product.product'].create({ |
| 654 |
'name': 'Product B', |
| 655 |
'available_in_pos': True, |
| 656 |
'lst_price': 5.0, |
| 657 |
'taxes_id': [tax_2.id], |
| 658 |
}) |
| 659 |
|
| 660 |
product_c = self.env['product.product'].create({ |
| 661 |
'name': 'Product C', |
| 662 |
'available_in_pos': True, |
| 663 |
'lst_price': 15.0, |
| 664 |
'taxes_id': [], |
| 665 |
}) |
| 666 |
partner_test = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 667 |
|
| 668 |
sale_order = self.env['sale.order'].sudo().create({ |
| 669 |
'partner_id': partner_test.id, |
| 670 |
'order_line': [(0, 0, { |
| 671 |
'product_id': product_a.id, |
| 672 |
'name': product_a.name, |
| 673 |
'product_uom_qty': 1, |
| 674 |
'price_unit': product_a.lst_price, |
| 675 |
}), (0, 0, { |
| 676 |
'product_id': product_b.id, |
| 677 |
'name': product_b.name, |
| 678 |
'product_uom_qty': 1, |
| 679 |
'price_unit': product_b.lst_price, |
| 680 |
}), (0, 0, { |
| 681 |
'product_id': product_c.id, |
| 682 |
'name': product_c.name, |
| 683 |
'product_uom_qty': 1, |
| 684 |
'price_unit': product_c.lst_price, |
| 685 |
})], |
| 686 |
}) |
| 687 |
sale_order.action_confirm() |
| 688 |
|
| 689 |
self.downpayment_product = self.env['product.product'].create({ |
| 690 |
'name': 'Down Payment', |
| 691 |
'available_in_pos': True, |
| 692 |
'type': 'service', |
| 693 |
'taxes_id': [], |
| 694 |
}) |
| 695 |
self.main_pos_config.write({ |
| 696 |
'down_payment_product_id': self.downpayment_product.id, |
| 697 |
}) |
| 698 |
self.main_pos_config.open_ui() |
| 699 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PoSDownPaymentLinesPerTax', login="accountman") |
| 700 |
|
| 701 |
|
| 702 |
invoice_pdf_content = str(self.env['pos.order'].search([]).account_move._get_invoice_legal_documents('pdf', allow_fallback=True).get('content')) |
| 703 |
self.assertEqual(invoice_pdf_content.count('Product A'), 1) |
| 704 |
self.assertEqual(invoice_pdf_content.count('Product B'), 1) |
| 705 |
self.assertEqual(invoice_pdf_content.count('Product C'), 1) |
| 706 |
|
| 707 |
for order_line in sale_order.order_line.filtered(lambda l: l.product_id == self.downpayment_product): |
| 708 |
order_line = order_line.with_context(lang=partner_test.lang) |
| 709 |
self.assertIn(format_date(order_line.env, order_line.order_id.date_order), order_line.name) |
| 710 |
|
| 711 |
def test_settle_so_with_non_pos_groupable_uom(self): |
| 712 |
""" |
| 713 |
For products with a non-groupable PoS UoM (e.g., Kg), ensure that when a SO |
| 714 |
uses another UoM (e.g., g), the PoS correctly displays the quantity converted |
| 715 |
back to the original UoM. |
| 716 |
""" |
| 717 |
self.component_kg = self.env['product.product'].create({ |
| 718 |
'name': 'Pomme de Terre', |
| 719 |
'is_storable': True, |
| 720 |
'available_in_pos': True, |
| 721 |
'taxes_id': False, |
| 722 |
'lst_price': 10.0, |
| 723 |
'uom_id': self.env.ref('uom.product_uom_kgm').id, |
| 724 |
}) |
| 725 |
|
| 726 |
sale_order = self.env['sale.order'].sudo().create({ |
| 727 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 728 |
'order_line': [(0, 0, { |
| 729 |
'product_id': self.component_kg.id, |
| 730 |
'name': self.component_kg.name, |
| 731 |
'product_uom_qty': 500, |
| 732 |
'product_uom_id': self.env.ref('uom.product_uom_gram').id, |
| 733 |
'price_unit': 0.01, |
| 734 |
})], |
| 735 |
}) |
| 736 |
sale_order.action_confirm() |
| 737 |
|
| 738 |
self.start_pos_tour('test_settle_so_with_non_pos_groupable_uom') |
| 739 |
|
| 740 |
def test_settle_so_with_pos_downpayment(self): |
| 741 |
so = self.env['sale.order'].sudo().create({ |
| 742 |
'partner_id': self.partner_a.id, |
| 743 |
'order_line': [ |
| 744 |
(0, 0, { |
| 745 |
'name': self.product_a.name, |
| 746 |
'product_id': self.product_a.id, |
| 747 |
'product_uom_qty': 1.0, |
| 748 |
'price_unit': 100, |
| 749 |
'tax_ids': False, |
| 750 |
})], |
| 751 |
}) |
| 752 |
so.action_confirm() |
| 753 |
|
| 754 |
|
| 755 |
self.main_pos_config.open_ui() |
| 756 |
self.main_pos_config.down_payment_product_id = self.env.ref("pos_sale.default_downpayment_product") |
| 757 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PoSApplyDownpayment', login="accountman") |
| 758 |
|
| 759 |
invoice = so._create_invoices(final=True) |
| 760 |
invoice.action_post() |
| 761 |
self.assertEqual(invoice.amount_total, 90) |
| 762 |
|
| 763 |
def test_ship_later_no_default(self): |
| 764 |
""" Verify that when settling an order the ship later is not activated by default""" |
| 765 |
product = self.env['product.product'].create({ |
| 766 |
'name': 'Product', |
| 767 |
'available_in_pos': True, |
| 768 |
'lst_price': 10.0, |
| 769 |
'taxes_id': False, |
| 770 |
}) |
| 771 |
|
| 772 |
sale_order = self.env['sale.order'].sudo().create({ |
| 773 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 774 |
'order_line': [(0, 0, { |
| 775 |
'product_id': product.id, |
| 776 |
'name': product.name, |
| 777 |
'product_uom_qty': 4, |
| 778 |
'price_unit': product.lst_price, |
| 779 |
})], |
| 780 |
}) |
| 781 |
sale_order.action_confirm() |
| 782 |
self.main_pos_config.write({'ship_later': True}) |
| 783 |
self.main_pos_config.open_ui() |
| 784 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosShipLaterNoDefault', login="accountman") |
| 785 |
|
| 786 |
def test_order_sale_team(self): |
| 787 |
self.env['product.product'].create({ |
| 788 |
'name': 'Test Product', |
| 789 |
'available_in_pos': True, |
| 790 |
'lst_price': 100.0, |
| 791 |
'taxes_id': False, |
| 792 |
}) |
| 793 |
sale_team = self.env['crm.team'].create({'name': 'Test team'}) |
| 794 |
self.main_pos_config.write({'crm_team_id': sale_team}) |
| 795 |
self.main_pos_config.open_ui() |
| 796 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosSaleTeam', login="accountman") |
| 797 |
order = self.env['pos.order'].search([]) |
| 798 |
self.assertEqual(len(order), 1) |
| 799 |
self.assertEqual(order.crm_team_id, sale_team) |
| 800 |
|
| 801 |
def test_show_orders_for_pos_currency_only(self): |
| 802 |
currency = self.env['res.currency'].create({ |
| 803 |
'name': 'C', |
| 804 |
'symbol': 'C', |
| 805 |
'rounding': 0.01, |
| 806 |
'currency_unit_label': 'Curr', |
| 807 |
'rate': 1, |
| 808 |
}) |
| 809 |
pricelist = self.env['product.pricelist'].create({ |
| 810 |
'name': 'Pricelist Different Currency', |
| 811 |
'currency_id': currency.id, |
| 812 |
}) |
| 813 |
product = self.env['product.product'].create({ |
| 814 |
'name': 'Product', |
| 815 |
'available_in_pos': True, |
| 816 |
'lst_price': 10, |
| 817 |
'taxes_id': False, |
| 818 |
}) |
| 819 |
sale_order = self.env['sale.order'].sudo().create({ |
| 820 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 821 |
'order_line': [(0, 0, { |
| 822 |
'product_id': product.id, |
| 823 |
'name': product.name, |
| 824 |
'product_uom_qty': 4, |
| 825 |
'price_unit': product.lst_price, |
| 826 |
})], |
| 827 |
'pricelist_id': pricelist.id |
| 828 |
}) |
| 829 |
sale_order.action_confirm() |
| 830 |
self.main_pos_config.with_user(self.pos_admin).open_ui() |
| 831 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosOrdersListDifferentCurrency', login="pos_admin") |
| 832 |
|
| 833 |
def test_downpayment_amount_to_invoice(self): |
| 834 |
product_a = self.env['product.product'].create({ |
| 835 |
'name': 'Product A', |
| 836 |
'available_in_pos': True, |
| 837 |
'lst_price': 100.0, |
| 838 |
'taxes_id': [], |
| 839 |
}) |
| 840 |
partner_test = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 841 |
|
| 842 |
sale_order = self.env['sale.order'].sudo().create({ |
| 843 |
'partner_id': partner_test.id, |
| 844 |
'order_line': [(0, 0, { |
| 845 |
'product_id': product_a.id, |
| 846 |
'name': product_a.name, |
| 847 |
'product_uom_qty': 1, |
| 848 |
'price_unit': product_a.lst_price, |
| 849 |
})], |
| 850 |
}) |
| 851 |
sale_order.action_confirm() |
| 852 |
self.main_pos_config.down_payment_product_id = self.env.ref("pos_sale.default_downpayment_product") |
| 853 |
self.main_pos_config.open_ui() |
| 854 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PoSDownPaymentAmount', login="accountman") |
| 855 |
self.assertEqual(sale_order.amount_to_invoice, 80.0, "Downpayment amount not considered!") |
| 856 |
self.assertEqual(sale_order.amount_invoiced, 20.0, "Downpayment amount not considered!") |
| 857 |
|
| 858 |
self.assertEqual(sale_order.order_line[2].price_unit, 20) |
| 859 |
|
| 860 |
|
| 861 |
sale_order.order_line[0].write({'qty_delivered': 1.0}) |
| 862 |
|
| 863 |
|
| 864 |
self.env['sale.advance.payment.inv'].sudo().with_context({ |
| 865 |
'active_model': 'sale.order', |
| 866 |
'active_ids': [sale_order.id], |
| 867 |
'active_id': sale_order.id, |
| 868 |
'default_journal_id': self.company_data['default_journal_sale'].id, |
| 869 |
}).create({}).create_invoices() |
| 870 |
|
| 871 |
|
| 872 |
sale_order.invoice_ids.action_post() |
| 873 |
self.assertEqual(sale_order.order_line[2].price_unit, 20) |
| 874 |
|
| 875 |
def test_settle_order_with_multistep_delivery_receipt(self): |
| 876 |
"""This test create an order and settle it in the PoS. It also uses multistep delivery |
| 877 |
and we need to make sure that all the picking are cancelled if the order is fully delivered. |
| 878 |
""" |
| 879 |
if not self.env["ir.module.module"].search([("name", "=", "purchase"), ("state", "=", "installed")]): |
| 880 |
self.skipTest("purchase module is required for this test") |
| 881 |
|
| 882 |
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) |
| 883 |
warehouse.delivery_steps = 'pick_pack_ship' |
| 884 |
warehouse.reception_steps = 'three_steps' |
| 885 |
self.env.ref('stock.route_warehouse0_mto').active = True |
| 886 |
route_buy = self.env.ref('purchase_stock.route_warehouse0_buy') |
| 887 |
route_mto = self.env.ref('stock.route_warehouse0_mto') |
| 888 |
route_mto.rule_ids.procure_method = 'mts_else_mto' |
| 889 |
self.partner_test = self.env['res.partner'].create({ |
| 890 |
'name': 'Partner Test A', |
| 891 |
'is_company': True, |
| 892 |
'street': '77 Santa Barbara Rd', |
| 893 |
'city': 'Pleasant Hill', |
| 894 |
'country_id': self.env.ref('base.nl').id, |
| 895 |
'zip': '1105AA', |
| 896 |
'state_id': False, |
| 897 |
'email': '[email protected]', |
| 898 |
'phone': '(603)-996-3829', |
| 899 |
}) |
| 900 |
|
| 901 |
product_a = self.env['product.product'].create({ |
| 902 |
'name': 'Product A', |
| 903 |
'available_in_pos': True, |
| 904 |
'is_storable': True, |
| 905 |
'lst_price': 10.0, |
| 906 |
'seller_ids': [(0, 0, { |
| 907 |
'partner_id': self.partner_test.id, |
| 908 |
'min_qty': 1.0, |
| 909 |
'price': 1.0, |
| 910 |
})], |
| 911 |
'route_ids': [(6, 0, [route_buy.id, route_mto.id])], |
| 912 |
}) |
| 913 |
|
| 914 |
sale_order = self.env['sale.order'].sudo().create({ |
| 915 |
'partner_id': self.partner_test.id, |
| 916 |
'order_line': [(0, 0, { |
| 917 |
'product_id': product_a.id, |
| 918 |
'name': product_a.name, |
| 919 |
'product_uom_qty': 1, |
| 920 |
'price_unit': product_a.lst_price, |
| 921 |
})], |
| 922 |
}) |
| 923 |
sale_order.action_confirm() |
| 924 |
|
| 925 |
|
| 926 |
po = sale_order._get_purchase_orders() |
| 927 |
po.button_confirm() |
| 928 |
picking = po.picking_ids |
| 929 |
|
| 930 |
picking.button_validate() |
| 931 |
picking = picking._get_next_transfers() |
| 932 |
picking.button_validate() |
| 933 |
picking = picking._get_next_transfers() |
| 934 |
picking.button_validate() |
| 935 |
|
| 936 |
self.main_pos_config.ship_later = True |
| 937 |
self.main_pos_config.open_ui() |
| 938 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosSettleOrder4', login="accountman") |
| 939 |
|
| 940 |
self.assertEqual(sale_order.picking_ids[0].state, 'cancel') |
| 941 |
self.assertEqual(sale_order.pos_order_line_ids.order_id.picking_ids.state, 'assigned') |
| 942 |
self.assertEqual(self.env['purchase.order.line'].search_count([('product_id', '=', product_a.id)]), 1) |
| 943 |
|
| 944 |
def test_pos_sale_warnings(self): |
| 945 |
self.env['res.partner'].create([ |
| 946 |
{'name': 'A Test Customer 1', 'sale_warn_msg': 'Highly infectious disease'}, |
| 947 |
{'name': 'A Test Customer 2', 'sale_warn_msg': 'Cannot afford our services'} |
| 948 |
]) |
| 949 |
self.main_pos_config.open_ui() |
| 950 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosSaleWarning', login="accountman") |
| 951 |
|
| 952 |
def test_downpayment_invoice(self): |
| 953 |
"""This test check that users that don't have the pos user group can invoice downpayments""" |
| 954 |
self.env['res.partner'].create({'name': 'Test Partner AAA'}) |
| 955 |
|
| 956 |
sale_order = self.env['sale.order'].sudo().create({ |
| 957 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner BBB'}).id, |
| 958 |
'order_line': [(0, 0, { |
| 959 |
'product_id': self.product_a.id, |
| 960 |
'name': self.product_a.name, |
| 961 |
'product_uom_qty': 1, |
| 962 |
'price_unit': 100, |
| 963 |
'tax_ids': False, |
| 964 |
})], |
| 965 |
}) |
| 966 |
sale_order.action_confirm() |
| 967 |
|
| 968 |
self.env['sale.advance.payment.inv'].sudo().with_context({ |
| 969 |
'active_model': 'sale.order', |
| 970 |
'active_ids': [sale_order.id], |
| 971 |
'active_id': sale_order.id, |
| 972 |
'default_journal_id': self.company_data['default_journal_sale'].id, |
| 973 |
}).create({ |
| 974 |
'advance_payment_method': 'fixed', |
| 975 |
'fixed_amount': 100, |
| 976 |
}).create_invoices() |
| 977 |
|
| 978 |
selected_groups = self.user.group_ids |
| 979 |
self.user.group_ids = self.env.ref('account.group_account_manager') + self.env.ref('sales_team.group_sale_salesman_all_leads') |
| 980 |
|
| 981 |
downpayment_line = sale_order.order_line.filtered(lambda l: l.is_downpayment and not l.display_type) |
| 982 |
downpayment_invoice = downpayment_line.order_id.order_line.invoice_lines.move_id |
| 983 |
downpayment_invoice.action_post() |
| 984 |
self.user.group_ids = selected_groups |
| 985 |
self.assertEqual(downpayment_line.price_unit, 100) |
| 986 |
|
| 987 |
def test_downpayment_invoice_link(self): |
| 988 |
|
| 989 |
|
| 990 |
tax = self.env['account.tax'].create({ |
| 991 |
'name': 'Base Tax', |
| 992 |
'amount': 15, |
| 993 |
}) |
| 994 |
customer = self.env['res.partner'].create({'name': 'Test Partner A'}) |
| 995 |
sale_orders = self.env['sale.order'].create([{ |
| 996 |
'partner_id': customer.id, |
| 997 |
'order_line': [Command.create({ |
| 998 |
'product_id': self.product_a.id, |
| 999 |
'name': self.product_a.name, |
| 1000 |
'product_uom_qty': 1, |
| 1001 |
'price_unit': 100, |
| 1002 |
'tax_ids': [tax.id], |
| 1003 |
})], |
| 1004 |
} for _ in range(2)]) |
| 1005 |
|
| 1006 |
sale_orders.action_confirm() |
| 1007 |
|
| 1008 |
|
| 1009 |
sale_order = sale_orders[1] |
| 1010 |
self.main_pos_config.open_ui() |
| 1011 |
self.main_pos_config.down_payment_product_id = self.env.ref("pos_sale.default_downpayment_product") |
| 1012 |
self.start_pos_tour('PoSApplyDownpaymentInvoice') |
| 1013 |
|
| 1014 |
downpayment_invoice = sale_order.pos_order_line_ids.order_id.account_move |
| 1015 |
self.assertTrue(downpayment_invoice._is_downpayment()) |
| 1016 |
|
| 1017 |
self.env['sale.advance.payment.inv'].with_context({ |
| 1018 |
'active_model': 'sale.order', |
| 1019 |
'active_ids': [sale_order.id], |
| 1020 |
'active_id': sale_order.id, |
| 1021 |
'default_journal_id': self.company_data['default_journal_sale'].id, |
| 1022 |
}).create({}).create_invoices() |
| 1023 |
|
| 1024 |
final_invoice_downpayment_line = sale_order.invoice_ids.invoice_line_ids.filtered(lambda r: r.quantity < 0) |
| 1025 |
|
| 1026 |
self.assertEqual( |
| 1027 |
final_invoice_downpayment_line._get_downpayment_lines(), |
| 1028 |
downpayment_invoice.invoice_line_ids, |
| 1029 |
) |
| 1030 |
|
| 1031 |
|
| 1032 |
sale_order = sale_orders[0] |
| 1033 |
self.start_pos_tour('PoSApplyDownpaymentInvoice2') |
| 1034 |
|
| 1035 |
downpayment_invoice = sale_order.pos_order_line_ids.order_id.account_move |
| 1036 |
self.assertTrue(downpayment_invoice._is_downpayment()) |
| 1037 |
|
| 1038 |
self.start_pos_tour('PosSettleAndInvoiceOrder2') |
| 1039 |
|
| 1040 |
final_invoice_downpayment_line = sale_order.pos_order_line_ids[-1].order_id.account_move.invoice_line_ids.filtered(lambda r: r.quantity < 0) |
| 1041 |
|
| 1042 |
self.assertEqual( |
| 1043 |
final_invoice_downpayment_line._get_downpayment_lines(), |
| 1044 |
downpayment_invoice.invoice_line_ids, |
| 1045 |
) |
| 1046 |
|
| 1047 |
def test_settle_order_ship_later_effect_on_so(self): |
| 1048 |
"""This test create an order, settle it in the PoS and ship it later. |
| 1049 |
We need to make sure that the quantity delivered on the original sale is updated correctly, |
| 1050 |
And that the picking associated to the original sale order is cancelled. |
| 1051 |
""" |
| 1052 |
|
| 1053 |
product_a = self.env['product.product'].create({ |
| 1054 |
'name': 'Product A', |
| 1055 |
'available_in_pos': True, |
| 1056 |
'lst_price': 10.0, |
| 1057 |
}) |
| 1058 |
|
| 1059 |
product_b = self.env['product.product'].create({ |
| 1060 |
'name': 'Product B', |
| 1061 |
'available_in_pos': True, |
| 1062 |
'lst_price': 5.0, |
| 1063 |
}) |
| 1064 |
|
| 1065 |
partner_test = self.env['res.partner'].create({ |
| 1066 |
'name': 'Test Partner', |
| 1067 |
'city': 'San Francisco', |
| 1068 |
'state_id': self.env.ref('base.state_us_5').id, |
| 1069 |
'country_id': self.env.ref('base.us').id, |
| 1070 |
'zip': '94134', |
| 1071 |
'street': 'Rue du burger', |
| 1072 |
}) |
| 1073 |
|
| 1074 |
sale_order_single = self.env['sale.order'].sudo().create({ |
| 1075 |
'partner_id': partner_test.id, |
| 1076 |
'order_line': [(0, 0, { |
| 1077 |
'product_id': product_a.id, |
| 1078 |
'name': product_a.name, |
| 1079 |
'product_uom_qty': 1, |
| 1080 |
'price_unit': product_a.lst_price, |
| 1081 |
})], |
| 1082 |
}) |
| 1083 |
|
| 1084 |
sale_order_multi = self.env['sale.order'].sudo().create({ |
| 1085 |
'partner_id': partner_test.id, |
| 1086 |
'order_line': [(0, 0, { |
| 1087 |
'product_id': product_a.id, |
| 1088 |
'name': product_a.name, |
| 1089 |
'product_uom_qty': 1, |
| 1090 |
'price_unit': product_a.lst_price, |
| 1091 |
}), (0, 0, { |
| 1092 |
'product_id': product_b.id, |
| 1093 |
'name': product_b.name, |
| 1094 |
'product_uom_qty': 1, |
| 1095 |
'price_unit': product_b.lst_price, |
| 1096 |
})], |
| 1097 |
}) |
| 1098 |
self.assertEqual(sale_order_single.order_line[0].qty_delivered, 0) |
| 1099 |
|
| 1100 |
self.main_pos_config.ship_later = True |
| 1101 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 1102 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosSettleOrderShipLater', login="accountman") |
| 1103 |
|
| 1104 |
self.assertEqual(len(sale_order_single.picking_ids), 1) |
| 1105 |
self.assertEqual(sale_order_single.picking_ids.state, "cancel") |
| 1106 |
self.assertEqual(len(sale_order_single.pos_order_line_ids.order_id.picking_ids), 1) |
| 1107 |
self.assertEqual(sale_order_single.pos_order_line_ids.order_id.picking_ids.state, "assigned") |
| 1108 |
|
| 1109 |
|
| 1110 |
self.assertEqual(sale_order_single.order_line[0].qty_delivered, 0) |
| 1111 |
|
| 1112 |
|
| 1113 |
pickings = sale_order_single.pos_order_line_ids.order_id.picking_ids |
| 1114 |
pickings.move_ids.quantity = 1 |
| 1115 |
pickings.button_validate() |
| 1116 |
self.assertEqual(sale_order_single.order_line[0].qty_delivered, 1) |
| 1117 |
|
| 1118 |
|
| 1119 |
self.assertEqual(sale_order_multi.order_line[0].qty_delivered, 0) |
| 1120 |
self.assertEqual(sale_order_multi.order_line[1].qty_delivered, 0) |
| 1121 |
|
| 1122 |
self.assertEqual(len(sale_order_multi.picking_ids), 1) |
| 1123 |
self.assertEqual(sale_order_multi.picking_ids.state, "cancel") |
| 1124 |
self.assertEqual(len(sale_order_multi.pos_order_line_ids.order_id.picking_ids), 1) |
| 1125 |
self.assertEqual(sale_order_multi.pos_order_line_ids.order_id.picking_ids.state, "assigned") |
| 1126 |
|
| 1127 |
def test_draft_pos_order_linked_sale_order(self): |
| 1128 |
"""This test create an order and settle it in the PoS. It will let the PoS order in draft state. |
| 1129 |
As the order is still in draft state it shouldn't have impact on invoiced qty of the linked sale order. |
| 1130 |
""" |
| 1131 |
|
| 1132 |
product_a = self.env['product.product'].create({ |
| 1133 |
'name': 'Product A', |
| 1134 |
'available_in_pos': True, |
| 1135 |
'is_storable': True, |
| 1136 |
'lst_price': 10.0, |
| 1137 |
}) |
| 1138 |
|
| 1139 |
sale_order = self.env['sale.order'].sudo().create({ |
| 1140 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner BBB'}).id, |
| 1141 |
'order_line': [(0, 0, { |
| 1142 |
'product_id': product_a.id, |
| 1143 |
'name': product_a.name, |
| 1144 |
'product_uom_qty': 1, |
| 1145 |
'price_unit': product_a.lst_price, |
| 1146 |
})], |
| 1147 |
}) |
| 1148 |
sale_order.action_confirm() |
| 1149 |
self.main_pos_config.open_ui() |
| 1150 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'PosSettleOrder5', login="accountman") |
| 1151 |
self.assertEqual(sale_order.order_line.qty_invoiced, 0) |
| 1152 |
self.assertEqual(sale_order.order_line.qty_delivered, 0) |
| 1153 |
|
| 1154 |
def test_settle_quotation_delivered_qty(self): |
| 1155 |
""" Test if a quotation (unconfirmed sale order) is settled in the PoS, the delivered quantity is updated correctly """ |
| 1156 |
|
| 1157 |
product1 = self.env['product.product'].create({ |
| 1158 |
'name': 'product1', |
| 1159 |
'available_in_pos': True, |
| 1160 |
'is_storable': True, |
| 1161 |
'lst_price': 10, |
| 1162 |
'taxes_id': [Command.clear()], |
| 1163 |
}) |
| 1164 |
partner_1 = self.env['res.partner'].create({'name': 'Test Partner 1'}) |
| 1165 |
order = self.env['sale.order'].sudo().create({ |
| 1166 |
'partner_id': partner_1.id, |
| 1167 |
'order_line': [Command.create({'product_id': product1.id})], |
| 1168 |
}) |
| 1169 |
self.main_pos_config.open_ui() |
| 1170 |
self.start_pos_tour('PoSSettleQuotation', login="accountman") |
| 1171 |
self.assertEqual(order.order_line.qty_delivered, 1) |
| 1172 |
|
| 1173 |
def test_edit_invoice_with_pos_order(self): |
| 1174 |
self.main_pos_config.open_ui() |
| 1175 |
current_session = self.main_pos_config.current_session_id |
| 1176 |
partner_1 = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 1177 |
|
| 1178 |
pos_order = self.env['pos.order'].create({ |
| 1179 |
'company_id': self.env.company.id, |
| 1180 |
'session_id': current_session.id, |
| 1181 |
'partner_id': partner_1.id, |
| 1182 |
'pricelist_id': partner_1.property_product_pricelist.id, |
| 1183 |
'lines': [(0, 0, { |
| 1184 |
'name': "OL/0001", |
| 1185 |
'product_id': self.desk_pad.product_variant_id.id, |
| 1186 |
'price_unit': self.desk_pad.product_variant_id.lst_price, |
| 1187 |
'discount': 0.0, |
| 1188 |
'qty': 1.0, |
| 1189 |
'tax_ids': [], |
| 1190 |
'price_subtotal': self.desk_pad.product_variant_id.lst_price, |
| 1191 |
'price_subtotal_incl': self.desk_pad.product_variant_id.lst_price, |
| 1192 |
})], |
| 1193 |
'amount_total': self.desk_pad.product_variant_id.lst_price, |
| 1194 |
'amount_tax': 0.0, |
| 1195 |
'amount_paid': 0.0, |
| 1196 |
'amount_return': 0.0, |
| 1197 |
'last_order_preparation_change': '{}' |
| 1198 |
}) |
| 1199 |
|
| 1200 |
|
| 1201 |
res = pos_order.action_pos_order_invoice() |
| 1202 |
self.assertIn('res_id', res, "Invoice should be created") |
| 1203 |
self.assertEqual(res['res_id'], pos_order.account_move.id) |
| 1204 |
|
| 1205 |
invoice = pos_order.account_move |
| 1206 |
self.assertEqual(invoice.state, 'posted') |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
invoice.button_draft() |
| 1211 |
self.assertEqual(invoice.state, 'posted') |
| 1212 |
|
| 1213 |
def test_pos_order_and_invoice_amounts(self): |
| 1214 |
payment_term = self.env['account.payment.term'].create({ |
| 1215 |
'name': "early_payment_term", |
| 1216 |
'discount_percentage': 10, |
| 1217 |
'discount_days': 10, |
| 1218 |
'early_discount': True, |
| 1219 |
'early_pay_discount_computation': 'mixed', |
| 1220 |
'line_ids': [Command.create({ |
| 1221 |
'value': 'percent', |
| 1222 |
'nb_days': 0, |
| 1223 |
'value_amount': 100, |
| 1224 |
})] |
| 1225 |
}) |
| 1226 |
partner_test = self.env['res.partner'].create({ |
| 1227 |
'name': 'AAA - Test Partner invoice', |
| 1228 |
'property_payment_term_id': payment_term.id, |
| 1229 |
}) |
| 1230 |
|
| 1231 |
tax = self.env['account.tax'].create({ |
| 1232 |
'name': 'Tax 10%', |
| 1233 |
'amount': 10, |
| 1234 |
'amount_type': 'percent', |
| 1235 |
'type_tax_use': 'sale', |
| 1236 |
}) |
| 1237 |
test_product = self.env['product.product'].create({ |
| 1238 |
'name': 'Product Test', |
| 1239 |
'available_in_pos': True, |
| 1240 |
'list_price': 1000, |
| 1241 |
'taxes_id': [(6, 0, [tax.id])], |
| 1242 |
}) |
| 1243 |
|
| 1244 |
self.env['sale.order'].sudo().create({ |
| 1245 |
'partner_id': partner_test.id, |
| 1246 |
'order_line': [ |
| 1247 |
Command.create({ |
| 1248 |
'product_id': test_product.id, |
| 1249 |
'price_unit': test_product.lst_price, |
| 1250 |
}), |
| 1251 |
], |
| 1252 |
}) |
| 1253 |
|
| 1254 |
self.main_pos_config.open_ui() |
| 1255 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'POSSalePaymentScreenInvoiceOrder', login="accountman") |
| 1256 |
|
| 1257 |
order = self.env['pos.order'].search([('partner_id', '=', partner_test.id)], limit=1) |
| 1258 |
self.assertTrue(order) |
| 1259 |
self.assertEqual(order.partner_id, partner_test) |
| 1260 |
|
| 1261 |
invoice = self.env['account.move'].search([('invoice_origin', '=', order.pos_reference)], limit=1) |
| 1262 |
self.assertTrue(invoice) |
| 1263 |
self.assertFalse(invoice.invoice_payment_term_id) |
| 1264 |
|
| 1265 |
self.assertAlmostEqual(order.amount_total, invoice.amount_total, places=2, msg="Order and Invoice amounts do not match.") |
| 1266 |
|
| 1267 |
def test_settle_order_with_lot(self): |
| 1268 |
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) |
| 1269 |
stock_location = warehouse.lot_stock_id |
| 1270 |
product = self.env['product.product'].create({ |
| 1271 |
'name': 'Product A', |
| 1272 |
'tracking': 'serial', |
| 1273 |
'is_storable': True, |
| 1274 |
'lst_price': 10, |
| 1275 |
}) |
| 1276 |
|
| 1277 |
lot1 = self.env['stock.lot'].create({ |
| 1278 |
'name': '1001', |
| 1279 |
'product_id': product.id, |
| 1280 |
'company_id': self.env.company.id, |
| 1281 |
}) |
| 1282 |
lot2 = self.env['stock.lot'].create({ |
| 1283 |
'name': '1002', |
| 1284 |
'product_id': product.id, |
| 1285 |
'company_id': self.env.company.id, |
| 1286 |
}) |
| 1287 |
|
| 1288 |
self.env['stock.quant'].with_context(inventory_mode=True).create({ |
| 1289 |
'product_id': product.id, |
| 1290 |
'inventory_quantity': 1, |
| 1291 |
'location_id': stock_location.id, |
| 1292 |
'lot_id': lot1.id |
| 1293 |
}).action_apply_inventory() |
| 1294 |
self.env['stock.quant'].with_context(inventory_mode=True).create({ |
| 1295 |
'product_id': product.id, |
| 1296 |
'inventory_quantity': 1, |
| 1297 |
'location_id': stock_location.id, |
| 1298 |
'lot_id': lot2.id |
| 1299 |
}).action_apply_inventory() |
| 1300 |
|
| 1301 |
partner_test = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 1302 |
|
| 1303 |
sale_order = self.env['sale.order'].sudo().create({ |
| 1304 |
'partner_id': partner_test.id, |
| 1305 |
'order_line': [ |
| 1306 |
(0, 0, { |
| 1307 |
'name': 'section line', |
| 1308 |
'display_type': 'line_section', |
| 1309 |
}), |
| 1310 |
(0, 0, { |
| 1311 |
'product_id': product.id, |
| 1312 |
'name': product.name, |
| 1313 |
'product_uom_qty': 2, |
| 1314 |
'price_unit': product.lst_price, |
| 1315 |
}) |
| 1316 |
], |
| 1317 |
}) |
| 1318 |
sale_order.action_confirm() |
| 1319 |
self.main_pos_config.open_ui() |
| 1320 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'test_settle_order_with_lot', login="accountman") |
| 1321 |
|
| 1322 |
def test_down_payment_displayed(self): |
| 1323 |
""" |
| 1324 |
Tests that a down payment for a Sale Order will be displayed and applied when settling the order |
| 1325 |
""" |
| 1326 |
product_a = self.env['product.product'].create({ |
| 1327 |
'name': 'Product A', |
| 1328 |
'lst_price': 10.0, |
| 1329 |
}) |
| 1330 |
so = self.env['sale.order'].sudo().create({ |
| 1331 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 1332 |
'order_line': [(0, 0, { |
| 1333 |
'product_id': product_a.id, |
| 1334 |
'product_uom_qty': 1, |
| 1335 |
'price_unit': product_a.lst_price, |
| 1336 |
})] |
| 1337 |
}) |
| 1338 |
so.action_confirm() |
| 1339 |
self.main_pos_config.down_payment_product_id = self.env.ref("pos_sale.default_downpayment_product") |
| 1340 |
self.main_pos_config.open_ui() |
| 1341 |
self.start_pos_tour('test_down_payment_displayed', login="accountman") |
| 1342 |
|
| 1343 |
def test_amount_to_invoice(self): |
| 1344 |
""" |
| 1345 |
Checks that the amount to invoice is updated correctly when paying an order in the PoS |
| 1346 |
""" |
| 1347 |
|
| 1348 |
product_a = self.env["product.product"].create( |
| 1349 |
{ |
| 1350 |
"name": "Test service product", |
| 1351 |
"available_in_pos": True, |
| 1352 |
"type": "service", |
| 1353 |
"invoice_policy": "order", |
| 1354 |
"lst_price": 100.0, |
| 1355 |
"taxes_id": [], |
| 1356 |
} |
| 1357 |
) |
| 1358 |
|
| 1359 |
partner_test = self.env["res.partner"].create({"name": "Test Partner"}) |
| 1360 |
|
| 1361 |
sale_order = self.env["sale.order"].sudo().create( |
| 1362 |
{ |
| 1363 |
"partner_id": partner_test.id, |
| 1364 |
"order_line": [Command.create( |
| 1365 |
{ |
| 1366 |
"product_id": product_a.id, |
| 1367 |
"name": product_a.name, |
| 1368 |
"product_uom_qty": 1, |
| 1369 |
"price_unit": product_a.lst_price, |
| 1370 |
}, |
| 1371 |
) |
| 1372 |
], |
| 1373 |
} |
| 1374 |
) |
| 1375 |
self.main_pos_config.open_ui() |
| 1376 |
order_data = { |
| 1377 |
"amount_paid": 100, |
| 1378 |
"amount_tax": 0, |
| 1379 |
"amount_return": 0, |
| 1380 |
"amount_total": 100, |
| 1381 |
"session_id": self.main_pos_config.current_session_id.id, |
| 1382 |
"date_order": fields.Datetime.to_string(fields.Datetime.now()), |
| 1383 |
"fiscal_position_id": False, |
| 1384 |
"lines": [ |
| 1385 |
Command.create({ |
| 1386 |
"discount": 0, |
| 1387 |
"pack_lot_ids": [], |
| 1388 |
"price_unit": 100.0, |
| 1389 |
"product_id": self.product_a.id, |
| 1390 |
"price_subtotal": 100.0, |
| 1391 |
"price_subtotal_incl": 100.0, |
| 1392 |
"tax_ids": [], |
| 1393 |
"sale_order_line_id": sale_order.order_line[0].id, |
| 1394 |
"sale_order_origin_id": sale_order.id, |
| 1395 |
"qty": 1, |
| 1396 |
}), |
| 1397 |
], |
| 1398 |
"name": "Order 12345-123-1234", |
| 1399 |
"partner_id": self.partner_a.id, |
| 1400 |
"sequence_number": 2, |
| 1401 |
"payment_ids": [ |
| 1402 |
Command.create({ |
| 1403 |
"amount": 100, |
| 1404 |
"name": fields.Datetime.now(), |
| 1405 |
"payment_method_id": self.main_pos_config.payment_method_ids[0].id, |
| 1406 |
}), |
| 1407 |
], |
| 1408 |
"uuid": "12345-123-1234", |
| 1409 |
"last_order_preparation_change": "{}", |
| 1410 |
"user_id": self.env.uid, |
| 1411 |
"to_invoice": True, |
| 1412 |
} |
| 1413 |
self.assertEqual(sale_order.amount_to_invoice, 100.0, "Amount to invoice should be 100.0") |
| 1414 |
self.env['pos.order'].sync_from_ui([order_data]) |
| 1415 |
self.assertEqual(sale_order.amount_to_invoice, 0.0, "Amount to invoice should be 0.0") |
| 1416 |
|
| 1417 |
def test_payment_terms_with_early_discount(self): |
| 1418 |
"""Make sure that orders invoiced in the pos do not use payment terms with early discount""" |
| 1419 |
|
| 1420 |
product_a = self.env['product.product'].create({ |
| 1421 |
'name': 'Product A', |
| 1422 |
'available_in_pos': True, |
| 1423 |
'is_storable': True, |
| 1424 |
'lst_price': 10.0, |
| 1425 |
'taxes_id': [], |
| 1426 |
}) |
| 1427 |
|
| 1428 |
partner_test = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 1429 |
|
| 1430 |
payment_terms = self.env['account.payment.term'].create({ |
| 1431 |
'name': "Test Payment Term", |
| 1432 |
'early_discount': True, |
| 1433 |
'line_ids': [(0, 0, { |
| 1434 |
'value': 'percent', |
| 1435 |
'value_amount': 100, |
| 1436 |
'nb_days': 45, |
| 1437 |
})] |
| 1438 |
}) |
| 1439 |
|
| 1440 |
sale_order = self.env['sale.order'].sudo().create({ |
| 1441 |
'partner_id': partner_test.id, |
| 1442 |
'payment_term_id': payment_terms.id, |
| 1443 |
'order_line': [(0, 0, { |
| 1444 |
'product_id': product_a.id, |
| 1445 |
'name': product_a.name, |
| 1446 |
'product_uom_qty': 1, |
| 1447 |
'price_unit': product_a.lst_price, |
| 1448 |
})], |
| 1449 |
}) |
| 1450 |
sale_order.action_confirm() |
| 1451 |
self.main_pos_config.open_ui() |
| 1452 |
current_session = self.main_pos_config.current_session_id |
| 1453 |
|
| 1454 |
pos_order = {'amount_paid': 10, |
| 1455 |
'amount_return': 0, |
| 1456 |
'amount_tax': 0, |
| 1457 |
'amount_total': 10, |
| 1458 |
'date_order': fields.Datetime.to_string(fields.Datetime.now()), |
| 1459 |
'fiscal_position_id': False, |
| 1460 |
'to_invoice': True, |
| 1461 |
'partner_id': partner_test.id, |
| 1462 |
'pricelist_id': self.main_pos_config.available_pricelist_ids[0].id, |
| 1463 |
'lines': [[0, |
| 1464 |
0, |
| 1465 |
{'discount': 0, |
| 1466 |
'pack_lot_ids': [], |
| 1467 |
'price_unit': 10, |
| 1468 |
'product_id': product_a.id, |
| 1469 |
'price_subtotal': 10, |
| 1470 |
'price_subtotal_incl': 10, |
| 1471 |
'sale_order_line_id': sale_order.order_line[0].id, |
| 1472 |
'sale_order_origin_id': sale_order.id, |
| 1473 |
'qty': 1, |
| 1474 |
'tax_ids': []}]], |
| 1475 |
'name': 'Order 00044-003-0014', |
| 1476 |
'session_id': current_session.id, |
| 1477 |
'sequence_number': self.main_pos_config.journal_id.id, |
| 1478 |
'payment_ids': [[0, |
| 1479 |
0, |
| 1480 |
{'amount': 10, |
| 1481 |
'name': fields.Datetime.now(), |
| 1482 |
'payment_method_id': self.main_pos_config.payment_method_ids[0].id}]], |
| 1483 |
'uuid': '00044-003-0014', |
| 1484 |
'user_id': self.env.uid} |
| 1485 |
|
| 1486 |
pos_order_id = self.env['pos.order'].sync_from_ui([pos_order])['pos.order'][0]['id'] |
| 1487 |
pos_order = self.env['pos.order'].browse(pos_order_id) |
| 1488 |
self.assertFalse(pos_order.account_move.invoice_payment_term_id) |
| 1489 |
|
| 1490 |
def test_sale_order_fp_different_from_partner_one(self): |
| 1491 |
""" |
| 1492 |
Tests that the fiscal position of the sale order is not the same as the partner's fiscal position. |
| 1493 |
The PoS should always use the fiscal position of the sale order when settling it. |
| 1494 |
""" |
| 1495 |
self.env.user.group_ids += self.quick_ref('sales_team.group_sale_salesman') |
| 1496 |
tax = self.env['account.tax'].create({ |
| 1497 |
'name': 'Base Tax', |
| 1498 |
'amount': 15, |
| 1499 |
}) |
| 1500 |
fp_1 = self.env['account.fiscal.position'].create({ |
| 1501 |
'name': "Partner FP", |
| 1502 |
}) |
| 1503 |
fp_2 = self.env['account.fiscal.position'].create({ |
| 1504 |
'name': "Sale Order FP", |
| 1505 |
}) |
| 1506 |
tax_override_1 = self.env['account.tax'].create({ |
| 1507 |
'name': 'Tax Override 1', |
| 1508 |
'amount': 100, |
| 1509 |
'amount_type': 'percent', |
| 1510 |
'fiscal_position_ids': [fp_1.id], |
| 1511 |
'original_tax_ids': [tax.id], |
| 1512 |
}) |
| 1513 |
tax_override_2 = self.env['account.tax'].create({ |
| 1514 |
'name': 'Tax Override 2', |
| 1515 |
'amount': 0, |
| 1516 |
'amount_type': 'percent', |
| 1517 |
'fiscal_position_ids': [fp_2.id], |
| 1518 |
'original_tax_ids': [tax.id], |
| 1519 |
}) |
| 1520 |
product_a = self.env['product.product'].create({ |
| 1521 |
'name': 'Product A', |
| 1522 |
'available_in_pos': True, |
| 1523 |
'lst_price': 10.0, |
| 1524 |
'taxes_id': [tax.id], |
| 1525 |
}) |
| 1526 |
partner_test = self.env['res.partner'].create({ |
| 1527 |
'name': 'Test Partner', |
| 1528 |
'property_account_position_id': fp_1.id, |
| 1529 |
}) |
| 1530 |
sale_a = self.env['sale.order'].create({ |
| 1531 |
'partner_id': partner_test.id, |
| 1532 |
'order_line': [(0, 0, { |
| 1533 |
'product_id': product_a.id, |
| 1534 |
'product_uom_qty': 1, |
| 1535 |
'price_unit': product_a.lst_price, |
| 1536 |
})] |
| 1537 |
}) |
| 1538 |
sale_b = self.env['sale.order'].create({ |
| 1539 |
'partner_id': partner_test.id, |
| 1540 |
'fiscal_position_id': fp_2.id, |
| 1541 |
'order_line': [(0, 0, { |
| 1542 |
'product_id': product_a.id, |
| 1543 |
'product_uom_qty': 1, |
| 1544 |
'price_unit': product_a.lst_price, |
| 1545 |
})] |
| 1546 |
}) |
| 1547 |
self.main_pos_config.write({ |
| 1548 |
'tax_regime_selection': True, |
| 1549 |
'default_fiscal_position_id': False, |
| 1550 |
}) |
| 1551 |
self.assertEqual(sale_a.fiscal_position_id, fp_1, "Sale order should have the fiscal position of the partner") |
| 1552 |
self.assertEqual(sale_a.amount_total, 20, "Sale order amount should be 20 with the tax override 1") |
| 1553 |
self.assertEqual(sale_a.amount_untaxed, 10, "Sale order untaxed amount should be 10 with the tax override 1") |
| 1554 |
self.assertEqual(sale_b.fiscal_position_id, fp_2, "Sale order should have the fiscal position set on the sale order") |
| 1555 |
self.assertEqual(sale_b.amount_total, 10, "Sale order amount should be 10 with the tax override 2") |
| 1556 |
self.assertEqual(sale_b.amount_untaxed, 10, "Sale order untaxed amount should be 10 with the tax override 2") |
| 1557 |
self.start_pos_tour("test_sale_order_fp_different_from_partner_one", login="accountman") |
| 1558 |
|
| 1559 |
pos_order_a = self.env['pos.order'].search([('fiscal_position_id', '=', fp_1.id)], limit=1, order='id desc') |
| 1560 |
pos_order_b = self.env['pos.order'].search([('fiscal_position_id', '=', fp_2.id)], limit=1, order='id desc') |
| 1561 |
self.assertEqual(pos_order_a.amount_total, 20, "PoS order amount should be 20 with the tax override 1") |
| 1562 |
self.assertEqual(pos_order_a.amount_tax, 10, "PoS order untaxed amount should be 10 with the tax override 1") |
| 1563 |
self.assertEqual(pos_order_a.lines[0].tax_ids, tax_override_1, "PoS order should have the tax override 1") |
| 1564 |
self.assertEqual(pos_order_b.amount_total, 10, "PoS order amount should be 10 with the tax override 2") |
| 1565 |
self.assertEqual(pos_order_b.amount_tax, 0, "PoS order untaxed amount should be 10 with the tax override 2") |
| 1566 |
self.assertEqual(pos_order_b.lines[0].tax_ids, tax_override_2, "PoS order should have the tax override 2") |
| 1567 |
|
| 1568 |
def test_quantity_updated_settle(self): |
| 1569 |
""" |
| 1570 |
Tests that the quantity is updated when partially settling an order, so that the |
| 1571 |
settle displays the right amount that still needs to be settled. |
| 1572 |
""" |
| 1573 |
product_a = self.env['product.product'].create({ |
| 1574 |
'name': 'Product A', |
| 1575 |
'lst_price': 10.0, |
| 1576 |
}) |
| 1577 |
self.env['sale.order'].sudo().create({ |
| 1578 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 1579 |
'order_line': [(0, 0, { |
| 1580 |
'product_id': product_a.id, |
| 1581 |
'product_uom_qty': 5, |
| 1582 |
'price_unit': product_a.lst_price, |
| 1583 |
})] |
| 1584 |
}) |
| 1585 |
self.main_pos_config.open_ui() |
| 1586 |
self.start_pos_tour('test_quantity_updated_settle', login="accountman") |
| 1587 |
|
| 1588 |
def test_settle_order_with_different_uom(self): |
| 1589 |
"""Verify that a qty has changed according to UOM""" |
| 1590 |
product_a = self.env['product.product'].create({ |
| 1591 |
'name': 'Product A', |
| 1592 |
'available_in_pos': True, |
| 1593 |
'is_storable': True, |
| 1594 |
'lst_price': 10.0, |
| 1595 |
}) |
| 1596 |
test_partner = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 1597 |
|
| 1598 |
sale_order = self.env['sale.order'].sudo().create({ |
| 1599 |
'partner_id': test_partner.id, |
| 1600 |
'order_line': [Command.create({ |
| 1601 |
'product_id': product_a.id, |
| 1602 |
'name': product_a.name, |
| 1603 |
'product_uom_qty': 1, |
| 1604 |
'product_uom_id': self.env.ref('uom.product_uom_dozen').id, |
| 1605 |
'price_unit': product_a.lst_price, |
| 1606 |
})] |
| 1607 |
}) |
| 1608 |
sale_order.action_confirm() |
| 1609 |
|
| 1610 |
self.main_pos_config.open_ui() |
| 1611 |
self.start_pos_tour('PoSSettleQuotation', login="accountman") |
| 1612 |
pos_order = self.env['pos.order'].search([('partner_id', '=', test_partner.id)], limit=1) |
| 1613 |
|
| 1614 |
self.assertEqual(pos_order.lines[0].qty, 12.0, "quantity should be 12.0") |
| 1615 |
self.assertEqual(pos_order.lines[0].price_unit, 0.83, "price of product should be 0.83") |
| 1616 |
|
| 1617 |
def test_multiple_lots_sale_order(self): |
| 1618 |
self.product = self.env['product.product'].create({ |
| 1619 |
'name': 'Product', |
| 1620 |
'available_in_pos': True, |
| 1621 |
'is_storable': True, |
| 1622 |
'lst_price': 10.0, |
| 1623 |
'taxes_id': False, |
| 1624 |
'categ_id': self.product_category.id, |
| 1625 |
'tracking': 'lot', |
| 1626 |
}) |
| 1627 |
|
| 1628 |
self.warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) |
| 1629 |
self.shelf_1 = self.env['stock.location'].create({ |
| 1630 |
'name': 'Shelf 1', |
| 1631 |
'usage': 'internal', |
| 1632 |
'location_id': self.warehouse.lot_stock_id.id, |
| 1633 |
}) |
| 1634 |
self.shelf_2 = self.env['stock.location'].create({ |
| 1635 |
'name': 'Shelf 2', |
| 1636 |
'usage': 'internal', |
| 1637 |
'location_id': self.warehouse.lot_stock_id.id, |
| 1638 |
}) |
| 1639 |
|
| 1640 |
quants = self.env['stock.quant'].with_context(inventory_mode=True).create({ |
| 1641 |
'product_id': self.product.id, |
| 1642 |
'inventory_quantity': 1, |
| 1643 |
'location_id': self.shelf_1.id, |
| 1644 |
'lot_id': self.env['stock.lot'].create({ |
| 1645 |
'name': '1001', |
| 1646 |
'product_id': self.product.id, |
| 1647 |
'location_id': self.shelf_1.id, |
| 1648 |
}).id, |
| 1649 |
}) |
| 1650 |
quants |= self.env['stock.quant'].with_context(inventory_mode=True).create({ |
| 1651 |
'product_id': self.product.id, |
| 1652 |
'inventory_quantity': 2, |
| 1653 |
'location_id': self.shelf_2.id, |
| 1654 |
'lot_id': self.env['stock.lot'].create({ |
| 1655 |
'name': '1002', |
| 1656 |
'product_id': self.product.id, |
| 1657 |
'location_id': self.shelf_2.id, |
| 1658 |
}).id, |
| 1659 |
}) |
| 1660 |
quants.action_apply_inventory() |
| 1661 |
|
| 1662 |
partner_test = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 1663 |
|
| 1664 |
sale_order = self.env['sale.order'].sudo().create({ |
| 1665 |
'partner_id': partner_test.id, |
| 1666 |
'order_line': [Command.create({ |
| 1667 |
'product_id': self.product.id, |
| 1668 |
'name': self.product.name, |
| 1669 |
'product_uom_qty': 3, |
| 1670 |
'price_unit': self.product.lst_price, |
| 1671 |
})], |
| 1672 |
}) |
| 1673 |
self.main_pos_config.open_ui() |
| 1674 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_multiple_lots_sale_order_1', login="accountman") |
| 1675 |
sale_order.action_confirm() |
| 1676 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_multiple_lots_sale_order_2', login="accountman") |
| 1677 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_multiple_lots_sale_order_3', login="accountman") |
| 1678 |
self.main_pos_config.current_session_id.action_pos_session_close() |
| 1679 |
picking = sale_order.pos_order_line_ids.order_id.picking_ids |
| 1680 |
self.assertEqual(picking.move_ids.quantity, 3) |
| 1681 |
self.assertEqual(len(picking.move_ids.move_line_ids), 2) |
| 1682 |
self.assertEqual(picking.move_ids.move_line_ids[0].lot_id.name, '1001') |
| 1683 |
self.assertEqual(picking.move_ids.move_line_ids[0].quantity, 1) |
| 1684 |
self.assertEqual(picking.move_ids.move_line_ids[1].lot_id.name, '1002') |
| 1685 |
self.assertEqual(picking.move_ids.move_line_ids[1].quantity, 2) |
| 1686 |
|
| 1687 |
def test_selected_partner_quotation_loading(self): |
| 1688 |
""" |
| 1689 |
Tests that when a partner is selected in the PoS, then a quotation for this partner is loaded |
| 1690 |
""" |
| 1691 |
self.env.user.group_ids += self.quick_ref('sales_team.group_sale_salesman') |
| 1692 |
product_a = self.env['product.product'].create({ |
| 1693 |
'name': 'Product A', |
| 1694 |
'available_in_pos': True, |
| 1695 |
'lst_price': 10.0, |
| 1696 |
}) |
| 1697 |
product_b = self.env['product.product'].create({ |
| 1698 |
'name': 'Product B', |
| 1699 |
'available_in_pos': True, |
| 1700 |
'lst_price': 5.0, |
| 1701 |
}) |
| 1702 |
partner_1 = self.env['res.partner'].create({'name': 'A Test Partner 1'}) |
| 1703 |
partner_2 = self.env['res.partner'].create({'name': 'A Test Partner 2'}) |
| 1704 |
self.env['sale.order'].create({ |
| 1705 |
'partner_id': partner_1.id, |
| 1706 |
'order_line': [(0, 0, { |
| 1707 |
'product_id': product_a.id, |
| 1708 |
'product_uom_qty': 1, |
| 1709 |
'price_unit': product_a.lst_price, |
| 1710 |
})] |
| 1711 |
}) |
| 1712 |
self.env['sale.order'].create({ |
| 1713 |
'partner_id': partner_2.id, |
| 1714 |
'order_line': [(0, 0, { |
| 1715 |
'product_id': product_b.id, |
| 1716 |
'product_uom_qty': 2, |
| 1717 |
'price_unit': product_b.lst_price, |
| 1718 |
})] |
| 1719 |
}) |
| 1720 |
self.main_pos_config.open_ui() |
| 1721 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_selected_partner_quotation_loading', login="accountman") |
| 1722 |
|
| 1723 |
def test_ecommerce_paid_order_is_hidden_in_pos(self): |
| 1724 |
""" |
| 1725 |
Tests that a Sale Order fully paid via a payment.transaction (eCommerce) |
| 1726 |
does not appear in the list of orders fetched by the Point of Sale. |
| 1727 |
""" |
| 1728 |
self.env.user.group_ids += self.quick_ref('sales_team.group_sale_salesman') |
| 1729 |
partner_1 = self.env['res.partner'].create({'name': 'A Test Partner 1'}) |
| 1730 |
product_a = self.env['product.product'].create({ |
| 1731 |
'name': 'Product A', |
| 1732 |
'available_in_pos': True, |
| 1733 |
'lst_price': 10.0, |
| 1734 |
}) |
| 1735 |
sale_order = self.env['sale.order'].create({ |
| 1736 |
'partner_id': partner_1.id, |
| 1737 |
'order_line': [(0, 0, { |
| 1738 |
'product_id': product_a.id, |
| 1739 |
'product_uom_qty': 2, |
| 1740 |
'price_unit': product_a.lst_price |
| 1741 |
})] |
| 1742 |
}) |
| 1743 |
provider = self.env['payment.provider'].create({ |
| 1744 |
'name': 'Test', |
| 1745 |
}) |
| 1746 |
transaction = self.env['payment.transaction'].create({ |
| 1747 |
'provider_id': provider.id, |
| 1748 |
'payment_method_id': self.env.ref('payment.payment_method_unknown').id, |
| 1749 |
'amount': sale_order.amount_total, |
| 1750 |
'currency_id': sale_order.currency_id.id, |
| 1751 |
'partner_id': sale_order.partner_id.id, |
| 1752 |
'sale_order_ids': [(6, 0, [sale_order.id])], |
| 1753 |
}) |
| 1754 |
transaction._set_done() |
| 1755 |
sale_order.invalidate_recordset(['transaction_ids']) |
| 1756 |
|
| 1757 |
self.assertEqual( |
| 1758 |
sale_order.amount_unpaid, 0.0, |
| 1759 |
"The amount_unpaid for the SO should be 0 after a successful transaction." |
| 1760 |
) |
| 1761 |
self.main_pos_config.open_ui() |
| 1762 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_ecommerce_paid_order_is_hidden_in_pos', login="accountman") |
| 1763 |
|
| 1764 |
def test_ecommerce_unpaid_order_is_shown_in_pos(self): |
| 1765 |
""" |
| 1766 |
Tests that a Sale Order fully paid via a payment.transaction (eCommerce) |
| 1767 |
does not appear in the list of orders fetched by the Point of Sale. |
| 1768 |
""" |
| 1769 |
self.env.user.group_ids += self.quick_ref('sales_team.group_sale_salesman') |
| 1770 |
partner_1 = self.env['res.partner'].create({'name': 'A Test Partner 1'}) |
| 1771 |
product_a = self.env['product.product'].create({ |
| 1772 |
'name': 'Product A', |
| 1773 |
'available_in_pos': True, |
| 1774 |
'lst_price': 10.0, |
| 1775 |
}) |
| 1776 |
sale_order = self.env['sale.order'].create({ |
| 1777 |
'partner_id': partner_1.id, |
| 1778 |
'order_line': [(0, 0, { |
| 1779 |
'product_id': product_a.id, |
| 1780 |
'product_uom_qty': 2, |
| 1781 |
'price_unit': product_a.lst_price |
| 1782 |
})] |
| 1783 |
}) |
| 1784 |
self.assertEqual( |
| 1785 |
sale_order.amount_unpaid, sale_order.amount_total, |
| 1786 |
"The amount_unpaid for the SO should not be 0 if there are no transactions." |
| 1787 |
) |
| 1788 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_ecommerce_unpaid_order_is_shown_in_pos', login="accountman") |
| 1789 |
|
| 1790 |
def test_backend_settle_refund(self): |
| 1791 |
"""Make sure that sale orders settled in PoS and refunded in the backend get their invoiced quantity updated correctly.""" |
| 1792 |
|
| 1793 |
product_a = self.env['product.product'].create({ |
| 1794 |
'name': 'Product A', |
| 1795 |
'available_in_pos': True, |
| 1796 |
'lst_price': 10.0, |
| 1797 |
'taxes_id': [], |
| 1798 |
}) |
| 1799 |
|
| 1800 |
partner_test = self.env['res.partner'].create({'name': 'Test Partner'}) |
| 1801 |
|
| 1802 |
sale_order = self.env['sale.order'].sudo().create({ |
| 1803 |
'partner_id': partner_test.id, |
| 1804 |
'order_line': [(0, 0, { |
| 1805 |
'product_id': product_a.id, |
| 1806 |
'name': product_a.name, |
| 1807 |
'product_uom_qty': 1, |
| 1808 |
'price_unit': product_a.lst_price, |
| 1809 |
})], |
| 1810 |
}) |
| 1811 |
sale_order.action_confirm() |
| 1812 |
self.main_pos_config.open_ui() |
| 1813 |
current_session = self.main_pos_config.current_session_id |
| 1814 |
|
| 1815 |
pos_order = { |
| 1816 |
'amount_paid': 10, |
| 1817 |
'amount_return': 0, |
| 1818 |
'amount_tax': 0, |
| 1819 |
'amount_total': 10, |
| 1820 |
'date_order': fields.Datetime.to_string(fields.Datetime.now()), |
| 1821 |
'fiscal_position_id': False, |
| 1822 |
'to_invoice': True, |
| 1823 |
'partner_id': partner_test.id, |
| 1824 |
'pricelist_id': self.main_pos_config.available_pricelist_ids[0].id, |
| 1825 |
'lines': [[0, |
| 1826 |
0, |
| 1827 |
{'discount': 0, |
| 1828 |
'pack_lot_ids': [], |
| 1829 |
'price_unit': 10, |
| 1830 |
'product_id': product_a.id, |
| 1831 |
'price_subtotal': 10, |
| 1832 |
'price_subtotal_incl': 10, |
| 1833 |
'sale_order_line_id': sale_order.order_line[0].id, |
| 1834 |
'sale_order_origin_id': sale_order.id, |
| 1835 |
'qty': 1, |
| 1836 |
'tax_ids': []}]], |
| 1837 |
'name': 'Order 00044-003-0014', |
| 1838 |
'session_id': current_session.id, |
| 1839 |
'sequence_number': self.main_pos_config.journal_id.id, |
| 1840 |
'payment_ids': [[0, |
| 1841 |
0, |
| 1842 |
{'amount': 10, |
| 1843 |
'name': fields.Datetime.now(), |
| 1844 |
'payment_method_id': self.main_pos_config.payment_method_ids[0].id}]], |
| 1845 |
'user_id': self.env.uid, |
| 1846 |
'uuid': str(uuid.uuid4()), |
| 1847 |
} |
| 1848 |
|
| 1849 |
data = self.env['pos.order'].sync_from_ui([pos_order]) |
| 1850 |
self.assertEqual(sale_order.order_line.qty_invoiced, 1) |
| 1851 |
pos_order_id = data['pos.order'][0]['id'] |
| 1852 |
pos_order_record = self.env['pos.order'].browse(pos_order_id) |
| 1853 |
refund_action = pos_order_record.refund() |
| 1854 |
refund = self.env['pos.order'].browse(refund_action['res_id']) |
| 1855 |
payment_context = {"active_ids": refund.ids, "active_id": refund.id} |
| 1856 |
refund_payment = self.env['pos.make.payment'].with_context(**payment_context).create({ |
| 1857 |
'amount': refund.amount_total, |
| 1858 |
'payment_method_id': self.bank_payment_method.id, |
| 1859 |
}) |
| 1860 |
|
| 1861 |
self.env.flush_all() |
| 1862 |
refund_payment.with_context(**payment_context).check() |
| 1863 |
self.assertEqual(sale_order.order_line.qty_invoiced, 0) |
| 1864 |
|
| 1865 |
def test_settle_order_with_multiple_uom(self): |
| 1866 |
""" Verify that a sale order with multiple UoM can be settled from the PoS.""" |
| 1867 |
uom_a, uom_b = self.env['uom.uom'].create([{ |
| 1868 |
"name": "UoM A" |
| 1869 |
}, { |
| 1870 |
"name": "UoM B" |
| 1871 |
}]) |
| 1872 |
|
| 1873 |
product_a, product_b = self.env['product.product'].create([{ |
| 1874 |
"name": "Product A", |
| 1875 |
"available_in_pos": True, |
| 1876 |
"is_storable": True, |
| 1877 |
"lst_price": 10.0, |
| 1878 |
"uom_id": uom_a.id, |
| 1879 |
"taxes_id": [], |
| 1880 |
}, { |
| 1881 |
"name": "Product B", |
| 1882 |
"available_in_pos": True, |
| 1883 |
"is_storable": True, |
| 1884 |
"lst_price": 20.0, |
| 1885 |
"uom_id": uom_b.id, |
| 1886 |
"taxes_id": [], |
| 1887 |
}]) |
| 1888 |
|
| 1889 |
sale_order = self.env["sale.order"].sudo().create({ |
| 1890 |
"partner_id": self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 1891 |
"order_line": [ |
| 1892 |
(0, 0, { |
| 1893 |
"product_id": product_a.id, |
| 1894 |
"name": product_a.name, |
| 1895 |
"product_uom_qty": 2, |
| 1896 |
"product_uom_id": uom_a.id, |
| 1897 |
"price_unit": product_a.lst_price, |
| 1898 |
}), |
| 1899 |
(0, 0, { |
| 1900 |
"product_id": product_b.id, |
| 1901 |
"name": product_b.name, |
| 1902 |
"product_uom_qty": 3, |
| 1903 |
"product_uom_id": uom_b.id, |
| 1904 |
"price_unit": product_b.lst_price, |
| 1905 |
}), |
| 1906 |
], |
| 1907 |
}) |
| 1908 |
sale_order.action_confirm() |
| 1909 |
self.main_pos_config.open_ui() |
| 1910 |
self.start_pos_tour('PoSSettleQuotation', login="accountman") |
| 1911 |
|
| 1912 |
def test_settle_groupable_lot_total_amount(self): |
| 1913 |
groupable_uom_unit = self.env['uom.uom'].create({ |
| 1914 |
'name': 'Groupable Unit', |
| 1915 |
'is_pos_groupable': True, |
| 1916 |
}) |
| 1917 |
|
| 1918 |
groupable_uom_dozens = self.env['uom.uom'].create({ |
| 1919 |
'name': 'Groupable Dozens', |
| 1920 |
'relative_factor': 12, |
| 1921 |
'relative_uom_id': groupable_uom_unit.id, |
| 1922 |
}) |
| 1923 |
|
| 1924 |
self.product = self.env['product.product'].create({ |
| 1925 |
'name': 'Product', |
| 1926 |
'available_in_pos': True, |
| 1927 |
'is_storable': True, |
| 1928 |
'lst_price': 1.0, |
| 1929 |
'taxes_id': False, |
| 1930 |
'categ_id': self.product_category.id, |
| 1931 |
'tracking': 'lot', |
| 1932 |
'uom_id': groupable_uom_unit.id, |
| 1933 |
}) |
| 1934 |
|
| 1935 |
self.warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) |
| 1936 |
|
| 1937 |
self.shelf = self.env['stock.location'].create({ |
| 1938 |
'name': 'Shelf 1', |
| 1939 |
'usage': 'internal', |
| 1940 |
'location_id': self.warehouse.lot_stock_id.id, |
| 1941 |
}) |
| 1942 |
|
| 1943 |
quants = self.env['stock.quant'].with_context(inventory_mode=True).create({ |
| 1944 |
'product_id': self.product.id, |
| 1945 |
'inventory_quantity': 10_000, |
| 1946 |
'location_id': self.shelf.id, |
| 1947 |
'lot_id': self.env['stock.lot'].create({ |
| 1948 |
'name': '1001', |
| 1949 |
'product_id': self.product.id, |
| 1950 |
'location_id': self.shelf.id, |
| 1951 |
}).id, |
| 1952 |
}) |
| 1953 |
|
| 1954 |
quants.action_apply_inventory() |
| 1955 |
|
| 1956 |
sale_order = self.env['sale.order'].create({ |
| 1957 |
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id, |
| 1958 |
'order_line': [(0, 0, { |
| 1959 |
'product_id': self.product.id, |
| 1960 |
'name': self.product.name, |
| 1961 |
'product_uom_qty': 1, |
| 1962 |
'product_uom_id': groupable_uom_dozens.id, |
| 1963 |
'price_unit': 12.0, |
| 1964 |
})], |
| 1965 |
}) |
| 1966 |
|
| 1967 |
sale_order.action_confirm() |
| 1968 |
self.main_pos_config.open_ui() |
| 1969 |
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_settle_groupable_lot_total_amount', login="accountman") |
| 1970 |
|
| 1971 |
def test_refund_ship_later_qty_delivered(self): |
| 1972 |
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) |
| 1973 |
warehouse.delivery_steps = 'pick_pack_ship' |
| 1974 |
sale_order = self.env['sale.order'].create({ |
| 1975 |
'partner_id': self.partner_a.id, |
| 1976 |
'order_line': [Command.create({ |
| 1977 |
'product_id': self.product_a.id, |
| 1978 |
'name': self.product_a.name, |
| 1979 |
'product_uom_qty': 5, |
| 1980 |
'price_unit': self.product_a.lst_price, |
| 1981 |
'product_uom_id': self.product_a.uom_id.id |
| 1982 |
})], |
| 1983 |
}) |
| 1984 |
sale_order.action_confirm() |
| 1985 |
|
| 1986 |
self.main_pos_config.ship_later = True |
| 1987 |
self.main_pos_config.open_ui() |
| 1988 |
current_session = self.main_pos_config.current_session_id |
| 1989 |
|
| 1990 |
pos_order = { |
| 1991 |
'amount_paid': self.product_a.lst_price * 5, |
| 1992 |
'amount_return': 0, |
| 1993 |
'amount_tax': 0, |
| 1994 |
'amount_total': self.product_a.lst_price * 5, |
| 1995 |
'company_id': self.env.company.id, |
| 1996 |
'date_order': fields.Datetime.to_string(fields.Datetime.now()), |
| 1997 |
'fiscal_position_id': False, |
| 1998 |
'to_invoice': True, |
| 1999 |
'partner_id': self.partner_a.id, |
| 2000 |
'pricelist_id': self.main_pos_config.available_pricelist_ids[0].id, |
| 2001 |
'lines': [[0, |
| 2002 |
0, |
| 2003 |
{'discount': 0, |
| 2004 |
'pack_lot_ids': [], |
| 2005 |
'price_unit': self.product_a.lst_price, |
| 2006 |
'product_id': self.product_a.id, |
| 2007 |
'price_subtotal': self.product_a.lst_price * 5, |
| 2008 |
'price_subtotal_incl': self.product_a.lst_price * 5, |
| 2009 |
'sale_order_line_id': sale_order.order_line[0].id, |
| 2010 |
'sale_order_origin_id': sale_order.id, |
| 2011 |
'qty': 5, |
| 2012 |
'tax_ids': []}]], |
| 2013 |
'name': 'Order 00044-003-0014', |
| 2014 |
'session_id': current_session.id, |
| 2015 |
'sequence_number': self.main_pos_config.journal_id.id, |
| 2016 |
'payment_ids': [[0, |
| 2017 |
0, |
| 2018 |
{'amount': self.product_a.lst_price * 5, |
| 2019 |
'name': fields.Datetime.now(), |
| 2020 |
'payment_method_id': self.main_pos_config.payment_method_ids[0].id}]], |
| 2021 |
'user_id': self.env.uid, |
| 2022 |
'uuid': str(uuid.uuid4()), |
| 2023 |
} |
| 2024 |
|
| 2025 |
data = self.env['pos.order'].sync_from_ui([pos_order]) |
| 2026 |
pos_order_id = data['pos.order'][0]['id'] |
| 2027 |
pos_order_record = self.env['pos.order'].browse(pos_order_id) |
| 2028 |
|
| 2029 |
pos_order_refund = { |
| 2030 |
'amount_paid': -self.product_a.lst_price * 3, |
| 2031 |
'amount_return': 0, |
| 2032 |
'amount_tax': 0, |
| 2033 |
'amount_total': -self.product_a.lst_price * 3, |
| 2034 |
'company_id': self.env.company.id, |
| 2035 |
'date_order': fields.Datetime.to_string(fields.Datetime.now()), |
| 2036 |
'fiscal_position_id': False, |
| 2037 |
'to_invoice': True, |
| 2038 |
'partner_id': self.partner_a.id, |
| 2039 |
'pricelist_id': self.main_pos_config.available_pricelist_ids[0].id, |
| 2040 |
'lines': [[0, |
| 2041 |
0, |
| 2042 |
{'discount': 0, |
| 2043 |
'pack_lot_ids': [], |
| 2044 |
'price_unit': self.product_a.lst_price, |
| 2045 |
'product_id': self.product_a.id, |
| 2046 |
'price_subtotal': -self.product_a.lst_price * 3, |
| 2047 |
'price_subtotal_incl': -self.product_a.lst_price * 3, |
| 2048 |
'refund_orderline_ids': [], |
| 2049 |
'refunded_orderline_id': pos_order_record.lines[0].id, |
| 2050 |
'qty': -3, |
| 2051 |
'tax_ids': []}]], |
| 2052 |
'name': 'Order 00044-003-0014', |
| 2053 |
'session_id': current_session.id, |
| 2054 |
'sequence_number': self.main_pos_config.journal_id.id, |
| 2055 |
'payment_ids': [[0, |
| 2056 |
0, |
| 2057 |
{'amount': -self.product_a.lst_price * 3, |
| 2058 |
'name': fields.Datetime.now(), |
| 2059 |
'payment_method_id': self.main_pos_config.payment_method_ids[0].id}]], |
| 2060 |
'user_id': self.env.uid, |
| 2061 |
'uuid': str(uuid.uuid4()), |
| 2062 |
'shipping_date': '2023-01-01', |
| 2063 |
} |
| 2064 |
data = self.env['pos.order'].sync_from_ui([pos_order_refund]) |
| 2065 |
pos_order_refund_id = data['pos.order'][1]['id'] |
| 2066 |
pos_order_refund_record = self.env['pos.order'].browse(pos_order_refund_id) |
| 2067 |
self.assertEqual(sale_order.order_line.qty_delivered, 5) |
| 2068 |
for picking in pos_order_refund_record.picking_ids: |
| 2069 |
picking.button_validate() |
| 2070 |
self.assertEqual(sale_order.order_line.qty_delivered, 2) |