Skip to content

Commit 317f776

Browse files
committed
[FIX]delivery_auto_refresh: Adapt to 14.0
1 parent 87d34ab commit 317f776

File tree

7 files changed

+61
-109
lines changed

7 files changed

+61
-109
lines changed

delivery_auto_refresh/__manifest__.py

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
"application": False,
1414
"installable": True,
1515
"depends": ["delivery"],
16-
# Migration Note 17.0: Add dependency to sale_order_carrier_auto_assign
17-
# "depends": ["delivery", "sale_order_carrier_auto_assign"],
1816
"data": [
1917
"data/ir_config_parameter.xml",
2018
"views/sale_order_views.xml",

delivery_auto_refresh/migrations/16.0.2.0.0/post-migration.py

-31
This file was deleted.

delivery_auto_refresh/models/res_company.py

-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
class ResCompany(models.Model):
88
_inherit = "res.company"
99

10-
# Migration Note 17.0: move this to module sale_order_carrier_auto_assign
1110
sale_auto_assign_carrier_on_create = fields.Boolean(
1211
"Set default shipping method automatically"
1312
)
14-
# End migration note
1513

1614
sale_auto_add_delivery_line = fields.Boolean(
1715
"Refresh shipping cost line automatically",

delivery_auto_refresh/models/res_config_settings.py

-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
class ResConfigSettings(models.TransientModel):
88
_inherit = "res.config.settings"
99

10-
# Migration Note 17.0: move this to module sale_order_carrier_auto_assign
1110
sale_auto_assign_carrier_on_create = fields.Boolean(
1211
related="company_id.sale_auto_assign_carrier_on_create",
1312
readonly=False,
1413
)
15-
# End migration note
1614

1715
sale_auto_add_delivery_line = fields.Boolean(
1816
related="company_id.sale_auto_add_delivery_line",

delivery_auto_refresh/models/sale_order.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
55

6-
from odoo import api, fields, models, _
6+
from odoo import _, api, fields, models
77

88

99
class SaleOrder(models.Model):
1010
_inherit = "sale.order"
1111

12-
# Migration note: This field is not used anymore and can be dropped in later versions
1312
available_carrier_ids = fields.Many2many(
1413
comodel_name="delivery.carrier",
1514
compute="_compute_available_carrier_ids",
@@ -22,9 +21,6 @@ def _compute_available_carrier_ids(self):
2221
wizard = self.env["choose.delivery.carrier"].new({"order_id": sale.id})
2322
sale.available_carrier_ids = wizard.available_carrier_ids._origin
2423

25-
# End migration note
26-
27-
# Migration Note 17.0: move this section to module sale_order_carrier_auto_assign
2824
def _set_delivery_carrier(self, set_delivery_line=True):
2925
for order in self:
3026
delivery_wiz_action = order.action_open_delivery_wizard()
@@ -70,8 +66,6 @@ def _is_auto_set_carrier_on_create(self):
7066
return False
7167
return self.company_id.sale_auto_assign_carrier_on_create
7268

73-
# End migration note
74-
7569
def _is_auto_add_delivery_line(self):
7670
# When we have the context 'website_id' it means that we are doing the order from
7771
# e-commerce. So we don't want to add the delivery line automatically.
@@ -84,41 +78,49 @@ def _prepare_delivery_line_vals(self, carrier, price_unit):
8478
context = {}
8579
if self.partner_id:
8680
# set delivery detail in the customer language
87-
context['lang'] = self.partner_id.lang
81+
context["lang"] = self.partner_id.lang
8882
carrier = carrier.with_context(lang=self.partner_id.lang)
8983

9084
# Apply fiscal position
91-
taxes = carrier.product_id.taxes_id.filtered(lambda t: t.company_id.id == self.company_id.id)
85+
taxes = carrier.product_id.taxes_id.filtered(
86+
lambda t: t.company_id.id == self.company_id.id
87+
)
9288
taxes_ids = taxes.ids
9389
if self.partner_id and self.fiscal_position_id:
9490
taxes_ids = self.fiscal_position_id.map_tax(taxes).ids
9591

9692
# Create the sales order line
9793

9894
if carrier.product_id.description_sale:
99-
so_description = '%s: %s' % (carrier.name, carrier.product_id.description_sale)
95+
so_description = "%s: %s" % (
96+
carrier.name,
97+
carrier.product_id.description_sale,
98+
)
10099
else:
101100
so_description = carrier.name
102101
values = {
103-
'order_id': self.id,
104-
'name': so_description,
105-
'product_uom_qty': 1,
106-
'product_uom': carrier.product_id.uom_id.id,
107-
'product_id': carrier.product_id.id,
108-
'tax_id': [(6, 0, taxes_ids)],
109-
'is_delivery': True,
102+
"order_id": self.id,
103+
"name": so_description,
104+
"product_uom_qty": 1,
105+
"product_uom": carrier.product_id.uom_id.id,
106+
"product_id": carrier.product_id.id,
107+
"tax_id": [(6, 0, taxes_ids)],
108+
"is_delivery": True,
110109
}
111-
if carrier.invoice_policy == 'real':
112-
values['price_unit'] = 0
113-
values['name'] += _(' (Estimated Cost: %s )', self._format_currency_amount(price_unit))
110+
if carrier.invoice_policy == "real":
111+
values["price_unit"] = 0
112+
values["name"] += _(
113+
" (Estimated Cost: %s )", self._format_currency_amount(price_unit)
114+
)
114115
else:
115-
values['price_unit'] = price_unit
116-
if carrier.free_over and self.currency_id.is_zero(price_unit) :
117-
values['name'] += '\n' + _('Free Shipping')
116+
values["price_unit"] = price_unit
117+
if carrier.free_over and self.currency_id.is_zero(price_unit):
118+
values["name"] += "\n" + _("Free Shipping")
118119
if self.order_line:
119-
values['sequence'] = self.order_line[-1].sequence + 1
120+
values["sequence"] = self.order_line[-1].sequence + 1
120121
del context
121122
return values
123+
122124
# end of the odoo part
123125

124126
def _update_delivery_line(self, delivery_line, price_unit):
@@ -131,13 +133,13 @@ def _update_delivery_line(self, delivery_line, price_unit):
131133
# Tax is set with a SET command
132134
clear = update = False
133135
for cmd in val:
134-
if cmd[0] == fields.Command.SET:
136+
if cmd[0] == 6:
135137
if delivery_line[f].ids != cmd[2]:
136138
update = True
137139
else:
138140
clear = True
139141
if clear:
140-
new_vals[f] = [fields.Command.CLEAR] + val
142+
new_vals[f] = [(5, 0, 0)] + val
141143
elif update:
142144
new_vals[f] = val
143145
elif isinstance(field_def, fields.Many2one):
@@ -194,10 +196,8 @@ def create(self, vals_list):
194196
.with_context(auto_refresh_delivery=False)
195197
)
196198
for order in orders:
197-
# Migration Note 17.0: move this to module sale_order_carrier_auto_assign
198199
if not order.carrier_id and order._is_auto_set_carrier_on_create():
199200
order._set_delivery_carrier()
200-
# End migration note
201201
order._auto_refresh_delivery()
202202
return orders
203203

delivery_auto_refresh/tests/test_sale_order_carrier_auto_assign.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
33

4-
# MIGRATION NOTE for 17.0: Move this to module sale_order_carrier_auto_assign
5-
64
from odoo.tests import Form, common
75

86

delivery_auto_refresh/views/res_config_settings_views.xml

+33-42
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,47 @@
55
<field name="model">res.config.settings</field>
66
<field name="priority" eval="9" />
77
<field name="inherit_id" ref="sale.res_config_settings_view_form" />
8-
<!-- Migration note 17.0: depend on sale_order_carrier_auto_assign
9-
<field
10-
name="inherit_id"
11-
ref="sale_order_carrier_auto_assign.res_config_settings_view_form_sale"
12-
/>
13-
-->
148
<field name="arch" type="xml">
159
<xpath expr="//div[@name='shipping_setting_container']" position="inside">
16-
<!-- Migration note 17.0: depend on sale_order_carrier_auto_assign
17-
<xpath expr="//div[@id='carrier_auto_assign']" position="inside">
18-
-->
19-
<!-- Migration note 17.0: move this to module sale_order_carrier_auto_assign -->
20-
<div class="o_setting_left_pane">
21-
<field name="sale_auto_assign_carrier_on_create" />
22-
</div>
23-
<div class="o_setting_right_pane">
24-
<label for="sale_auto_assign_carrier_on_create" />
25-
<div class="text-muted">
26-
On the sales quotation, add the shipping method on creation.
10+
<div class="col-12 col-lg-6 o_setting_box" id="sale_auto_refresh">
11+
<div class="o_setting_left_pane">
12+
<field name="sale_auto_assign_carrier_on_create" />
13+
</div>
14+
<div class="o_setting_right_pane">
15+
<label for="sale_auto_assign_carrier_on_create" />
16+
<div class="text-muted">
17+
On the sales quotation, add the shipping method on creation.
18+
</div>
2719
</div>
28-
</div>
29-
<!-- End Migratio note -->
3020

31-
<div class="o_setting_left_pane">
32-
<field name="sale_auto_add_delivery_line" />
33-
</div>
34-
<div class="o_setting_right_pane">
35-
<label for="sale_auto_add_delivery_line" />
36-
<div class="text-muted">
37-
On the sales quotation, refresh the shipping cost line when saving
21+
<div class="o_setting_left_pane">
22+
<field name="sale_auto_add_delivery_line" />
23+
</div>
24+
<div class="o_setting_right_pane">
25+
<label for="sale_auto_add_delivery_line" />
26+
<div class="text-muted">
27+
On the sales quotation, refresh the shipping cost line when saving
28+
</div>
3829
</div>
39-
</div>
4030

41-
<div class="o_setting_left_pane">
42-
<field name="sale_refresh_delivery_after_picking" />
43-
</div>
44-
<div class="o_setting_right_pane">
45-
<label for="sale_refresh_delivery_after_picking" />
46-
<div class="text-muted">
47-
After delivering a sales order, update the shipping cost line based on what has been delivered
31+
<div class="o_setting_left_pane">
32+
<field name="sale_refresh_delivery_after_picking" />
33+
</div>
34+
<div class="o_setting_right_pane">
35+
<label for="sale_refresh_delivery_after_picking" />
36+
<div class="text-muted">
37+
After delivering a sales order, update the shipping cost line based on what has been delivered
38+
</div>
4839
</div>
49-
</div>
5040

51-
<div class="o_setting_left_pane">
52-
<field name="sale_auto_void_delivery_line" />
53-
</div>
54-
<div class="o_setting_right_pane">
55-
<label for="sale_auto_void_delivery_line" />
56-
<div class="text-muted">
57-
Void the shipping cost line when the delivery is returned before invoicing
41+
<div class="o_setting_left_pane">
42+
<field name="sale_auto_void_delivery_line" />
43+
</div>
44+
<div class="o_setting_right_pane">
45+
<label for="sale_auto_void_delivery_line" />
46+
<div class="text-muted">
47+
Void the shipping cost line when the delivery is returned before invoicing
48+
</div>
5849
</div>
5950
</div>
6051
</xpath>

0 commit comments

Comments
 (0)