Skip to content

Commit

Permalink
[MIG] delivery_carrier_pricelist: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chaule97 committed Dec 27, 2024
1 parent 2529f99 commit 6bff3f5
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 37 deletions.
4 changes: 3 additions & 1 deletion delivery_carrier_pricelist/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ Contributors

- Guewen Baconnier <[email protected]>
- Phuc Tran Thanh <[email protected]>
- Chau Le <[email protected]>

Other credits
-------------

The development of this module has been financially supported by:
The development and migration of this module has been financially
supported by:

- Camptocamp

Expand Down
4 changes: 2 additions & 2 deletions delivery_carrier_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{
"name": "Shipping Method Pricelist",
"summary": "Compute method method fees based on the product's pricelist.",
"version": "16.0.1.0.2",
"version": "18.0.1.0.0",
"category": "Delivery",
"website": "https://github.com/OCA/delivery-carrier",
"author": "Camptocamp, Odoo Community Association (OCA)",
"installable": True,
"license": "AGPL-3",
"depends": ["delivery"],
"depends": ["stock_delivery"],
"data": ["security/ir.model.access.csv"],
}
42 changes: 17 additions & 25 deletions delivery_carrier_pricelist/models/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# Copyright 2020 Camptocamp
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


from odoo import _, api, fields, models
from odoo.osv import expression
from odoo.tools.safe_eval import safe_eval

from odoo.addons.base.models.ir_ui_view import (
transfer_modifiers_to_node,
transfer_node_to_modifiers,
)
from odoo import api, fields, models


class DeliveryCarrier(models.Model):
Expand Down Expand Up @@ -77,7 +69,7 @@ def pricelist_rate_shipment(self, order):
return {
"success": False,
"price": 0.0,
"error_message": _(
"error_message": self.env._(
"Error: this delivery method is not available for this address."
),
"warning_message": False,
Expand Down Expand Up @@ -114,32 +106,32 @@ def _get_view(self, view_id=None, view_type="form", **options):
arch = self._fields_view_get_adapt_attrs(arch)
return arch, view

@property
def attrs_list(self):
return ["invisible", "required", "readonly"]

def _add_pricelist_domain(
self,
doc,
xpath_expr,
attrs_key,
domain_operator=expression.OR,
field_operator="=",
domain_operator="or",
field_operator="==",
):
"""Add the delivery type domain for 'pricelist' in attrs"""

if attrs_key not in self.attrs_list:
return

Check warning on line 124 in delivery_carrier_pricelist/models/delivery_carrier.py

View check run for this annotation

Codecov / codecov/patch

delivery_carrier_pricelist/models/delivery_carrier.py#L124

Added line #L124 was not covered by tests

nodes = doc.xpath(xpath_expr)
for field in nodes:
attrs = safe_eval(field.attrib.get("attrs", "{}"))
if not attrs.get(attrs_key):
domain = field.attrib.get(attrs_key, "")
if not domain:
continue

invisible_domain = domain_operator(
[attrs[attrs_key], [("delivery_type", field_operator, "pricelist")]]
)
attrs[attrs_key] = invisible_domain
field.set("attrs", str(attrs))
modifiers = {}
transfer_node_to_modifiers(
field,
modifiers,
)
transfer_modifiers_to_node(modifiers, field)
delivery_type_domain = f"delivery_type {field_operator} 'pricelist'"
domain = f"{domain} {domain_operator} {delivery_type_domain}"
field.set(attrs_key, domain)

def _fields_view_get_adapt_attrs(self, view_arch):
"""Adapt the attrs of elements in the view with 'pricelist' delivery type"""
Expand Down
3 changes: 1 addition & 2 deletions delivery_carrier_pricelist/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo.osv import expression


class StockPicking(models.Model):
Expand Down Expand Up @@ -30,7 +29,7 @@ def _fields_view_get_adapt_attrs(self, view_arch):
view_arch,
"//field[@name='partner_id']",
"required",
domain_operator=expression.AND,
domain_operator="and",
field_operator="!=",
)
return view_arch

Check warning on line 35 in delivery_carrier_pricelist/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_carrier_pricelist/models/stock_picking.py#L35

Added line #L35 was not covered by tests
1 change: 1 addition & 0 deletions delivery_carrier_pricelist/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Guewen Baconnier \<<[email protected]>\>
- Phuc Tran Thanh \<<[email protected]>\>
- Chau Le \<<[email protected]>\>
2 changes: 1 addition & 1 deletion delivery_carrier_pricelist/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
The development of this module has been financially supported by:
The development and migration of this module has been financially supported by:

- Camptocamp
4 changes: 3 additions & 1 deletion delivery_carrier_pricelist/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,13 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Guewen Baconnier &lt;<a class="reference external" href="mailto:guewen.baconnier&#64;camptocamp.com">guewen.baconnier&#64;camptocamp.com</a>&gt;</li>
<li>Phuc Tran Thanh &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</li>
<li>Chau Le &lt;<a class="reference external" href="mailto:chaulb&#64;trobz.com">chaulb&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<p>The development of this module has been financially supported by:</p>
<p>The development and migration of this module has been financially
supported by:</p>
<ul class="simple">
<li>Camptocamp</li>
</ul>
Expand Down
13 changes: 9 additions & 4 deletions delivery_carrier_pricelist/tests/test_delivery_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@

from lxml import etree

from odoo.tests.common import Form, TransactionCase
from odoo.tests import Form

from odoo.addons.base.tests.common import BaseCommon

class TestCarrierPricelist(TransactionCase):

class TestCarrierPricelist(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.partner_18 = cls.env.ref("base.res_partner_18")
cls.product_4 = cls.env.ref("product.product_product_4")
cls.product_uom_unit = cls.env.ref("uom.product_uom_unit")
cls.pricelist = cls.env.ref("product.list0")
cls.pricelist = cls.env["product.pricelist"].create(
{
"name": "Public Pricelist",
}
)
cls.sale_normal_delivery_charges = cls.env["sale.order"].create(
{
"partner_id": cls.partner_18.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _fields_view_get_adapt_attrs(self, view_arch):
def _onchange_carrier_id(self):
self.delivery_message = False
if "pricelist" in (self.delivery_type, self.invoice_policy):
vals = self._get_shipment_rate()
vals = self._get_delivery_rate()
if vals.get("error_message"):
return {"error": vals["error_message"]}
else:
Expand Down

0 comments on commit 6bff3f5

Please sign in to comment.