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 19, 2024
1 parent ddcc55d commit 7bf1c8e
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 17 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:4d827f40aab684341e020ef60c38d39d7d79e99e0bd0a8da9ba844af85654859
!! source digest: sha256:f9bd2d08712fb141b78c5240867f1c672c3d6f693c345e8b3feabf2d2bcf4ec7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
9 changes: 7 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.3",
"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 All @@ -41,10 +41,15 @@
"views/stock_picking.xml",
"views/portal_templates.xml",
"views/portal_my_delivery_notes.xml",
"wizard/delivery_note_confirm.xml",
"wizard/delivery_note_create.xml",
"wizard/delivery_note_invoice.xml",
"wizard/delivery_note_select.xml",
"wizard/delivery_note_template.xml",
"wizard/sale_advance_payment_inv.xml",
],
"demo": [
"demo/res_partner_demo.xml",
"demo/delivery_carrier_demo.xml",
],
}
3 changes: 2 additions & 1 deletion l10n_it_delivery_note/cli/migrate_l10n_it_ddt.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def vals_getter(record):
"type_id": self._document_types[record.ddt_type_id].id,
"date": record.date,
"carrier_id": record.carrier_id.id,
"delivery_method_id": record.partner_id.property_delivery_carrier_id.id,
"delivery_method_id": record.picking_ids.mapped("carrier_id")[:1].id
or record.partner_id.property_delivery_carrier_id.id,
"transport_datetime": record.date_done,
"packages": record.parcels,
"volume": record.volume,
Expand Down
14 changes: 14 additions & 0 deletions l10n_it_delivery_note/demo/delivery_carrier_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="delivery.delivery_carrier" model="delivery.carrier">
<field name="partner_id" ref="l10n_it_delivery_note.partner_carrier_1" />
</record>

<record id="delivery.free_delivery_carrier" model="delivery.carrier">
<field name="partner_id" ref="l10n_it_delivery_note.partner_carrier_1" />
</record>

<record id="delivery.normal_delivery_carrier" model="delivery.carrier">
<field name="partner_id" ref="l10n_it_delivery_note.partner_carrier_2" />
</record>
</odoo>
10 changes: 10 additions & 0 deletions l10n_it_delivery_note/demo/res_partner_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="partner_carrier_1" model="res.partner">
<field name="name">Carrier 1</field>
</record>

<record id="partner_carrier_2" model="res.partner">
<field name="name">Carrier 2</field>
</record>
</odoo>
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.delivery_method_id.write({"partner_id": note_id.carrier_id.id})
1 change: 0 additions & 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,3 @@ class ResPartner(models.Model):
default_transport_method_id = fields.Many2one(
"stock.picking.transport.method", string="Method of transport"
)
is_carrier = fields.Boolean("Is Carrier")
42 changes: 40 additions & 2 deletions l10n_it_delivery_note/models/stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def _domain_weight_uom(self):
string="Carrier",
states=DONE_READONLY_STATE,
tracking=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
)
delivery_method_id = fields.Many2one(
"delivery.carrier",
Expand Down Expand Up @@ -364,6 +363,10 @@ def _compute_weights(self):
def _onchange_picking_ids(self):
self._compute_weights()

@api.onchange("delivery_method_id")
def _onchange_delivery_method_id(self):
self.carrier_id = self.delivery_method_id.partner_id

Check warning on line 368 in l10n_it_delivery_note/models/stock_delivery_note.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/models/stock_delivery_note.py#L368

Added line #L368 was not covered by tests

def _inverse_set_pickings(self):
for note in self:
if note.pickings_picker:
Expand Down Expand Up @@ -532,7 +535,7 @@ def action_draft(self):
self.write({"state": DOMAIN_DELIVERY_NOTE_STATES[0]})
self.line_ids.sync_invoice_status()

def action_confirm(self):
def _action_confirm(self):
for note in self:
sequence = note.type_id.sequence_id

Expand All @@ -546,6 +549,41 @@ def action_confirm(self):
).next_by_id()
note.sequence_id = sequence

def action_confirm(self):
for note in self:
warning_message = False
carrier_ids = note.mapped("picking_ids.carrier_id")
transporter_ids = carrier_ids.mapped("partner_id")
if len(transporter_ids) > 1:
warning_message = _(

Check warning on line 558 in l10n_it_delivery_note/models/stock_delivery_note.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/models/stock_delivery_note.py#L558

Added line #L558 was not covered by tests
"This delivery note contains pickings related to different transporters. "
"Are you sure you want to proceed? \nTransporters: %(transporters)s",
transporters=", ".join(transporter_ids.mapped("name")),
)
elif len(carrier_ids) > 1:
warning_message = _(

Check warning on line 564 in l10n_it_delivery_note/models/stock_delivery_note.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/models/stock_delivery_note.py#L564

Added line #L564 was not covered by tests
"This delivery note contains pickings related to different "
"delivery methods from the same transporter. "
"Are you sure you want to proceed? \nDelivery Methods: %(carriers)s",
carriers=", ".join(carrier_ids.mapped("name")),
)
if warning_message:
return {

Check warning on line 571 in l10n_it_delivery_note/models/stock_delivery_note.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/models/stock_delivery_note.py#L571

Added line #L571 was not covered by tests
"type": "ir.actions.act_window",
"name": _("Warning"),
"res_model": "stock.delivery.note.confirm.wizard",
"view_type": "form",
"target": "new",
"view_mode": "form",
"context": {
"default_delivery_note_id": note.id,
"default_warning_message": warning_message,
**self._context,
},
}
else:
note._action_confirm()

def _check_delivery_notes_before_invoicing(self):
for delivery_note_id in self:
if not delivery_note_id.sale_ids:
Expand Down
10 changes: 9 additions & 1 deletion l10n_it_delivery_note/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class StockPicking(models.Model):
string="DN Operation Type", related="picking_type_id.code"
)

carrier_partner_id = fields.Many2one("res.partner", related="carrier_id.partner_id")

use_delivery_note = fields.Boolean(compute="_compute_boolean_flags")
use_advanced_behaviour = fields.Boolean(compute="_compute_boolean_flags")
delivery_note_exists = fields.Boolean(compute="_compute_boolean_flags")
Expand Down Expand Up @@ -141,6 +143,10 @@ def _compute_boolean_flags(self):
)
picking.can_be_invoiced = bool(picking.delivery_note_id.sale_ids)

@api.onchange("delivery_method_id")
def _onchange_delivery_method_id(self):
self.delivery_note_carrier_id = self.delivery_method_id.partner_id

@api.onchange("delivery_note_type_id")
def _onchange_delivery_note_type(self):
if self.delivery_note_type_id:
Expand Down Expand Up @@ -336,6 +342,7 @@ def _create_delivery_note(self):
],
limit=1,
)
delivery_method_id = self.mapped("carrier_id")[:1]
return self.env["stock.delivery.note"].create(
{
"company_id": self.company_id.id,
Expand All @@ -346,7 +353,8 @@ def _create_delivery_note(self):
"partner_shipping_id": partners[1].id,
"type_id": type_id.id,
"date": self.date_done,
"delivery_method_id": self.partner_id.property_delivery_carrier_id.id,
"carrier_id": delivery_method_id.partner_id.id,
"delivery_method_id": delivery_method_id.id,
"transport_condition_id": (
self.sale_id.default_transport_condition_id.id
or partners[1].default_transport_condition_id.id
Expand Down
2 changes: 2 additions & 0 deletions l10n_it_delivery_note/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ access_stock_delivery_note_line_portal,stock.delivery.note.line.portal,l10n_it_d
access_stock_delivery_note_type_user,access_stock_delivery_note_type user,l10n_it_delivery_note_base.model_stock_delivery_note_type,stock.group_stock_user,1,0,0,0
access_stock_delivery_note_type_manager,access_stock_delivery_note_type manager,l10n_it_delivery_note_base.model_stock_delivery_note_type,stock.group_stock_manager,1,1,1,1
access_stock_delivery_note_type_user_account,access_stock_delivery_note_type user_account,l10n_it_delivery_note_base.model_stock_delivery_note_type,account.group_account_invoice,1,0,0,0
access_stock_delivery_note_confirm_wizard_manager,access_stock_delivery_note_confirm_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_confirm_wizard,,1,1,1,1
access_stock_delivery_note_create_wizard_manager,access_stock_delivery_note_create_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_create_wizard,,1,1,1,1
access_stock_delivery_note_select_wizard_manager,access_stock_delivery_note_select_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_select_wizard,,1,1,1,1
access_stock_delivery_note_base_wizard_manager,access_stock_delivery_note_base_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_base_wizard,,1,1,1,1
access_stock_delivery_note_invoice_wizard_manager,access_stock_delivery_note_invoice_wizard manager,l10n_it_delivery_note.model_stock_delivery_note_invoice_wizard,,1,1,1,1
access_delivery_carrier_portal,delivery.carrier portal,delivery.model_delivery_carrier,base.group_portal,1,0,0,0
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:4d827f40aab684341e020ef60c38d39d7d79e99e0bd0a8da9ba844af85654859
!! source digest: sha256:f9bd2d08712fb141b78c5240867f1c672c3d6f693c345e8b3feabf2d2bcf4ec7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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
7 changes: 3 additions & 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 Expand Up @@ -421,6 +418,8 @@
/>
<field name="scheduled_date" readonly="True" />
<field name="origin" />
<field name="carrier_id" string="Delivery Method" />
<field name="carrier_partner_id" />
<field name="backorder_id" />
<field name="state" />
</tree>
Expand Down
4 changes: 3 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 Expand Up @@ -356,6 +355,9 @@
<field name="delivery_note_state" optional="show" />
<field name="delivery_note_date" optional="show" />
</field>
<field name="partner_id" position="after">
<field name="carrier_id" string="Delivery Method" />
</field>
</field>
</record>

Expand Down
1 change: 1 addition & 0 deletions l10n_it_delivery_note/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import delivery_note_base
from . import delivery_note_confirm
from . import delivery_note_create
from . import delivery_note_invoice
from . import delivery_note_select
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
17 changes: 17 additions & 0 deletions l10n_it_delivery_note/wizard/delivery_note_confirm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2019, Link IT Europe Srl
# @author: Matteo Bilotta <mbilotta@linkeurope.it>


from odoo import fields, models


class StockDeliveryNoteCreateWizard(models.TransientModel):
_name = "stock.delivery.note.confirm.wizard"
_description = "Delivery Note Confirm"

delivery_note_id = fields.Many2one("stock.delivery.note", readonly=True)
warning_message = fields.Text("Warning Message", readonly=True)

def confirm(self):
self.ensure_one()
self.delivery_note_id._action_confirm()

Check warning on line 17 in l10n_it_delivery_note/wizard/delivery_note_confirm.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/wizard/delivery_note_confirm.py#L16-L17

Added lines #L16 - L17 were not covered by tests
21 changes: 21 additions & 0 deletions l10n_it_delivery_note/wizard/delivery_note_confirm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="stock_delivery_note_confirm_form_view" model="ir.ui.view">
<field name="name">stock.delivery.note.confirm.form</field>
<field name="model">stock.delivery.note.confirm.wizard</field>
<field name="arch" type="xml">
<form>
<field name="warning_message" />
<footer>
<button
name="confirm"
type="object"
class="btn-primary"
string="Confirm"
/>
<button special="cancel" class="btn-secondary" string="Cancel" />
</footer>
</form>
</field>
</record>
</odoo>
4 changes: 3 additions & 1 deletion l10n_it_delivery_note/wizard/delivery_note_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def _onchange_partner(self):
)

def _prepare_delivery_note_vals(self, sale_order_id):
delivery_method_id = self.selected_picking_ids.mapped("carrier_id")[:1]
return {
"company_id": (
self.selected_picking_ids.mapped("company_id")[:1].id or False
Expand All @@ -88,7 +89,8 @@ def _prepare_delivery_note_vals(self, sale_order_id):
"partner_shipping_id": self.partner_shipping_id.id,
"type_id": self.type_id.id,
"date": self.date,
"delivery_method_id": self.partner_id.property_delivery_carrier_id.id,
"carrier_id": delivery_method_id.partner_id.id,
"delivery_method_id": delivery_method_id.id,
"transport_condition_id": (
sale_order_id
and sale_order_id.default_transport_condition_id.id
Expand Down
15 changes: 14 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 <mbilotta@linkeurope.it>

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


class StockDeliveryNoteSelectWizard(models.TransientModel):
Expand Down Expand Up @@ -37,6 +37,19 @@ 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")

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.mapped("partner_id")) > 1:
res = _(
"The selected pickings have different delivery methods: %(carriers)s",
carriers=", ".join(
'"%s: %s"' % (i.name, i.partner_id.name) for i in carrier_ids
),
)
return res

Check warning on line 52 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#L52

Added line #L52 was not covered by tests

def check_compliance(self, pickings):
super().check_compliance(pickings)
Expand Down
Loading

0 comments on commit 7bf1c8e

Please sign in to comment.