[FIX] point_of_sale: use pos journal default account

Current behavior:
When no account is set on a product category, you cannot close a POS
session. This happens because we are not using the default account set
on the POS journal in this case.

Steps to reproduce:
- Create product A, and product category B that has no account set on it
- Open a POS session, add product A. Validate the order
- Close the POS session, you will get an error message.

opw-3178181

closes odoo/odoo#116838

X-original-commit: 18be148083ebce27154452bef7aa2620e68f18f0
Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
Signed-off-by: Engels Robin (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2023-03-28 18:45:56 +02:00
parent fa19780371
commit d46882b088
2 changed files with 55 additions and 1 deletions
+1 -1
View File
@@ -1147,7 +1147,7 @@ class PosSession(models.Model):
"""
def get_income_account(order_line):
product = order_line.product_id
income_account = product.with_company(order_line.company_id)._get_product_accounts()['income']
income_account = product.with_company(order_line.company_id)._get_product_accounts()['income'] or self.config_id.journal_id.default_account_id
if not income_account:
raise UserError(_('Please define income account for this product: "%s" (id:%d).')
% (product.name, product.id))
@@ -1370,3 +1370,57 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
refund_payment.with_context(**payment_context).check()
current_session.action_pos_session_closing_control()
self.assertEqual(refund.picking_ids.move_line_ids_without_package.owner_id.id, order.picking_ids.move_line_ids_without_package.owner_id.id, "The owner of the refund is not the same as the owner of the original order")
def test_journal_entries_category_without_account(self):
#create a new product category without account
category = self.env['product.category'].create({
'name': 'Category without account',
'property_account_income_categ_id': False,
'property_account_expense_categ_id': False,
})
product = self.env['product.product'].create({
'name': 'Product with category without account',
'type': 'product',
'categ_id': category.id,
'property_account_income_id': False,
'property_account_expense_id': False,
})
account = self.env['account.account'].create({
'name': 'Account for category without account',
'code': 'X1111',
})
self.pos_config.journal_id.default_account_id = account.id
#create a new pos order with the product
self.pos_config.open_ui()
current_session = self.pos_config.current_session_id
order = 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': [(0, 0, {
'name': "OL/0001",
'product_id': product.id,
'price_unit': 10,
'discount': 0.0,
'qty': 1,
'tax_ids': [],
'price_subtotal': 10,
'price_subtotal_incl': 10,
})],
'amount_total': 10,
'amount_tax': 0.0,
'amount_paid': 10,
'amount_return': 0.0,
'to_invoice': True
})
#create a payment
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': self.cash_payment_method.id
})
order_payment.with_context(**payment_context).check()
current_session.action_pos_session_closing_control()
self.assertEqual(current_session.move_id.line_ids[0].account_id.id, account.id)