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
100 changes: 100 additions & 0 deletions account_invoice_report_grouped_by_picking_mrp/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
===================================================
Account Invoice Grouped by Picking considering BOMs
===================================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4aaf2b5eb271f68da13ad88043e0415f6e4751b88cd93349388d10841f167c1a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/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%2Faccount--invoice--reporting-lightgray.png?logo=github
:target: https://github.com/OCA/account-invoice-reporting/tree/17.0/account_invoice_report_grouped_by_picking_mrp
:alt: OCA/account-invoice-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-invoice-reporting-17-0/account-invoice-reporting-17-0-account_invoice_report_grouped_by_picking_mrp
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoice-reporting&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows print invoices with picking info, considering BOMs.
This module groups invoice lines and shows information related to sales
and pickings on every group.

It also groups under the same block those service lines that are not in
the picking, but belongs to the same sales order as the rest of the
lines of the picking.

**Table of contents**

.. contents::
:local:

Usage
=====

1. Create several quotation orders and confirm them.
2. Deliver pickings related to each sale order.
3. Go to *Sales > To Invoice > Orders to Invoice* and invoice these sale
orders.
4. Open invoice newly created and print it.
5. Invoice report will group invoice lines and show information about
sales and pickings in every group.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoice-reporting/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-invoice-reporting/issues/new?body=module:%20account_invoice_report_grouped_by_picking_mrp%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* APIK

Contributors
------------

- `Apik <https://apik.cloud>`__:

- Thomas HERBIN

Other credits
-------------



Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/account-invoice-reporting <https://github.com/OCA/account-invoice-reporting/tree/17.0/account_invoice_report_grouped_by_picking_mrp>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_invoice_report_grouped_by_picking_mrp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions account_invoice_report_grouped_by_picking_mrp/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Account Invoice Grouped by Picking considering BOMs",
"summary": "Print invoice lines grouped by picking considering BOMs",
"version": "17.0.1.0.0",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/account-invoice-reporting",
"author": "APIK, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["account_invoice_report_grouped_by_picking", "mrp"],
"data": [],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_move
134 changes: 134 additions & 0 deletions account_invoice_report_grouped_by_picking_mrp/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models
from odoo.tools import float_round


class AccountMove(models.Model):
_inherit = "account.move"

def _get_signed_quantity_done(self, invoice_line, move, sign, get_line_qty=False):
"""Hook method. Usage example:
account_invoice_report_grouped_by_picking_sale_mrp module
"""
qty = invoice_line.quantity if get_line_qty else move.quantity
if move.location_id.usage == "customer":
return -qty * sign
if move.location_dest_id.usage == "customer":
return qty * sign
return 0

def lines_grouped_by_picking(self):
"""This prepares a data structure for printing the invoice report
grouped by pickings."""
self.ensure_one()
picking_dict = {}
lines_dict = {}
picking_obj = self.env["stock.picking"]
# Determine the sign based on the move type
# Not change sign if the credit note has been created from reverse move option
# and it has the same pickings related than the reversed invoice instead of sale
# order invoicing process after picking reverse transfer
sign = (
-1.0
if self.move_type == "out_refund"
and (
not self.reversed_entry_id
or self.reversed_entry_id.picking_ids != self.picking_ids
)
else 1.0
)
# Let's get first a correspondance between pickings and sales order
so_dict = {p.sale_id: p for p in self.picking_ids if p.sale_id}
# Now group by picking by direct link or via same SO as picking's one
previous_section = previous_note = False
last_section_notes = []
sorted_lines = self._get_grouped_by_picking_sorted_lines()
for line in sorted_lines:
# Process section or note lines
if line.display_type in ["line_section", "line_note"]:
if line.display_type == "line_section":
previous_section = line
else:
previous_note = line
last_section_notes.append(
{
"picking": picking_obj,
"line": line,
"qty": 0.0,
"is_last_section_notes": True,
}
)
continue
# Reset sections and notes when encountering a regular line
last_section_notes = []
has_returned_qty = False
remaining_qty = line.quantity
# Process moves related to the line
# If line is a bom, picking will have only components, and we don't want to
# count X times the product. So if it's a bom, we gonna loop one time
# through move lines to get section and note grouped, and picking name
line_is_bom = any([move.bom_line_id for move in line.move_line_ids])
for move in line.move_line_ids:
key = (move.picking_id, line)
self._process_section_note_lines_grouped(
previous_section, previous_note, picking_dict, move.picking_id
)
qty = self._get_signed_quantity_done(line, move, sign, line_is_bom)
picking_dict[key] = picking_dict.get(key, 0.0) + qty
remaining_qty -= qty
if move.location_id.usage == "customer":
has_returned_qty = True
if line_is_bom:
break
# Process sale order lines without moves
if not line.move_line_ids and line.sale_line_ids:
for so_line in line.sale_line_ids:
picking = so_dict.get(so_line.order_id)
if picking:
key = (picking, line)
self._process_section_note_lines_grouped(
previous_section, previous_note, picking_dict, picking
)
qty = min(so_line.product_uom_qty, remaining_qty)
picking_dict[key] = picking_dict.get(key, 0.0) + qty
remaining_qty -= qty
# Process lines without moves or sale orders
elif not line.move_line_ids and not line.sale_line_ids:
key = (picking_obj, line)
self._process_section_note_lines_grouped(
previous_section, previous_note, lines_dict
)
qty = line.quantity
picking_dict[key] = picking_dict.get(key, 0.0) + qty
remaining_qty -= qty
# To avoid to print duplicate lines because the invoice is a refund
# without returned goods to refund.
remaining_qty = float_round(
remaining_qty,
precision_rounding=line.product_id.uom_id.rounding or 0.01,
)
if (
self.move_type == "out_refund"
and not has_returned_qty
and remaining_qty
and line.product_id.type != "service"
and picking_dict
):
remaining_qty = 0.0
for key in picking_dict:
picking_dict[key] = abs(picking_dict[key])
if remaining_qty:
self._process_section_note_lines_grouped(
previous_section, previous_note, lines_dict
)
lines_dict[line] = remaining_qty
no_picking = [
{"picking": picking_obj, "line": key, "quantity": value}
for key, value in lines_dict.items()
]
with_picking = [
{"picking": key[0], "line": key[1], "quantity": value}
for key, value in picking_dict.items()
]
return no_picking + self._sort_grouped_lines(with_picking + last_section_notes)
3 changes: 3 additions & 0 deletions account_invoice_report_grouped_by_picking_mrp/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Apik](https://apik.cloud):
- Thomas HERBIN
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module allows print invoices with picking info, considering BOMs. This module groups
invoice lines and shows information related to sales and pickings on
every group.

It also groups under the same block those service lines that are not in
the picking, but belongs to the same sales order as the rest of the
lines of the picking.
7 changes: 7 additions & 0 deletions account_invoice_report_grouped_by_picking_mrp/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1. Create several quotation orders and confirm them.
2. Deliver pickings related to each sale order.
3. Go to *Sales \> To Invoice \> Orders to Invoice* and invoice these
sale orders.
4. Open invoice newly created and print it.
5. Invoice report will group invoice lines and show information about
sales and pickings in every group.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading