Skip to content

Commit

Permalink
[FIX]delivery_auto_refresh: Adapt to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
toita86 committed Sep 3, 2024
1 parent 87d34ab commit ba54be3
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 109 deletions.
2 changes: 0 additions & 2 deletions delivery_auto_refresh/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"application": False,
"installable": True,
"depends": ["delivery"],
# Migration Note 17.0: Add dependency to sale_order_carrier_auto_assign
# "depends": ["delivery", "sale_order_carrier_auto_assign"],
"data": [
"data/ir_config_parameter.xml",
"views/sale_order_views.xml",
Expand Down
31 changes: 0 additions & 31 deletions delivery_auto_refresh/migrations/16.0.2.0.0/post-migration.py

This file was deleted.

2 changes: 0 additions & 2 deletions delivery_auto_refresh/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
class ResCompany(models.Model):
_inherit = "res.company"

# Migration Note 17.0: move this to module sale_order_carrier_auto_assign
sale_auto_assign_carrier_on_create = fields.Boolean(
"Set default shipping method automatically"
)
# End migration note

sale_auto_add_delivery_line = fields.Boolean(
"Refresh shipping cost line automatically",
Expand Down
2 changes: 0 additions & 2 deletions delivery_auto_refresh/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

# Migration Note 17.0: move this to module sale_order_carrier_auto_assign
sale_auto_assign_carrier_on_create = fields.Boolean(
related="company_id.sale_auto_assign_carrier_on_create",
readonly=False,
)
# End migration note

sale_auto_add_delivery_line = fields.Boolean(
related="company_id.sale_auto_add_delivery_line",
Expand Down
56 changes: 28 additions & 28 deletions delivery_auto_refresh/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
from odoo import _, api, fields, models


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

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

# End migration note

# Migration Note 17.0: move this section to module sale_order_carrier_auto_assign
def _set_delivery_carrier(self, set_delivery_line=True):
for order in self:
delivery_wiz_action = order.action_open_delivery_wizard()
Expand Down Expand Up @@ -70,8 +66,6 @@ def _is_auto_set_carrier_on_create(self):
return False

Check warning on line 66 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L66

Added line #L66 was not covered by tests
return self.company_id.sale_auto_assign_carrier_on_create

# End migration note

def _is_auto_add_delivery_line(self):
# When we have the context 'website_id' it means that we are doing the order from
# e-commerce. So we don't want to add the delivery line automatically.
Expand All @@ -84,41 +78,49 @@ def _prepare_delivery_line_vals(self, carrier, price_unit):
context = {}
if self.partner_id:
# set delivery detail in the customer language
context['lang'] = self.partner_id.lang
context["lang"] = self.partner_id.lang
carrier = carrier.with_context(lang=self.partner_id.lang)

# Apply fiscal position
taxes = carrier.product_id.taxes_id.filtered(lambda t: t.company_id.id == self.company_id.id)
taxes = carrier.product_id.taxes_id.filtered(
lambda t: t.company_id.id == self.company_id.id
)
taxes_ids = taxes.ids
if self.partner_id and self.fiscal_position_id:
taxes_ids = self.fiscal_position_id.map_tax(taxes).ids

Check warning on line 90 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L90

Added line #L90 was not covered by tests

# Create the sales order line

if carrier.product_id.description_sale:
so_description = '%s: %s' % (carrier.name, carrier.product_id.description_sale)
so_description = "%s: %s" % (

Check warning on line 95 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L95

Added line #L95 was not covered by tests
carrier.name,
carrier.product_id.description_sale,
)
else:
so_description = carrier.name
values = {
'order_id': self.id,
'name': so_description,
'product_uom_qty': 1,
'product_uom': carrier.product_id.uom_id.id,
'product_id': carrier.product_id.id,
'tax_id': [(6, 0, taxes_ids)],
'is_delivery': True,
"order_id": self.id,
"name": so_description,
"product_uom_qty": 1,
"product_uom": carrier.product_id.uom_id.id,
"product_id": carrier.product_id.id,
"tax_id": [(6, 0, taxes_ids)],
"is_delivery": True,
}
if carrier.invoice_policy == 'real':
values['price_unit'] = 0
values['name'] += _(' (Estimated Cost: %s )', self._format_currency_amount(price_unit))
if carrier.invoice_policy == "real":
values["price_unit"] = 0
values["name"] += _(

Check warning on line 112 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L111-L112

Added lines #L111 - L112 were not covered by tests
" (Estimated Cost: %s )", self._format_currency_amount(price_unit)
)
else:
values['price_unit'] = price_unit
if carrier.free_over and self.currency_id.is_zero(price_unit) :
values['name'] += '\n' + _('Free Shipping')
values["price_unit"] = price_unit
if carrier.free_over and self.currency_id.is_zero(price_unit):
values["name"] += "\n" + _("Free Shipping")

Check warning on line 118 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L118

Added line #L118 was not covered by tests
if self.order_line:
values['sequence'] = self.order_line[-1].sequence + 1
values["sequence"] = self.order_line[-1].sequence + 1
del context
return values

# end of the odoo part

def _update_delivery_line(self, delivery_line, price_unit):
Expand All @@ -131,13 +133,13 @@ def _update_delivery_line(self, delivery_line, price_unit):
# Tax is set with a SET command
clear = update = False
for cmd in val:
if cmd[0] == fields.Command.SET:
if cmd[0] == 6:
if delivery_line[f].ids != cmd[2]:
update = True

Check warning on line 138 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L138

Added line #L138 was not covered by tests
else:
clear = True

Check warning on line 140 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L140

Added line #L140 was not covered by tests
if clear:
new_vals[f] = [fields.Command.CLEAR] + val
new_vals[f] = [(5, 0, 0)] + val

Check warning on line 142 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L142

Added line #L142 was not covered by tests
elif update:
new_vals[f] = val

Check warning on line 144 in delivery_auto_refresh/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

delivery_auto_refresh/models/sale_order.py#L144

Added line #L144 was not covered by tests
elif isinstance(field_def, fields.Many2one):
Expand Down Expand Up @@ -194,10 +196,8 @@ def create(self, vals_list):
.with_context(auto_refresh_delivery=False)
)
for order in orders:
# Migration Note 17.0: move this to module sale_order_carrier_auto_assign
if not order.carrier_id and order._is_auto_set_carrier_on_create():
order._set_delivery_carrier()
# End migration note
order._auto_refresh_delivery()
return orders

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

# MIGRATION NOTE for 17.0: Move this to module sale_order_carrier_auto_assign

from odoo.tests import Form, common


Expand Down
75 changes: 33 additions & 42 deletions delivery_auto_refresh/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,47 @@
<field name="model">res.config.settings</field>
<field name="priority" eval="9" />
<field name="inherit_id" ref="sale.res_config_settings_view_form" />
<!-- Migration note 17.0: depend on sale_order_carrier_auto_assign
<field
name="inherit_id"
ref="sale_order_carrier_auto_assign.res_config_settings_view_form_sale"
/>
-->
<field name="arch" type="xml">
<xpath expr="//div[@name='shipping_setting_container']" position="inside">
<!-- Migration note 17.0: depend on sale_order_carrier_auto_assign
<xpath expr="//div[@id='carrier_auto_assign']" position="inside">
-->
<!-- Migration note 17.0: move this to module sale_order_carrier_auto_assign -->
<div class="o_setting_left_pane">
<field name="sale_auto_assign_carrier_on_create" />
</div>
<div class="o_setting_right_pane">
<label for="sale_auto_assign_carrier_on_create" />
<div class="text-muted">
On the sales quotation, add the shipping method on creation.
<div class="col-12 col-lg-6 o_setting_box" id="sale_auto_refresh">
<div class="o_setting_left_pane">
<field name="sale_auto_assign_carrier_on_create" />
</div>
<div class="o_setting_right_pane">
<label for="sale_auto_assign_carrier_on_create" />
<div class="text-muted">
On the sales quotation, add the shipping method on creation.
</div>
</div>
</div>
<!-- End Migratio note -->

<div class="o_setting_left_pane">
<field name="sale_auto_add_delivery_line" />
</div>
<div class="o_setting_right_pane">
<label for="sale_auto_add_delivery_line" />
<div class="text-muted">
On the sales quotation, refresh the shipping cost line when saving
<div class="o_setting_left_pane">
<field name="sale_auto_add_delivery_line" />
</div>
<div class="o_setting_right_pane">
<label for="sale_auto_add_delivery_line" />
<div class="text-muted">
On the sales quotation, refresh the shipping cost line when saving
</div>
</div>
</div>

<div class="o_setting_left_pane">
<field name="sale_refresh_delivery_after_picking" />
</div>
<div class="o_setting_right_pane">
<label for="sale_refresh_delivery_after_picking" />
<div class="text-muted">
After delivering a sales order, update the shipping cost line based on what has been delivered
<div class="o_setting_left_pane">
<field name="sale_refresh_delivery_after_picking" />
</div>
<div class="o_setting_right_pane">
<label for="sale_refresh_delivery_after_picking" />
<div class="text-muted">
After delivering a sales order, update the shipping cost line based on what has been delivered
</div>
</div>
</div>

<div class="o_setting_left_pane">
<field name="sale_auto_void_delivery_line" />
</div>
<div class="o_setting_right_pane">
<label for="sale_auto_void_delivery_line" />
<div class="text-muted">
Void the shipping cost line when the delivery is returned before invoicing
<div class="o_setting_left_pane">
<field name="sale_auto_void_delivery_line" />
</div>
<div class="o_setting_right_pane">
<label for="sale_auto_void_delivery_line" />
<div class="text-muted">
Void the shipping cost line when the delivery is returned before invoicing
</div>
</div>
</div>
</xpath>
Expand Down

0 comments on commit ba54be3

Please sign in to comment.