mirror of
https://github.com/bringout/oca-ocb-pos.git
synced 2026-04-24 02:22:06 +02:00
19.0 vanilla
This commit is contained in:
parent
6e54c1af6c
commit
3ca647e428
1087 changed files with 132065 additions and 108499 deletions
|
|
@ -1,5 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_frontend
|
||||
from . import test_loyalty_history
|
||||
from . import test_unlink_reward
|
||||
from . import common
|
||||
from . import test_product_loading
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
from odoo.addons.point_of_sale.tests.common import CommonPosTest
|
||||
from odoo.fields import Command
|
||||
|
||||
|
||||
class CommonPosLoyaltyTest(CommonPosTest):
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
super().setUpClass()
|
||||
|
||||
self.loyalty_create_programs(self)
|
||||
self.loyalty_create_rewards(self)
|
||||
|
||||
def loyalty_create_programs(self):
|
||||
self.four_20_dollars_one_free_program = self.env['loyalty.program'].create({
|
||||
'name': 'Buy 4 20 dollars Take 1 20 dollars',
|
||||
'program_type': 'loyalty',
|
||||
'trigger': 'auto',
|
||||
'applies_on': 'both',
|
||||
'rule_ids': [Command.create({
|
||||
'product_ids': self.twenty_dollars_no_tax.product_variant_id.ids,
|
||||
'reward_point_mode': 'unit',
|
||||
'minimum_qty': 1,
|
||||
})],
|
||||
})
|
||||
|
||||
def loyalty_create_rewards(self):
|
||||
self.twenty_dollars_reward = self.env['loyalty.reward'].create({
|
||||
'program_id': self.four_20_dollars_one_free_program.id,
|
||||
'reward_type': 'product',
|
||||
'reward_product_id': self.twenty_dollars_no_tax.product_variant_id.id,
|
||||
'reward_product_qty': 1,
|
||||
'required_points': 4,
|
||||
})
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,169 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details
|
||||
|
||||
from odoo import Command
|
||||
from odoo.tests import tagged
|
||||
|
||||
from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestPOSLoyaltyHistory(TestPointOfSaleHttpCommon):
|
||||
|
||||
def test_pos_loyalty_history(self):
|
||||
partner_aaa = self.env['res.partner'].create({'name': 'AAA Test Partner'})
|
||||
self.whiteboard_pen.product_variant_ids.write({'lst_price': 10})
|
||||
self.main_pos_config.write({
|
||||
'tax_regime_selection': False,
|
||||
'use_pricelist': False,
|
||||
})
|
||||
self.main_pos_config.with_user(self.pos_user).open_ui()
|
||||
loyalty_program = self.env['loyalty.program'].create({
|
||||
'name': 'Test Loyalty Program',
|
||||
'program_type': 'loyalty',
|
||||
'trigger': 'auto',
|
||||
'applies_on': 'both',
|
||||
'rule_ids': [Command.create({
|
||||
'reward_point_amount': 1,
|
||||
'reward_point_mode': 'money',
|
||||
'minimum_qty': 1,
|
||||
})],
|
||||
'reward_ids': [Command.create({
|
||||
'reward_type': 'discount',
|
||||
'discount_mode': 'percent',
|
||||
'discount': 15,
|
||||
'discount_applicability': 'order',
|
||||
})],
|
||||
})
|
||||
self.start_pos_tour("LoyaltyHistoryTour")
|
||||
loyalty_card = loyalty_program.coupon_ids.filtered(lambda coupon: coupon.partner_id.id == partner_aaa.id)
|
||||
self.assertEqual(len(loyalty_card.history_ids), 1,
|
||||
"Loyalty History line should be created on pos oder confirmation")
|
||||
|
||||
def test_duplicate_coupon_confirm(self):
|
||||
""" Test that duplicate coupon confirm calls do not affect the coupon."""
|
||||
test_partner = self.env['res.partner'].create({'name': 'Test Partner'})
|
||||
ewallet_program = self.env['loyalty.program'].create({
|
||||
'name': 'eWallet Program',
|
||||
'program_type': 'ewallet',
|
||||
'trigger': 'auto',
|
||||
'applies_on': 'future',
|
||||
'reward_ids': [Command.create({
|
||||
'reward_type': 'discount',
|
||||
'discount_mode': 'per_point',
|
||||
'discount': 1,
|
||||
})],
|
||||
'rule_ids': [Command.create({
|
||||
'reward_point_amount': '1',
|
||||
'reward_point_mode': 'money',
|
||||
'product_ids': self.env.ref('loyalty.ewallet_product_50'),
|
||||
})],
|
||||
'trigger_product_ids': self.env.ref('loyalty.ewallet_product_50'),
|
||||
})
|
||||
|
||||
self.main_pos_config.open_ui()
|
||||
pos_order = self.env['pos.order'].create({
|
||||
'config_id': self.main_pos_config.id,
|
||||
'session_id': self.main_pos_config.current_session_id.id,
|
||||
'partner_id': test_partner.id,
|
||||
'amount_paid': 50,
|
||||
'amount_return': 0,
|
||||
'amount_tax': 0,
|
||||
'amount_total': 50,
|
||||
})
|
||||
|
||||
coupon_data = {
|
||||
-1: {
|
||||
'points': 50,
|
||||
'program_id': ewallet_program.id,
|
||||
'coupon_id': -1,
|
||||
'barcode': '',
|
||||
'partner_id': test_partner.id,
|
||||
}
|
||||
}
|
||||
pos_order.confirm_coupon_programs(coupon_data)
|
||||
|
||||
def check_coupon(points, history_count):
|
||||
created_card = self.env['loyalty.card'].search([('program_id', '=', ewallet_program.id), ('partner_id', '=', test_partner.id)])
|
||||
self.assertEqual(created_card.points, points, "The coupon should have 50 points after the first confirmation.")
|
||||
self.assertEqual(len(created_card.history_ids), history_count, "The history should have one entry after the first confirmation.")
|
||||
|
||||
check_coupon(50, 1)
|
||||
# Confirm the coupon again
|
||||
pos_order.confirm_coupon_programs(coupon_data)
|
||||
check_coupon(50, 1)
|
||||
|
||||
new_pos_order = self.env['pos.order'].create({
|
||||
'config_id': self.main_pos_config.id,
|
||||
'session_id': self.main_pos_config.current_session_id.id,
|
||||
'partner_id': test_partner.id,
|
||||
'amount_paid': 0,
|
||||
'amount_return': 0,
|
||||
'amount_tax': 0,
|
||||
'amount_total': 0,
|
||||
})
|
||||
|
||||
loyalty_card = self.env['loyalty.card'].search([('program_id', '=', ewallet_program.id), ('partner_id', '=', test_partner.id)])
|
||||
coupon_data = {
|
||||
loyalty_card.id: {
|
||||
'points': -10,
|
||||
'program_id': ewallet_program.id,
|
||||
'coupon_id': loyalty_card.id,
|
||||
'barcode': '',
|
||||
'partner_id': test_partner.id,
|
||||
}
|
||||
}
|
||||
|
||||
new_pos_order.confirm_coupon_programs(coupon_data)
|
||||
# Check that the coupon points are reduced correctly
|
||||
check_coupon(40, 2)
|
||||
# Confirm the coupon again
|
||||
new_pos_order.confirm_coupon_programs(coupon_data)
|
||||
check_coupon(40, 2)
|
||||
|
||||
def test_programs_loaded(self):
|
||||
eur_currency = self.setup_other_currency('EUR')
|
||||
usd_loyalty = self.env['loyalty.program'].create({'name': "USD program"})
|
||||
eur_loyalty = self.env['loyalty.program'].create({'name': "EUR program", 'currency_id': eur_currency.id})
|
||||
loaded_programs = self.main_pos_config._get_program_ids()
|
||||
self.assertIn(usd_loyalty, loaded_programs)
|
||||
self.assertNotIn(eur_loyalty, loaded_programs)
|
||||
|
||||
def test_gift_card_partner(self):
|
||||
""" Test that the gift card's partner is correctly set as the customer who bought it."""
|
||||
test_partner = self.env['res.partner'].create({'name': 'Test Partner'})
|
||||
LoyaltyProgram = self.env['loyalty.program']
|
||||
self.env.ref('loyalty.gift_card_product_50').write({'active': True})
|
||||
gift_card_program = LoyaltyProgram.browse(
|
||||
LoyaltyProgram.create_from_template('gift_card')['res_id']
|
||||
)
|
||||
gift_card_program.pos_report_print_id = self.env.ref('loyalty.report_gift_card')
|
||||
self.main_pos_config.open_ui()
|
||||
pos_order = self.env['pos.order'].create({
|
||||
'config_id': self.main_pos_config.id,
|
||||
'session_id': self.main_pos_config.current_session_id.id,
|
||||
'partner_id': test_partner.id,
|
||||
'lines': [Command.create({
|
||||
'product_id': self.env.ref('loyalty.gift_card_product_50').id,
|
||||
'price_unit': 50,
|
||||
'discount': 0,
|
||||
'qty': 1,
|
||||
'price_subtotal': 10.00,
|
||||
'price_subtotal_incl': 10.00,
|
||||
})],
|
||||
'amount_paid': 50.0,
|
||||
'amount_total': 50.0,
|
||||
'amount_tax': 0.0,
|
||||
'amount_return': 0.0,
|
||||
})
|
||||
coupon_data = {
|
||||
'-1': {
|
||||
'points': 50,
|
||||
'program_id': gift_card_program.id,
|
||||
'coupon_id': -1,
|
||||
'product_id': self.env.ref('loyalty.gift_card_product_50').id,
|
||||
'code': 'test-code'
|
||||
}
|
||||
}
|
||||
pos_order.confirm_coupon_programs(coupon_data)
|
||||
loyalty_card = self.env['loyalty.card'].search([('code', '=', 'test-code')])
|
||||
self.assertEqual(loyalty_card.partner_id, test_partner)
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details
|
||||
|
||||
from odoo import Command
|
||||
from odoo.tests import tagged
|
||||
|
||||
from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestPOSLoyaltyProductLoading(TestPointOfSaleHttpCommon):
|
||||
def test_loyalty_product_loading(self):
|
||||
""" Test that loyalty products are loaded correctly in the PoS session. """
|
||||
new_product = self.env['product.product'].create({
|
||||
'name': 'New Product',
|
||||
'is_storable': True,
|
||||
'list_price': 1,
|
||||
'available_in_pos': True,
|
||||
'taxes_id': False,
|
||||
})
|
||||
|
||||
program = self.env['loyalty.program'].create({
|
||||
'name': 'Program',
|
||||
'program_type': 'promotion',
|
||||
'trigger': 'auto',
|
||||
'applies_on': 'current',
|
||||
'reward_ids': [(0, 0, {
|
||||
'reward_type': 'product',
|
||||
'reward_product_id': new_product.id,
|
||||
'reward_product_qty': 1,
|
||||
'required_points': 2,
|
||||
})],
|
||||
})
|
||||
self.env['loyalty.program'].search([]).write({
|
||||
'active': False,
|
||||
})
|
||||
|
||||
self.env['ir.config_parameter'].sudo().set_param('point_of_sale.limited_product_count', 1)
|
||||
|
||||
self.main_pos_config.open_ui()
|
||||
current_session = self.main_pos_config.current_session_id
|
||||
|
||||
data = current_session.with_context(
|
||||
pos_limited_loading=True,
|
||||
).load_data(['pos.config', 'product.template'])
|
||||
|
||||
self.assertNotIn(new_product.id, data['pos.config'][0]['_pos_special_products_ids'],
|
||||
"Loyalty product should not be in _pos_special_products_ids when program is inactive.")
|
||||
|
||||
# Activate the program to ensure the product is loaded
|
||||
program.write({'active': True})
|
||||
|
||||
data = current_session.with_context(
|
||||
pos_limited_loading=True,
|
||||
).load_data(['pos.config', 'product.template'])
|
||||
|
||||
self.assertIn(new_product.product_tmpl_id.id, [product['id'] for product in data['product.template']],
|
||||
"Loyalty product should be loaded in the PoS session when program is active.")
|
||||
|
||||
self.assertNotIn(new_product.id, data['pos.config'][0]['_pos_special_products_ids'],
|
||||
"Loyalty product should not be in _pos_special_products_ids since it is loaded.")
|
||||
|
||||
# Make the product not available in the PoS
|
||||
new_product.write({'available_in_pos': False})
|
||||
|
||||
data = current_session.with_context(
|
||||
pos_limited_loading=True,
|
||||
).load_data(['pos.config', 'product.template'])
|
||||
|
||||
self.assertIn(new_product.product_tmpl_id.id, [product['id'] for product in data['product.template']],
|
||||
"Loyalty product should be loaded in the PoS session when it is used in a program, even if not available in the PoS.")
|
||||
|
||||
self.assertIn(new_product.id, data['pos.config'][0]['_pos_special_products_ids'],
|
||||
"Loyalty product should be in _pos_special_products_ids since it is loaded but not available in the PoS.")
|
||||
|
||||
def test_product_loading_without_gift_card(self):
|
||||
"""
|
||||
Test that products are loaded correctly in the PoS session of company
|
||||
if special loyalty products are not visible to them
|
||||
"""
|
||||
gift_card = self.env.ref('loyalty.gift_card_product_50').sudo()
|
||||
gift_card.company_id = self.env.company
|
||||
|
||||
company_b_data = self.setup_other_company(name='Company B')
|
||||
company_b = company_b_data['company']
|
||||
payment_method = self.env['pos.payment.method'].create({
|
||||
'name': 'Cash',
|
||||
'receivable_account_id': company_b_data['default_account_receivable'].id,
|
||||
'journal_id': company_b_data['default_journal_cash'].id,
|
||||
'company_id': company_b.id,
|
||||
})
|
||||
pos_config = self.env['pos.config'].create({
|
||||
'name': 'new pos',
|
||||
'company_id': company_b.id,
|
||||
'journal_id': company_b_data['default_journal_sale'].id,
|
||||
'invoice_journal_id': company_b_data['default_journal_sale'].id,
|
||||
'payment_method_ids': [Command.set([payment_method.id])],
|
||||
})
|
||||
pos_config.open_ui()
|
||||
current_session = pos_config.current_session_id
|
||||
data = current_session.with_company(company_b).load_data(['pos.config', 'product.template'])
|
||||
self.assertTrue(len(data['product.template']) > 0)
|
||||
self.assertNotIn(gift_card.product_tmpl_id.id, [product['id'] for product in data['product.template']],
|
||||
"Product should be loaded in the PoS session, even if Gift card is not available in the PoS.")
|
||||
|
|
@ -1,62 +1,24 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import Command
|
||||
from odoo.addons.point_of_sale.tests.common import TestPointOfSaleCommon
|
||||
from odoo.addons.pos_loyalty.tests.common import CommonPosLoyaltyTest
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestUnlinkReward(TestPointOfSaleCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
# Create a loyalty program
|
||||
cls.loyalty_program = cls.env['loyalty.program'].create({
|
||||
'name': 'Buy 4 whiteboard_pen, Take 1 whiteboard_pen',
|
||||
'program_type': 'loyalty',
|
||||
'trigger': 'auto',
|
||||
'applies_on': 'both',
|
||||
'rule_ids': [Command.create({
|
||||
'product_ids': cls.whiteboard_pen.ids,
|
||||
'reward_point_mode': 'unit',
|
||||
'minimum_qty': 1,
|
||||
})],
|
||||
})
|
||||
|
||||
# Create a reward
|
||||
cls.reward = cls.env['loyalty.reward'].create({
|
||||
'program_id': cls.loyalty_program.id,
|
||||
'reward_type': 'product',
|
||||
'reward_product_id': cls.whiteboard_pen.id,
|
||||
'reward_product_qty': 1,
|
||||
'required_points': 4,
|
||||
})
|
||||
|
||||
class TestUnlinkReward(CommonPosLoyaltyTest):
|
||||
def test_pos_unlink_reward(self):
|
||||
self.pos_config.open_ui()
|
||||
current_session = self.pos_config.current_session_id
|
||||
self.PosOrder.create({
|
||||
'company_id': self.env.company.id,
|
||||
'session_id': current_session.id,
|
||||
'partner_id': self.partner1.id,
|
||||
'pricelist_id': self.partner1.property_product_pricelist.id,
|
||||
'lines': [
|
||||
Command.create({
|
||||
'product_id': self.whiteboard_pen.id,
|
||||
'qty': 5,
|
||||
'price_subtotal': 12.0,
|
||||
'price_subtotal_incl': 12.0,
|
||||
'reward_id': self.reward.id,
|
||||
})
|
||||
],
|
||||
'amount_tax': 0.0,
|
||||
'amount_total': 134.38,
|
||||
'amount_paid': 0.0,
|
||||
'amount_return': 0.0,
|
||||
self.create_backend_pos_order({
|
||||
'order_data': {
|
||||
'partner_id': self.partner_lowe.id,
|
||||
'pricelist_id': self.partner_lowe.property_product_pricelist.id,
|
||||
},
|
||||
'line_data': [{
|
||||
'qty': 5,
|
||||
'product_id': self.twenty_dollars_no_tax.product_variant_id.id,
|
||||
'reward_id': self.twenty_dollars_reward.id,
|
||||
}],
|
||||
})
|
||||
# Attempt to delete the reward
|
||||
self.reward.unlink()
|
||||
|
||||
# Ensure the reward is archived and not deleted
|
||||
self.assertTrue(self.reward.exists())
|
||||
self.assertFalse(self.reward.active)
|
||||
self.twenty_dollars_reward.unlink()
|
||||
self.assertTrue(self.twenty_dollars_reward.exists())
|
||||
self.assertFalse(self.twenty_dollars_reward.active)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue