Skip to content

Commit

Permalink
[IMP] l10n_it_delivery_note: link carrier with delivery method
Browse files Browse the repository at this point in the history
  • Loading branch information
renda-dev committed Jan 11, 2024
1 parent 3b88d0a commit 19693e7
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 13 deletions.
2 changes: 1 addition & 1 deletion l10n_it_delivery_note/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ITA - Documento di trasporto
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:48fb8a0d085dce618e7696ef8bdb30aa56d61f48d3db5f895cf477ddf0d3505c
!! source digest: sha256:e389fbd4dff70da2d65271df7684c21141a86b5e861217fe285b4df642e5a57a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
4 changes: 2 additions & 2 deletions l10n_it_delivery_note/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"author": "Marco Calcagni, Gianmarco Conte, Link IT Europe Srl, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-italy",
"version": "14.0.2.5.0",
"version": "14.0.2.6.0",
"category": "Localization/Italy",
"license": "AGPL-3",
"maintainers": ["MarcoCalcagni", "aleuffre", "renda-dev"],
"depends": [
"delivery",
"delivery_carrier_partner",
"l10n_it_delivery_note_base",
"mail",
"sale_stock",
Expand Down
11 changes: 11 additions & 0 deletions l10n_it_delivery_note/migrations/14.0.2.6.0/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
note_ids = env["stock.delivery.note"].search(
[("carrier_id", "!=", False), ("delivery_method_id", "!=", False)]
)

for note_id in note_ids:
note_id.carrier_id.write({"carrier_ids": [(4, note_id.delivery_method_id.id)]})
2 changes: 1 addition & 1 deletion l10n_it_delivery_note/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class ResPartner(models.Model):
default_transport_method_id = fields.Many2one(
"stock.picking.transport.method", string="Method of transport"
)
is_carrier = fields.Boolean("Is Carrier")
carrier_ids = fields.One2many("delivery.carrier", "partner_id", string="Carrier")
2 changes: 1 addition & 1 deletion l10n_it_delivery_note/models/stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _domain_weight_uom(self):
string="Carrier",
states=DONE_READONLY_STATE,
tracking=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
related="delivery_method_id.partner_id",
)
delivery_method_id = fields.Many2one(
"delivery.carrier",
Expand Down
3 changes: 2 additions & 1 deletion l10n_it_delivery_note/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">ITA - Documento di trasporto</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:48fb8a0d085dce618e7696ef8bdb30aa56d61f48d3db5f895cf477ddf0d3505c
!! source digest: sha256:e389fbd4dff70da2d65271df7684c21141a86b5e861217fe285b4df642e5a57a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-italy/tree/14.0/l10n_it_delivery_note"><img alt="OCA/l10n-italy" src="https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-italy-14-0/l10n-italy-14-0-l10n_it_delivery_note"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><strong>English</strong></p>
Expand Down
1 change: 0 additions & 1 deletion l10n_it_delivery_note/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<field name="arch" type="xml">
<xpath expr="//page[@name='sales_purchases']/group" position="inside">
<group string="Shipping information">
<field name="is_carrier" />
<field name="default_goods_appearance_id" widget="selection" />
<field name="default_transport_condition_id" widget="selection" />
<field name="default_transport_reason_id" widget="selection" />
Expand Down
5 changes: 1 addition & 4 deletions l10n_it_delivery_note/views/stock_delivery_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@
</group>
<group>
<group>
<field
name="carrier_id"
domain="[('is_carrier','=', True)]"
/>
<field name="carrier_id" />
<field name="delivery_method_id" />
</group>
<group>
Expand Down
1 change: 0 additions & 1 deletion l10n_it_delivery_note/views/stock_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
<field
name="delivery_note_carrier_id"
attrs="{'readonly': [('delivery_note_readonly', '=', True)]}"
domain="[('is_carrier','=', True)]"
string="Carrier"
/>
<field
Expand Down
12 changes: 12 additions & 0 deletions l10n_it_delivery_note/wizard/delivery_note_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def _domain_type_id(self):
)

error_message = fields.Html(compute="_compute_fields")
warning_message = fields.Char("Warning", readonly=True, compute="_compute_fields")

def _get_validation_errors(self, pickings):
validators = [
Expand All @@ -63,6 +64,16 @@ def _get_validation_errors(self, pickings):

return errors

def _get_warning_message(self):
"""
This method is used to be inherited and extended
to display whatever message could be used to improve the
user experience when creating a delivery note
:return: message to be displayed
"""
return False

@api.depends("selected_picking_ids")
def _compute_fields(self):
try:
Expand All @@ -84,6 +95,7 @@ def _compute_fields(self):
)

else:
self.warning_message = self._get_warning_message()
partners = self.selected_picking_ids.get_partners()
self.partner_sender_id = partners[0]
self.partner_id = partners[1]
Expand Down
13 changes: 12 additions & 1 deletion l10n_it_delivery_note/wizard/delivery_note_select.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2019, Link IT Europe Srl
# @author: Matteo Bilotta <[email protected]>

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


class StockDeliveryNoteSelectWizard(models.TransientModel):
Expand Down Expand Up @@ -37,6 +37,17 @@ def _compute_fields(self):
self.picking_ids += self.selected_picking_ids
else:
self.picking_ids = self.picking_ids
self.warning_message = self._get_warning_message()

Check warning on line 40 in l10n_it_delivery_note/wizard/delivery_note_select.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/wizard/delivery_note_select.py#L40

Added line #L40 was not covered by tests

def _get_warning_message(self):
res = super()._get_warning_message()
carrier_ids = self.picking_ids.mapped("carrier_id.partner_id")

Check warning on line 44 in l10n_it_delivery_note/wizard/delivery_note_select.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/wizard/delivery_note_select.py#L43-L44

Added lines #L43 - L44 were not covered by tests
if len(carrier_ids) > 1:
res = _(

Check warning on line 46 in l10n_it_delivery_note/wizard/delivery_note_select.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/wizard/delivery_note_select.py#L46

Added line #L46 was not covered by tests
"The selected pickings have different delivery methods: %(carriers)s",
carriers=", ".join(carrier_ids.mapped("name")),
)
return res

Check warning on line 50 in l10n_it_delivery_note/wizard/delivery_note_select.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/wizard/delivery_note_select.py#L50

Added line #L50 was not covered by tests

def check_compliance(self, pickings):
super().check_compliance(pickings)
Expand Down
8 changes: 8 additions & 0 deletions l10n_it_delivery_note/wizard/delivery_note_select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
<field name="error_message" />
</div>
<field name="selected_picking_ids" invisible="True" />
<p
class="text-center alert alert-warning"
role="alert"
attrs="{'invisible': [('warning_message', '=', False)]}"
>
<span class="fa fa-warning" />
<field name="warning_message" />
</p>
<div
class="oe_title"
attrs="{'invisible': [('error_message', '!=', False)]}"
Expand Down

0 comments on commit 19693e7

Please sign in to comment.