[FIX] account, point_of_sale: allow branches own account payment
Steps to reproduce: - Install point of sale and accounting - Create a branch - Make a copy of the outstanding receipts account and change company to the branch - Attach the branch to this account in the accounting settings - Open a PoS make a transaction and close the session Issues: An error is displayed notifying the user that the journal entry draft is not valid. Solution: Accounts that are attached to a branch should be valid for them as well as their parents account. opw-3659707 closes odoo/odoo#148810 Signed-off-by: Quentin De Paoli <qdp@odoo.com>
This commit is contained in:
@@ -204,11 +204,13 @@ class AccountPayment(models.Model):
|
||||
return lines
|
||||
|
||||
def _get_valid_liquidity_accounts(self):
|
||||
journal_comp = self.journal_id.company_id
|
||||
accessible_branches = journal_comp.with_company(journal_comp)._accessible_branches()
|
||||
return (
|
||||
self.journal_id.default_account_id |
|
||||
self.payment_method_line_id.payment_account_id |
|
||||
self.journal_id.company_id.account_journal_payment_debit_account_id |
|
||||
self.journal_id.company_id.account_journal_payment_credit_account_id |
|
||||
accessible_branches.account_journal_payment_debit_account_id |
|
||||
accessible_branches.account_journal_payment_credit_account_id |
|
||||
self.journal_id.inbound_payment_method_line_ids.payment_account_id |
|
||||
self.journal_id.outbound_payment_method_line_ids.payment_account_id
|
||||
)
|
||||
|
||||
@@ -957,6 +957,7 @@ class PosSession(models.Model):
|
||||
'ref': _('Combine %s POS payments from %s', payment_method.name, self.name),
|
||||
'pos_payment_method_id': payment_method.id,
|
||||
'pos_session_id': self.id,
|
||||
'company_id': self.company_id.id,
|
||||
})
|
||||
|
||||
diff_amount_compare_to_zero = self.currency_id.compare_amounts(diff_amount, 0)
|
||||
|
||||
@@ -2005,3 +2005,61 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
self.pos_config.current_session_id.action_pos_session_closing_control()
|
||||
self.assertEqual(quant2.quantity, 4)
|
||||
self.assertEqual(quant1.quantity, 3)
|
||||
|
||||
def test_pos_branch_account(self):
|
||||
branch = self.env['res.company'].create({
|
||||
'name': 'Branch 1',
|
||||
'parent_id': self.env.company.id,
|
||||
'chart_template': self.env.company.chart_template,
|
||||
})
|
||||
|
||||
outstanding_receipts = self.env.company.account_journal_payment_debit_account_id.copy()
|
||||
outstanding_receipts.company_id = branch
|
||||
|
||||
self.env.cr.precommit.run()
|
||||
branch.account_journal_payment_debit_account_id = outstanding_receipts
|
||||
|
||||
bank_payment_method = self.bank_payment_method.copy()
|
||||
bank_payment_method.company_id = branch.id
|
||||
|
||||
b_pos_config = self.env['pos.config'].with_company(branch).create({
|
||||
'name': 'Main',
|
||||
'journal_id': self.company_data['default_journal_sale'].id,
|
||||
'invoice_journal_id': self.company_data['default_journal_sale'].id,
|
||||
'payment_method_ids': [(4, bank_payment_method.id)],
|
||||
})
|
||||
|
||||
b_pos_config.open_ui()
|
||||
current_session = b_pos_config.current_session_id
|
||||
|
||||
order = self.PosOrder.create({
|
||||
'session_id': current_session.id,
|
||||
'partner_id': self.partner1.id,
|
||||
'lines': [(0, 0, {
|
||||
'name': "OL/0001",
|
||||
'product_id': self.product3.id,
|
||||
'price_unit': 450,
|
||||
'discount': 0,
|
||||
'qty': 1,
|
||||
'tax_ids': [[6, False, []]],
|
||||
'price_subtotal': 450,
|
||||
'price_subtotal_incl': 450,
|
||||
})],
|
||||
'pricelist_id': b_pos_config.pricelist_id.id,
|
||||
'amount_paid': 450.0,
|
||||
'amount_total': 450.0,
|
||||
'amount_tax': 0.0,
|
||||
'amount_return': 0.0,
|
||||
'to_invoice': False,
|
||||
'last_order_preparation_change': '{}'
|
||||
})
|
||||
|
||||
payment_context = {"active_ids": order.ids, "active_id": order.id}
|
||||
order_payment = self.PosMakePayment.with_context(payment_context).create({
|
||||
'amount': order.amount_total,
|
||||
'payment_method_id': bank_payment_method.id,
|
||||
})
|
||||
order_payment.with_context(payment_context).check()
|
||||
b_pos_config.current_session_id.action_pos_session_closing_control()
|
||||
|
||||
self.assertEqual(current_session.state, 'closed', msg='State of current session should be closed.')
|
||||
|
||||
Reference in New Issue
Block a user