Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP]l10n_it_delivery_note: create invoice from delivery note #4184

Draft
wants to merge 4 commits into
base: 16.0
Choose a base branch
from
Draft
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
12 changes: 11 additions & 1 deletion l10n_it_delivery_note/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ To configure this module, go to:
1. *Inventory → Configuration → Settings - Delivery Notes*

Checking 'Use Advanced DN Features' allows you to manage more picking
on one delivery note.
on one delivery note. Checking 'Group Invoice Lines by Delivery Note
which generated them' too, you will have invoice lines grouped and it
can be useful if you invoice many DNs with same product and you want
to show the details to your customer.

Checking 'Display Ref. Order in Delivery Note Report' or 'Display
Ref. Customer in Delivery Note Report" enables in report fields
Expand Down Expand Up @@ -156,6 +159,13 @@ permessi dell'utente.
Le fatture generate dai DDT contengono i riferimenti al DDT stesso nelle
righe nota.

Raggruppa righe fattura per DDT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Attivando le funzionalità avanzate viene mostrata l'opzione per
abilitare il raggruppamento delle righe fattura in base al DDT che le ha
generate ("Raggruppa righe fattura per le DN che le hanno generate").

Accesso da portale
------------------

Expand Down
44 changes: 44 additions & 0 deletions l10n_it_delivery_note/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
}

def _prepare_note_dn_value(self, sequence, delivery_note_id):
if self.env.company.invoice_lines_grouped_by_dn:
delivery_note_line_sequence = self.invoice_line_ids.filtered(
lambda x: x.delivery_note_id == delivery_note_id
).mapped("sequence")
if delivery_note_line_sequence:
sequence = min(delivery_note_line_sequence) - 1
return {
"sequence": sequence,
"display_type": "line_note",
Expand Down Expand Up @@ -123,6 +129,44 @@
),
)
)
elif self.env.company.invoice_lines_grouped_by_dn:
sequence = 1
done_invoice_lines = self.env["account.move.line"]
delivery_notes = invoice.mapped(
"invoice_line_ids.sale_line_ids.delivery_note_line_ids."
"delivery_note_id"
).sorted(key="name")
for dn in delivery_notes:
dn_invoice_lines = invoice.invoice_line_ids.filtered(
lambda x, dn=dn, done_invoice_lines=done_invoice_lines: x
not in done_invoice_lines
and dn
in x.mapped(
"sale_line_ids.delivery_note_line_ids.delivery_note_id"
)
# fixme test invoice from 2 sale lines
)
done_invoice_lines |= dn_invoice_lines
for note_line in dn.line_ids.filtered(
lambda line: line.invoice_status == DOMAIN_INVOICE_STATUSES[2]
):
for invoice_line in dn_invoice_lines.filtered(
lambda x: not x.delivery_note_id
):
if (
note_line
in invoice_line.sale_line_ids.delivery_note_line_ids
):
invoice_line.delivery_note_id = (

Check warning on line 160 in l10n_it_delivery_note/models/account_invoice.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_delivery_note/models/account_invoice.py#L160

Added line #L160 was not covered by tests
note_line.delivery_note_id.id
)
new_lines.append(
(
0,
False,
self._prepare_note_dn_value(sequence, dn),
)
)
else:
for line in invoice.invoice_line_ids:
sequence = line.sequence - 1
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 @@ -20,3 +20,7 @@ class ResCompany(models.Model):
"Display Delivery Method in Delivery Note Report",
default=False,
)
invoice_lines_grouped_by_dn = fields.Boolean(
"Group Delivery note invoices by quantity",
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 @@ -49,3 +49,8 @@ def _default_virtual_locations_root(self):
related="company_id.display_delivery_method_dn_report",
readonly=False,
)
invoice_lines_grouped_by_dn = fields.Boolean(
string="Group Invoice Lines by Delivery Note",
related="company_id.invoice_lines_grouped_by_dn",
readonly=False,
)
Loading
Loading