diff --git a/account_invoice_report_grouped_by_picking/README.rst b/account_invoice_report_grouped_by_picking/README.rst new file mode 100644 index 000000000..786b5acf3 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/README.rst @@ -0,0 +1,114 @@ +================================== +Account Invoice Grouped by Picking +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:849712b84c478d2e89387eb21a571843b8e784a88ff9203c3205359336b55cc9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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 + :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 + :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. 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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Carlos Dauden + - David Vidal + - Pedro M. Baeza + - Sergio Teruel + - João Marques + - Carlos Roca + +- `Studio73 `__: + + - Ioan Galan + +- `Trobz `__: + + - Thao Le + +Other credits +------------- + +The migration of this module from 16.0 to 17.0 was financially supported +by Camptocamp. + +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/__init__.py b/account_invoice_report_grouped_by_picking/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_invoice_report_grouped_by_picking/__manifest__.py b/account_invoice_report_grouped_by_picking/__manifest__.py new file mode 100644 index 000000000..d46fe1a74 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2017-2019 Carlos Dauden +# Copyright 2018 David Vidal +# Copyright 2018-2019 Tecnativa - Pedro M. Baeza +# Copyright 2021 Tecnativa - João Marques +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Invoice Grouped by Picking", + "summary": "Print invoice lines grouped by picking", + "version": "17.0.1.0.0", + "category": "Accounting & Finance", + "website": "https://github.com/OCA/account-invoice-reporting", + "author": "Tecnativa, " "Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["stock_picking_invoice_link"], + "data": ["views/report_invoice.xml"], + "installable": True, +} diff --git a/account_invoice_report_grouped_by_picking/i18n/account_invoice_report_grouped_by_picking.pot b/account_invoice_report_grouped_by_picking/i18n/account_invoice_report_grouped_by_picking.pot new file mode 100644 index 000000000..a962ae41d --- /dev/null +++ b/account_invoice_report_grouped_by_picking/i18n/account_invoice_report_grouped_by_picking.pot @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_report_grouped_by_picking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Order:" +msgstr "" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Picking:" +msgstr "" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "" +"\n" +" Without reference\n" +" " +msgstr "" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Subtotal: " +msgstr "" + +#. module: account_invoice_report_grouped_by_picking +#: model:ir.model,name:account_invoice_report_grouped_by_picking.model_account_move +msgid "Journal Entry" +msgstr "" diff --git a/account_invoice_report_grouped_by_picking/i18n/de.po b/account_invoice_report_grouped_by_picking/i18n/de.po new file mode 100644 index 000000000..7d69a0953 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/i18n/de.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_report_grouped_by_picking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-05-11 13:05+0000\n" +"Last-Translator: Maria Sparenberg \n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Order:" +msgstr "Auftrag:" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Picking:" +msgstr "Lieferung:" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "" +"\n" +" Without reference\n" +" " +msgstr "" +"\n" +" Ohne Referenz\n" +" " + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Subtotal: " +msgstr "Zwischensumme: " + +#. module: account_invoice_report_grouped_by_picking +#: model:ir.model,name:account_invoice_report_grouped_by_picking.model_account_move +msgid "Journal Entry" +msgstr "Journalbuchung" + +#~ msgid "Display Name" +#~ msgstr "Anzeigename" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Zuletzt geändert am" diff --git a/account_invoice_report_grouped_by_picking/i18n/es.po b/account_invoice_report_grouped_by_picking/i18n/es.po new file mode 100644 index 000000000..176e58f47 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/i18n/es.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_report_grouped_by_picking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-06-25 22:35+0000\n" +"PO-Revision-Date: 2020-06-26 00:36+0200\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 2.0.6\n" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Order:" +msgstr "Pedido:" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Picking:" +msgstr "Albarán:" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "" +"\n" +" Without reference\n" +" " +msgstr "" +"\n" +" Sin referencia\n" +" " + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Subtotal: " +msgstr "Subtotal: " + +#. module: account_invoice_report_grouped_by_picking +#: model:ir.model,name:account_invoice_report_grouped_by_picking.model_account_move +msgid "Journal Entry" +msgstr "" + +#~ msgid "Journal Entries" +#~ msgstr "Asientos contables" diff --git a/account_invoice_report_grouped_by_picking/i18n/fr_FR.po b/account_invoice_report_grouped_by_picking/i18n/fr_FR.po new file mode 100644 index 000000000..20eaef649 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/i18n/fr_FR.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_report_grouped_by_picking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-04-10 15:46+0000\n" +"Last-Translator: Yves Le Doeuff \n" +"Language-Team: none\n" +"Language: fr_FR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Order:" +msgstr "Commande:" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Picking:" +msgstr "" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "" +"\n" +" Without reference\n" +" " +msgstr "" +"\n" +" Sans référence\n" +" " + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Subtotal: " +msgstr "Sous-total : " + +#. module: account_invoice_report_grouped_by_picking +#: model:ir.model,name:account_invoice_report_grouped_by_picking.model_account_move +msgid "Journal Entry" +msgstr "Ecriture" + +#~ msgid "Last Modified on" +#~ msgstr "Dernière modification" diff --git a/account_invoice_report_grouped_by_picking/i18n/pt.po b/account_invoice_report_grouped_by_picking/i18n/pt.po new file mode 100644 index 000000000..52a42f194 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/i18n/pt.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_report_grouped_by_picking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-02-29 20:13+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Order:" +msgstr "Encomenda:" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Picking:" +msgstr "Entrega:" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "" +"\n" +" Without reference\n" +" " +msgstr "" + +#. module: account_invoice_report_grouped_by_picking +#: model_terms:ir.ui.view,arch_db:account_invoice_report_grouped_by_picking.report_invoice_document +msgid "Subtotal: " +msgstr "" + +#. module: account_invoice_report_grouped_by_picking +#: model:ir.model,name:account_invoice_report_grouped_by_picking.model_account_move +msgid "Journal Entry" +msgstr "" + +#~ msgid "Invoice" +#~ msgstr "Fatura" diff --git a/account_invoice_report_grouped_by_picking/models/__init__.py b/account_invoice_report_grouped_by_picking/models/__init__.py new file mode 100644 index 000000000..9c0a42138 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/models/__init__.py @@ -0,0 +1 @@ +from . import account_move diff --git a/account_invoice_report_grouped_by_picking/models/account_move.py b/account_invoice_report_grouped_by_picking/models/account_move.py new file mode 100644 index 000000000..b2b3299c1 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/models/account_move.py @@ -0,0 +1,141 @@ +# Copyright 2017 Tecnativa - Carlos Dauden +# Copyright 2018 Tecnativa - David Vidal +# Copyright 2018-2019 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import datetime +from collections import OrderedDict + +from odoo import api, models +from odoo.tools import float_is_zero + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.model + def _sort_grouped_lines(self, lines_dic): + DTF = "%Y-%m-%d %H:%M:%S" + min_date = datetime.datetime.min + return sorted( + lines_dic, + key=lambda x: ( + x["picking"] + and ( + (x["picking"].date or min_date).strftime(DTF), + (x["picking"].date_done or x["picking"].date or min_date).strftime( + DTF + ), + ) + or ("", "") + ), + ) + + def _get_signed_quantity_done(self, invoice_line, move, sign): + """Hook method. Usage example: + account_invoice_report_grouped_by_picking_sale_mrp module + """ + qty = 0 + if move.location_id.usage == "customer": + qty = -move.quantity * sign + elif move.location_dest_id.usage == "customer": + qty = move.quantity * sign + return qty + + def _process_section_note_lines_grouped( + self, previous_section, previous_note, lines_dic, pick_order=None + ): + key_section = (pick_order, previous_section) if pick_order else previous_section + if previous_section and key_section not in lines_dic: + lines_dic[key_section] = 0.0 + key_note = (pick_order, previous_note) if pick_order else previous_note + if previous_note and key_note not in lines_dic: + lines_dic[key_note] = 0.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 = OrderedDict() + lines_dict = OrderedDict() + picking_obj = self.env["stock.picking"] + # 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 = {x.sale_id: x for x in self.picking_ids if x.sale_id} + # Now group by picking by direct link or via same SO as picking's one + previous_section = previous_note = False + for line in self.invoice_line_ids.sorted( + lambda ln: (-ln.sequence, ln.date, ln.move_name, -ln.id), reverse=True + ): + if line.display_type == "line_section": + previous_section = line + continue + if line.display_type == "line_note": + previous_note = line + continue + has_returned_qty = False + remaining_qty = line.quantity + 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 + ) + picking_dict.setdefault(key, 0) + if move.location_id.usage == "customer": + has_returned_qty = True + qty = self._get_signed_quantity_done(line, move, sign) + picking_dict[key] += qty + remaining_qty -= qty + if not line.move_line_ids and line.sale_line_ids: + for so_line in line.sale_line_ids: + if so_dict.get(so_line.order_id): + key = (so_dict[so_line.order_id], line) + self._process_section_note_lines_grouped( + previous_section, + previous_note, + picking_dict, + so_dict[so_line.order_id], + ) + picking_dict.setdefault(key, 0) + qty = so_line.product_uom_qty + picking_dict[key] += qty + remaining_qty -= qty + elif not line.move_line_ids and not line.sale_line_ids: + key = (picking_obj, line) + picking_dict.setdefault(key, 0) + qty = line.quantity + picking_dict[key] += qty + remaining_qty -= qty + # To avoid to print duplicate lines because the invoice is a refund + # without returned goods to refund. + if self.move_type == "out_refund" and not has_returned_qty: + remaining_qty = 0.0 + for key in picking_dict: + picking_dict[key] = abs(picking_dict[key]) + if not float_is_zero( + remaining_qty, + precision_rounding=line.product_id.uom_id.rounding or 0.01, + ): + 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) diff --git a/account_invoice_report_grouped_by_picking/pyproject.toml b/account_invoice_report_grouped_by_picking/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/account_invoice_report_grouped_by_picking/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_invoice_report_grouped_by_picking/readme/CONTRIBUTORS.md b/account_invoice_report_grouped_by_picking/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..552afbc4a --- /dev/null +++ b/account_invoice_report_grouped_by_picking/readme/CONTRIBUTORS.md @@ -0,0 +1,11 @@ +- [Tecnativa](https://www.tecnativa.com): + - Carlos Dauden + - David Vidal + - Pedro M. Baeza + - Sergio Teruel + - João Marques + - Carlos Roca +- [Studio73](https://www.studio73.es): + - Ioan Galan \<\> +- [Trobz](https://trobz.com): + - Thao Le \<\> diff --git a/account_invoice_report_grouped_by_picking/readme/CREDITS.md b/account_invoice_report_grouped_by_picking/readme/CREDITS.md new file mode 100644 index 000000000..8add88a2e --- /dev/null +++ b/account_invoice_report_grouped_by_picking/readme/CREDITS.md @@ -0,0 +1 @@ +The migration of this module from 16.0 to 17.0 was financially supported by Camptocamp. diff --git a/account_invoice_report_grouped_by_picking/readme/DESCRIPTION.md b/account_invoice_report_grouped_by_picking/readme/DESCRIPTION.md new file mode 100644 index 000000000..cf687b707 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module allows print invoices with picking info. 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/readme/USAGE.md b/account_invoice_report_grouped_by_picking/readme/USAGE.md new file mode 100644 index 000000000..b249bdb08 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/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/static/description/icon.png b/account_invoice_report_grouped_by_picking/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_invoice_report_grouped_by_picking/static/description/icon.png differ diff --git a/account_invoice_report_grouped_by_picking/static/description/index.html b/account_invoice_report_grouped_by_picking/static/description/index.html new file mode 100644 index 000000000..bf0d63f23 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/static/description/index.html @@ -0,0 +1,460 @@ + + + + + +Account Invoice Grouped by Picking + + + +
+

Account Invoice Grouped by Picking

+ + +

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

+

This module allows print invoices with picking info. 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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 16.0 to 17.0 was financially supported +by Camptocamp.

+
+
+

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.

+
+
+
+ + diff --git a/account_invoice_report_grouped_by_picking/tests/__init__.py b/account_invoice_report_grouped_by_picking/tests/__init__.py new file mode 100644 index 000000000..fde7e7285 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_invoice_group_picking diff --git a/account_invoice_report_grouped_by_picking/tests/test_account_invoice_group_picking.py b/account_invoice_report_grouped_by_picking/tests/test_account_invoice_group_picking.py new file mode 100644 index 000000000..fe5a56bc9 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/tests/test_account_invoice_group_picking.py @@ -0,0 +1,336 @@ +# Copyright 2017 Carlos Dauden +# Copyright 2018 David Vidal +# Copyright 2019 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from lxml import html + +from odoo import fields +from odoo.tests.common import Form, TransactionCase + + +class TestAccountInvoiceGroupPicking(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls.product = cls.env["product.product"].create( + { + "name": "Product for test", + "default_code": "TESTPROD01", + "invoice_policy": "delivery", + } + ) + cls.service = cls.env["product.product"].create( + { + "name": "Test service product", + "type": "service", + "invoice_policy": "order", + } + ) + cls.partner = cls.env["res.partner"].create({"name": "Partner for test"}) + cls.sale = cls.env["sale.order"].create( + { + "partner_id": cls.partner.id, + "order_line": [ + ( + 0, + 0, + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_uom_qty": 2, + "product_uom": cls.product.uom_id.id, + "price_unit": 100.0, + }, + ), + ( + 0, + 0, + { + "name": cls.service.name, + "product_id": cls.service.id, + "product_uom_qty": 3, + "product_uom": cls.service.uom_id.id, + "price_unit": 50.0, + }, + ), + ], + } + ) + + def get_return_picking_wizard(self, picking): + stock_return_picking_form = Form( + self.env["stock.return.picking"].with_context( + active_ids=picking.ids, + active_id=picking.ids[0], + active_model="stock.picking", + ) + ) + return stock_return_picking_form.save() + + def test_account_invoice_group_picking(self): + # confirm quotation + self.sale.action_confirm() + # deliver lines2 + self.sale.picking_ids[:1].action_confirm() + self.sale.picking_ids[:1].move_line_ids.write({"quantity": 1}) + wiz_act = self.sale.picking_ids[:1].button_validate() + wiz = Form( + self.env[wiz_act["res_model"]].with_context(wiz_act["context"]) + ).save() + wiz.process() + # create another sale + self.sale2 = self.sale.copy() + self.sale2.order_line[:1].product_uom_qty = 4 + self.sale2.order_line[:1].price_unit = 50.0 + # confirm new quotation + self.sale2.action_confirm() + self.sale2.picking_ids[:1].action_confirm() + self.sale2.picking_ids[:1].move_line_ids.write({"quantity": 1}) + wiz_act = self.sale2.picking_ids[:1].button_validate() + wiz = Form( + self.env[wiz_act["res_model"]].with_context(wiz_act["context"]) + ).save() + wiz.process() + sales = self.sale | self.sale2 + # invoice sales + invoice = sales._create_invoices() + # Test directly grouping method + groups = invoice.lines_grouped_by_picking() + self.assertEqual(len(groups), 4) + self.assertEqual(groups[0]["picking"], groups[1]["picking"]) + self.assertEqual(groups[2]["picking"], groups[3]["picking"]) + # mix with invoice line that doesn't have neither move_line_ids + # nor sale_line_ids + vals = [ + { + "name": "test invoice line", + "move_id": invoice.id, + "price_unit": 10.0, + "account_id": invoice.invoice_line_ids[0].account_id.id, + } + ] + invoice.invoice_line_ids.create(vals) + # Test report + content = html.document_fromstring( + self.env["ir.actions.report"]._render_qweb_html( + "account.account_invoices", invoice.id + )[0] + ) + tbody = content.xpath("//tbody[@class='invoice_tbody']") + tbody = [html.tostring(line, encoding="utf-8").strip() for line in tbody][ + 0 + ].decode() + # information about sales is printed + self.assertEqual(tbody.count(self.sale.name), 1) + self.assertEqual(tbody.count(self.sale2.name), 1) + # information about pickings is printed + self.assertTrue(self.sale.invoice_ids.picking_ids[:1].name in tbody) + self.assertTrue(self.sale2.invoice_ids.picking_ids[:1].name in tbody) + + def test_account_invoice_group_picking_return(self): + self.sale.action_confirm() + # deliver lines2 + picking = self.sale.picking_ids[:1] + picking.action_confirm() + picking.move_line_ids.write({"quantity": 1}) + wiz_act = picking.button_validate() + wiz = Form( + self.env[wiz_act["res_model"]].with_context(wiz_act["context"]) + ).save() + wiz.process() + self.sale._create_invoices() + # Return one picking from sale1 + wiz_return = self.get_return_picking_wizard(picking) + res = wiz_return.create_returns() + picking_return = self.env["stock.picking"].browse(res["res_id"]) + picking_return.move_line_ids.write({"quantity": 1}) + picking_return.button_validate() + # Test directly grouping method + invoice = self.sale._create_invoices(final=True) + groups = invoice.lines_grouped_by_picking() + self.assertEqual(len(groups), 1) + self.assertEqual(groups[0]["picking"], picking_return) + + def test_account_invoice_return_without_returned_good(self): + self.sale.action_confirm() + picking = self.sale.picking_ids[:1] + picking.action_confirm() + picking.move_line_ids.write({"quantity": 1}) + wiz_act = picking.button_validate() + wiz = Form( + self.env[wiz_act["res_model"]].with_context(wiz_act["context"]) + ).save() + wiz.process() + invoice = self.sale._create_invoices() + invoice.action_post() + # Refund invoice without return picking + move_reversal = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=invoice.ids) + .create( + { + "date": fields.Date.today(), + "reason": "no reason", + "journal_id": invoice.journal_id.id, + } + ) + ) + reversal = move_reversal.refund_moves() + refund_invoice = self.env["account.move"].browse(reversal["res_id"]) + groups = refund_invoice.lines_grouped_by_picking() + self.assertEqual(len(groups), 2) + + def test_account_invoice_group_picking_refund(self): + # confirm quotation + self.sale.action_confirm() + # deliver lines2 + picking = self.sale.picking_ids[:1] + picking.action_confirm() + picking.move_line_ids.write({"quantity": 1}) + wiz_act = picking.button_validate() + wiz = Form( + self.env[wiz_act["res_model"]].with_context(wiz_act["context"]) + ).save() + wiz.process() + # invoice sales + invoice = self.sale._create_invoices() + invoice._post() + # Test directly grouping method + # invoice = self.env["account.move"].browse(inv_id) + groups = invoice.lines_grouped_by_picking() + self.assertEqual(len(groups), 2) + self.assertEqual(groups[0]["picking"], groups[1]["picking"]) + # Test report + content = html.document_fromstring( + self.env["ir.actions.report"]._render_qweb_html( + "account.account_invoices", invoice.id + )[0] + ) + tbody = content.xpath("//tbody[@class='invoice_tbody']") + tbody = [html.tostring(line, encoding="utf-8").strip() for line in tbody][ + 0 + ].decode() + # information about sales is printed + self.assertEqual(tbody.count(self.sale.name), 1) + # information about pickings is printed + self.assertTrue(picking.name in tbody) + # Return picking + wiz_return = self.get_return_picking_wizard(picking) + res = wiz_return.create_returns() + picking_return = self.env["stock.picking"].browse(res["res_id"]) + picking_return.move_line_ids.write({"quantity": 1}) + picking_return.button_validate() + # Refund invoice + wiz_invoice_refund = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=invoice.ids) + .create( + { + "reason": "test", + "journal_id": invoice.journal_id.id, + } + ) + ) + wiz_invoice_refund.refund_moves() + new_invoice = self.sale.invoice_ids.filtered( + lambda i: i.move_type == "out_refund" + ) + # Test directly grouping method + # invoice = self.env["account.move"].browse(inv_id) + groups = new_invoice.lines_grouped_by_picking() + self.assertEqual(len(groups), 2) + self.assertEqual(groups[0]["picking"], groups[1]["picking"]) + # Test report + content = html.document_fromstring( + self.env["ir.actions.report"]._render_qweb_html( + "account.account_invoices", new_invoice.id + )[0] + ) + tbody = content.xpath("//tbody[@class='invoice_tbody']") + tbody = [html.tostring(line, encoding="utf-8").strip() for line in tbody][ + 0 + ].decode() + # information about sales is printed + self.assertEqual(tbody.count(self.sale.name), 1) + # information about pickings is printed + self.assertTrue(picking_return.name in tbody) + + def test_account_invoice_group_picking_refund_without_return(self): + # confirm quotation + self.sale.action_confirm() + # deliver lines2 + picking = self.sale.picking_ids[:1] + picking.action_confirm() + picking.move_line_ids.write({"quantity": 1}) + wiz_act = picking.button_validate() + wiz = Form( + self.env[wiz_act["res_model"]].with_context(wiz_act["context"]) + ).save() + wiz.process() + # invoice sales + invoice = self.sale._create_invoices() + invoice._post() + # Test directly grouping method + # invoice = self.env["account.move"].browse(inv_id) + groups = invoice.lines_grouped_by_picking() + self.assertEqual(len(groups), 2) + self.assertEqual(groups[0]["picking"], groups[1]["picking"]) + # Test report + content = html.document_fromstring( + self.env["ir.actions.report"]._render_qweb_html( + "account.account_invoices", invoice.id + )[0] + ) + tbody = content.xpath("//tbody[@class='invoice_tbody']") + tbody = [html.tostring(line, encoding="utf-8").strip() for line in tbody][ + 0 + ].decode() + # information about sales is printed + self.assertEqual(tbody.count(self.sale.name), 1) + # information about pickings is printed + self.assertTrue(picking.name in tbody) + # Refund invoice + wiz_invoice_refund = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=invoice.ids) + .create( + { + "reason": "test", + "journal_id": invoice.journal_id.id, + } + ) + ) + wiz_invoice_refund.refund_moves() + new_invoice = self.sale.invoice_ids.filtered( + lambda i: i.move_type == "out_refund" + ) + # Test directly grouping method + # invoice = self.env["account.move"].browse(inv_id) + groups = new_invoice.lines_grouped_by_picking() + self.assertEqual(len(groups), 2) + self.assertEqual(groups[0]["picking"], groups[1]["picking"]) + # Test report + content = html.document_fromstring( + self.env["ir.actions.report"]._render_qweb_html( + "account.account_invoices", new_invoice.id + )[0] + ) + tbody = content.xpath("//tbody[@class='invoice_tbody']") + tbody = [html.tostring(line, encoding="utf-8").strip() for line in tbody][ + 0 + ].decode() + # information about sales is printed + self.assertEqual(tbody.count(self.sale.name), 1) + # information about pickings is printed + self.assertTrue(picking.name in tbody) diff --git a/account_invoice_report_grouped_by_picking/views/report_invoice.xml b/account_invoice_report_grouped_by_picking/views/report_invoice.xml new file mode 100644 index 000000000..958643627 --- /dev/null +++ b/account_invoice_report_grouped_by_picking/views/report_invoice.xml @@ -0,0 +1,112 @@ + + + +