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 22, 2024
1 parent ddcc55d commit a37158b
Show file tree
Hide file tree
Showing 27 changed files with 340 additions and 36 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})
4 changes: 4 additions & 0 deletions l10n_it_delivery_note/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ class ResCompany(models.Model):
"Display Ref. Customer in Delivery Note Report",
default=False,
)
display_carrier_dn_report = fields.Boolean(
"Display Carrier in Delivery Note Report",
default=False,
)
5 changes: 5 additions & 0 deletions l10n_it_delivery_note/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ def _default_virtual_locations_root(self):
related="company_id.display_ref_customer_dn_report",
readonly=False,
)
display_carrier_dn_report = fields.Boolean(
string="Display Carrier in Delivery Note Report",
related="company_id.display_carrier_dn_report",
readonly=False,
)
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")
62 changes: 60 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,61 @@ 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 = _(
"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 (
transporter_ids
and note.carrier_id
and note.carrier_id != transporter_ids
):
warning_message = _(
"The carrier set in Delivery Note is different "
"from the carrier set in picking(s). "
"Are you sure you want to proceed?"
)
elif len(carrier_ids) > 1:
warning_message = _(
"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")),
)
elif (
carrier_ids
and note.delivery_method_id
and carrier_ids != note.delivery_method_id
):
warning_message = _(
"The shipping method set in Delivery Note is different "
"from the shipping method set in picking(s). "
"Are you sure you want to proceed?"
)
if warning_message:
return {
"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
7 changes: 7 additions & 0 deletions l10n_it_delivery_note/report/report_delivery_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@
</p>
</div>
</div>
<div
id="carrier"
t-if="doc.carrier_id and doc.company_id.display_carrier_dn_report"
>
<strong>Carrier:</strong>
<t t-esc="doc.carrier_id.name" />
</div>
<div id="dn_terms">
<strong> Delivery Note: </strong>
Under the terms of Italian Presidential Decree 472-96 of 14.08.1996
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
30 changes: 30 additions & 0 deletions l10n_it_delivery_note/tests/delivery_note_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ def create_delivery_note(self, **kwargs):

return self.env["stock.delivery.note"].create(vals)

def create_picking(self, **kwargs):
picking_data = {
"partner_id": self.recipient.id,
"picking_type_id": self.env.ref("stock.picking_type_out").id,
"location_id": self.env.ref("stock.stock_location_stock").id,
"location_dest_id": self.env.ref("stock.stock_location_customers").id,
"move_lines": [
(
0,
0,
{
"name": self.env.ref("product.product_product_8").name,
"product_id": self.env.ref("product.product_product_8").id,
"product_uom_qty": 1,
"product_uom": self.env.ref(
"product.product_product_8"
).uom_id.id,
"location_id": self.env.ref("stock.stock_location_stock").id,
"location_dest_id": self.env.ref(
"stock.stock_location_customers"
).id,
},
)
],
}

picking_data.update(kwargs)

return self.env["stock.picking"].create(picking_data)

def setUp(self):
super().setUp()

Expand Down
Loading

0 comments on commit a37158b

Please sign in to comment.