diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 3aa4d3f9066..527060cf0c0 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -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)) diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py index a231c9164e2..6c22dd8068e 100644 --- a/addons/point_of_sale/tests/test_point_of_sale_flow.py +++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py @@ -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)