Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
232 Prikazi

Getting this error while adding any services Example "Food" on Click "Add Line" following error is shown please check what would be the cause. What could be the issue and fix for it.

Odoo Server Error

RPC_ERROR

Odoo Server Error

Occured on localhost:8069 on model food.booking.line and id 21 on 2025-08-17 09:16:08 GMT

Traceback (most recent call last):
  File "C:\odoo18\server\odoo\http.py", line 1957, in _transactioning
    return service_model.retrying(func, env=self.env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\service\model.py", line 137, in retrying
    result = func()
             ^^^^^^
  File "C:\odoo18\server\odoo\http.py", line 1924, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\http.py", line 2171, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\addons\base\models\ir_http.py", line 329, in _dispatch
    result = endpoint(**request.params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\http.py", line 727, in route_wrapper
    result = endpoint(self, *args, **params_ok)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\addons\web\controllers\dataset.py", line 35, in call_kw
    return call_kw(request.env[model], method, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\api.py", line 517, in call_kw
    result = getattr(recs, name)(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\addons\web\models\models.py", line 1014, in onchange
    snapshot1 = RecordSnapshot(record, fields_spec)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\addons\web\models\models.py", line 1101, in __init__
    self.fetch(name)
  File "C:\odoo18\server\odoo\addons\web\models\models.py", line 1116, in fetch
    self[field_name] = self.record[field_name]
                       ~~~~~~~~~~~^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\models.py", line 6999, in __getitem__
    return self._fields[key].__get__(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\fields.py", line 1236, in __get__
    self.recompute(record)
  File "C:\odoo18\server\odoo\fields.py", line 1451, in recompute
    apply_except_missing(self.compute_value, recs)
  File "C:\odoo18\server\odoo\fields.py", line 1424, in apply_except_missing
    func(records)
  File "C:\odoo18\server\odoo\fields.py", line 1473, in compute_value
    records._compute_field_value(self)
  File "C:\odoo18\server\odoo\models.py", line 5238, in _compute_field_value
    fields.determine(field.compute, self)
  File "C:\odoo18\server\odoo\fields.py", line 110, in determine
    return needle(*args)
           ^^^^^^^^^^^^^
  File "C:\odoo18\server\odoo\addons\hotel_management_odoo\models\food_booking_line.py", line 88, in _compute_price_subtotal
    base_line = line._prepare_base_line_for_taxes_computation()
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'total_excluded_currency'

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (http://localhost:8069/web/assets/080c996/web.assets_web.min.js:3116:163)
        at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/080c996/web.assets_web.min.js:3121:13)
food_booking_line.py

    @api.depends('uom_qty', 'price_unit', 'tax_ids')

    def _compute_price_subtotal(self):

        """Compute the amounts of the room booking line."""

        for line in self:

            base_line = line._prepare_base_line_for_taxes_computation()

            self.env['account.tax']._add_tax_details_in_base_line(base_line, self.env.company)

            ## Line 88 Error shown

            line.price_subtotal = base_line['tax_details']['total_excluded_currency'] 

            line.price_total = base_line['tax_details']['total_included_currency']

            line.price_tax = line.price_total - line.price_subtotal

            if self.env.context.get('import_file',

                                    False) and not self.env.user. \

                    user_has_groups('account.group_account_manager'):

                line.tax_id.invalidate_recordset(

                    ['invoice_repartition_line_ids'])




Avatar
Opusti
Avtor Best Answer

Thanks for your feedback still getting error, can you please make above suggested change to below model and resend the code. 

class FoodBookingLine(models.Model):

    """Model that handles the food booking"""

    _name = "food.booking.line"

    _description = "Hotel Food Line"

    _rec_name = 'food_id'


    @tools.ormcache()

    def _get_default_uom_id(self):

        """Method for getting the default uom id"""

        return self.env.ref('uom.product_uom_unit')


    booking_id = fields.Many2one("room.booking", string="Booking",

                                 help="Shows the room Booking",

                                 ondelete="cascade")

    food_id = fields.Many2one('lunch.product', string="Product",

                              help="Indicates the Food Product")

    description = fields.Char(string='Description',

                              help="Description of Food Product",

                              related='food_id.display_name')

    uom_qty = fields.Float(string="Qty", default=1,

                           help="The quantity converted into the UoM used by "

                                "the product")

    uom_id = fields.Many2one('uom.uom', readonly=True,

                             string="Unit of Measure",

                             default=_get_default_uom_id, help="This will set "

                                                               "the unit of"

                                                               " measure used")

    price_unit = fields.Float(related='food_id.price', string='Price',

                              digits='Product Price',

                              help="The price of the selected food item.")

    tax_ids = fields.Many2many('account.tax',

                               'hotel_food_order_line_taxes_rel',

                               'food_id', 'tax_id',

                               string='Taxes',

                               help="Default taxes used when selling the food"

                                    " products.",

                               domain=[('type_tax_use', '=', 'sale')])

    currency_id = fields.Many2one(related='booking_id.pricelist_id.currency_id'

                                  , string="Currency",

                                  help='The currency used')

    price_subtotal = fields.Float(string="Subtotal",

                                  compute='_compute_price_subtotal',

                                  help="Total Price Excluding Tax",

                                  store=True)

    price_tax = fields.Float(string="Total Tax",

                             compute='_compute_price_subtotal',

                             help="Tax Amount",

                             store=True)

    price_total = fields.Float(string="Total",

                               compute='_compute_price_subtotal',

                               help="Total Price Including Tax",

                               store=True)

    state = fields.Selection(related='booking_id.state',

                             string="Order Status",

                             help=" Status of the Order",

                             copy=False)


    @api.depends('uom_qty', 'price_unit', 'tax_ids')

    def _compute_price_subtotal(self):

        """Compute the amounts of the room booking line."""

        for line in self:  

            base_line = line._prepare_base_line_for_taxes_computation()

            self.env['account.tax']._add_tax_details_in_base_line(base_line, self.env.company)

            line.price_subtotal = base_line['tax_details']['total_excluded_currency']

            line.price_total = base_line['tax_details']['total_included_currency']

            line.price_tax = line.price_total - line.price_subtotal

            if self.env.context.get('import_file',

                                    False) and not self.env.user. \

                    user_has_groups('account.group_account_manager'):

                line.tax_id.invalidate_recordset(

                    ['invoice_repartition_line_ids'])

    def _prepare_base_line_for_taxes_computation(self):

        """ Convert the current record to a dictionary in order to use the generic taxes computation method

        defined on account.tax.


        :return: A python dictionary.

        """

        self.ensure_one()

        return self.env['account.tax']._prepare_base_line_for_taxes_computation(

            self,

            **{

                'tax_ids': self.tax_ids,

                'quantity': self.uom_qty,

                'partner_id': self.booking_id.partner_id,

                'currency_id': self.currency_id,

            },

        )


    def search_food_orders(self):

        """Returns list of food orders"""

        return (self.search([]).filtered(lambda r: r.booking_id.state not in [

            'check_out', 'cancel', 'done']).ids)



Avatar
Opusti
Best Answer

Hi,


The error occurs when adding a service line such as Food. Odoo raises a KeyError: 'total_excluded_currency' because the compute method in your custom food_booking_line model expects the keys total_excluded_currency and total_included_currency in the tax details dictionary, but these keys are not always present.

The root cause is that Odoo’s tax computation API normally returns total_excluded and total_included. The _currency versions of those keys are only provided if a currency is explicitly passed to _add_tax_details_in_base_line. In your module, the logic was adapted from account.move.line but the necessary currency argument was not included, which is why the expected keys are missing.

To fix this, you have a few options. The simplest is to switch your code to use total_excluded and total_included instead of the _currency versions. Alternatively, you can pass currency=line.currency_id to _add_tax_details_in_base_line, which will ensure that the _currency keys are added to the dictionary. A safer approach is to use .get() with fallback values so your code works whether or not those keys are present.

In short, adjusting your _compute_price_subtotal method to either use the correct keys, pass the currency, or handle both cases defensively will resolve the error.


Hope it helps

Avatar
Opusti