From 820c5df2c13578bb31ae5b91453a0465d7a944b9 Mon Sep 17 00:00:00 2001 From: John Herholz Date: Tue, 15 Oct 2024 18:53:58 +0200 Subject: [PATCH] [17][FW] sale_automatic_workflow: forward-port of PR 2642 - add send invoice option --- sale_automatic_workflow/README.rst | 74 ++++++++++--------- .../models/automatic_workflow_job.py | 55 +++----------- .../models/sale_workflow_process.py | 8 -- .../readme/CONTRIBUTORS.rst | 12 --- .../readme/DESCRIPTION.rst | 22 ------ .../static/description/index.html | 13 ++-- .../tests/test_multicompany.py | 6 -- .../views/sale_workflow_process_views.xml | 8 +- 8 files changed, 60 insertions(+), 138 deletions(-) delete mode 100644 sale_automatic_workflow/readme/CONTRIBUTORS.rst delete mode 100644 sale_automatic_workflow/readme/DESCRIPTION.rst diff --git a/sale_automatic_workflow/README.rst b/sale_automatic_workflow/README.rst index 3ee4c94f133..1f48a138503 100644 --- a/sale_automatic_workflow/README.rst +++ b/sale_automatic_workflow/README.rst @@ -2,7 +2,7 @@ Sale Automatic Workflow ======================= -.. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! @@ -17,13 +17,13 @@ Sale Automatic Workflow :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github - :target: https://github.com/OCA/sale-workflow/tree/16.0/sale_automatic_workflow + :target: https://github.com/OCA/sale-workflow/tree/17.0/sale_automatic_workflow :alt: OCA/sale-workflow .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_automatic_workflow + :target: https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-sale_automatic_workflow :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/sale-workflow&target_branch=16.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=17.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -33,22 +33,23 @@ orders. A workflow can: -- Apply default values: +- Apply default values: - * Shipping Policy (Deliver each product when available or Deliver all products at once) - * Set the invoice's date to the sale order's date - * Set a sales team + - Shipping Policy (Deliver each product when available or Deliver + all products at once) + - Set the invoice's date to the sale order's date + - Set a sales team -- Apply automatic actions: +- Apply automatic actions: - * Validate the order (only if paid, always, never) - * Send order confirmation mail (only when order confirmed) - * Create an invoice - * Validate the invoice - * Confirm the picking + - Validate the order (only if paid, always, never) + - Send order confirmation mail (only when order confirmed) + - Create an invoice + - Validate the invoice + - Confirm the picking -This module is used by Magentoerpconnect and Prestashoperpconnect. -It is well suited for other E-Commerce connectors as well. +This module is used by Magentoerpconnect and Prestashoperpconnect. It is +well suited for other E-Commerce connectors as well. **Table of contents** @@ -61,7 +62,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -69,37 +70,38 @@ Credits ======= Authors -~~~~~~~ +------- * Akretion * Camptocamp * Sodexis Contributors -~~~~~~~~~~~~ - -* Guewen Baconnier -* Beau Sebastien -* Leonardo Pistone -* Stéphane Bidoul -* Damien Crier -* Alexandre Fayolle -* Sodexis -* Dave Lasley -* Akim Juillerat -* Thomas Fossoul -* Phuc Tran Thanh -* John Herholz +------------ + +- Guewen Baconnier +- Beau Sebastien +- Leonardo Pistone +- Stéphane Bidoul +- Damien Crier +- Alexandre Fayolle +- Sodexis +- Dave Lasley +- Akim Juillerat +- Thomas Fossoul +- Phuc Tran Thanh +- Sander Lienaerts +- Tri Doan Other credits -~~~~~~~~~~~~~ +------------- The development of this module has been financially supported by: -* Camptocamp +- Camptocamp Maintainers -~~~~~~~~~~~ +----------- This module is maintained by the OCA. @@ -111,6 +113,6 @@ 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/sale-workflow `_ project on GitHub. +This module is part of the `OCA/sale-workflow `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_automatic_workflow/models/automatic_workflow_job.py b/sale_automatic_workflow/models/automatic_workflow_job.py index 18f12fc3155..9e72922810c 100644 --- a/sale_automatic_workflow/models/automatic_workflow_job.py +++ b/sale_automatic_workflow/models/automatic_workflow_job.py @@ -117,35 +117,18 @@ def _do_send_invoice(self, invoice, domain_filter): if not self.env["account.move"].search_count( [("id", "=", invoice.id)] + domain_filter ): - return "{} {} job bypassed".format(invoice.display_name, invoice) - - # take the context from the actual action_invoice_sent method - action = invoice.action_invoice_sent() - action_context = action["context"] + return f"{invoice.display_name} {invoice} job bypassed" - # Create the email using the wizard + move_template = self.env.ref("account.email_template_edi_invoice") invoice_send_wizard = ( - self.env["account.invoice.send"] - .with_context( - action_context, - mark_invoice_as_sent=True, - active_ids=[invoice.id], - force_email=True, - ) - .create( - { - "is_print": False, - "composition_mode": "comment", - "model": "account.move", - "res_id": invoice.id, - } - ) + self.env["account.move.send"] + .with_context(active_model="account.move", active_ids=invoice.ids) + .create({"checkbox_download": False, "mail_template_id": move_template.id}) ) - invoice_send_wizard.onchange_is_email() - invoice_send_wizard._send_email() + invoice_send_wizard.action_send_and_print(force_synchronous=True) - return "{} {} sent invoice successfully".format(invoice.display_name, invoice) + return f"{invoice.display_name} {invoice} sent invoice successfully" @api.model def _send_invoices(self, send_invoice_filter): @@ -158,34 +141,14 @@ def _send_invoices(self, send_invoice_filter): invoice.with_company(invoice.company_id), send_invoice_filter ) - def _do_validate_picking(self, picking, domain_filter): - """Validate a stock.picking, filter ensure no duplication""" - if not self.env["stock.picking"].search_count( - [("id", "=", picking.id)] + domain_filter - ): - return "{} {} job bypassed".format(picking.display_name, picking) - picking.validate_picking() - return "{} {} validate picking successfully".format( - picking.display_name, picking - ) - - @api.model - def _validate_pickings(self, picking_filter): - picking_obj = self.env["stock.picking"] - pickings = picking_obj.search(picking_filter) - _logger.debug("Pickings to validate: %s", pickings.ids) - for picking in pickings: - with savepoint(self.env.cr): - self._do_validate_picking(picking, picking_filter) - def _do_sale_done(self, sale, domain_filter): """Set a sales order to done, filter ensure no duplication""" if not self.env["sale.order"].search_count( [("id", "=", sale.id)] + domain_filter ): - return "{} {} job bypassed".format(sale.display_name, sale) + return f"{sale.display_name} {sale} job bypassed" sale.action_done() - return "{} {} set done successfully".format(sale.display_name, sale) + return f"{sale.display_name} {sale} set done successfully" @api.model def _sale_done(self, sale_done_filter): diff --git a/sale_automatic_workflow/models/sale_workflow_process.py b/sale_automatic_workflow/models/sale_workflow_process.py index fb81adb2418..a1bc575f7fe 100644 --- a/sale_automatic_workflow/models/sale_workflow_process.py +++ b/sale_automatic_workflow/models/sale_workflow_process.py @@ -28,14 +28,6 @@ def _default_filter(self, xmlid): return self.env["ir.filters"].browse() name = fields.Char(required=True) - picking_policy = fields.Selection( - selection=[ - ("direct", "Deliver each product when available"), - ("one", "Deliver all products at once"), - ], - string="Shipping Policy", - default="direct", - ) validate_order = fields.Boolean() send_order_confirmation_mail = fields.Boolean( help="When checked, after order confirmation, a confirmation email will be " diff --git a/sale_automatic_workflow/readme/CONTRIBUTORS.rst b/sale_automatic_workflow/readme/CONTRIBUTORS.rst deleted file mode 100644 index 324b53be26d..00000000000 --- a/sale_automatic_workflow/readme/CONTRIBUTORS.rst +++ /dev/null @@ -1,12 +0,0 @@ -* Guewen Baconnier -* Beau Sebastien -* Leonardo Pistone -* Stéphane Bidoul -* Damien Crier -* Alexandre Fayolle -* Sodexis -* Dave Lasley -* Akim Juillerat -* Thomas Fossoul -* Phuc Tran Thanh -* John Herholz diff --git a/sale_automatic_workflow/readme/DESCRIPTION.rst b/sale_automatic_workflow/readme/DESCRIPTION.rst deleted file mode 100644 index 8a51def1e2f..00000000000 --- a/sale_automatic_workflow/readme/DESCRIPTION.rst +++ /dev/null @@ -1,22 +0,0 @@ -Create workflows with more or less automatization and apply it on sales -orders. - -A workflow can: - -- Apply default values: - - * Shipping Policy (Deliver each product when available or Deliver all products at once) - * Set the invoice's date to the sale order's date - * Set a sales team - -- Apply automatic actions: - - * Validate the order (only if paid, always, never) - * Send order confirmation mail (only when order confirmed) - * Create an invoice - * Validate the invoice - * Send the invoice via e-mail - * Confirm the picking - -This module is used by Magentoerpconnect and Prestashoperpconnect. -It is well suited for other E-Commerce connectors as well. diff --git a/sale_automatic_workflow/static/description/index.html b/sale_automatic_workflow/static/description/index.html index 546a3cd99ec..57a49f8ce0b 100644 --- a/sale_automatic_workflow/static/description/index.html +++ b/sale_automatic_workflow/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -366,7 +367,7 @@

Sale Automatic Workflow

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:2e02c7c445382c52a5a523e511d78a5d40cecafe955493cbe280b78597066a5a +!! source digest: sha256:6c461bb0f25bae8120a4bba197db362e406de92f6fa19a1a3f8609971609b1f8 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

Create workflows with more or less automatization and apply it on sales @@ -450,7 +451,9 @@

Other credits

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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.

diff --git a/sale_automatic_workflow/tests/test_multicompany.py b/sale_automatic_workflow/tests/test_multicompany.py index 7eb9f0d199e..50f45abe5d6 100644 --- a/sale_automatic_workflow/tests/test_multicompany.py +++ b/sale_automatic_workflow/tests/test_multicompany.py @@ -33,12 +33,6 @@ def test_sale_order_multicompany(self): self.assertEqual(order_fr_daughter.state, "draft") self.env["automatic.workflow.job"].run() - self.assertTrue(order_fr.picking_ids) - self.assertTrue(order_ch.picking_ids) - self.assertTrue(order_be.picking_ids) - self.assertEqual(order_fr.picking_ids.state, "done") - self.assertEqual(order_ch.picking_ids.state, "done") - self.assertEqual(order_be.picking_ids.state, "done") invoice_fr = order_fr.invoice_ids invoice_ch = order_ch.invoice_ids invoice_be = order_be.invoice_ids diff --git a/sale_automatic_workflow/views/sale_workflow_process_views.xml b/sale_automatic_workflow/views/sale_workflow_process_views.xml index d4d7e82b648..c2638e9ac81 100644 --- a/sale_automatic_workflow/views/sale_workflow_process_views.xml +++ b/sale_automatic_workflow/views/sale_workflow_process_views.xml @@ -171,15 +171,17 @@