Skip to content

Commit

Permalink
[MIG] sale_automatic_workflow: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderlienaerts authored and trisdoan committed Jun 21, 2024
1 parent c25f9bd commit 6a3f68b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 54 deletions.
2 changes: 1 addition & 1 deletion sale_automatic_workflow/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "Sale Automatic Workflow",
"version": "16.0.1.0.2",
"version": "17.0.1.0.0",
"category": "Sales Management",
"license": "AGPL-3",
"author": "Akretion, "
Expand Down
2 changes: 1 addition & 1 deletion sale_automatic_workflow/data/automatic_workflow_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<field name="model_id">sale.order</field>
<field
name="domain"
>[('state','in',['sale','done']),('invoice_status','=','to invoice')]</field>
>[('state','=','sale'),('invoice_status','=','to invoice')]</field>
<field name="user_id" ref="base.user_root" />
</record>
<record id="automatic_workflow_validate_invoice_filter" model="ir.filters">
Expand Down
9 changes: 4 additions & 5 deletions sale_automatic_workflow/models/automatic_workflow_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,17 @@ def _validate_pickings(self, picking_filter):
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"""
"""Lock a sales order, filter ensure no duplication"""
if not self.env["sale.order"].search_count(
[("id", "=", sale.id)] + domain_filter
):
return f"{sale.display_name} {sale} job bypassed"
sale.action_done()
return f"{sale.display_name} {sale} set done successfully"
sale.action_lock()
return f"{sale.display_name} {sale} locked successfully"

@api.model
def _sale_done(self, sale_done_filter):
sale_obj = self.env["sale.order"]
sales = sale_obj.search(sale_done_filter)
sales = self.env["sale.order"].search(sale_done_filter)
_logger.debug("Sale Orders to done: %s", sales.ids)
for sale in sales:
with savepoint(self.env.cr):
Expand Down
6 changes: 3 additions & 3 deletions sale_automatic_workflow/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def validate_picking(self):
for picking in self:
picking.action_assign()
for move in picking.move_ids.filtered(
lambda m: m.state not in ["done", "cancel"]
lambda m: m.picked and m.state not in ["done", "cancel"]
):
rounding = move.product_id.uom_id.rounding
if (
float_compare(
move.quantity_done,
move.quantity,
move.product_qty,
precision_rounding=rounding,
)
== -1
):
for move_line in move.move_line_ids:
move_line.qty_done = move_line.reserved_uom_qty
move_line.quantity = move_line.quantity_product_uom
picking.with_context(skip_immediate=True, skip_sms=True).button_validate()
return True
36 changes: 12 additions & 24 deletions sale_automatic_workflow/tests/test_multicompany.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests import tagged

from .common import TestCommon
from odoo.addons.account.tests.common import AccountTestInvoicingCommon


@tagged("post_install", "-at_install")
class TestMultiCompany(TestCommon):
def setUp(self):
super().setUp()

@classmethod
def create_company(cls, values):
return cls.env["res.company"].create(values)

class TestMultiCompany(AccountTestInvoicingCommon):
@classmethod
def create_product(cls, values):
values.update({"type": "consu", "invoice_policy": "order"})
product_template = cls.env["product.template"].create(values)
return product_template.product_variant_id

@classmethod
def setUpClass(cls):
def setUpClass(cls, chart_template_ref=None):
super().setUpClass()
cls.env = cls.env(
context=dict(
Expand All @@ -34,46 +26,44 @@ def setUpClass(cls):
_job_force_sync=True,
)
)
coa = cls.env.user.company_id.chart_template_id
cls.company_fr = cls.create_company(
cls.company_fr = cls.setup_company_data(
{
"name": "French company",
"currency_id": cls.env.ref("base.EUR").id,
"country_id": cls.env.ref("base.fr").id,
}
)
)["company"]

cls.company_ch = cls.create_company(
cls.company_ch = cls.setup_company_data(
{
"name": "Swiss company",
"currency_id": cls.env.ref("base.CHF").id,
"country_id": cls.env.ref("base.ch").id,
}
)
)["company"]

cls.company_be = cls.create_company(
cls.company_be = cls.setup_company_data(
{
"name": "Belgian company",
"currency_id": cls.env.ref("base.EUR").id,
"country_id": cls.env.ref("base.be").id,
}
)
)["company"]

cls.company_fr_daughter = cls.create_company(
cls.company_fr_daughter = cls.setup_company_data(
{
"name": "French company daughter",
"currency_id": cls.env.ref("base.EUR").id,
"country_id": cls.env.ref("base.fr").id,
}
)
)["company"]

cls.env.user.company_ids |= cls.company_fr
cls.env.user.company_ids |= cls.company_ch
cls.env.user.company_ids |= cls.company_be
cls.env.user.company_ids |= cls.company_fr_daughter

cls.env.user.company_id = cls.company_fr.id
coa.try_loading(company=cls.env.user.company_id)
cls.customer_fr = (
cls.env["res.partner"]
.with_context(default_company_id=cls.company_fr.id)
Expand All @@ -82,14 +72,13 @@ def setUpClass(cls):
cls.product_fr = cls.create_product({"name": "Evian bottle", "list_price": 2.0})

cls.env.user.company_id = cls.company_ch.id
coa.try_loading(company=cls.env.user.company_id)

cls.customer_ch = cls.env["res.partner"].create({"name": "Customer CH"})
cls.product_ch = cls.create_product(
{"name": "Henniez bottle", "list_price": 3.0}
)

cls.env.user.company_id = cls.company_be.id
coa.try_loading(company=cls.env.user.company_id)
cls.customer_be = cls.env["res.partner"].create({"name": "Customer BE"})
cls.product_be = (
cls.env["product.template"]
Expand All @@ -105,7 +94,6 @@ def setUpClass(cls):
)

cls.env.user.company_id = cls.company_fr_daughter.id
coa.try_loading(company=cls.env.user.company_id)
cls.customer_fr_daughter = cls.env["res.partner"].create(
{"name": "Customer FR Daughter"}
)
Expand Down
49 changes: 29 additions & 20 deletions sale_automatic_workflow/views/sale_workflow_process_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@
<div class="col-sm-8">
<label
for="order_filter_id"
attrs="{'required':[('validate_order','=',True)], 'invisible':[('validate_order','!=',True)]}"
required="validate_order"
invisible="not validate_order"
/>
<div
attrs="{'required':[('validate_order','=',True)], 'invisible':[('validate_order','!=',True)]}"
required="validate_order"
invisible="not validate_order"
>
<field
name="order_filter_domain"
widget="domain"
attrs="{'invisible': [('order_filter_id', '=', False)]}"
invisible="not order_filter_id"
options="{'model': 'sale.order'}"
/>
<div class="oe_edit_only oe_inline">
Expand Down Expand Up @@ -104,15 +106,17 @@
<div class="col-sm-8">
<label
for="picking_filter_id"
attrs="{'required':[('validate_picking','=',True)], 'invisible':[('validate_picking','!=',True)]}"
required="validate_picking"
invisible="not validate_picking"
/>
<div
attrs="{'required':[('validate_picking','=',True)], 'invisible':[('validate_picking','!=',True)]}"
required="validate_picking"
invisible="not validate_picking"
>
<field
name="picking_filter_domain"
widget="domain"
attrs="{'invisible': [('picking_filter_id', '=', False)]}"
invisible="not picking_filter_id"
options="{'model': 'stock.picking'}"
/>
<div class="oe_edit_only oe_inline">
Expand Down Expand Up @@ -140,15 +144,17 @@
<div class="col-sm-8">
<label
for="create_invoice_filter_id"
attrs="{'required':[('create_invoice','=',True)], 'invisible':[('create_invoice','!=',True)]}"
required="create_invoice"
invisible="not create_invoice"
/>
<div
attrs="{'required':[('create_invoice','=',True)], 'invisible':[('create_invoice','!=',True)]}"
required="create_invoice"
invisible="not create_invoice"
>
<field
name="create_invoice_filter_domain"
widget="domain"
attrs="{'invisible': [('create_invoice_filter_id', '=', False)]}"
invisible="not create_invoice_filter_id"
options="{'model': 'sale.order'}"
/>
<div class="oe_edit_only oe_inline">
Expand Down Expand Up @@ -176,15 +182,17 @@
<div class="col-sm-8">
<label
for="validate_invoice_filter_id"
attrs="{'required':[('validate_invoice','=',True)], 'invisible':[('validate_invoice','!=',True)]}"
required="validate_invoice"
invisible="not validate_invoice"
/>
<div
attrs="{'required':[('validate_invoice','=',True)], 'invisible':[('validate_invoice','!=',True)]}"
required="validate_invoice"
invisible="not validate_invoice"
>
<field
name="validate_invoice_filter_domain"
widget="domain"
attrs="{'invisible': [('validate_invoice_filter_id', '=', False)]}"
invisible="not validate_invoice_filter_id"
options="{'model': 'account.move'}"
/>
<div class="oe_edit_only oe_inline">
Expand Down Expand Up @@ -212,15 +220,17 @@
<div class="col-sm-8">
<label
for="payment_filter_id"
attrs="{'required':[('register_payment','=',True)], 'invisible':[('register_payment','!=',True)]}"
required="register_payment"
invisible="not register_payment"
/>
<div
attrs="{'required':[('register_payment','=',True)], 'invisible':[('register_payment','!=',True)]}"
required="register_payment"
invisible="not register_payment"
>
<field
name="payment_filter_domain"
widget="domain"
attrs="{'invisible': [('payment_filter_id', '=', False)]}"
invisible="not payment_filter_id"
options="{'model': 'account.move'}"
/>
<div class="oe_edit_only oe_inline">
Expand All @@ -245,15 +255,14 @@
<div class="col-sm-8">
<label
for="sale_done_filter_id"
attrs="{'required':[('sale_done','=',True)], 'invisible':[('sale_done','!=',True)]}"
required="sale_done"
invisible="not sale_done"
/>
<div
attrs="{'required':[('sale_done','=',True)], 'invisible':[('sale_done','!=',True)]}"
>
<div required="sale_done" invisible="not sale_done">
<field
name="sale_done_filter_domain"
widget="domain"
attrs="{'invisible': [('sale_done_filter_id', '=', False)]}"
invisible="not sale_done_filter_id"
options="{'model': 'sale.order'}"
/>
<div class="oe_edit_only oe_inline">
Expand Down

0 comments on commit 6a3f68b

Please sign in to comment.