Skip to content

Commit abd741f

Browse files
committed
[REF] point_of_sale: accounting
Refactor of the pos accounting and invoicing logic, now when closing a session, it will create two moves if needed - Sales move: containing all pos.order of type sale with aggregated lines - Refunds move: containing all pos.order of type refund with aggregated lines One of the major changes here is `pos_settle_due` in which is now only possible to settle invoices and not pos order. That's because when paying by customer account it will create an invoice each time. Removed fields - `invoice_journal_id` and `pos_invoice_journal_id` because now all invoice are created with the same journal, the one defined on the pos config. - `split_transactions` because now, we don't allow to split payments transactions on cash and bank, only when the type is pay_later - `account_default_pos_receivable_account_id` because now the receivable account is defined though a default partner on the pos.config - `cash_real_transaction`, `cash_register_balance_start`, `cash_register_balance_end_real`, `cash_journal_id`, `cash_register_difference` and `cash_register_balance_end` all these infos are now handled though the cash statement and its lines, so no need to have them on the session - `is_cash_count` because cash is now identified by type == 'cash' - `is_invoiced` replaced by `is_singly_invoiced` and `is_globally_invoiced` - `session_move_id` because account_move is now used to link the order to the session move if it was not invoiced - `is_online_payment` because online payment method is now identified by type == 'online' and not by a boolean field - `settle_invoice_product_id`, `deposit_product_id` and `settle_due_product_id` because we don't create a pos.order when settling an invoice, so no need to have these products. - `settled_invoice_id` and `settled_order_id` because we don't create a pos.order when settling an invoice, so no need to link them anymore. - `init_customer_due_total`, `customer_due_total`, `settled_order_line_ids`, `settled_orders_count`, `commercial_partner_id` because we don't settle pos.order anymore - `pos_order_line_ids` and `pos_amount_unsettled` because we don't settle pos.order anymore - `pos_orders_amount_due` because we don't settle pos.order anymore Test tracking A lot of tests were replaced because all accounting entries for order and session closing are now refactored. Some tests were also removed because they were not relevant anymore with the new way of handling payment and invoicing on pos.order. Replaced tests `test_classic_sale_order` replace: - `test_state_when_closing_register` `test_fifo_valuation_with_invoice` replace: - `test_fifo_valuation_with_invoice_when_pos_customer_is_delivery_type` `test_fixed_tax_negative_qty_should_be_negative` replace: - `test_fixed_tax_negative_qty` - `test_fixed_tax_positive_qty` `test_user_right_on_statement_line_for_pos_user` replace: - `test_pos_closing_cash_details` `test_rounding_when_closing_session` replace: - `test_invoice_rounding_overpaid_backend` - `test_pos_create_account_move_round_globally` - `test_rounding_method` Moved in `test_pos_accounting.py`: `test_journal_entries_category_without_account` `test_tax_change_blocked_when_open_pos_session` `test_order_partial_refund_rounding` Test suite in `test_pos_accounting.py` replace: - `test_pos_simple_invoiced_orders.py` - `test_orders_no_invoiced` - `test_orders_with_invoiced` - `test_01_invoiced_order_from_other_customer` - `test_02_all_orders_invoiced_mixed_customers` - `test_total_due.py` - `test_02_orders_without_invoice` - `test_03_orders_with_invoice` `test_invoice_a_negative_order_should_create_credit_note` replace: - `test_manual_refund_negative_qty_invoice_creates_credit_note` `test_invoice_an_order_from_closed_session` replace: - `test_invoice_past_order_affecting_taxes` - `test_invoice_past_refund` - `test_invoice_past_order` - `test_sale_order_postponed_invoicing` - `test_order_invoiced_after_session_closed` - `test_order_invoiced_customer_account_after_session_closed` - `test_sale_order_postponed_invoicing` `test_pos_order_sale_and_refund_with_taxes` replace: - `test_orders_with_invoiced` - `test_return_order` `test_pos_order_sale_and_refund_with_taxes_invoiced` replace: - `test_pos_create_correct_account_move` - `test_return_order_invoiced` `test_pos_order_sale_and_refund_with_taxes_not_invoiced` replace: - `test_pos_create_correct_account_move` - `test_return_order` `test_invoiced_order_with_discount_sale_and_refund_with_tax` replace: - `test_pos_create_correct_account_move_round_globally_discount` - `test_pos_create_correct_account_move_round_globally_discount_real_use_case` `test_tax_change_blocked_when_open_pos_session` replace: - `test_tax_is_used_when_in_transactions` `test_pos_payment_direction_and_account` replace: - `test_pos_payment_direction_and_accounts` `test_cash_statement_opening_and_closing_consistency` replace: - `test_cash_register_if_no_order` - `test_cash_payments_should_reflect_on_next_opening` `test_invoicing_zero_amount_pos_order` replace: - `test_orders_with_zero_valued_invoiced` `test_order_partial_refund_rounding` replace: - `test_refund_rounding_backend` - `test_order_partial_refund` `test_pos_config_with_other_currency_than_company` replace: - `test_order_to_payment_currency` `test_accounting_items_when_closing_with_bank_difference` replace: - `test_payment_difference_accounting_items` - `test_state_when_closing_register` `test_pos_order_with_closing_storno` replace: - `test_sale_order_postponed_invoicing_storno` `test_various_orders` replace: - `test_correct_partner_on_invoice_receivables` `test_pos_order_session_closing_with_fp` replace: - `test_01_no_invoice_fpos` - `test_02_no_invoice_fpos_no_tax_dest` `test_available_stock_order_no_invoice` replace: - `test_orders_no_invoiced` - `test_return_order` `test_available_stock_order_with_invoice` replace: - `test_orders_with_invoiced` - `test_return_order` `test_pos_order_with_company_branch` replace: - `test_pos_branch_account` Removed tests `test_ZATCA_blocks_settle_due_and_sale_on_same_order` not usefull settle due doesn't create pos.order anymore `test_order_with_deleted_tax` removed because isn't possible to edit taxes with open orders anymore. `test_split_payment_linked_to_accounting_partner` split transaction is now only available when using customer account (type == pay_layer) `test_pos_hr_session_name_gap` removed not useful `test_order_to_invoice_no_tax` not useful `test_order_invoiced_customer_account_after_session_closed` not useful, customer account payment are always invoiced but this test is almost the same `test_invoice_an_order_from_closed_session` `test_start_balance_with_two_pos` useless test, cash payment cannot be shared. `test_different_customer_invoices_settlement_same_session_reconciled_separately` settling an invoice doesn't create `pos.order` anymore `test_split_cash_payments` removed because split on customer account is now available only when using `pay_later` payment method. `test_receivable_account_reconciliation.py`, `test_pos_reconcile` no more necessary, payment are now directly added to the account.move `test_pos_settling_account_resets_on_payment_screen_unmount` removed because now when leaving payment screen it will delete the order if its a settling one. `test_pos_settle_due_with_rounding` deleted, wtf we round on a money deposit ? `test_split_payment_linked_to_accounting_partner` split_transactions is no more available with classic pm, only with pay_later. `test_05_tax_base_amount` removed tax base amount are handled and tested by accounting helpers `test_no_kitchen_confirmation_for_deposit_money` removed because deposit money doesn't create a pos.order anymore. `test_order_with_deleted_tax` is now not possible to archive a tax used by an open order. `fastValidate` hoot deleted in pos_settle_due because isn't possible to use fast validation with settle customer invoice anymore. `test_double_syncing_same_order` removed, sync data with the same UUID will update the same order, but since a payment_ids create command is in the data, its normal that this payment is created two times. `test_session_name_gap` removed, sequences are never rollbacked, so the test is not correct.
1 parent adab3e6 commit abd741f

199 files changed

Lines changed: 5073 additions & 8521 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

addons/l10n_ar_pos/tests/test_pos_ar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ def setUpClass(cls):
2929

3030
cls.bank_pm = cls.env['pos.payment.method'].sudo().create({
3131
'name': 'Bank',
32+
'type': 'bank',
3233
'journal_id': cls.company_data['default_journal_bank'].id,
3334
'receivable_account_id': cls.pos_receivable_bank.id,
3435
'outstanding_account_id': cls.outstanding_bank.id,
3536
'company_id': cls.company.id,
3637
})
3738
cls.cash_pm = cls.env['pos.payment.method'].sudo().create({
3839
'name': 'Cash',
40+
'type': 'cash',
3941
'journal_id': cls.company_data['default_journal_cash'].id,
4042
'receivable_account_id': cls.pos_receivable_bank.id,
4143
'outstanding_account_id': cls.outstanding_bank.id,

addons/l10n_ar_pos/views/templates.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<attribute name="t-if">pos_order.company_id.country_code != 'AR'</attribute>
99
</xpath>
1010
<xpath expr="//div[@id='get_my_invoice']/.." position="after">
11-
<h4 class="text-danger" t-if="pos_order.company_id.country_code == 'AR' and not pos_order.is_invoiced">Invoice not available. You can contact us for more info</h4>
11+
<h4 class="text-danger" t-if="pos_order.company_id.country_code == 'AR' and not pos_order.is_singly_invoiced">Invoice not available. You can contact us for more info</h4>
1212
</xpath>
1313

1414
<!-- If the user is NOT log in we should hide the partner form, this one lost functionality because the get my invoice button is not shown and then the partner info is never save. In they want they can sign up and fill data from there -->

addons/l10n_be_pos_sale/tests/test_l10n_be_pos_sale.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def test_pos_branch_company_access(self):
9292
b_pos_config = self.env['pos.config'].with_company(branch).create({
9393
'name': 'Main',
9494
'journal_id': self.company_data['default_journal_sale'].id,
95-
'invoice_journal_id': self.company_data['default_journal_sale'].id,
9695
'payment_method_ids': [(4, bank_payment_method.id)],
9796
})
9897

addons/l10n_ch_pos/tests/test_frontend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def _get_main_company(cls):
1717
def test_l10n_ch_pos_pay_later_invoice_has_bank_partner(self):
1818
customer_account_payment_method = self.env['pos.payment.method'].create({
1919
'name': 'Customer Account',
20-
'split_transactions': True,
20+
'type': 'pay_later',
2121
})
2222
self.main_pos_config.write({
2323
'payment_method_ids': [Command.link(customer_account_payment_method.id)],

addons/l10n_es_edi_tbai_pos/models/pos_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _l10n_es_tbai_create_edi_document(self, cancel=False):
169169
def _l10n_es_tbai_get_values(self):
170170
self.ensure_one()
171171

172-
base_lines = self.lines._prepare_tax_base_line_values()
172+
base_lines = self.lines._prepare_base_lines_for_taxes_computation()
173173
for base_line in base_lines:
174174
base_line['name'] = base_line['record'].name
175175
self.env['l10n_es_edi_tbai.document']._add_base_lines_tax_amounts(base_lines, self.company_id)

addons/l10n_es_edi_verifactu_pos/models/pos_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def _l10n_es_edi_verifactu_get_record_values(self, cancellation=False):
194194
'clave_regimen': clave_regimen,
195195
})
196196

197-
base_lines = self.lines._prepare_tax_base_line_values()
197+
base_lines = self.lines._prepare_base_lines_for_taxes_computation()
198198
vals['tax_details'] = self.env['l10n_es_edi_verifactu.document']._get_tax_details(base_lines, company)
199199

200200
return vals

addons/l10n_es_edi_verifactu_pos/tests/test_pos_order.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ def setUpClass(cls):
3232
def with_pos_session(self):
3333
session = self.open_new_session(0.0)
3434
yield session
35-
session.post_closing_cash_details(0.0)
36-
session.close_session_from_ui()
35+
cash_pm = self.config._get_cash_payment_method()
36+
session.close_session_from_ui({
37+
cash_pm.id: 0,
38+
})
3739

3840
def _create_order(self, data):
3941
date_order = data.pop('date_order', None)
@@ -140,7 +142,7 @@ def test_order_not_invoiced(self):
140142
})
141143
refund.l10n_es_edi_verifactu_refund_reason = 'R5'
142144
refund_payment.with_context(**payment_context).check()
143-
self.pos_session.action_pos_session_validate()
145+
self.pos_session.close_session_from_ui()
144146

145147
self.assertRecordValues(order, [{
146148
'l10n_es_edi_verifactu_state': 'accepted',

addons/l10n_es_pos/static/tests/tours/spanish_pos_tour.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,9 @@ registry.category("web_tour.tours").add("l10n_es_pos_settle_account_due", {
9393
Dialog.confirm("Open Register"),
9494
ProductScreen.clickPartnerButton(),
9595
PartnerList.settleCustomerAccount("Partner Test 1", "10.0", "TSJ/", "/00001", true),
96-
ProductScreen.clickPayButton(),
9796
PaymentScreen.clickPaymentMethod("Bank"),
9897
PaymentScreen.clickValidate(),
99-
Chrome.confirmPopup(),
100-
FeedbackScreen.isShown(),
101-
FeedbackScreen.checkTicketData({
102-
payment_lines: [
103-
{ name: "Bank", amount: "10.0" },
104-
{ name: "Customer Account", amount: "-10.0" },
105-
],
106-
}),
98+
ProductScreen.isShown(),
10799
Chrome.endTour(),
108100
].flat(),
109101
});

addons/l10n_es_pos/tests/test_frontend.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _get_main_company(cls):
2222
def test_spanish_pos(self):
2323
split_payment_method = self.env['pos.payment.method'].create({
2424
'name': 'Customer Account',
25-
'split_transactions': True,
25+
'type': 'pay_later',
2626
})
2727
self.main_pos_config.payment_method_ids = [(4, split_payment_method.id)]
2828

@@ -33,7 +33,7 @@ def test_spanish_pos(self):
3333
'code': 'SIMP',
3434
})
3535
def get_number_of_regular_invoices():
36-
return self.env['account.move'].search_count([('journal_id', '=', self.main_pos_config.invoice_journal_id.id), ('l10n_es_is_simplified', '=', False), ('pos_order_ids', '!=', False)])
36+
return self.env['account.move'].search_count([('journal_id', '=', self.main_pos_config.journal_id.id), ('l10n_es_is_simplified', '=', False), ('pos_order_ids', '!=', False)])
3737
initial_number_of_regular_invoices = get_number_of_regular_invoices()
3838
self.main_pos_config.l10n_es_simplified_invoice_journal_id = simp
3939
# this `limit` value is linked to the `SIMPLIFIED_INVOICE_LIMIT` const in the tour
@@ -52,7 +52,7 @@ def test_l10n_es_pos_reconcile(self):
5252
# create customer account payment method
5353
self.customer_account_payment_method = self.env['pos.payment.method'].create({
5454
'name': 'Customer Account',
55-
'split_transactions': True,
55+
'type': 'pay_later',
5656
})
5757
# add customer account payment method to pos config
5858
self.main_pos_config.write({
@@ -91,7 +91,7 @@ def test_l10n_es_pos_reconcile(self):
9191
order_payment.with_context(**payment_context).check()
9292

9393
self.assertEqual(self.partner_test_1.total_due, 10)
94-
current_session.action_pos_session_closing_control()
94+
current_session.close_session_from_ui()
9595

9696
self.main_pos_config.with_user(self.pos_admin).open_ui()
9797
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'l10n_es_pos_settle_account_due', login="accountman")
@@ -120,11 +120,11 @@ def test_spanish_pos_invoice_no_certificate(self):
120120
'price_unit': 100,
121121
'qty': 1.0,
122122
'tax_ids': self.product_a.taxes_id,
123-
'price_subtotal': 85,
124-
'price_subtotal_incl': 100,
123+
'price_subtotal': 100,
124+
'price_subtotal_incl': 115,
125125
'discount': 0,
126126
})],
127-
'amount_total': 100,
127+
'amount_total': 115,
128128
'amount_tax': 15,
129129
'amount_paid': 0,
130130
'amount_return': 0,
@@ -133,7 +133,7 @@ def test_spanish_pos_invoice_no_certificate(self):
133133

134134
context_make_payment = {"active_ids": [self.pos_order_pos0.id], "active_id": self.pos_order_pos0.id}
135135
self.pos_make_payment_0 = self.env['pos.make.payment'].with_context(context_make_payment).create({
136-
'amount': 100.0,
136+
'amount': 115.0,
137137
'payment_method_id': self.main_pos_config.payment_method_ids[0].id,
138138
})
139139
context_payment = {'active_id': self.pos_order_pos0.id}

addons/l10n_fr_pos_cert/tests/test_hash.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def setUpClass(cls):
1313
super().setUpClass()
1414

1515
def test_hashes_should_be_equal_if_no_alteration(self):
16+
journal = self.env['account.journal']._ensure_company_account_journal()
17+
if self.pos_config_usd.journal_id != journal:
18+
self.pos_config_usd.journal_id = journal
19+
1620
product1 = self.env['product.product'].create({
1721
'name': 'product1',
1822
})
@@ -76,6 +80,6 @@ def test_hashes_should_be_equal_if_no_alteration(self):
7680
posted_order = self.env['pos.order'].search([('uuid', '=', '12345-123-1234')])
7781
self.assertEqual(posted_order.state, 'paid')
7882

79-
self.pos_config_usd.current_session_id.action_pos_session_closing_control()
83+
self.pos_config_usd.current_session_id.close_session_from_ui()
8084

8185
self.assertEqual(posted_order.l10n_fr_hash, posted_order._compute_hash(''))

0 commit comments

Comments
 (0)