Skip to content

Commit

Permalink
[REF] sale_automatic_workflow|_stock: separate
Browse files Browse the repository at this point in the history
There is an issue for service companies that do not need the stock
module to be installed when using `sale_automatic_workflow`. Module
depended on `stock`, therefore it was auto installed. Now, stock related
part is moved to a separate module - `sale_automatic_workflow_stock` and
can be installed separately.
  • Loading branch information
SButko authored and trisdoan committed Jun 21, 2024
1 parent 6a3f68b commit 1d0e79e
Show file tree
Hide file tree
Showing 38 changed files with 1,294 additions and 342 deletions.
1 change: 1 addition & 0 deletions sale_automatic_workflow/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Contributors
- Thomas Fossoul <[email protected]>
- Phuc Tran Thanh <[email protected]>
- Sander Lienaerts <[email protected]>
- Tri Doan <[email protected]>

Other credits
-------------
Expand Down
6 changes: 3 additions & 3 deletions sale_automatic_workflow/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"Sodexis, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"depends": ["sale_stock", "sales_team"],
"depends": ["sale"],
"data": [
"security/ir.model.access.csv",
"views/sale_view.xml",
"views/sale_workflow_process_view.xml",
"views/sale_order_views.xml",
"views/sale_workflow_process_views.xml",
"data/automatic_workflow_data.xml",
],
"installable": True,
Expand Down
14 changes: 0 additions & 14 deletions sale_automatic_workflow/data/automatic_workflow_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
<field name="domain">[('state', '=', 'draft')]</field>
<field name="user_id" ref="base.user_root" />
</record>
<record id="automatic_workflow_picking_filter" model="ir.filters">
<field name="name">Automatic Workflow Picking Filter</field>
<field name="model_id">stock.picking</field>
<field
name="domain"
>[('state', 'in', ['draft', 'confirmed', 'assigned'])]</field>
<field name="user_id" ref="base.user_root" />
</record>
<record id="automatic_workflow_create_invoice_filter" model="ir.filters">
<field name="name">Automatic Workflow Create Invoice Filter</field>
<field name="model_id">sale.order</field>
Expand Down Expand Up @@ -52,7 +44,6 @@
</record>
<record id="automatic_validation" model="sale.workflow.process">
<field name="name">Automatic</field>
<field name="picking_policy">one</field>
<field name="validate_order" eval="1" />
<field name="send_order_confirmation_mail" eval="1" />
<field name="order_filter_id" eval="automatic_workflow_order_filter" />
Expand All @@ -67,8 +58,6 @@
eval="automatic_workflow_validate_invoice_filter"
/>
<field name="invoice_date_is_order_date" eval="0" />
<field name="validate_picking" eval="0" />
<field name="picking_filter_id" eval="automatic_workflow_picking_filter" />
<field name="sale_done" eval="0" />
<field name="sale_done_filter_id" eval="automatic_workflow_sale_done_filter" />
<field name="register_payment" eval="0" />
Expand All @@ -79,11 +68,9 @@
</record>
<record id="manual_validation" model="sale.workflow.process">
<field name="name">Manual</field>
<field name="picking_policy">one</field>
<field name="validate_order" eval="0" />
<field name="validate_invoice" eval="0" />
<field name="invoice_date_is_order_date" eval="0" />
<field name="validate_picking" eval="0" />
<field name="order_filter_id" eval="automatic_workflow_order_filter" />
<field
name="create_invoice_filter_id"
Expand All @@ -93,7 +80,6 @@
name="validate_invoice_filter_id"
eval="automatic_workflow_validate_invoice_filter"
/>
<field name="picking_filter_id" eval="automatic_workflow_picking_filter" />
<field name="sale_done_filter_id" eval="automatic_workflow_sale_done_filter" />
<field name="register_payment" eval="0" />
<field name="payment_filter_id" ref="automatic_workflow_payment_filter" />
Expand Down
2 changes: 0 additions & 2 deletions sale_automatic_workflow/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
from . import automatic_workflow_job
from . import sale_order
from . import sale_workflow_process
from . import stock_move
from . import stock_picking
27 changes: 5 additions & 22 deletions sale_automatic_workflow/models/automatic_workflow_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,6 @@ def _validate_invoices(self, validate_invoice_filter):
invoice.with_company(invoice.company_id), validate_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 f"{picking.display_name} {picking} job bypassed"
picking.validate_picking()
return f"{picking.display_name} {picking} validate picking successfully"

@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):
"""Lock a sales order, filter ensure no duplication"""
if not self.env["sale.order"].search_count(
Expand Down Expand Up @@ -188,6 +170,10 @@ def _register_payment_invoice(self, invoice):
[("account_id", "=", account.id), ("reconciled", "=", False)]
).reconcile()

@api.model
def _handle_pickings(self, sale_workflow):
pass

@api.model
def run_with_workflow(self, sale_workflow):
workflow_domain = [("workflow_process_id", "=", sale_workflow.id)]
Expand All @@ -197,10 +183,7 @@ def run_with_workflow(self, sale_workflow):
)._validate_sale_orders(
safe_eval(sale_workflow.order_filter_id.domain) + workflow_domain
)
if sale_workflow.validate_picking:
self._validate_pickings(
safe_eval(sale_workflow.picking_filter_id.domain) + workflow_domain
)
self._handle_pickings(sale_workflow)
if sale_workflow.create_invoice:
self._create_invoices(
safe_eval(sale_workflow.create_invoice_filter_id.domain)
Expand Down
35 changes: 24 additions & 11 deletions sale_automatic_workflow/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.tools import float_compare


class SaleOrder(models.Model):
Expand All @@ -20,10 +21,20 @@ class SaleOrder(models.Model):
store=True,
)

@api.depends("delivery_status")
@api.depends("order_line.qty_delivered", "order_line.product_uom_qty")
def _compute_all_qty_delivered(self):
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
for order in self:
order.all_qty_delivered = order.delivery_status == "full"
order.all_qty_delivered = all(
line.product_id.type == "service"
or float_compare(
line.qty_delivered, line.product_uom_qty, precision_digits=precision
)
== 0
for line in order.order_line
)

def _prepare_invoice(self):
invoice_vals = super()._prepare_invoice()
Expand All @@ -41,17 +52,19 @@ def _prepare_invoice(self):

@api.onchange("workflow_process_id")
def _onchange_workflow_process_id(self):
if not self.workflow_process_id:
return
workflow = self.workflow_process_id
if workflow.picking_policy:
self.picking_policy = workflow.picking_policy
if workflow.team_id:
self.team_id = workflow.team_id.id
if workflow.warning:
warning = {"title": _("Workflow Warning"), "message": workflow.warning}
if self.workflow_process_id.warning:
warning = {
"title": _("Workflow Warning"),
"message": self.workflow_process_id.warning,
}
return {"warning": warning}

@api.depends("partner_id", "user_id", "workflow_process_id")
def _compute_team_id(self): # pylint: disable=W8110
super()._compute_team_id()
if self.workflow_process_id.team_id:
self.team_id = self.workflow_process_id.team_id.id

def _create_invoices(self, grouped=False, final=False, date=None):
for order in self:
if not order.workflow_process_id.invoice_service_delivery:
Expand Down
19 changes: 0 additions & 19 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 All @@ -53,10 +45,6 @@ def _default_filter(self, xmlid):
string="Validate Invoice Filter Domain",
related="validate_invoice_filter_id.domain",
)
validate_picking = fields.Boolean(string="Confirm and Transfer Picking")
picking_filter_domain = fields.Text(
string="Picking Filter Domain", related="picking_filter_id.domain"
)
invoice_date_is_order_date = fields.Boolean(
string="Force Invoice Date",
help="When checked, the invoice date will be " "the same than the order's date",
Expand Down Expand Up @@ -91,13 +79,6 @@ def _default_filter(self, xmlid):
"sale_automatic_workflow.automatic_workflow_order_filter"
),
)
picking_filter_id = fields.Many2one(
"ir.filters",
string="Picking Filter",
default=lambda self: self._default_filter(
"sale_automatic_workflow.automatic_workflow_picking_filter"
),
)
create_invoice_filter_id = fields.Many2one(
"ir.filters",
string="Create Invoice Filter",
Expand Down
1 change: 1 addition & 0 deletions sale_automatic_workflow/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
- Thomas Fossoul \<<[email protected]>\>
- Phuc Tran Thanh \<<[email protected]>\>
- Sander Lienaerts \<<[email protected]>\>
- Tri Doan \<<[email protected]>\>
13 changes: 8 additions & 5 deletions sale_automatic_workflow/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,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 @@ -275,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 @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

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

span.section-subtitle {
Expand Down Expand Up @@ -438,6 +438,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Thomas Fossoul &lt;<a class="reference external" href="mailto:thomas&#64;niboo.com">thomas&#64;niboo.com</a>&gt;</li>
<li>Phuc Tran Thanh &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</li>
<li>Sander Lienaerts &lt;<a class="reference external" href="mailto:sander.lienaerts&#64;codeforward.nl">sander.lienaerts&#64;codeforward.nl</a>&gt;</li>
<li>Tri Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -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
Loading

0 comments on commit 1d0e79e

Please sign in to comment.