| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
|
| 4 |
import odoo |
| 5 |
|
| 6 |
from odoo import tools |
| 7 |
from odoo.addons.point_of_sale.tests.common import TestPoSCommon |
| 8 |
|
| 9 |
@odoo.tests.tagged('post_install', '-at_install') |
| 10 |
class TestPoSMultipleReceivableAccounts(TestPoSCommon): |
| 11 |
""" Test for invoiced orders with customers having receivable account different from default |
| 12 |
|
| 13 |
Thus, for this test, there are two receivable accounts involved and are set in the |
| 14 |
customers. |
| 15 |
self.customer -> self.receivable_account |
| 16 |
self.other_customer -> self.other_receivable_account |
| 17 |
|
| 18 |
ADDITIONALLY, this tests different sales account on the products. |
| 19 |
|
| 20 |
NOTE That both receivable accounts above are different from the pos receivable account. |
| 21 |
""" |
| 22 |
|
| 23 |
def setUp(self): |
| 24 |
super(TestPoSMultipleReceivableAccounts, self).setUp() |
| 25 |
self.config = self.basic_config |
| 26 |
self.product1 = self.create_product( |
| 27 |
'Product 1', |
| 28 |
self.categ_basic, |
| 29 |
lst_price=10.99, |
| 30 |
standard_price=5.0, |
| 31 |
tax_ids=self.taxes['tax7'].ids, |
| 32 |
) |
| 33 |
self.product2 = self.create_product( |
| 34 |
'Product 2', |
| 35 |
self.categ_basic, |
| 36 |
lst_price=19.99, |
| 37 |
standard_price=10.0, |
| 38 |
tax_ids=self.taxes['tax10'].ids, |
| 39 |
sale_account=self.other_sale_account, |
| 40 |
) |
| 41 |
self.product3 = self.create_product( |
| 42 |
'Product 3', |
| 43 |
self.categ_basic, |
| 44 |
lst_price=30.99, |
| 45 |
standard_price=15.0, |
| 46 |
tax_ids=self.taxes['tax_group_7_10'].ids, |
| 47 |
) |
| 48 |
self.adjust_inventory([self.product1, self.product2, self.product3], [100, 50, 50]) |
| 49 |
|
| 50 |
def test_01_invoiced_order_from_other_customer(self): |
| 51 |
""" |
| 52 |
Orders |
| 53 |
====== |
| 54 |
+---------+----------+-----------+----------+-----+---------+--------------------------+--------+ |
| 55 |
| order | payments | invoiced? | product | qty | untaxed | tax | total | |
| 56 |
+---------+----------+-----------+----------+-----+---------+--------------------------+--------+ |
| 57 |
| order 1 | cash | no | product1 | 10 | 109.9 | 7.69 [7%] | 117.59 | |
| 58 |
| | | | product2 | 10 | 181.73 | 18.17 [10%] | 199.9 | |
| 59 |
| | | | product3 | 10 | 281.73 | 19.72 [7%] + 28.17 [10%] | 329.62 | |
| 60 |
+---------+----------+-----------+----------+-----+---------+--------------------------+--------+ |
| 61 |
| order 2 | bank | no | product1 | 5 | 54.95 | 3.85 [7%] | 58.80 | |
| 62 |
| | | | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 | |
| 63 |
+---------+----------+-----------+----------+-----+---------+--------------------------+--------+ |
| 64 |
| order 3 | bank | yes | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 | |
| 65 |
| | | | product3 | 5 | 140.86 | 9.86 [7%] + 14.09 [10%] | 164.81 | |
| 66 |
+---------+----------+-----------+----------+-----+---------+--------------------------+--------+ |
| 67 |
|
| 68 |
Expected Result |
| 69 |
=============== |
| 70 |
+---------------------+---------+ |
| 71 |
| account | balance | |
| 72 |
+---------------------+---------+ |
| 73 |
| sale_account | -164.85 | |
| 74 |
| sale_account | -281.73 | |
| 75 |
| other_sale_account | -272.59 | |
| 76 |
| tax 7% | -31.26 | |
| 77 |
| tax 10% | -55.43 | |
| 78 |
| pos receivable cash | 647.11 | |
| 79 |
| pos receivable bank | 423.51 | |
| 80 |
| other receivable | -264.76 | |
| 81 |
+---------------------+---------+ |
| 82 |
| Total balance | 0.00 | |
| 83 |
+---------------------+---------+ |
| 84 |
""" |
| 85 |
|
| 86 |
def _before_closing_cb(): |
| 87 |
# check values before closing the session |
| 88 |
self.assertEqual(3, self.pos_session.order_count) |
| 89 |
orders_total = sum(order.amount_total for order in self.pos_session.order_ids) |
| 90 |
self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.') |
| 91 |
|
| 92 |
# check if there is one invoiced order |
| 93 |
self.assertEqual(len(self.pos_session.order_ids.filtered(lambda order: order.account_move)), 1, 'There should only be one invoiced order.') |
| 94 |
|
| 95 |
self._run_test({ |
| 96 |
'payment_methods': self.cash_pm1 | self.bank_pm1, |
| 97 |
'orders': [ |
| 98 |
{'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'uuid': '00100-010-0001'}, |
| 99 |
{'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'payments': [(self.bank_pm1, 158.75)], 'uuid': '00100-010-0002'}, |
| 100 |
{'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm1, 264.76)], 'is_invoiced': True, 'customer': self.other_customer, 'uuid': '09876-098-0987'}, |
| 101 |
], |
| 102 |
'before_closing_cb': _before_closing_cb, |
| 103 |
'journal_entries_before_closing': { |
| 104 |
'09876-098-0987': { |
| 105 |
'invoice': { |
| 106 |
'line_ids_predicate': lambda line: line.account_id in self.other_sale_account | self.sales_account | self.other_receivable_account, |
| 107 |
'line_ids': [ |
| 108 |
{'account_id': self.other_sale_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 90.86, 'reconciled': False}, |
| 109 |
{'account_id': self.sales_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 140.87, 'reconciled': False}, |
| 110 |
{'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 264.76, 'credit': 0, 'reconciled': True}, |
| 111 |
] |
| 112 |
}, |
| 113 |
'payments': [ |
| 114 |
((self.bank_pm1, 264.76), { |
| 115 |
'line_ids': [ |
| 116 |
{'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 264.76, 'reconciled': True}, |
| 117 |
{'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 264.76, 'credit': 0, 'reconciled': False}, |
| 118 |
] |
| 119 |
}), |
| 120 |
], |
| 121 |
} |
| 122 |
}, |
| 123 |
'journal_entries_after_closing': { |
| 124 |
'session_journal_entry': { |
| 125 |
'line_ids': [ |
| 126 |
{'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 31.26, 'reconciled': False}, |
| 127 |
{'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 55.44, 'reconciled': False}, |
| 128 |
{'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 164.85, 'reconciled': False}, |
| 129 |
{'account_id': self.other_sale_account.id, 'partner_id': False, 'debit': 0, 'credit': 272.59, 'reconciled': False}, |
| 130 |
{'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 281.72, 'reconciled': False}, |
| 131 |
{'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 423.51, 'credit': 0, 'reconciled': True}, |
| 132 |
{'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': True}, |
| 133 |
{'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 264.76, 'reconciled': True}, |
| 134 |
], |
| 135 |
}, |
| 136 |
'cash_statement': [ |
| 137 |
((647.11, ), { |
| 138 |
'line_ids': [ |
| 139 |
{'account_id': self.cash_pm1.journal_id.default_account_id.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': False}, |
| 140 |
{'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 647.11, 'reconciled': True}, |
| 141 |
] |
| 142 |
}), |
| 143 |
], |
| 144 |
'bank_payments': [ |
| 145 |
((423.51, ), { |
| 146 |
'line_ids': [ |
| 147 |
{'account_id': self.bank_pm1.outstanding_account_id.id, 'partner_id': False, 'debit': 423.51, 'credit': 0, 'reconciled': False}, |
| 148 |
{'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 423.51, 'reconciled': True}, |
| 149 |
] |
| 150 |
}), |
| 151 |
], |
| 152 |
}, |
| 153 |
}) |
| 154 |
|
| 155 |
def test_02_all_orders_invoiced_mixed_customers(self): |
| 156 |
""" |
| 157 |
Orders |
| 158 |
====== |
| 159 |
+---------+----------+---------------------+----------+-----+---------+--------------------------+--------+ |
| 160 |
| order | payments | invoiced? | product | qty | untaxed | tax | total | |
| 161 |
+---------+----------+---------------------+----------+-----+---------+--------------------------+--------+ |
| 162 |
| order 1 | cash | yes, other_customer | product1 | 10 | 109.90 | 7.69 [7%] | 117.59 | |
| 163 |
| | | | product2 | 10 | 181.73 | 18.17 [10%] | 199.90 | |
| 164 |
| | | | product3 | 10 | 281.73 | 19.72 [7%] + 28.17 [10%] | 329.62 | |
| 165 |
+---------+----------+---------------------+----------+-----+---------+--------------------------+--------+ |
| 166 |
| order 2 | bank | yes, customer | product1 | 5 | 54.95 | 3.85 [7%] | 58.80 | |
| 167 |
| | | | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 | |
| 168 |
+---------+----------+---------------------+----------+-----+---------+--------------------------+--------+ |
| 169 |
| order 3 | bank | yes, other customer | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 | |
| 170 |
| | | | product3 | 5 | 140.86 | 9.86 [7%] + 14.09 [10%] | 164.81 | |
| 171 |
+---------+----------+---------------------+----------+-----+---------+--------------------------+--------+ |
| 172 |
|
| 173 |
Expected Result |
| 174 |
=============== |
| 175 |
+----------------------+---------+ |
| 176 |
| account | balance | |
| 177 |
+----------------------+---------+ |
| 178 |
| pos receivable cash | 647.11 | |
| 179 |
| pos receivable bank | 423.51 | |
| 180 |
| received bank | -423.51 | |
| 181 |
| received cash | -647.11 | |
| 182 |
+----------------------+---------+ |
| 183 |
| Total balance | 0.00 | |
| 184 |
+----------------------+---------+ |
| 185 |
|
| 186 |
""" |
| 187 |
|
| 188 |
def _before_closing_cb(): |
| 189 |
# check values before closing the session |
| 190 |
self.assertEqual(3, self.pos_session.order_count) |
| 191 |
orders_total = sum(order.amount_total for order in self.pos_session.order_ids) |
| 192 |
self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.') |
| 193 |
|
| 194 |
# check if there is one invoiced order |
| 195 |
self.assertEqual(len(self.pos_session.order_ids.filtered(lambda order: order.account_move)), 3, 'All orders should be invoiced.') |
| 196 |
|
| 197 |
self._run_test({ |
| 198 |
'payment_methods': self.cash_pm1 | self.bank_pm1, |
| 199 |
'orders': [ |
| 200 |
{'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'is_invoiced': True, 'customer': self.other_customer, 'uuid': '09876-098-0987'}, |
| 201 |
{'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'payments': [(self.bank_pm1, 158.75)], 'is_invoiced': True, 'customer': self.customer, 'uuid': '09876-098-0988'}, |
| 202 |
{'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm1, 264.76)], 'is_invoiced': True, 'customer': self.other_customer, 'uuid': '09876-098-0989'}, |
| 203 |
], |
| 204 |
'before_closing_cb': _before_closing_cb, |
| 205 |
'journal_entries_before_closing': { |
| 206 |
'09876-098-0987': { |
| 207 |
'invoice': { |
| 208 |
'line_ids_predicate': lambda line: line.account_id in self.other_sale_account | self.sales_account | self.other_receivable_account, |
| 209 |
'line_ids': [ |
| 210 |
{'account_id': self.sales_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 109.90, 'reconciled': False}, |
| 211 |
{'account_id': self.other_sale_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 181.73, 'reconciled': False}, |
| 212 |
{'account_id': self.sales_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 281.72, 'reconciled': False}, |
| 213 |
{'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 647.11, 'credit': 0, 'reconciled': True}, |
| 214 |
] |
| 215 |
}, |
| 216 |
'payments': [ |
| 217 |
((self.cash_pm1, 647.11), { |
| 218 |
'line_ids': [ |
| 219 |
{'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 647.11, 'reconciled': True}, |
| 220 |
{'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': False}, |
| 221 |
] |
| 222 |
}), |
| 223 |
], |
| 224 |
}, |
| 225 |
'09876-098-0988': { |
| 226 |
'invoice': { |
| 227 |
'line_ids_predicate': lambda line: line.account_id in self.other_sale_account | self.sales_account | self.c1_receivable, |
| 228 |
'line_ids': [ |
| 229 |
{'account_id': self.sales_account.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 54.95, 'reconciled': False}, |
| 230 |
{'account_id': self.other_sale_account.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 90.86, 'reconciled': False}, |
| 231 |
{'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 158.75, 'credit': 0, 'reconciled': True}, |
| 232 |
] |
| 233 |
}, |
| 234 |
'payments': [ |
| 235 |
((self.bank_pm1, 158.75), { |
| 236 |
'line_ids': [ |
| 237 |
{'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 158.75, 'reconciled': True}, |
| 238 |
{'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 158.75, 'credit': 0, 'reconciled': False}, |
| 239 |
] |
| 240 |
}), |
| 241 |
], |
| 242 |
}, |
| 243 |
'09876-098-0989': { |
| 244 |
'invoice': { |
| 245 |
'line_ids_predicate': lambda line: line.account_id in self.other_sale_account | self.sales_account | self.other_receivable_account, |
| 246 |
'line_ids': [ |
| 247 |
{'account_id': self.other_sale_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 90.86, 'reconciled': False}, |
| 248 |
{'account_id': self.sales_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 140.87, 'reconciled': False}, |
| 249 |
{'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 264.76, 'credit': 0, 'reconciled': True}, |
| 250 |
] |
| 251 |
}, |
| 252 |
'payments': [ |
| 253 |
((self.bank_pm1, 264.76), { |
| 254 |
'line_ids': [ |
| 255 |
{'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 264.76, 'reconciled': True}, |
| 256 |
{'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 264.76, 'credit': 0, 'reconciled': False}, |
| 257 |
] |
| 258 |
}), |
| 259 |
], |
| 260 |
}, |
| 261 |
}, |
| 262 |
'journal_entries_after_closing': { |
| 263 |
'session_journal_entry': { |
| 264 |
'line_ids': [ |
| 265 |
{'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 423.51, 'credit': 0, 'reconciled': True}, |
| 266 |
{'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': True}, |
| 267 |
{'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 647.11, 'reconciled': True}, |
| 268 |
{'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 423.51, 'reconciled': True}, |
| 269 |
], |
| 270 |
}, |
| 271 |
'cash_statement': [ |
| 272 |
((647.11, ), { |
| 273 |
'line_ids': [ |
| 274 |
{'account_id': self.cash_pm1.journal_id.default_account_id.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': False}, |
| 275 |
{'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 647.11, 'reconciled': True}, |
| 276 |
] |
| 277 |
}), |
| 278 |
], |
| 279 |
'bank_payments': [ |
| 280 |
((423.51, ), { |
| 281 |
'line_ids': [ |
| 282 |
{'account_id': self.bank_pm1.outstanding_account_id.id, 'partner_id': False, 'debit': 423.51, 'credit': 0, 'reconciled': False}, |
| 283 |
{'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 423.51, 'reconciled': True}, |
| 284 |
] |
| 285 |
}), |
| 286 |
], |
| 287 |
}, |
| 288 |
}) |