| 1 |
from odoo import Command |
| 2 |
from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon |
| 3 |
from odoo.tests import tagged |
| 4 |
|
| 5 |
|
| 6 |
@tagged('post_install', '-at_install') |
| 7 |
class TestPosCashRounding(TestPointOfSaleHttpCommon): |
| 8 |
|
| 9 |
@classmethod |
| 10 |
def setUpClass(cls): |
| 11 |
super().setUpClass() |
| 12 |
cls.partner_a.name = "AAAAAA" # The POS only load the first 100 partners |
| 13 |
cls.cash_rounding_add_invoice_line = cls.env['account.cash.rounding'].create({ |
| 14 |
'name': "cash_rounding_add_invoice_line", |
| 15 |
'rounding': 0.05, |
| 16 |
'rounding_method': 'HALF-UP', |
| 17 |
'strategy': 'add_invoice_line', |
| 18 |
'profit_account_id': cls.env.company.default_cash_difference_income_account_id.id, |
| 19 |
'loss_account_id': cls.env.company.default_cash_difference_expense_account_id.id, |
| 20 |
}) |
| 21 |
cls.cash_rounding_biggest_tax = cls.env['account.cash.rounding'].create({ |
| 22 |
'name': "cash_rounding_biggest_tax", |
| 23 |
'rounding': 0.05, |
| 24 |
'rounding_method': 'HALF-UP', |
| 25 |
'strategy': 'biggest_tax', |
| 26 |
'profit_account_id': cls.env.company.default_cash_difference_income_account_id.id, |
| 27 |
'loss_account_id': cls.env.company.default_cash_difference_expense_account_id.id, |
| 28 |
}) |
| 29 |
|
| 30 |
cls.product = cls.env['product.product'].create({ |
| 31 |
'name': "random_product", |
| 32 |
'available_in_pos': True, |
| 33 |
'list_price': 13.67, |
| 34 |
'taxes_id': [Command.set(cls.company_data['default_tax_sale'].ids)], |
| 35 |
'pos_categ_ids': [Command.set(cls.pos_desk_misc_test.ids)], |
| 36 |
}) |
| 37 |
|
| 38 |
def test_cash_rounding_halfup_biggest_tax_not_only_round_cash_method(self): |
| 39 |
self.skipTest('To re-introduce when feature is ready') |
| 40 |
self.main_pos_config.write({ |
| 41 |
'rounding_method': self.cash_rounding_biggest_tax.id, |
| 42 |
'cash_rounding': True, |
| 43 |
'only_round_cash_method': False, |
| 44 |
}) |
| 45 |
with self.with_new_session(user=self.pos_user) as session: |
| 46 |
self.start_pos_tour('test_cash_rounding_halfup_biggest_tax_not_only_round_cash_method') |
| 47 |
refund, order = self.env['pos.order'].search([('session_id', '=', session.id)], limit=2) |
| 48 |
self.assertRecordValues(order, [{ |
| 49 |
'amount_tax': 2.03, |
| 50 |
'amount_total': 15.7, |
| 51 |
'amount_paid': 15.7, |
| 52 |
}]) |
| 53 |
self.assertRecordValues(order.account_move, [{ |
| 54 |
'amount_untaxed': 13.67, |
| 55 |
'amount_tax': 2.03, |
| 56 |
'amount_total': 15.7, |
| 57 |
}]) |
| 58 |
self.assertRecordValues(refund, [{ |
| 59 |
'amount_tax': -2.03, |
| 60 |
'amount_total': -15.7, |
| 61 |
'amount_paid': -15.7, |
| 62 |
}]) |
| 63 |
self.assertRecordValues(refund.account_move, [{ |
| 64 |
'amount_untaxed': 13.67, |
| 65 |
'amount_tax': 2.03, |
| 66 |
'amount_total': 15.7, |
| 67 |
}]) |
| 68 |
|
| 69 |
def test_cash_rounding_halfup_biggest_tax_not_only_round_cash_method_pay_by_bank_and_cash(self): |
| 70 |
self.skipTest('To re-introduce when feature is ready') |
| 71 |
self.main_pos_config.write({ |
| 72 |
'rounding_method': self.cash_rounding_biggest_tax.id, |
| 73 |
'cash_rounding': True, |
| 74 |
'only_round_cash_method': False, |
| 75 |
}) |
| 76 |
with self.with_new_session(user=self.pos_user) as session: |
| 77 |
self.start_pos_tour('test_cash_rounding_halfup_biggest_tax_not_only_round_cash_method_pay_by_bank_and_cash') |
| 78 |
refund, order = self.env['pos.order'].search([('session_id', '=', session.id)], limit=2) |
| 79 |
self.assertRecordValues(order, [{ |
| 80 |
'amount_tax': 2.03, |
| 81 |
'amount_total': 15.7, |
| 82 |
'amount_paid': 15.72, |
| 83 |
}]) |
| 84 |
self.assertRecordValues(order.account_move, [{ |
| 85 |
'amount_untaxed': 13.69, |
| 86 |
'amount_tax': 2.03, |
| 87 |
'amount_total': 15.72, |
| 88 |
}]) |
| 89 |
self.assertRecordValues(refund, [{ |
| 90 |
'amount_tax': -2.03, |
| 91 |
'amount_total': -15.7, |
| 92 |
'amount_paid': -15.72, |
| 93 |
}]) |
| 94 |
self.assertRecordValues(refund.account_move, [{ |
| 95 |
'amount_untaxed': 13.69, |
| 96 |
'amount_tax': 2.03, |
| 97 |
'amount_total': 15.72, |
| 98 |
}]) |
| 99 |
|
| 100 |
def test_cash_rounding_halfup_biggest_tax_only_round_cash_method(self): |
| 101 |
self.skipTest('To re-introduce when feature is ready') |
| 102 |
self.main_pos_config.write({ |
| 103 |
'rounding_method': self.cash_rounding_biggest_tax.id, |
| 104 |
'cash_rounding': True, |
| 105 |
'only_round_cash_method': True, |
| 106 |
}) |
| 107 |
with self.with_new_session(user=self.pos_user) as session: |
| 108 |
self.start_pos_tour('test_cash_rounding_halfup_biggest_tax_only_round_cash_method') |
| 109 |
refund, order = self.env['pos.order'].search([('session_id', '=', session.id)], limit=2) |
| 110 |
self.assertRecordValues(order, [{ |
| 111 |
'amount_tax': 2.05, |
| 112 |
'amount_total': 15.72, |
| 113 |
'amount_paid': 15.7, |
| 114 |
}]) |
| 115 |
self.assertRecordValues(order.account_move, [{ |
| 116 |
'amount_untaxed': 13.67, |
| 117 |
'amount_tax': 2.03, |
| 118 |
'amount_total': 15.7, |
| 119 |
}]) |
| 120 |
self.assertRecordValues(refund, [{ |
| 121 |
'amount_tax': -2.05, |
| 122 |
'amount_total': -15.72, |
| 123 |
'amount_paid': -15.7, |
| 124 |
}]) |
| 125 |
self.assertRecordValues(refund.account_move, [{ |
| 126 |
'amount_untaxed': 13.67, |
| 127 |
'amount_tax': 2.03, |
| 128 |
'amount_total': 15.7, |
| 129 |
}]) |
| 130 |
|
| 131 |
def test_cash_rounding_halfup_biggest_tax_only_round_cash_method_pay_by_bank_and_cash(self): |
| 132 |
self.skipTest('To re-introduce when feature is ready') |
| 133 |
self.main_pos_config.write({ |
| 134 |
'rounding_method': self.cash_rounding_biggest_tax.id, |
| 135 |
'cash_rounding': True, |
| 136 |
'only_round_cash_method': True, |
| 137 |
}) |
| 138 |
with self.with_new_session(user=self.pos_user) as session: |
| 139 |
self.start_pos_tour('test_cash_rounding_halfup_biggest_tax_only_round_cash_method_pay_by_bank_and_cash') |
| 140 |
refund, order = self.env['pos.order'].search([('session_id', '=', session.id)], limit=2) |
| 141 |
self.assertRecordValues(order, [{ |
| 142 |
'amount_tax': 2.05, |
| 143 |
'amount_total': 15.72, |
| 144 |
'amount_paid': 15.73, |
| 145 |
}]) |
| 146 |
self.assertRecordValues(order.account_move, [{ |
| 147 |
'amount_untaxed': 13.70, |
| 148 |
'amount_tax': 2.03, |
| 149 |
'amount_total': 15.73, |
| 150 |
}]) |
| 151 |
self.assertRecordValues(refund, [{ |
| 152 |
'amount_tax': -2.05, |
| 153 |
'amount_total': -15.72, |
| 154 |
'amount_paid': -15.73, |
| 155 |
}]) |
| 156 |
self.assertRecordValues(refund.account_move, [{ |
| 157 |
'amount_untaxed': 13.70, |
| 158 |
'amount_tax': 2.03, |
| 159 |
'amount_total': 15.73, |
| 160 |
}]) |
| 161 |
|
| 162 |
def test_archived_product_removed_and_order_is_refunded(self): |
| 163 |
""" |
| 164 |
Tests that once product is archived after order is created |
| 165 |
product is not shown but the order can still be refunded. |
| 166 |
""" |
| 167 |
self.pos_admin.write({ |
| 168 |
'group_ids': [ |
| 169 |
(4, self.env.ref('product.group_product_manager').id), |
| 170 |
(4, self.env.ref('account.group_account_manager').id), |
| 171 |
] |
| 172 |
}) |
| 173 |
self.env['product.product'].create({ |
| 174 |
'is_storable': True, |
| 175 |
'name': 'A Test Product', |
| 176 |
'available_in_pos': True, |
| 177 |
'list_price': 1, |
| 178 |
}) |
| 179 |
self.main_pos_config.with_user(self.pos_admin).open_ui() |
| 180 |
self.start_tour( |
| 181 |
"/pos/ui?config_id=%d" % self.main_pos_config.id, |
| 182 |
"test_archived_product_removed_and_order_is_refunded", |
| 183 |
login="pos_admin" |
| 184 |
) |