diff --git a/account_invoice_report_grouped_by_picking_mrp/README.rst b/account_invoice_report_grouped_by_picking_mrp/README.rst new file mode 100644 index 000000000..79bc35c98 --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* APIK + +Contributors +------------ + +- `Apik `__: + + - 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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_invoice_report_grouped_by_picking_mrp/__init__.py b/account_invoice_report_grouped_by_picking_mrp/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_invoice_report_grouped_by_picking_mrp/__manifest__.py b/account_invoice_report_grouped_by_picking_mrp/__manifest__.py new file mode 100644 index 000000000..1e3569070 --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/__manifest__.py @@ -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, +} diff --git a/account_invoice_report_grouped_by_picking_mrp/models/__init__.py b/account_invoice_report_grouped_by_picking_mrp/models/__init__.py new file mode 100644 index 000000000..9c0a42138 --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/models/__init__.py @@ -0,0 +1 @@ +from . import account_move diff --git a/account_invoice_report_grouped_by_picking_mrp/models/account_move.py b/account_invoice_report_grouped_by_picking_mrp/models/account_move.py new file mode 100644 index 000000000..8ce11f1bf --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/models/account_move.py @@ -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) diff --git a/account_invoice_report_grouped_by_picking_mrp/pyproject.toml b/account_invoice_report_grouped_by_picking_mrp/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_invoice_report_grouped_by_picking_mrp/readme/CONTRIBUTORS.md b/account_invoice_report_grouped_by_picking_mrp/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..15c43c90c --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Apik](https://apik.cloud): + - Thomas HERBIN diff --git a/account_invoice_report_grouped_by_picking_mrp/readme/CREDITS.md b/account_invoice_report_grouped_by_picking_mrp/readme/CREDITS.md new file mode 100644 index 000000000..e69de29bb diff --git a/account_invoice_report_grouped_by_picking_mrp/readme/DESCRIPTION.md b/account_invoice_report_grouped_by_picking_mrp/readme/DESCRIPTION.md new file mode 100644 index 000000000..61f20b2b4 --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/readme/DESCRIPTION.md @@ -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. diff --git a/account_invoice_report_grouped_by_picking_mrp/readme/USAGE.md b/account_invoice_report_grouped_by_picking_mrp/readme/USAGE.md new file mode 100644 index 000000000..b249bdb08 --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/readme/USAGE.md @@ -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. diff --git a/account_invoice_report_grouped_by_picking_mrp/static/description/icon.png b/account_invoice_report_grouped_by_picking_mrp/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_invoice_report_grouped_by_picking_mrp/static/description/icon.png differ diff --git a/account_invoice_report_grouped_by_picking_mrp/static/description/index.html b/account_invoice_report_grouped_by_picking_mrp/static/description/index.html new file mode 100644 index 000000000..fe8d92173 --- /dev/null +++ b/account_invoice_report_grouped_by_picking_mrp/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +Account Invoice Grouped by Picking considering BOMs + + + +
+

Account Invoice Grouped by Picking considering BOMs

+ + +

Beta License: AGPL-3 OCA/account-invoice-reporting Translate me on Weblate Try me on Runboat

+

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

+ +
+

Usage

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

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • APIK
  • +
+
+
+

Contributors

+
    +
  • Apik:
      +
    • Thomas HERBIN
    • +
    +
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ +