From 0bba71022dfea1675e8238b274607eca10d03dd5 Mon Sep 17 00:00:00 2001 From: CarlosRoca13 Date: Wed, 24 Aug 2022 10:00:11 +0200 Subject: [PATCH 01/12] [ADD] account_purchase_stock_report_non_billed: New module Module that extends account_sale_stock_report_non_billed to add the non billed stock moves comming from purchase orders. TT38550 --- .../README.rst | 95 ++++ .../__init__.py | 2 + .../__manifest__.py | 18 + ...count_purchase_stock_report_non_billed.pot | 26 ++ .../i18n/es.po | 28 ++ .../models/__init__.py | 1 + .../models/stock_move.py | 74 +++ .../readme/CONTRIBUTORS.rst | 4 + .../readme/DESCRIPTION.rst | 2 + .../readme/USAGE.rst | 6 + .../static/description/index.html | 437 ++++++++++++++++++ .../tests/__init__.py | 1 + ...ccount_purchase_stock_report_non_billed.py | 308 ++++++++++++ .../wizard/__init__.py | 1 + ...ccount_sale_stock_report_non_billed_wiz.py | 36 ++ 15 files changed, 1039 insertions(+) create mode 100644 account_purchase_stock_report_non_billed/README.rst create mode 100644 account_purchase_stock_report_non_billed/__init__.py create mode 100644 account_purchase_stock_report_non_billed/__manifest__.py create mode 100644 account_purchase_stock_report_non_billed/i18n/account_purchase_stock_report_non_billed.pot create mode 100644 account_purchase_stock_report_non_billed/i18n/es.po create mode 100644 account_purchase_stock_report_non_billed/models/__init__.py create mode 100644 account_purchase_stock_report_non_billed/models/stock_move.py create mode 100644 account_purchase_stock_report_non_billed/readme/CONTRIBUTORS.rst create mode 100644 account_purchase_stock_report_non_billed/readme/DESCRIPTION.rst create mode 100644 account_purchase_stock_report_non_billed/readme/USAGE.rst create mode 100644 account_purchase_stock_report_non_billed/static/description/index.html create mode 100644 account_purchase_stock_report_non_billed/tests/__init__.py create mode 100644 account_purchase_stock_report_non_billed/tests/test_account_purchase_stock_report_non_billed.py create mode 100644 account_purchase_stock_report_non_billed/wizard/__init__.py create mode 100644 account_purchase_stock_report_non_billed/wizard/account_sale_stock_report_non_billed_wiz.py diff --git a/account_purchase_stock_report_non_billed/README.rst b/account_purchase_stock_report_non_billed/README.rst new file mode 100644 index 00000000..adfea8ce --- /dev/null +++ b/account_purchase_stock_report_non_billed/README.rst @@ -0,0 +1,95 @@ +======================================== +Account Purchase Stock Report Non Billed +======================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--financial--reporting-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-reporting/tree/13.0/account_purchase_stock_report_non_billed + :alt: OCA/account-financial-reporting +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-reporting-13-0/account-financial-reporting-13-0-account_purchase_stock_report_non_billed + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/91/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Module that extends account_sale_stock_report_non_billed to add the non billed stock +moves comming from purchase orders. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to `Invicing > Reporting > Non Billed Stock Moves`. +#. Select a concrete date. +#. The stock moves created before this date with quantity to be invoiced, are being + showed at the tree view. + +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 smashing 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 Roca + * Pedro M. Baeza + +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. + +.. |maintainer-CarlosRoca13| image:: https://github.com/CarlosRoca13.png?size=40px + :target: https://github.com/CarlosRoca13 + :alt: CarlosRoca13 + +Current `maintainer `__: + +|maintainer-CarlosRoca13| + +This module is part of the `OCA/account-financial-reporting `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_purchase_stock_report_non_billed/__init__.py b/account_purchase_stock_report_non_billed/__init__.py new file mode 100644 index 00000000..9b429614 --- /dev/null +++ b/account_purchase_stock_report_non_billed/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/account_purchase_stock_report_non_billed/__manifest__.py b/account_purchase_stock_report_non_billed/__manifest__.py new file mode 100644 index 00000000..c4f19f3c --- /dev/null +++ b/account_purchase_stock_report_non_billed/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2022 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Account Purchase Stock Report Non Billed", + "version": "13.0.1.0.0", + "license": "AGPL-3", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-reporting", + "depends": [ + "account_sale_stock_report_non_billed", + "purchase_stock_picking_invoice_link", + "purchase_stock", + ], + "data": [], + "installable": True, + "maintainers": ["CarlosRoca13"], + "development_status": "Beta", +} diff --git a/account_purchase_stock_report_non_billed/i18n/account_purchase_stock_report_non_billed.pot b/account_purchase_stock_report_non_billed/i18n/account_purchase_stock_report_non_billed.pot new file mode 100644 index 00000000..3f271840 --- /dev/null +++ b/account_purchase_stock_report_non_billed/i18n/account_purchase_stock_report_non_billed.pot @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_purchase_stock_report_non_billed +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-08-30 06:00+0000\n" +"PO-Revision-Date: 2022-08-30 06:00+0000\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_purchase_stock_report_non_billed +#: model:ir.model,name:account_purchase_stock_report_non_billed.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: account_purchase_stock_report_non_billed +#: model:ir.model,name:account_purchase_stock_report_non_billed.model_account_sale_stock_report_non_billed_wiz +msgid "Wizard to open stock moves that have not been invoiced at that time" +msgstr "" diff --git a/account_purchase_stock_report_non_billed/i18n/es.po b/account_purchase_stock_report_non_billed/i18n/es.po new file mode 100644 index 00000000..5416b675 --- /dev/null +++ b/account_purchase_stock_report_non_billed/i18n/es.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_purchase_stock_report_non_billed +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-08-30 06:00+0000\n" +"PO-Revision-Date: 2022-08-30 08:15+0200\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.3\n" +"Last-Translator: \n" +"Language: es\n" + +#. module: account_purchase_stock_report_non_billed +#: model:ir.model,name:account_purchase_stock_report_non_billed.model_stock_move +msgid "Stock Move" +msgstr "Movimiento de stock" + +#. module: account_purchase_stock_report_non_billed +#: model:ir.model,name:account_purchase_stock_report_non_billed.model_account_sale_stock_report_non_billed_wiz +msgid "Wizard to open stock moves that have not been invoiced at that time" +msgstr "Asistente para abrir movimientos de stock que no han sido facturados a una fecha dada." diff --git a/account_purchase_stock_report_non_billed/models/__init__.py b/account_purchase_stock_report_non_billed/models/__init__.py new file mode 100644 index 00000000..6bda2d24 --- /dev/null +++ b/account_purchase_stock_report_non_billed/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move diff --git a/account_purchase_stock_report_non_billed/models/stock_move.py b/account_purchase_stock_report_non_billed/models/stock_move.py new file mode 100644 index 00000000..d205a00e --- /dev/null +++ b/account_purchase_stock_report_non_billed/models/stock_move.py @@ -0,0 +1,74 @@ +# Copyright 2022 Tecnativa - Carlos Roca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + @api.depends("purchase_line_id") + def _compute_currency_id(self): + for move in self: + if move.purchase_line_id: + move.currency_id = move.purchase_line_id.currency_id + else: + super(StockMove, move)._compute_currency_id() + + def get_quantity_invoiced(self, invoice_lines): + if self.purchase_line_id: + if not invoice_lines: + return 0 + qty_invoiced = abs( + sum( + invoice_lines.mapped( + lambda l: l.quantity + if (l.move_id.type == "in_invoice" and not self.to_refund) + or (l.move_id.type == "in_refund" and self.to_refund) + else -l.quantity + ) + ) + ) + # Check when grouping different moves in an invoice line + moves = invoice_lines.mapped("move_line_ids") + total_qty = moves.get_total_devolution_moves() + if qty_invoiced != total_qty: + invoiced = 0.0 + for move in moves: + qty = ( + move.quantity_done + if move.quantity_done <= (qty_invoiced - invoiced) + else qty_invoiced - invoiced + ) + if move.check_is_return(): + qty = -qty + if move == self: + return qty + invoiced += qty + return 0 + return ( + self.quantity_done + if not self.check_is_return() + else -self.quantity_done + ) + return super().get_quantity_invoiced(invoice_lines) + + def _set_not_invoiced_values(self, qty_to_invoice, invoiced_qty): + self.ensure_one() + if self.purchase_line_id: + self.quantity_not_invoiced = qty_to_invoice - invoiced_qty + self.price_not_invoiced = ( + qty_to_invoice - invoiced_qty + ) * self.purchase_line_id.price_unit + else: + super()._set_not_invoiced_values(qty_to_invoice, invoiced_qty) + + @api.depends("purchase_line_id") + @api.depends_context("date_check_invoiced_moves") + def _compute_not_invoiced_values(self): + super()._compute_not_invoiced_values() + + def _get_model_id_origin_document(self): + if not self.purchase_line_id: + return super()._get_model_id_origin_document() + return self.purchase_line_id.order_id._name, self.purchase_line_id.order_id.id diff --git a/account_purchase_stock_report_non_billed/readme/CONTRIBUTORS.rst b/account_purchase_stock_report_non_billed/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..bd8c9d93 --- /dev/null +++ b/account_purchase_stock_report_non_billed/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Carlos Roca + * Pedro M. Baeza diff --git a/account_purchase_stock_report_non_billed/readme/DESCRIPTION.rst b/account_purchase_stock_report_non_billed/readme/DESCRIPTION.rst new file mode 100644 index 00000000..d39c672c --- /dev/null +++ b/account_purchase_stock_report_non_billed/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Module that extends account_sale_stock_report_non_billed to add the non billed stock +moves comming from purchase orders. diff --git a/account_purchase_stock_report_non_billed/readme/USAGE.rst b/account_purchase_stock_report_non_billed/readme/USAGE.rst new file mode 100644 index 00000000..0d477b84 --- /dev/null +++ b/account_purchase_stock_report_non_billed/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module, you need to: + +#. Go to `Invicing > Reporting > Non Billed Stock Moves`. +#. Select a concrete date. +#. The stock moves created before this date with quantity to be invoiced, are being + showed at the tree view. diff --git a/account_purchase_stock_report_non_billed/static/description/index.html b/account_purchase_stock_report_non_billed/static/description/index.html new file mode 100644 index 00000000..8ece01fb --- /dev/null +++ b/account_purchase_stock_report_non_billed/static/description/index.html @@ -0,0 +1,437 @@ + + + + + + +Account Purchase Stock Report Non Billed + + + +
+

Account Purchase Stock Report Non Billed

+ + +

Beta License: AGPL-3 OCA/account-financial-reporting Translate me on Weblate Try me on Runbot

+

Module that extends account_sale_stock_report_non_billed to add the non billed stock +moves comming from purchase orders.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Invicing > Reporting > Non Billed Stock Moves.
  2. +
  3. Select a concrete date.
  4. +
  5. The stock moves created before this date with quantity to be invoiced, are being +showed at the tree view.
  6. +
+
+
+

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 smashing 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 Roca
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

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.

+

Current maintainer:

+

CarlosRoca13

+

This module is part of the OCA/account-financial-reporting project on GitHub.

+

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

+
+
+
+ + diff --git a/account_purchase_stock_report_non_billed/tests/__init__.py b/account_purchase_stock_report_non_billed/tests/__init__.py new file mode 100644 index 00000000..974228eb --- /dev/null +++ b/account_purchase_stock_report_non_billed/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_purchase_stock_report_non_billed diff --git a/account_purchase_stock_report_non_billed/tests/test_account_purchase_stock_report_non_billed.py b/account_purchase_stock_report_non_billed/tests/test_account_purchase_stock_report_non_billed.py new file mode 100644 index 00000000..5484245b --- /dev/null +++ b/account_purchase_stock_report_non_billed/tests/test_account_purchase_stock_report_non_billed.py @@ -0,0 +1,308 @@ +# Copyright 2022 Tecnativa - Carlos Roca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import fields +from odoo.tests import Form, common + + +class TestAccountPurchaseStockReportNonBilled(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.supplier = cls.env["res.partner"].create({"name": "Supplier for Test"}) + cls.product = cls.env["product.product"].create({"name": "Product for Test"}) + po_form = Form(cls.env["purchase.order"]) + po_form.partner_id = cls.supplier + with po_form.order_line.new() as po_line_form: + po_line_form.product_id = cls.product + po_line_form.price_unit = 15.0 + cls.po = po_form.save() + + def get_picking_done_po(self): + self.po.button_confirm() + picking = self.po.picking_ids[0] + picking.action_confirm() + picking.move_lines.quantity_done = 1.0 + picking.button_validate() + return picking + + def test_01_report_move_not_invoiced(self): + picking = self.get_picking_done_po() + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertIn(move.id, domain_ids) + + def test_02_report_move_full_invoiced(self): + picking = self.get_picking_done_po() + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + invoice = inv_form.save() + invoice.action_post() + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertNotIn(move.id, domain_ids) + + def test_03_report_move_partially_invoiced(self): + # First done just one move + invoice + self.po.button_confirm() + picking = self.po.picking_ids[0] + picking.action_confirm() + move_done = picking.move_lines[0] + move_done.quantity_done = 1.0 + picking.action_done() + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + inv = inv_form.save() + inv.action_post() + # Done other moves to appear at report + picking_ret = self.po.picking_ids.filtered(lambda p: p.state == "assigned") + picking_ret.action_confirm() + picking_ret.move_lines.quantity_done = 1.0 + picking_ret.action_done() + moves_not_done = picking_ret.move_lines + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + self.assertNotIn(move_done.id, domain_ids) + for move in moves_not_done: + self.assertIn(move.id, domain_ids) + + def test_04_report_move_full_invoice_refund(self): + self.po.button_confirm() + # Validate shipment + picking = self.po.picking_ids[0] + # Process pickings + picking.action_confirm() + picking.move_lines.quantity_done = 1.0 + picking.button_validate() + # Create invoice + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + invoice = inv_form.save() + invoice.action_post() + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertNotIn(move.id, domain_ids) + # Refund invoice + wiz_invoice_refund = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=invoice.ids) + .create({"refund_method": "cancel", "reason": "test"}) + ) + wiz_invoice_refund.reverse_moves() + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertIn(move.id, domain_ids) + # Create invoice again + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + new_inv = inv_form.save() + new_inv.action_post() + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertNotIn(move.id, domain_ids) + + def test_05_report_move_partial_pickings_full_invoice(self): + self.po.order_line.product_qty = 5 + self.po.button_confirm() + picking = self.po.picking_ids[0] + picking.action_confirm() + picking.move_lines.quantity_done = 3.0 + picking.button_validate() + move_lines = picking.move_lines + wiz = self.env["stock.backorder.confirmation"].create( + {"pick_ids": [(4, picking.id)]} + ) + wiz.process() + picking = self.po.picking_ids.filtered(lambda p: p.state != "done") + picking.action_confirm() + picking.move_lines.quantity_done = 2.0 + picking.button_validate() + move_lines += picking.move_lines + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in move_lines: + self.assertIn(move.id, domain_ids) + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + invoice = inv_form.save() + invoice.action_post() + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in move_lines: + self.assertNotIn(move.id, domain_ids) + + def test_06_report_move_partial_pickings_each_invoice(self): + self.po.order_line.product_qty = 5 + self.po.button_confirm() + picking = self.po.picking_ids[0] + picking.action_confirm() + picking.move_lines.quantity_done = 3.0 + picking.button_validate() + wiz = self.env["stock.backorder.confirmation"].create( + {"pick_ids": [(4, picking.id)]} + ) + wiz.process() + move_lines = picking.move_lines + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + invoice = inv_form.save() + invoice.action_post() + picking = self.po.picking_ids.filtered(lambda p: p.state != "done") + picking.action_confirm() + picking.move_lines.quantity_done = 2.0 + picking.button_validate() + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in move_lines: + self.assertNotIn(move.id, domain_ids) + for move in picking.move_lines: + self.assertIn(move.id, domain_ids) + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + invoice = inv_form.save() + invoice.action_post() + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in move_lines + picking.move_lines: + self.assertNotIn(move.id, domain_ids) + + def test_07_report_move_full_invoice_return_without_update(self): + self.po.button_confirm() + # Validate shipment + picking = self.po.picking_ids[0] + # Process pickings + picking.action_confirm() + picking.move_lines.quantity_done = 1.0 + picking.button_validate() + # Create invoice + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + invoice = inv_form.save() + invoice.action_post() + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertNotIn(move.id, domain_ids) + # Return move + wiz_return_form = Form( + self.env["stock.return.picking"].with_context( + active_model="stock.picking", active_id=picking.id + ) + ) + wiz_return = wiz_return_form.save() + wiz_return.product_return_moves.to_refund = False + return_id = wiz_return.create_returns()["res_id"] + picking_return = self.env["stock.picking"].browse(return_id) + picking_return.move_line_ids.write({"qty_done": 1}) + picking_return.action_done() + for move in picking_return.move_lines: + self.assertNotIn(move.id, domain_ids) + + def test_08_move_return_return_full_invoiced(self): + self.po.button_confirm() + # Validate shipment + picking = self.po.picking_ids[0] + # Process pickings + picking.action_confirm() + picking.move_lines.quantity_done = 1.0 + picking.button_validate() + wiz_return_form = Form( + self.env["stock.return.picking"].with_context( + active_model="stock.picking", active_id=picking.id + ) + ) + wiz_return = wiz_return_form.save() + return_id = wiz_return.create_returns()["res_id"] + picking_return = self.env["stock.picking"].browse(return_id) + picking_return.move_line_ids.write({"qty_done": 1}) + picking_return.action_done() + wiz_return_return_form = Form( + self.env["stock.return.picking"].with_context( + active_model="stock.picking", active_id=picking_return.id + ) + ) + wiz_return_return = wiz_return_return_form.save() + return_return_id = wiz_return_return.create_returns()["res_id"] + picking_return_return = self.env["stock.picking"].browse(return_return_id) + picking_return_return.move_line_ids.write({"qty_done": 1}) + picking_return_return.action_done() + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + inv_form.save() + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertNotIn(move.id, domain_ids) + for move in picking_return.move_lines: + self.assertNotIn(move.id, domain_ids) + for move in picking_return_return.move_lines: + self.assertNotIn(move.id, domain_ids) + + def test_09_move_return_return_non_invoiced(self): + self.po.button_confirm() + # Validate shipment + picking = self.po.picking_ids[0] + # Process pickings + picking.action_confirm() + picking.move_lines.quantity_done = 1.0 + picking.button_validate() + wiz_return_form = Form( + self.env["stock.return.picking"].with_context( + active_model="stock.picking", active_id=picking.id + ) + ) + wiz_return = wiz_return_form.save() + return_id = wiz_return.create_returns()["res_id"] + picking_return = self.env["stock.picking"].browse(return_id) + picking_return.move_line_ids.write({"qty_done": 1}) + picking_return.action_done() + wiz_return_return_form = Form( + self.env["stock.return.picking"].with_context( + active_model="stock.picking", active_id=picking_return.id + ) + ) + wiz_return_return = wiz_return_return_form.save() + return_return_id = wiz_return_return.create_returns()["res_id"] + picking_return_return = self.env["stock.picking"].browse(return_return_id) + picking_return_return.move_line_ids.write({"qty_done": 1}) + picking_return_return.action_done() + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertNotIn(move.id, domain_ids) + for move in picking_return.move_lines: + self.assertNotIn(move.id, domain_ids) + for move in picking_return_return.move_lines: + self.assertIn(move.id, domain_ids) diff --git a/account_purchase_stock_report_non_billed/wizard/__init__.py b/account_purchase_stock_report_non_billed/wizard/__init__.py new file mode 100644 index 00000000..f0ed0965 --- /dev/null +++ b/account_purchase_stock_report_non_billed/wizard/__init__.py @@ -0,0 +1 @@ +from . import account_sale_stock_report_non_billed_wiz diff --git a/account_purchase_stock_report_non_billed/wizard/account_sale_stock_report_non_billed_wiz.py b/account_purchase_stock_report_non_billed/wizard/account_sale_stock_report_non_billed_wiz.py new file mode 100644 index 00000000..0cc050c2 --- /dev/null +++ b/account_purchase_stock_report_non_billed/wizard/account_sale_stock_report_non_billed_wiz.py @@ -0,0 +1,36 @@ +# Copyright 2022 Tecnativa - Carlos Roca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, models +from odoo.osv import expression + + +class AccountSaleStockReportNonBilledWiz(models.TransientModel): + _inherit = "account.sale.stock.report.non.billed.wiz" + + def _get_search_domain(self): + domain = super()._get_search_domain() + res_domain = expression.OR( + [ + domain, + [ + ("date_done", "<=", self.date_check), + ("purchase_line_id", "!=", False), + ("state", "=", "done"), + ("scrapped", "=", False), + "|", + ("location_id.usage", "=", "supplier"), + "&", + ("location_dest_id.usage", "=", "supplier"), + ("to_refund", "=", True), + ], + ] + ) + return res_domain + + @api.model + def discart_kits_from_moves(self, stock_moves): + res = super().discart_kits_from_moves(stock_moves) + return res + stock_moves.filtered( + lambda move: move.product_id == move.purchase_line_id.product_id + ) From 88cce41bafbc4d222973795d6cddf2a3246af92b Mon Sep 17 00:00:00 2001 From: CarlosRoca13 Date: Wed, 26 Oct 2022 13:11:03 +0200 Subject: [PATCH 02/12] [FIX] account_sale_stock_report_non_billed: Don't care about returns that don't update received qty --- ...ccount_purchase_stock_report_non_billed.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/account_purchase_stock_report_non_billed/tests/test_account_purchase_stock_report_non_billed.py b/account_purchase_stock_report_non_billed/tests/test_account_purchase_stock_report_non_billed.py index 5484245b..59a8bdbf 100644 --- a/account_purchase_stock_report_non_billed/tests/test_account_purchase_stock_report_non_billed.py +++ b/account_purchase_stock_report_non_billed/tests/test_account_purchase_stock_report_non_billed.py @@ -306,3 +306,48 @@ class TestAccountPurchaseStockReportNonBilled(common.SavepointCase): self.assertNotIn(move.id, domain_ids) for move in picking_return_return.move_lines: self.assertIn(move.id, domain_ids) + + def test_10_move_invoice_return_without_update_qty(self): + self.po.button_confirm() + # Validate shipment + picking = self.po.picking_ids[0] + # Process pickings + picking.action_confirm() + picking.move_lines.quantity_done = 1.0 + picking.button_validate() + inv_action = self.po.action_view_invoice() + inv_form = Form(self.env["account.move"].with_context(**inv_action["context"])) + inv_form.save() + wiz_return_form = Form( + self.env["stock.return.picking"].with_context( + active_model="stock.picking", active_id=picking.id, to_refund=False + ) + ) + wiz_return = wiz_return_form.save() + return_id = wiz_return.create_returns()["res_id"] + picking_return = self.env["stock.picking"].browse(return_id) + picking_return.move_line_ids.write({"qty_done": 1}) + picking_return.action_done() + wiz_return_return_form = Form( + self.env["stock.return.picking"].with_context( + active_model="stock.picking", + active_id=picking_return.id, + to_refund=False, + ) + ) + wiz_return_return = wiz_return_return_form.save() + return_return_id = wiz_return_return.create_returns()["res_id"] + picking_return_return = self.env["stock.picking"].browse(return_return_id) + picking_return_return.move_line_ids.write({"qty_done": 1}) + picking_return_return.action_done() + wiz = self.env["account.sale.stock.report.non.billed.wiz"].create( + {"date_check": fields.Date.today()} + ) + action = wiz.open_at_date() + domain_ids = action["domain"][0][2] + for move in picking.move_lines: + self.assertNotIn(move.id, domain_ids) + for move in picking_return.move_lines: + self.assertNotIn(move.id, domain_ids) + for move in picking_return_return.move_lines: + self.assertNotIn(move.id, domain_ids) From 702518bd9c9faf0a3e196d751a4af2c2eb05f8b4 Mon Sep 17 00:00:00 2001 From: oca-ci Date: Wed, 26 Oct 2022 15:57:47 +0000 Subject: [PATCH 03/12] [UPD] Update account_purchase_stock_report_non_billed.pot --- .../i18n/account_purchase_stock_report_non_billed.pot | 2 -- 1 file changed, 2 deletions(-) diff --git a/account_purchase_stock_report_non_billed/i18n/account_purchase_stock_report_non_billed.pot b/account_purchase_stock_report_non_billed/i18n/account_purchase_stock_report_non_billed.pot index 3f271840..3b3e0148 100644 --- a/account_purchase_stock_report_non_billed/i18n/account_purchase_stock_report_non_billed.pot +++ b/account_purchase_stock_report_non_billed/i18n/account_purchase_stock_report_non_billed.pot @@ -6,8 +6,6 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-08-30 06:00+0000\n" -"PO-Revision-Date: 2022-08-30 06:00+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" From 581f505034959a4e507897a45846c8cca6224719 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Wed, 26 Oct 2022 16:03:24 +0000 Subject: [PATCH 04/12] [UPD] README.rst --- .../static/description/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_purchase_stock_report_non_billed/static/description/index.html b/account_purchase_stock_report_non_billed/static/description/index.html index 8ece01fb..f78a6085 100644 --- a/account_purchase_stock_report_non_billed/static/description/index.html +++ b/account_purchase_stock_report_non_billed/static/description/index.html @@ -3,7 +3,7 @@ - + Account Purchase Stock Report Non Billed