diff --git a/stock_picking_batch_account/README.rst b/stock_picking_batch_account/README.rst new file mode 100644 index 000000000000..78c4875d2af4 --- /dev/null +++ b/stock_picking_batch_account/README.rst @@ -0,0 +1,125 @@ +=========================== +Stock batch picking account +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8ab90eb47719b5032ace6f98b5daf6f62804a2788a3e23c65d7ea3e0e09dbc8f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fstock--logistics--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_picking_batch_account + :alt: OCA/stock-logistics-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_picking_batch_account + :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/stock-logistics-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds support for the automatic creation of invoices when a +batch is set to the **Done** state and allows printing the invoices of +the sales orders linked to the batch pickings. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to check 'Batch picking auto invoice' +field of the partners for whom you want the invoice to be automatically +generated when any batch that has a 'Picking' to which they belong is +set to 'done' state. + +1. Go to each of those partner, edit them, find 'Batch picking auto + invoice' field under 'Sales & Purchase' tab and check it. + +Usage +===== + +To use this module, you need to: + +1. Go to *Inventory > Operations > Batch Transfers*. +2. Create a new batch and add some pickings such that their partners + have the option 'Batch picking auto invoice' checked (See + configuration section). Make sure the selected pickings are linked to + a sales order. +3. Confirm the batch. +4. Set the batch to 'done' state. After that, invoices will be generated + for all sales orders linked to the pickings of the batch. +5. Click on 'Print Invoices' button in the status bar and you will see a + PDF report for all the generated invoices. + +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 `__: + + - Ernesto Tejeda + - Pedro M. Baeza + - Carlos Dauden + - Sergio Teruel + +- `Moduon Team `__: + + - Eduardo de Miguel + +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-ernestotejeda| image:: https://github.com/ernestotejeda.png?size=40px + :target: https://github.com/ernestotejeda + :alt: ernestotejeda +.. |maintainer-Andrii9090| image:: https://github.com/Andrii9090.png?size=40px + :target: https://github.com/Andrii9090 + :alt: Andrii9090 + +Current `maintainers `__: + +|maintainer-ernestotejeda| |maintainer-Andrii9090| + +This module is part of the `OCA/stock-logistics-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_picking_batch_account/__init__.py b/stock_picking_batch_account/__init__.py new file mode 100644 index 000000000000..31660d6a9650 --- /dev/null +++ b/stock_picking_batch_account/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/stock_picking_batch_account/__manifest__.py b/stock_picking_batch_account/__manifest__.py new file mode 100644 index 000000000000..e9e1e671e2d3 --- /dev/null +++ b/stock_picking_batch_account/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# Copyright 2023 Moduon Team - Eduardo de Miguel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock batch picking account", + "summary": "Generates invoices when batch is set to Done state", + "version": "18.0.1.0.0", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["ernestotejeda", "Andrii9090"], + "development_status": "Beta", + "category": "Warehouse Management", + "depends": ["stock_picking_batch", "sale"], + "website": "https://github.com/OCA/stock-logistics-workflow", + "data": ["views/stock_batch_picking.xml", "views/res_partner_views.xml"], + "installable": True, + "license": "AGPL-3", +} diff --git a/stock_picking_batch_account/i18n/es.po b/stock_picking_batch_account/i18n/es.po new file mode 100644 index 000000000000..83f696689867 --- /dev/null +++ b/stock_picking_batch_account/i18n/es.po @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_batch_extended_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-07-31 17:27+0000\n" +"PO-Revision-Date: 2022-07-31 19:28+0200\n" +"Last-Translator: Sergio Teruel \n" +"Language-Team: none\n" +"Language: es\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" + +#. module: stock_picking_batch_extended_account +#: model:ir.model.fields,field_description:stock_picking_batch_extended_account.field_res_partner__batch_picking_auto_invoice +#: model:ir.model.fields,field_description:stock_picking_batch_extended_account.field_res_users__batch_picking_auto_invoice +msgid "Batch Picking Auto Invoice" +msgstr "Facturación automática en agrupación de albaranes" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_stock_picking_batch +msgid "Batch Transfer" +msgstr "Agrupación de albaranes" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: stock_picking_batch_extended_account +#: model:ir.model.fields.selection,name:stock_picking_batch_extended_account.selection__res_partner__batch_picking_auto_invoice__no +msgid "No" +msgstr "No" + +#. module: stock_picking_batch_extended_account +#: code:addons/stock_picking_batch_extended_account/models/stock_batch_picking.py:0 +#, python-format +msgid "Nothing to print." +msgstr "Nada para imprimir." + +#. module: stock_picking_batch_extended_account +#: model_terms:ir.ui.view,arch_db:stock_picking_batch_extended_account.stock_picking_batch_form +msgid "Print Invoices" +msgstr "Imprimir facturas" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_stock_picking +msgid "Transfer" +msgstr "Albarán" + +#. module: stock_picking_batch_extended_account +#: model:ir.model.fields.selection,name:stock_picking_batch_extended_account.selection__res_partner__batch_picking_auto_invoice__yes +msgid "Yes" +msgstr "Si" diff --git a/stock_picking_batch_account/i18n/it.po b/stock_picking_batch_account/i18n/it.po new file mode 100644 index 000000000000..c0d45846f4e6 --- /dev/null +++ b/stock_picking_batch_account/i18n/it.po @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_batch_extended_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-02 10:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\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.17\n" + +#. module: stock_picking_batch_extended_account +#: model:ir.model.fields,field_description:stock_picking_batch_extended_account.field_res_partner__batch_picking_auto_invoice +#: model:ir.model.fields,field_description:stock_picking_batch_extended_account.field_res_users__batch_picking_auto_invoice +msgid "Batch Picking Auto Invoice" +msgstr "Auto fattura prelievo ragruppato" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_stock_picking_batch +msgid "Batch Transfer" +msgstr "Trasferimento raggruppato" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: stock_picking_batch_extended_account +#: model:ir.model.fields.selection,name:stock_picking_batch_extended_account.selection__res_partner__batch_picking_auto_invoice__no +msgid "No" +msgstr "No" + +#. module: stock_picking_batch_extended_account +#. odoo-python +#: code:addons/stock_picking_batch_extended_account/models/stock_batch_picking.py:0 +#, python-format +msgid "Nothing to print." +msgstr "Niente da stampare." + +#. module: stock_picking_batch_extended_account +#: model_terms:ir.ui.view,arch_db:stock_picking_batch_extended_account.stock_picking_batch_form +msgid "Print Invoices" +msgstr "Stampa fatture" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_stock_picking +msgid "Transfer" +msgstr "Trasferimento" + +#. module: stock_picking_batch_extended_account +#: model:ir.model.fields.selection,name:stock_picking_batch_extended_account.selection__res_partner__batch_picking_auto_invoice__yes +msgid "Yes" +msgstr "Sì" diff --git a/stock_picking_batch_account/i18n/stock_picking_batch_extended_account.pot b/stock_picking_batch_account/i18n/stock_picking_batch_extended_account.pot new file mode 100644 index 000000000000..1bd37751640f --- /dev/null +++ b/stock_picking_batch_account/i18n/stock_picking_batch_extended_account.pot @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_batch_extended_account +# +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: stock_picking_batch_extended_account +#: model:ir.model.fields,field_description:stock_picking_batch_extended_account.field_res_partner__batch_picking_auto_invoice +#: model:ir.model.fields,field_description:stock_picking_batch_extended_account.field_res_users__batch_picking_auto_invoice +msgid "Batch Picking Auto Invoice" +msgstr "" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_stock_picking_batch +msgid "Batch Transfer" +msgstr "" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_res_partner +msgid "Contact" +msgstr "" + +#. module: stock_picking_batch_extended_account +#: model:ir.model.fields.selection,name:stock_picking_batch_extended_account.selection__res_partner__batch_picking_auto_invoice__no +msgid "No" +msgstr "" + +#. module: stock_picking_batch_extended_account +#. odoo-python +#: code:addons/stock_picking_batch_extended_account/models/stock_batch_picking.py:0 +#, python-format +msgid "Nothing to print." +msgstr "" + +#. module: stock_picking_batch_extended_account +#: model_terms:ir.ui.view,arch_db:stock_picking_batch_extended_account.stock_picking_batch_form +msgid "Print Invoices" +msgstr "" + +#. module: stock_picking_batch_extended_account +#: model:ir.model,name:stock_picking_batch_extended_account.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: stock_picking_batch_extended_account +#: model:ir.model.fields.selection,name:stock_picking_batch_extended_account.selection__res_partner__batch_picking_auto_invoice__yes +msgid "Yes" +msgstr "" diff --git a/stock_picking_batch_account/models/__init__.py b/stock_picking_batch_account/models/__init__.py new file mode 100644 index 000000000000..f96ee6e9d120 --- /dev/null +++ b/stock_picking_batch_account/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import res_partner +from . import stock_batch_picking +from . import stock_picking diff --git a/stock_picking_batch_account/models/res_partner.py b/stock_picking_batch_account/models/res_partner.py new file mode 100644 index 000000000000..d40590bfb604 --- /dev/null +++ b/stock_picking_batch_account/models/res_partner.py @@ -0,0 +1,17 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + batch_picking_auto_invoice = fields.Selection( + [("yes", "Yes"), ("no", "No")], default="no", company_dependent=True + ) + + @api.model + def _commercial_fields(self): + res = super()._commercial_fields() + return res + ["batch_picking_auto_invoice"] diff --git a/stock_picking_batch_account/models/stock_batch_picking.py b/stock_picking_batch_account/models/stock_batch_picking.py new file mode 100644 index 000000000000..9fff45d258dc --- /dev/null +++ b/stock_picking_batch_account/models/stock_batch_picking.py @@ -0,0 +1,28 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models +from odoo.exceptions import UserError + + +class StockBatchPicking(models.Model): + _inherit = "stock.picking.batch" + + def action_print_invoices(self): + invoices = self.mapped("picking_ids.sale_id.invoice_ids") + if not invoices: + raise UserError(self.env._("Nothing to print.")) + report = self.env.ref("account.account_invoices_without_payment") + return report.report_action(invoices) + + def _get_domain_picking_to_invoice(self): + return [("partner_id.batch_picking_auto_invoice", "=", "yes")] + + def _get_self_with_context_to_invoice(self): + to_invoice = self.mapped("picking_ids").filtered_domain( + self._get_domain_picking_to_invoice() + ) + return self.with_context(picking_to_invoice_in_batch=to_invoice.ids) + + def action_done(self): + self_with_ctx = self._get_self_with_context_to_invoice() + return super(StockBatchPicking, self_with_ctx).action_done() diff --git a/stock_picking_batch_account/models/stock_picking.py b/stock_picking_batch_account/models/stock_picking.py new file mode 100644 index 000000000000..7a7f561c525d --- /dev/null +++ b/stock_picking_batch_account/models/stock_picking.py @@ -0,0 +1,34 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# Copyright 2023 Moduon +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _action_done(self): + result = super()._action_done() + picking_to_invoice_ids = self.env.context.get( + "picking_to_invoice_in_batch", + ) + if not picking_to_invoice_ids: + return result + sales = self.filtered(lambda r: r.id in picking_to_invoice_ids).mapped( + "sale_id" + ) + sales_to_invoice = sales.filtered(lambda so: so.invoice_status == "to invoice") + if not sales_to_invoice: + return result + self.env["sale.advance.payment.inv"].with_context( + active_model="sale.order", active_ids=sales_to_invoice.ids + ).create( + { + "advance_payment_method": "delivered", + } + ).create_invoices() + sales_to_invoice.mapped("invoice_ids").filtered( + lambda r: r.state == "draft", + ).action_post() + return result diff --git a/stock_picking_batch_account/pyproject.toml b/stock_picking_batch_account/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/stock_picking_batch_account/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/stock_picking_batch_account/readme/CONFIGURE.md b/stock_picking_batch_account/readme/CONFIGURE.md new file mode 100644 index 000000000000..69f22afa147f --- /dev/null +++ b/stock_picking_batch_account/readme/CONFIGURE.md @@ -0,0 +1,7 @@ +To configure this module, you need to check 'Batch picking auto invoice' +field of the partners for whom you want the invoice to be automatically +generated when any batch that has a 'Picking' to which they belong is +set to 'done' state. + +1. Go to each of those partner, edit them, find 'Batch picking auto + invoice' field under 'Sales & Purchase' tab and check it. diff --git a/stock_picking_batch_account/readme/CONTRIBUTORS.md b/stock_picking_batch_account/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..73e473db0255 --- /dev/null +++ b/stock_picking_batch_account/readme/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +- [Tecnativa](https://www.tecnativa.com): + - Ernesto Tejeda + - Pedro M. Baeza + - Carlos Dauden + - Sergio Teruel +- [Moduon Team](https://www.moduon.team): + - Eduardo de Miguel diff --git a/stock_picking_batch_account/readme/DESCRIPTION.md b/stock_picking_batch_account/readme/DESCRIPTION.md new file mode 100644 index 000000000000..c6f08e3b5219 --- /dev/null +++ b/stock_picking_batch_account/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module adds support for the automatic creation of invoices when a batch +is set to the **Done** state and allows printing the invoices of the sales orders +linked to the batch pickings. \ No newline at end of file diff --git a/stock_picking_batch_account/readme/USAGE.md b/stock_picking_batch_account/readme/USAGE.md new file mode 100644 index 000000000000..1554bfd2dea7 --- /dev/null +++ b/stock_picking_batch_account/readme/USAGE.md @@ -0,0 +1,12 @@ +To use this module, you need to: + +1. Go to *Inventory \> Operations \> Batch Transfers*. +2. Create a new batch and add some pickings such that their partners + have the option 'Batch picking auto invoice' checked (See + configuration section). Make sure the selected pickings are linked + to a sales order. +3. Confirm the batch. +4. Set the batch to 'done' state. After that, invoices will be + generated for all sales orders linked to the pickings of the batch. +5. Click on 'Print Invoices' button in the status bar and you will see + a PDF report for all the generated invoices. diff --git a/stock_picking_batch_account/static/description/icon.png b/stock_picking_batch_account/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/stock_picking_batch_account/static/description/icon.png differ diff --git a/stock_picking_batch_account/static/description/index.html b/stock_picking_batch_account/static/description/index.html new file mode 100644 index 000000000000..13415e0ab170 --- /dev/null +++ b/stock_picking_batch_account/static/description/index.html @@ -0,0 +1,466 @@ + + + + + +Stock batch picking account + + + +
+

Stock batch picking account

+ + +

Beta License: AGPL-3 OCA/stock-logistics-workflow Translate me on Weblate Try me on Runboat

+

This module adds support for the automatic creation of invoices when a +batch is set to the Done state and allows printing the invoices of +the sales orders linked to the batch pickings.

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to check ‘Batch picking auto invoice’ +field of the partners for whom you want the invoice to be automatically +generated when any batch that has a ‘Picking’ to which they belong is +set to ‘done’ state.

+
    +
  1. Go to each of those partner, edit them, find ‘Batch picking auto +invoice’ field under ‘Sales & Purchase’ tab and check it.
  2. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Inventory > Operations > Batch Transfers.
  2. +
  3. Create a new batch and add some pickings such that their partners +have the option ‘Batch picking auto invoice’ checked (See +configuration section). Make sure the selected pickings are linked to +a sales order.
  4. +
  5. Confirm the batch.
  6. +
  7. Set the batch to ‘done’ state. After that, invoices will be generated +for all sales orders linked to the pickings of the batch.
  8. +
  9. Click on ‘Print Invoices’ button in the status bar and you will see a +PDF report for all the generated invoices.
  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

+
    +
  • Tecnativa:
      +
    • Ernesto Tejeda
    • +
    • Pedro M. Baeza
    • +
    • Carlos Dauden
    • +
    • Sergio Teruel
    • +
    +
  • +
  • Moduon Team:
      +
    • Eduardo de Miguel
    • +
    +
  • +
+
+
+

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 maintainers:

+

ernestotejeda Andrii9090

+

This module is part of the OCA/stock-logistics-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_picking_batch_account/tests/__init__.py b/stock_picking_batch_account/tests/__init__.py new file mode 100644 index 000000000000..c675dc51a7ff --- /dev/null +++ b/stock_picking_batch_account/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2022 Sergio Teruel - Tecnativa +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import test_stock_picking_batch_extended_account diff --git a/stock_picking_batch_account/tests/test_stock_picking_batch_extended_account.py b/stock_picking_batch_account/tests/test_stock_picking_batch_extended_account.py new file mode 100644 index 000000000000..a54b2e40f8b2 --- /dev/null +++ b/stock_picking_batch_account/tests/test_stock_picking_batch_extended_account.py @@ -0,0 +1,128 @@ +# Copyright 2022 Tecnativa - Sergio Teruel +# Copyright 2023 Moduon Team - Eduardo de Miguel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.tests import Form, TransactionCase + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +class TestStockPickingBatchExtendedAccount(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + cls.SaleOrder = cls.env["sale.order"] + cls.product_uom_id = cls.env.ref("uom.product_uom_unit") + cls.stock_loc = cls.browse_ref(cls, "stock.stock_location_stock") + cls.company = cls.env.company + cls.product = cls.env["product.product"].create( + { + "name": "test", + "type": "consu", + "is_storable": True, + "list_price": 20.00, + "invoice_policy": "delivery", + } + ) + cls.env["stock.quant"].create( + { + "product_id": cls.product.id, + "product_uom_id": cls.product.uom_id.id, + "location_id": cls.stock_loc.id, + "quantity": 100.0, + } + ) + cls.partner = cls.env["res.partner"].create( + {"name": "partner test 1", "batch_picking_auto_invoice": "no"} + ) + cls.partner2 = cls.env["res.partner"].create( + {"name": "partner test 2", "batch_picking_auto_invoice": "no"} + ) + + def _create_sale_order(self, partner): + with Form(self.env["sale.order"]) as so_form: + so_form.partner_id = partner + with so_form.order_line.new() as line_form: + line_form.product_id = self.product + line_form.product_uom_qty = 1.0 + return so_form.save() + + def _create_batch_picking(self, pickings): + # Create the BP + with Form( + self.env["stock.picking.to.batch"].with_context( + active_ids=pickings.ids, active_model="stock.picking" + ) + ) as wiz_form: + wiz_form.mode = "new" + wiz = wiz_form.save() + wiz.attach_pickings() + return pickings.mapped("batch_id") + + def _process_immediate_transfer(self, res_action): + sit_model = self.env[res_action["res_model"]].with_context( + **res_action["context"] + ) + immediate_transfer_wiz_vals = sit_model.default_get( + [ + "pick_ids", + "show_transfers", + "immediate_transfer_line_ids", + ] + ) + wiz = sit_model.create(immediate_transfer_wiz_vals) + return wiz.process() + + def test_create_invoice_from_bp_no_invoices(self): + self.partner.batch_picking_auto_invoice = "no" + self.partner2.batch_picking_auto_invoice = "no" + self.order1 = self._create_sale_order(self.partner) + self.order2 = self._create_sale_order(self.partner2) + self.order1.action_confirm() + self.order2.action_confirm() + pickings = self.order1.picking_ids + self.order2.picking_ids + move_lines = pickings.mapped("move_line_ids") + move_lines.quantity = 1.0 + bp = self._create_batch_picking(pickings) + bp.action_assign() + action_done_res = bp.action_done() + if action_done_res is not True: + self._process_immediate_transfer(action_done_res) + self.assertFalse(self.order1.invoice_ids) + self.assertFalse(self.order2.invoice_ids) + + def test_create_invoice_from_bp_all_invoices(self): + self.partner.batch_picking_auto_invoice = "yes" + self.partner2.batch_picking_auto_invoice = "yes" + self.order1 = self._create_sale_order(self.partner) + self.order2 = self._create_sale_order(self.partner2) + self.order1.action_confirm() + self.order2.action_confirm() + pickings = self.order1.picking_ids + self.order2.picking_ids + move_lines = pickings.mapped("move_line_ids") + move_lines.quantity = 1.0 + bp = self._create_batch_picking(pickings) + bp.action_assign() + action_done_res = bp.action_done() + if action_done_res is not True: + self._process_immediate_transfer(action_done_res) + self.assertTrue(self.order1.invoice_ids) + self.assertTrue(self.order2.invoice_ids) + + def test_create_invoice_from_bp_mixin(self): + self.partner.batch_picking_auto_invoice = "yes" + self.partner2.batch_picking_auto_invoice = "no" + self.order1 = self._create_sale_order(self.partner) + self.order2 = self._create_sale_order(self.partner2) + self.order1.action_confirm() + self.order2.action_confirm() + pickings = self.order1.picking_ids + self.order2.picking_ids + move_lines = pickings.mapped("move_line_ids") + move_lines.quantity = 1.0 + bp = self._create_batch_picking(pickings) + bp.action_assign() + action_done_res = bp.action_done() + if action_done_res is not True: + self._process_immediate_transfer(action_done_res) + self.assertTrue(self.order1.invoice_ids) + self.assertFalse(self.order2.invoice_ids) diff --git a/stock_picking_batch_account/views/res_partner_views.xml b/stock_picking_batch_account/views/res_partner_views.xml new file mode 100644 index 000000000000..0fb98fe50a7b --- /dev/null +++ b/stock_picking_batch_account/views/res_partner_views.xml @@ -0,0 +1,21 @@ + + + + res.partner.form + res.partner + + + + + + + + + + + + + diff --git a/stock_picking_batch_account/views/stock_batch_picking.xml b/stock_picking_batch_account/views/stock_batch_picking.xml new file mode 100644 index 000000000000..7d38257f7e1b --- /dev/null +++ b/stock_picking_batch_account/views/stock_batch_picking.xml @@ -0,0 +1,17 @@ + + + + stock.picking.batch + + + +