pythonodooodoo-17

Odoo 17, Problems with the soft argument in the post_ method


I made a development that runs on the _post method of Odoo 17, while I was developing it there was no problem, it was not until I installed it on a new base when this error started to occur at the time of making a product receipt in a purchase (my development has nothing to do with purchases, I never make an inheritance of the purchase module, I do not know why it happens at that time). Needless to mention that I always pass the “soft” argument when I call the _post method, I have never forgotten it, that's why I find the problem so frustrating.

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
  File "D:\Documentos\odoo-17\odoo\odoo\http.py", line 1783, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Documentos\odoo-17\odoo\odoo\service\model.py", line 133, in retrying
    result = func()
             ^^^^^^
  File "D:\Documentos\odoo-17\odoo\odoo\http.py", line 1810, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Documentos\odoo-17\odoo\odoo\http.py", line 2014, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Documentos\odoo-17\odoo\odoo\addons\base\models\ir_http.py", line 222, in _dispatch
    result = endpoint(**request.params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Documentos\odoo-17\odoo\odoo\http.py", line 759, in route_wrapper
    result = endpoint(self, *args, **params_ok)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\documentos\odoo-17\odoo\addons\web\controllers\dataset.py", line 28, in call_button
    action = self._call_kw(model, method, args, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\documentos\odoo-17\odoo\addons\web\controllers\dataset.py", line 20, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Documentos\odoo-17\odoo\odoo\api.py", line 468, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Documentos\odoo-17\odoo\odoo\api.py", line 453, in _call_kw_multi
    result = method(recs, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\documentos\odoo-17\odoo\addons\stock\models\stock_picking.py", line 1156, in button_validate
    pickings_to_backorder.with_context(cancel_backorder=False)._action_done()
  File "d:\documentos\odoo-17\odoo\addons\sale_stock\models\stock.py", line 109, in _action_done
    res = super()._action_done()
          ^^^^^^^^^^^^^^^^^^^^^^
  File "d:\documentos\odoo-17\odoo\addons\stock\models\stock_picking.py", line 989, in _action_done
    todo_moves._action_done(cancel_backorder=self.env.context.get('cancel_backorder'))
  File "d:\documentos\odoo-17\odoo\addons\stock_account\models\stock_move.py", line 293, in _action_done
    stock_valuation_layers._validate_accounting_entries()
  File "d:\documentos\odoo-17\odoo\addons\stock_account\models\stock_valuation_layer.py", line 77, in _validate_accounting_entries
    account_moves._post()
TypeError: AccountMove._post() missing 1 required positional argument: 'soft'

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
    RPC_ERROR
        at makeErrorFromResponse (http://localhost:8069/web/assets/e226aa6/web.assets_web.min.js:2888:163)
        at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/e226aa6/web.assets_web.min.js:2892:13)

This is my code:

def _post(self, soft):
    facturas_especiales = self.filtered(lambda factura: factura.factura_especial)
    for factura_especial in facturas_especiales:
        if not factura_especial.journal_id.facturas_especiales:
            raise ValidationError("El diario no está configurado para trabajar con facturas especiales")

move_types = ["fact", "fact_cambiaria", "fact_exportacion", "out_refund"]
por_certificar = self.filtered(
    lambda factura: factura.journal_id.facturacion_activa
    and (factura.tipo_factura in move_types or factura.factura_especial or not factura.tipo_factura)
    and not factura.certificada
)

for factura in por_certificar:
    if self.company_id.proveedor == "infile":
        infile.facturacion_electronica(self, factura)
    elif self.company_id.proveedor == "cofidi":
        cofidi.facturacion_electronica(self, factura)

continuar_movimientos = self.filtered(lambda fact: not fact.certificacion_error)
return super(AccountMove, continuar_movimientos)._post(soft)

Solution

  • Switching a keyword argument to a positional argument could be the problem here.

    Odoo original (e.g. in account module):

    def _post(self, soft=True):
    

    yours:

    def _post(self, soft):
    

    The purchase module's call of that method probably calls it with a keyword argument which would explain the error message "TypeError: AccountMove._post() missing 1 required positional argument: 'soft'". That's because your method is expecting a positional argument, but the call is with a keyword argument.

    Just change your method signature to the original one and everything should be fine.