Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] delivery_product_restriction: migration to 16.0 #333

Open
wants to merge 15 commits into
base: 16.0
Choose a base branch
from

Conversation

huguesdk
Copy link
Member

odoo task

t12912

remytms and others added 6 commits October 25, 2024 17:31
Signed-off-by: Carmen Bianca Bakker <[email protected]>
call super() instead of re-implementing the default logic, to ensure
that other modules can also override it (like
delivery_multi_destination, for instance).
@huguesdk huguesdk force-pushed the 16.0-mig-delivery_product_restriction branch from 80a9395 to b4d1d2f Compare October 28, 2024 10:18
Copy link
Member

@polchampion polchampion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@huguesdk Tested on rotor-v16-test ; I can't get it to work in the backend

[edit] In odoo standard, the delivery method is not displayed on the SO, so not sure how to test the behaviour.

@huguesdk
Copy link
Member Author

huguesdk commented Dec 11, 2024

@polchampion thanks for the functional test. this module only works in the backend. the behavior has changed between version 12.0 and 16.0:

  • in odoo 12.0, the delivery method (carrier_id) can be directly selected on the sale order form, and this is where the restriction happens.
  • in odoo 16.0 (since odoo 13.0), the selection of the carrier has moved to a wizard that must be opened by clicking on the “add shipping” button at the bottom right of the sale order form, just above the total price. this is where the shipping method is restricted.

is this behavior enough or do you think it should behave differently? if you think that it’s ok, i’ll update the readme because i had a hard time understanding again how it is working even though it was i who ported the module. 😅

* refactor to use super() as much as possible instead of copying
  overridden code.
* remove default delivery carrier of the delivery wizards if it cannot
  be used for the sale order.
@polchampion
Copy link
Member

@huguesdk When opening the wizard on this SO, I have the error:

Odoo Server Error
Traceback (most recent call last):
  File "/home/odoomig16/src/odoo/odoo/models.py", line 5174, in ensure_one
    _id, = self._ids
ValueError: not enough values to unpack (expected 1, got 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoomig16/src/odoo/odoo/http.py", line 1638, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/home/odoomig16/src/odoo/odoo/service/model.py", line 133, in retrying
    result = func()
  File "/home/odoomig16/src/odoo/odoo/http.py", line 1665, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/odoomig16/src/odoo/odoo/http.py", line 1869, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/odoomig16/src/odoo/addons/website/models/ir_http.py", line 237, in _dispatch
    response = super()._dispatch(endpoint)
  File "/home/odoomig16/src/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
    result = endpoint(**request.params)
  File "/home/odoomig16/src/odoo/odoo/http.py", line 700, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/odoomig16/src/odoo/addons/web/controllers/dataset.py", line 46, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/home/odoomig16/src/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/odoomig16/src/odoo/odoo/api.py", line 468, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/odoomig16/src/odoo/odoo/api.py", line 453, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/odoomig16/src/coopiteasy/addons/delivery_product_restriction/models/sale_order.py", line 17, in action_open_delivery_wizard
    if not carrier._can_be_used_to_deliver_order_products(self):
  File "/home/odoomig16/src/coopiteasy/addons/delivery_product_restriction/models/delivery_carrier.py", line 21, in _can_be_used_to_deliver_order_products
    return self._can_be_used_to_deliver_products(products)
  File "/home/odoomig16/src/coopiteasy/addons/delivery_product_restriction/models/delivery_carrier.py", line 12, in _can_be_used_to_deliver_products
    self.ensure_one()
  File "/home/odoomig16/src/odoo/odoo/models.py", line 5177, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: delivery.carrier()

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
    RPCError@https://rotordc.mig16.staging.coopiteasy.be/web/assets/220513-38aff56/web.assets_backend.min.js:981:274
    makeErrorFromResponse@https://rotordc.mig16.staging.coopiteasy.be/web/assets/220513-38aff56/web.assets_backend.min.js:985:163
    jsonrpc/promise</<@https://rotordc.mig16.staging.coopiteasy.be/web/assets/220513-38aff56/web.assets_backend.min.js:993:34```

@huguesdk
Copy link
Member Author

huguesdk commented Feb 5, 2025

@polchampion good catch! it is now fixed, would you please try again?

@polchampion
Copy link
Member

@huguesdk The previous error is fixed, but when selecting the carrier "Pick up in store within 2 weeks" on this quotation, I have the following error:

Odoo Server Error
Traceback (most recent call last):
  File "/home/odoomig16/src/odoo/odoo/api.py", line 1007, in get
    cache_value = field_cache[record._ids[0]]
KeyError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoomig16/src/odoo/odoo/fields.py", line 1161, in __get__
    value = env.cache.get(record, self)
  File "/home/odoomig16/src/odoo/odoo/api.py", line 1014, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'choose.delivery.carrier(1,).available_carrier_ids'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoomig16/src/odoo/odoo/http.py", line 1638, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/home/odoomig16/src/odoo/odoo/service/model.py", line 133, in retrying
    result = func()
  File "/home/odoomig16/src/odoo/odoo/http.py", line 1665, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/odoomig16/src/odoo/odoo/http.py", line 1869, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/odoomig16/src/odoo/addons/website/models/ir_http.py", line 237, in _dispatch
    response = super()._dispatch(endpoint)
  File "/home/odoomig16/src/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
    result = endpoint(**request.params)
  File "/home/odoomig16/src/odoo/odoo/http.py", line 700, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/odoomig16/src/odoo/addons/web/controllers/dataset.py", line 42, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/odoomig16/src/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/odoomig16/src/odoo/odoo/api.py", line 468, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/odoomig16/src/odoo/odoo/api.py", line 453, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/odoomig16/src/odoo/odoo/models.py", line 2996, in read
    return self._read_format(fnames=fields, load=load)
  File "/home/odoomig16/src/odoo/odoo/models.py", line 3175, in _read_format
    vals[name] = convert(record[name], record, use_name_get)
  File "/home/odoomig16/src/odoo/odoo/models.py", line 5920, in __getitem__
    return self._fields[key].__get__(self, self.env.registry[self._name])
  File "/home/odoomig16/src/odoo/odoo/fields.py", line 2804, in __get__
    return super().__get__(records, owner)
  File "/home/odoomig16/src/odoo/odoo/fields.py", line 1210, in __get__
    self.compute_value(recs)
  File "/home/odoomig16/src/odoo/odoo/fields.py", line 1392, in compute_value
    records._compute_field_value(self)
  File "/home/odoomig16/src/odoo/odoo/models.py", line 4232, in _compute_field_value
    fields.determine(field.compute, self)
  File "/home/odoomig16/src/odoo/odoo/fields.py", line 98, in determine
    return needle(*args)
  File "/home/odoomig16/src/coopiteasy/addons/delivery_product_restriction/wizards/choose_delivery_carrier.py", line 20, in _compute_available_carrier
    available_carrier_ids = delivery_carrier_model.browse(
  File "/home/odoomig16/src/odoo/odoo/models.py", line 5145, in browse
    ids = tuple(ids)
  File "/home/odoomig16/src/coopiteasy/addons/delivery_product_restriction/wizards/choose_delivery_carrier.py", line 21, in <genexpr>
    r.id.origin for r in rec.available_carrier_ids
AttributeError: 'int' object has no attribute 'origin'

The above server error caused the following client error:
null```

@huguesdk
Copy link
Member Author

huguesdk commented Feb 7, 2025

@polchampion indeed, that was a bug. it should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants