Skip to content

Commit

Permalink
[17][FW] sale_automatic_workflow: forward-port of PR 2642 - add send …
Browse files Browse the repository at this point in the history
…invoice option
  • Loading branch information
john-herholz-dt committed Oct 21, 2024
1 parent 6bd244c commit 820c5df
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 138 deletions.
74 changes: 38 additions & 36 deletions sale_automatic_workflow/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Sale Automatic Workflow
=======================

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand All @@ -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|
Expand All @@ -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**

Expand All @@ -61,45 +62,46 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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 <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_automatic_workflow%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_automatic_workflow%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~
-------

* Akretion
* Camptocamp
* Sodexis

Contributors
~~~~~~~~~~~~

* Guewen Baconnier
* Beau Sebastien
* Leonardo Pistone
* Stéphane Bidoul
* Damien Crier
* Alexandre Fayolle
* Sodexis
* Dave Lasley <[email protected]>
* Akim Juillerat <[email protected]>
* Thomas Fossoul <[email protected]>
* Phuc Tran Thanh <[email protected]>
* John Herholz <[email protected]>
------------

- Guewen Baconnier
- Beau Sebastien
- Leonardo Pistone
- Stéphane Bidoul
- Damien Crier
- Alexandre Fayolle
- Sodexis
- Dave Lasley <[email protected]>
- Akim Juillerat <[email protected]>
- Thomas Fossoul <[email protected]>
- Phuc Tran Thanh <[email protected]>
- Sander Lienaerts <[email protected]>
- Tri Doan <[email protected]>

Other credits
~~~~~~~~~~~~~
-------------

The development of this module has been financially supported by:

* Camptocamp
- Camptocamp

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -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 <https://github.com/OCA/sale-workflow/tree/16.0/sale_automatic_workflow>`_ project on GitHub.
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/17.0/sale_automatic_workflow>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
55 changes: 9 additions & 46 deletions sale_automatic_workflow/models/automatic_workflow_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"

Check warning on line 151 in sale_automatic_workflow/models/automatic_workflow_job.py

View check run for this annotation

Codecov / codecov/patch

sale_automatic_workflow/models/automatic_workflow_job.py#L150-L151

Added lines #L150 - L151 were not covered by tests

@api.model
def _sale_done(self, sale_done_filter):
Expand Down
8 changes: 0 additions & 8 deletions sale_automatic_workflow/models/sale_workflow_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
12 changes: 0 additions & 12 deletions sale_automatic_workflow/readme/CONTRIBUTORS.rst

This file was deleted.

22 changes: 0 additions & 22 deletions sale_automatic_workflow/readme/DESCRIPTION.rst

This file was deleted.

13 changes: 8 additions & 5 deletions sale_automatic_workflow/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Sale Automatic Workflow</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2e02c7c445382c52a5a523e511d78a5d40cecafe955493cbe280b78597066a5a
!! source digest: sha256:6c461bb0f25bae8120a4bba197db362e406de92f6fa19a1a3f8609971609b1f8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-workflow/tree/17.0/sale_automatic_workflow"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-sale_automatic_workflow"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Create workflows with more or less automatization and apply it on sales
Expand Down Expand Up @@ -450,7 +451,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
6 changes: 0 additions & 6 deletions sale_automatic_workflow/tests/test_multicompany.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions sale_automatic_workflow/views/sale_workflow_process_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,17 @@
<div class="col-sm-8">
<label
for="send_invoice_filter_id"
attrs="{'required':[('send_invoice','=',True)], 'invisible':[('send_invoice','!=',True)]}"
required="send_invoice"
invisible="not send_invoice"
/>
<div
attrs="{'required':[('send_invoice','=',True)], 'invisible':[('send_invoice','!=',True)]}"
required="send_invoice"
invisible="not send_invoice"
>
<field
name="send_invoice_filter_domain"
widget="domain"
attrs="{'invisible': [('send_invoice_filter_id', '=', False)]}"
invisible="not send_invoice_filter_id"
options="{'model': 'account.move'}"
/>
<div class="oe_edit_only oe_inline">
Expand Down

0 comments on commit 820c5df

Please sign in to comment.