Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions l10n_it_delivery_note/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

============================
ITA - Documento di trasporto
============================
Expand All @@ -17,7 +13,7 @@ ITA - Documento di trasporto
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
Expand Down Expand Up @@ -94,6 +90,9 @@ To configure this module, go to:
Checking 'Display Delivery Method in Delivery Note Report' enables in
report field 'Delivery Method'.

Checking 'Display total in DN with prices' enables in report the
'Import' column and the list of taxes with the sum of the total.

2. *Inventory → Configuration → Warehouse Management → Delivery Note
Types*

Expand Down
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 @@ -23,6 +23,10 @@ class ResCompany(models.Model):
"Display Delivery Method in Delivery Note Report",
default=False,
)
display_total_in_dn_with_prices = fields.Boolean(
"Display total in DN with prices",
default=False,
)

@api.model_create_multi
def create(self, vals):
Expand Down
4 changes: 4 additions & 0 deletions l10n_it_delivery_note/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def _default_virtual_locations_root(self):
related="company_id.display_delivery_method_dn_report",
readonly=False,
)
display_total_in_dn_with_prices = fields.Boolean(
related="company_id.display_total_in_dn_with_prices",
readonly=False,
)
52 changes: 50 additions & 2 deletions l10n_it_delivery_note/models/stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import datetime

from odoo import api, fields, models
from odoo.exceptions import UserError
from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError

from ..mixins.delivery_mixin import (
_default_volume_uom,
Expand Down Expand Up @@ -248,6 +248,22 @@ def _domain_weight_uom(self):
sale_count = fields.Integer(compute="_compute_sales")
sales_transport_check = fields.Boolean(compute="_compute_sales", default=True)

currency_id = fields.Many2one("res.currency", compute="_compute_currency_id")

untaxed_amount_total = fields.Monetary(
"Untaxed Total Amount",
compute="_compute_amount_total",
currency_field="currency_id",
store=True,
)

amount_total = fields.Monetary(
"Total Amount",
compute="_compute_amount_total",
currency_field="currency_id",
store=True,
)

invoice_ids = fields.Many2many(
"account.move",
"stock_delivery_note_account_invoice_rel",
Expand All @@ -265,6 +281,7 @@ def _domain_weight_uom(self):
can_change_number = fields.Boolean(compute="_compute_boolean_flags")
show_product_information = fields.Boolean(compute="_compute_boolean_flags")
company_id = fields.Many2one("res.company", required=True, default=_default_company)
show_discount = fields.Boolean(compute="_compute_show_discount")

# Sync with delivery mixin fields
delivery_transport_reason_id = fields.Many2one(
Expand Down Expand Up @@ -371,6 +388,19 @@ def _compute_invoice_status(self):
invoice_status = DOMAIN_INVOICE_STATUSES[1]
note.invoice_status = invoice_status

@api.depends("line_ids.currency_id")
def _compute_currency_id(self):
for sdn in self:
sdn.currency_id = sdn.line_ids.mapped("currency_id")

@api.depends("line_ids.amount", "line_ids.untaxed_amount")
def _compute_amount_total(self):
for sdn in self:
sdn.untaxed_amount_total = (
sum(line.untaxed_amount or 0.0 for line in sdn.line_ids) or 0.0
)
sdn.amount_total = sum(line.amount or 0.0 for line in sdn.line_ids) or 0.0

def _compute_get_pickings(self):
for note in self:
note.pickings_picker = note.picking_ids
Expand All @@ -395,6 +425,13 @@ def _compute_weights(self):
note.gross_weight = gross_weight
note.net_weight = net_weight

@api.depends("line_ids.discount")
def _compute_show_discount(self):
for sdn in self:
sdn.show_discount = any(
sdn.line_ids.filtered(lambda line: line.discount != 0)
)

@api.onchange("picking_ids")
def _onchange_picking_ids(self):
self._compute_weights()
Expand Down Expand Up @@ -553,6 +590,17 @@ def _onchange_partner_shipping(self):
else:
self.delivery_method_id = False

@api.constrains("line_ids")
def _check_line_ids(self):
for rec in self:
if len(rec.line_ids.mapped("currency_id")) > 1:
raise ValidationError(
_(
"You cannot have different currencies in the lines of a"
"Delivery Note"
)
)

def check_compliance(self, pickings):
super().check_compliance(pickings)

Expand Down
39 changes: 39 additions & 0 deletions l10n_it_delivery_note/models/stock_delivery_note_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def _default_unit_uom(self):
copy=False,
)

untaxed_amount = fields.Monetary(compute="_compute_amount", store=True)
amount = fields.Monetary(compute="_compute_amount", store=True)

_sql_constraints = [
(
"move_uniq",
Expand All @@ -111,6 +114,42 @@ def _compute_sale_order_client_ref(self):
sdnl.sale_line_id.order_id.client_order_ref or ""
)

@api.depends(
"product_id",
"price_unit",
"discount",
"product_qty",
"tax_ids",
"currency_id",
"delivery_note_id.partner_shipping_id",
)
def _compute_amount(self):
for sdnl in self:
price = sdnl.price_unit * (100.0 - sdnl.discount or 0.0) / 100.0

taxed_amount_data = sdnl._get_taxed_amount()

sdnl.untaxed_amount = taxed_amount_data.get("total_excluded", price)
sdnl.amount = taxed_amount_data.get("total_included", price)

def _get_taxed_amount(self):
price = self.price_unit * (100.0 - self.discount or 0.0) / 100.0
res = {}
if self.tax_ids:
tax_data = self.tax_ids.compute_all(
price,
self.currency_id,
self.product_qty,
product=self.product_id,
partner=self.delivery_note_id.partner_shipping_id,
)
res.update(
total_excluded=tax_data.get("total_excluded"),
total_included=tax_data.get("total_included"),
taxes=tax_data.get("taxes"),
)
return res

@api.onchange("product_id")
def _onchange_product_id(self):
if self.product_id:
Expand Down
2 changes: 2 additions & 0 deletions l10n_it_delivery_note/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ To configure this module, go to:

Checking 'Display Delivery Method in Delivery Note Report' enables in report field 'Delivery Method'.

Checking 'Display total in DN with prices' enables in report the 'Import' column and the list of taxes with the sum of the total.

2. *Inventory → Configuration → Warehouse Management → Delivery Note
Types*

Expand Down
69 changes: 67 additions & 2 deletions l10n_it_delivery_note/report/report_delivery_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
Unit Price
</th>
<th
t-if="doc.print_prices"
t-if="doc.print_prices and doc.show_discount"
name="th_discount"
t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}"
groups="sale.group_discount_per_so_line"
Expand All @@ -174,6 +174,13 @@
>
Taxes
</th>
<th
t-if="doc.company_id.display_total_in_dn_with_prices and doc.print_prices"
name="th_amount"
class="text-right"
>
Amount
</th>
<th name="th_ref_order" t-if="doc.lines_have_so_number">
Ref. Order
</th>
Expand Down Expand Up @@ -230,7 +237,7 @@
/>
</td>
<td
t-if="doc.print_prices"
t-if="doc.print_prices and doc.show_discount"
name="td_discount"
t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}"
groups="sale.group_discount_per_so_line"
Expand All @@ -251,6 +258,13 @@
>
<span t-esc="taxes" />
</td>
<td
t-if="doc.company_id.display_total_in_dn_with_prices and doc.print_prices"
name="td_amount"
class="text-right"
>
<span t-field="line.untaxed_amount" />
</td>
<td
t-if="doc.lines_have_so_number"
name="td_rif_order"
Expand Down Expand Up @@ -316,6 +330,57 @@
</t>
</tbody>
</table>
<br />
<div
class="clearfix"
name="so_total_summary"
t-if="doc.company_id.display_total_in_dn_with_prices and doc.print_prices"
>
<div id="total" class="row" name="total">
<div
t-attf-class="#{'col-6' if report_type != 'html' else 'col-sm-7 col-md-6'} ml-auto"
>
<table class="table table-sm">
<tr class="border-black o_subtotal" style="">
<td name="td_amounts_label">
<strong>Subtotal</strong>
</td>
<td class="text-right">
<t t-if="doc.line_ids">
<span
t-esc="doc.untaxed_amount_total"
t-options="{'widget': 'monetary', 'display_currency': doc.currency_id}"
/>
</t>
</td>
</tr>
<t t-if="len(doc.line_ids) > 1">
<t t-foreach="doc.line_ids[1:]" t-as="line">
<tr style="">
<td />
<td class="text-right">
<span
t-esc="line.amount"
t-options="{'widget': 'monetary', 'display_currency': doc.company_currency_id}"
/>
</td>
</tr>
</t>
</t>
<tr class="border-black o_total">
<td name="td_amount_total_label">
<strong>Total</strong>
</td>
<td name="td_amount_total" class="text-right">
<strong>
<span t-field="doc.amount_total" />
</strong>
</td>
</tr>
</table>
</div>
</div>
</div>

<t t-call="l10n_it_delivery_note.parcels_data" />
</div>
Expand Down
Loading
Loading