Skip to content

Commit

Permalink
[17.0][MIG] base_delivery_carrier_label: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Luis-Mora authored and yankinmax committed Jun 17, 2024
1 parent f38d652 commit 99e3d58
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 69 deletions.
4 changes: 4 additions & 0 deletions base_delivery_carrier_label/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Contributors
- Dave Lasley <dave@laslabs.com>
- Timothée Ringeard <timothee.ringeard@camptocamp.com>
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
- Maksym Yankin <maksym.yankin@camptocamp.com>
- `Binhex <https://binhex.cloud//com>`__:

- David Luis Mora <d.luis@binhex.cloud>

Maintainers
-----------
Expand Down
4 changes: 2 additions & 2 deletions base_delivery_carrier_label/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Base module for carrier labels",
"version": "16.0.1.1.1",
"version": "17.0.1.0.0",
"author": "Camptocamp,Akretion,Odoo Community Association (OCA)",
"maintainer": "Camptocamp",
"category": "Delivery",
"depends": [
"delivery",
"stock_delivery",
"delivery_carrier_info",
],
"website": "https://github.com/OCA/delivery-carrier",
Expand Down
2 changes: 1 addition & 1 deletion base_delivery_carrier_label/models/delivery_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def send_shipping(self, pickings):
result = super().send_shipping(pickings)
if not result:
result = self.alternative_send_shipping(pickings)
for result_dict, picking in zip(result, pickings):
for result_dict, picking in zip(result, pickings, strict=False):
for label in result_dict.get("labels", []):
picking.attach_shipping_label(label)
return result
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class DeliveryCarrierTemplateOption(models.Model):
_description = "Delivery carrier template option"

partner_id = fields.Many2one(comodel_name="res.partner", string="Partner Carrier")
name = fields.Char(readonly=True)
code = fields.Char(readonly=True)
name = fields.Char()
code = fields.Char()
description = fields.Char(
readonly=True,
help="Allow to define a more complete description " "than in the name field.",
)
4 changes: 2 additions & 2 deletions base_delivery_carrier_label/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def get_weight(self):
"Type conversion not implemented for product %s", product.id
)
cant_calc_total = True
# reserved_qty may be 0 if you don't set move line
# quantity_product_uom may be 0 if you don't set move line
# individually but directly validate the picking
qty = operation.qty_done or operation.reserved_qty
qty = operation.quantity or operation.quantity_product_uom
operation.weight = product.weight * qty

total_weight += operation.weight
Expand Down
1 change: 0 additions & 1 deletion base_delivery_carrier_label/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class StockPicking(models.Model):
carrier_id = fields.Many2one(
comodel_name="delivery.carrier",
string="Carrier",
states={"done": [("readonly", True)]},
)
carrier_code = fields.Char(related="carrier_id.code", readonly=True)
option_ids = fields.Many2many(
Expand Down
5 changes: 3 additions & 2 deletions base_delivery_carrier_label/models/stock_quant_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StockQuantPackage(models.Model):
help="Link to the carrier's tracking page for this package."
)

@api.depends("shipping_weight")
@api.depends("shipping_weight", "quant_ids", "package_type_id")
def _compute_weight(self):
"""Use shipping_weight if defined
otherwise fallback on the computed weight
Expand All @@ -22,7 +22,7 @@ def _compute_weight(self):
for pack in self:
if pack.shipping_weight:
pack.weight = pack.shipping_weight
elif not pack.quant_ids and not self.env.context.get("picking_id"):
elif pack.quant_ids and not self.env.context.get("picking_id"):
# package.pack_operations would be too easy
operations = self.env["stock.move.line"].search(
[
Expand All @@ -31,6 +31,7 @@ def _compute_weight(self):
("product_id", "!=", False),
]
)

pack.weight = operations.get_weight()
else:
to_do |= pack
Expand Down
3 changes: 3 additions & 0 deletions base_delivery_carrier_label/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
- Dave Lasley \<<dave@laslabs.com>\>
- Timothée Ringeard \<<timothee.ringeard@camptocamp.com>\>
- Pimolnat Suntian \<<pimolnats@ecosoft.co.th>\>
- Maksym Yankin \<<maksym.yankin@camptocamp.com>\>
- [Binhex](https://binhex.cloud//com):
- David Luis Mora \<<d.luis@binhex.cloud>\>
16 changes: 12 additions & 4 deletions base_delivery_carrier_label/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -439,12 +440,19 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Dave Lasley &lt;<a class="reference external" href="mailto:dave&#64;laslabs.com">dave&#64;laslabs.com</a>&gt;</li>
<li>Timothée Ringeard &lt;<a class="reference external" href="mailto:timothee.ringeard&#64;camptocamp.com">timothee.ringeard&#64;camptocamp.com</a>&gt;</li>
<li>Pimolnat Suntian &lt;<a class="reference external" href="mailto:pimolnats&#64;ecosoft.co.th">pimolnats&#64;ecosoft.co.th</a>&gt;</li>
<li>Maksym Yankin &lt;<a class="reference external" href="mailto:maksym.yankin&#64;camptocamp.com">maksym.yankin&#64;camptocamp.com</a>&gt;</li>
<li><a class="reference external" href="https://binhex.cloud//com">Binhex</a>:<ul>
<li>David Luis Mora &lt;<a class="reference external" href="mailto:d.luis&#64;binhex.cloud">d.luis&#64;binhex.cloud</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
4 changes: 2 additions & 2 deletions base_delivery_carrier_label/tests/carrier_label_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class CarrierLabelCase(TransactionCase):
"""Base class for carrier label tests. Inherit and override _get_carrier
to return the carrier you want to test"""

def setUp(self, *args, **kwargs):
super().setUp(*args, **kwargs)
def setUpClass(self):
super().setUpClass(self)
self._create_order_picking()

@property
Expand Down
16 changes: 8 additions & 8 deletions base_delivery_carrier_label/tests/test_get_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_get_weight(self):
operations |= self._create_operation(
picking,
{
"reserved_uom_qty": 1,
"quantity": 1,
"product_id": product.id,
"product_uom_id": product.uom_id.id,
"result_package_id": package.id,
Expand All @@ -90,7 +90,7 @@ def test_get_weight(self):
for operation in operations:
self.assertEqual(
operation.get_weight(),
operation.product_id.weight * operation.reserved_uom_qty,
operation.product_id.weight * operation.quantity_product_uom,
)

# test package.weight
Expand All @@ -109,7 +109,7 @@ def test_total_weight(self):
operations |= self._create_operation(
picking,
{
"reserved_uom_qty": 1,
"quantity": 1,
"product_id": product.id,
"product_uom_id": product.uom_id.id,
"result_package_id": package.id,
Expand All @@ -122,7 +122,7 @@ def test_total_weight(self):
for operation in operations:
self.assertEqual(
operation.get_weight(),
operation.product_id.weight * operation.reserved_uom_qty,
operation.product_id.weight * operation.quantity_product_uom,
)

# test package.weight
Expand All @@ -136,11 +136,11 @@ def test_get_weight_with_qty(self):
picking = self._generate_picking(products)
package = self.env["stock.quant.package"].create({})
operations = self.env["stock.move.line"]
for idx, product in enumerate(products):
for idx, product in enumerate(products, start=1):
operations |= self._create_operation(
picking,
{
"reserved_uom_qty": idx, # nice one
"quantity": idx, # nice one
"product_id": product.id,
"product_uom_id": product.uom_id.id,
"result_package_id": package.id,
Expand All @@ -152,7 +152,7 @@ def test_get_weight_with_qty(self):
for operation in operations:
self.assertEqual(
operation.get_weight(),
operation.product_id.weight * operation.reserved_uom_qty,
operation.product_id.weight * operation.quantity_product_uom,
)

# test package._weight
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_get_weight_with_uom(self):
operations |= self._create_operation(
picking,
{
"reserved_uom_qty": 1,
"quantity": 1,
"product_id": product.id,
"product_uom_id": product.uom_id.id,
"result_package_id": package.id,
Expand Down
7 changes: 4 additions & 3 deletions base_delivery_carrier_label/tests/test_manifest_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@


class ManifestWizardCase(TransactionCase):
def setUp(self):
super(ManifestWizardCase, self).setUp()
self.free_delivery = self.env.ref("delivery.free_delivery_carrier")
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.free_delivery = cls.env.ref("delivery.free_delivery_carrier")

def test_wizard(self):
"""Create manifest wizard."""
Expand Down
10 changes: 5 additions & 5 deletions base_delivery_carrier_label/tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import base64
from unittest import mock

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


class TestSend(TransactionCase):
Expand All @@ -12,13 +12,13 @@ class TestSend(TransactionCase):
def test_send(self):
"""Test if the module picks up labels returned from delivery.carrier#send"""
carrier = self.env.ref("delivery.delivery_carrier")
picking_form = Form(
self.env["stock.picking"].with_context(
picking = (
self.env["stock.picking"]
.with_context(
default_picking_type_id=self.env.ref("stock.picking_type_out").id,
)
.create({"carrier_id": carrier.id})
)
picking_form.carrier_id = carrier
picking = picking_form.save()
package = self.env["stock.quant.package"].create({})

with mock.patch.object(type(carrier), "base_on_rule_send_shipping") as mocked:
Expand Down
27 changes: 9 additions & 18 deletions base_delivery_carrier_label/views/delivery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<form string="delivery_carrier_option">
<group>
<group>
<field name="name" />
<field name="name" readonly="True" />
</group>
<group>
<field name="partner_id" />
<field name="code" />
<field name="code" readonly="True" />
</group>
<field name="description" />
<field name="description" readonly="True" />
</group>
</form>
</field>
Expand All @@ -27,8 +27,8 @@
<field name="arch" type="xml">
<tree>
<field name="partner_id" />
<field name="code" />
<field name="name" />
<field name="code" readonly="True" />
<field name="name" readonly="True" />
</tree>
</field>
</record>
Expand All @@ -41,21 +41,12 @@
<group>
<group>
<field name="active" />
<field
name="mandatory"
attrs="{'readonly': [('readonly_flag','=',True)]}"
/>
<field
name="by_default"
attrs="{'invisible': [('mandatory', '=', True)]}"
/>
<field name="readonly_flag" attrs="{'invisible': True}" />
<field name="mandatory" readonly="readonly_flag" />
<field name="by_default" invisible="mandatory" />
<field name="readonly_flag" invisible="True" />
</group>
<group>
<field
name="tmpl_option_id"
attrs="{'readonly': [('readonly_flag','=',True)]}"
/>
<field name="tmpl_option_id" readonly="readonly_flag" />
</group>
<newline />
<field name="description" readonly="True" />
Expand Down
11 changes: 7 additions & 4 deletions base_delivery_carrier_label/views/stock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<!-- FORM -->
<record id="view_picking_withcarrier_out_form" model="ir.ui.view">
<field name="model">stock.picking</field>
<field name="inherit_id" ref="delivery.view_picking_withcarrier_out_form" />
<field
name="inherit_id"
ref="stock_delivery.view_picking_withcarrier_out_form"
/>
<field name="arch" type="xml">
<xpath expr="//page//field[@name='carrier_id']" position="after">
<field name="carrier_code" />
Expand All @@ -19,7 +22,7 @@
</record>
<record id="vpicktree" model="ir.ui.view">
<field name="model">stock.picking</field>
<field name="inherit_id" ref="delivery.vpicktree_view_tree" />
<field name="inherit_id" ref="stock_delivery.vpicktree_view_tree" />
<field name="arch" type="xml">
<field name="carrier_id" position="attributes">
<attribute name="optional">show</attribute>
Expand All @@ -42,7 +45,7 @@
class="oe_stat_button"
icon='fa-truck'
string="Tracking"
attrs="{'invisible': [('parcel_tracking','=',False)]}"
invisible="not parcel_tracking"
/>
</div>
</field>
Expand All @@ -58,7 +61,7 @@
icon='fa-truck'
title="Carrier Tracking URL"
string=""
attrs="{'invisible': [('parcel_tracking','=',False)]}"
invisible="not parcel_tracking"
/>
<field name="parcel_tracking" />
<field name="weight" />
Expand Down
8 changes: 3 additions & 5 deletions base_delivery_carrier_label/wizard/manifest_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ class ManifestWizard(models.TransientModel):
carrier_id = fields.Many2one(
comodel_name="delivery.carrier",
string="Carrier",
states={"done": [("readonly", True)]},
required=True,
)
from_date = fields.Datetime(required=True)
to_date = fields.Datetime()
file_out = fields.Binary("Manifest", readonly=True)
filename = fields.Char("File Name", readonly=True)
notes = fields.Text("Result", readonly=True)
file_out = fields.Binary("Manifest")
filename = fields.Char("File Name")
notes = fields.Text("Result")
state = fields.Selection(
[("init", "Init"), ("file", "File"), ("end", "END")],
readonly=True,
default="init",
)

Expand Down
Loading

0 comments on commit 99e3d58

Please sign in to comment.