Skip to content

Commit

Permalink
[IMP]l10n_it_delivery_note: parametro group in res config, controllo …
Browse files Browse the repository at this point in the history
…su create invoices
  • Loading branch information
matteonext committed Jun 5, 2024
1 parent 0b8c539 commit f7120b3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
15 changes: 6 additions & 9 deletions l10n_it_delivery_note/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@ def _prepare_note_dn_value(self, sequence, delivery_note_id):
delivery_note_line_sequence = self.invoice_line_ids.filtered(
lambda x: x.delivery_note_id == delivery_note_id
).mapped("sequence")
new_sequence = (
min(delivery_note_line_sequence) - 1
if delivery_note_line_sequence
else sequence
)
if delivery_note_line_sequence:
sequence = min(delivery_note_line_sequence) - 1
return {
"sequence": new_sequence,
"sequence": sequence,
"display_type": "line_note",
"name": _("""Delivery Note "%(ddt_name)s" of %(ddt_date)s""")
% {
Expand Down Expand Up @@ -169,9 +166,9 @@ def update_delivery_note_lines(self):
self._prepare_note_dn_value(sequence, dn),
)
)
for invoice_line in dn_invoice_lines:
sequence += 1
invoice_line.sequence = sequence
# for invoice_line in dn_invoice_lines:
# sequence += 1
# invoice_line.sequence = sequence

invoice.write({"line_ids": new_lines})

Expand Down
2 changes: 2 additions & 0 deletions l10n_it_delivery_note/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ def _default_virtual_locations_root(self):
string="Display Delivery Method in Delivery Note Report",
related="company_id.display_delivery_method_dn_report",
readonly=False,
delivery_note_group_by_quantity = fields.Boolean(
string="Group Delivery note invoices by quantity"
)
19 changes: 12 additions & 7 deletions l10n_it_delivery_note/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ def goto_delivery_notes(self, **kwargs):
return action

def _create_invoices(self, grouped=False, final=False, date=None): # noqa: C901
if len(self.delivery_note_ids) <= 1:
if (
not self.env["ir.config_parameter"]
.sudo()
.get_param("l10n_it_delivery_note.delivery_note_group_by_quantity")
):
# if len(self.delivery_note_ids) <= 1:
invoice_ids = super()._create_invoices(
grouped=False, final=False, date=None
)
Expand All @@ -176,7 +181,7 @@ def _create_invoices(self, grouped=False, final=False, date=None): # noqa: C901
# 1) Create invoices.
invoice_vals_list = []
invoice_item_sequence = (
0 # Incremental sequencing to keep the lines order on the invoice.
10 # Incremental sequencing to keep the lines order on the invoice.
)
for order in self:
order = order.with_company(order.company_id).with_context(
Expand All @@ -186,12 +191,12 @@ def _create_invoices(self, grouped=False, final=False, date=None): # noqa: C901
invoice_vals = order._prepare_invoice()
invoiceable_lines = order._get_invoiceable_lines(final)

if not any(not line.display_type for line in invoiceable_lines):
continue
# if not any(not line.display_type for line in invoiceable_lines):
# continue

invoice_line_vals = []
down_payment_section_added = False
for line in invoiceable_lines.delivery_note_line_ids:
for line in invoiceable_lines.mapped("delivery_note_line_ids"):
if not down_payment_section_added and line.sale_line_id.is_downpayment:
# Create a dedicated section for the down payments
# (put at the end of the invoiceable_lines)
Expand All @@ -203,13 +208,13 @@ def _create_invoices(self, grouped=False, final=False, date=None): # noqa: C901
),
)
down_payment_section_added = True
invoice_item_sequence += 1
invoice_item_sequence += 10
invoice_line_vals.append(
Command.create(
line._prepare_ddt_invoice_line(sequence=invoice_item_sequence)
),
)
invoice_item_sequence += 1
invoice_item_sequence += 10

invoice_vals["invoice_line_ids"] += invoice_line_vals
invoice_vals_list.append(invoice_vals)
Expand Down
14 changes: 10 additions & 4 deletions l10n_it_delivery_note/models/stock_delivery_note_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,24 @@ def sync_invoice_status(self):

def _prepare_ddt_invoice_line(self, **optional_values):
self.ensure_one()
sequence = optional_values["sequence"] or self.sequence
res = {
"display_type": "product",
"sequence": self.sequence,
"sequence": sequence,
"name": self.name,
"product_id": self.product_id.id,
"product_uom_id": self.product_uom_id.id,
"quantity": self.product_qty,
"discount": self.sale_line_id.discount,
"price_unit": self.price_unit,
"tax_ids": [Command.set(self.tax_ids.ids)],
"sale_line_ids": [Command.link(self.sale_line_id.id)],
"is_downpayment": self.sale_line_id.is_downpayment,
"delivery_note_id": self.delivery_note_id.id,
}
if self.sale_line_id:
res.update(
{
"sale_line_ids": [Command.link(self.sale_line_id.id)],
"is_downpayment": self.sale_line_id.is_downpayment,
"discount": self.sale_line_id.discount,
}
)
return res
16 changes: 16 additions & 0 deletions l10n_it_delivery_note/views/res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@
</div>
</div>
</div>
<h2>Group Delivery Notes by quantity</h2>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="delivery_note_group_by_quantity" />
</div>
<div class="o_setting_right_pane">
<label for="delivery_note_group_by_quantity" />
<div class="text-muted">
<p>
Group delivery note invoices by quantity
</p>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
Expand Down

0 comments on commit f7120b3

Please sign in to comment.