Skip to content

Commit

Permalink
Add sale_confirm_background
Browse files Browse the repository at this point in the history
  • Loading branch information
guewen committed Jun 9, 2020
1 parent c8a9171 commit 78beff6
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 0 deletions.
1 change: 1 addition & 0 deletions sale_confirm_background/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions sale_confirm_background/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Sale Confirmed in Background',
'version': '10.0.1.0.0',
'author': 'Camptocamp',
'license': 'AGPL-3',
'category': 'Sales',
'depends': [
'sale',
'queue_job',
'web_notify',
'sale_exception',
],
'website': 'https://www.camptocamp.com',
'data': [
'views/sale_order_views.xml',
],
'installable': True,
}
45 changes: 45 additions & 0 deletions sale_confirm_background/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_confirm_background
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-06-28 06:18+0000\n"
"PO-Revision-Date: 2018-06-28 06:18+0000\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: sale_confirm_background
#: model:ir.ui.view,arch_db:sale_confirm_background.view_order_background_form
msgid "Cancel"
msgstr "Annuler"

#. module: sale_confirm_background
#: code:addons/sale_confirm_background/models/sale_order.py:48
#, python-format
msgid "Confirmation of sales order %s"
msgstr "Confirmation de la commande %s"

#. module: sale_confirm_background
#: code:addons/sale_confirm_background/models/sale_order.py:30
#, python-format
msgid "Order %s is now confirmed."
msgstr "La commande %s est maintenant confirmée."

#. module: sale_confirm_background
#: code:addons/sale_confirm_background/models/sale_order.py:45
#, python-format
msgid "Order %s will be confirmed in background."
msgstr "La commande %s va être confirmée en arrière-plan."

#. module: sale_confirm_background
#: model:ir.model,name:sale_confirm_background.model_sale_order
msgid "Sales Order"
msgstr "Commandes"

45 changes: 45 additions & 0 deletions sale_confirm_background/i18n/sale_confirm_background.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_confirm_background
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-06-28 06:18+0000\n"
"PO-Revision-Date: 2018-06-28 06:18+0000\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: sale_confirm_background
#: model:ir.ui.view,arch_db:sale_confirm_background.view_order_background_form
msgid "Cancel"
msgstr ""

#. module: sale_confirm_background
#: code:addons/sale_confirm_background/models/sale_order.py:48
#, python-format
msgid "Confirmation of sales order %s"
msgstr ""

#. module: sale_confirm_background
#: code:addons/sale_confirm_background/models/sale_order.py:30
#, python-format
msgid "Order %s is now confirmed."
msgstr ""

#. module: sale_confirm_background
#: code:addons/sale_confirm_background/models/sale_order.py:45
#, python-format
msgid "Order %s will be confirmed in background."
msgstr ""

#. module: sale_confirm_background
#: model:ir.model,name:sale_confirm_background.model_sale_order
msgid "Sales Order"
msgstr ""

1 change: 1 addition & 0 deletions sale_confirm_background/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
53 changes: 53 additions & 0 deletions sale_confirm_background/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.addons.queue_job.job import job


class Sale(models.Model):
_inherit = 'sale.order'

state = fields.Selection(
selection_add=[('confirm_background', 'Confirm in Background')]
)

@job(default_channel='root.background.sale_confirm')
@api.multi
def confirm_in_background(self, notify=True):
"""Confirm sales order in background"""
self.ensure_one()
if self.state != 'confirm_background':
return
self.action_confirm()
if notify:
action = self.env.ref('sale.action_orders').read()[0]
action.update({
'res_id': self.id,
'views': [(False, 'form')],
})
self.env.user.notify_info(
_('Order %s is now confirmed.') % self.name,
sticky=True,
action=action,
)

def action_confirm_background(self):
# compatibility with sale_exception
# we want to raise interactively, not in background
if self.detect_exceptions():
return self._popup_exceptions()
self.write({
'state': 'confirm_background',
'confirmation_date': fields.Datetime.now(),
})
for order in self:
self.env.user.notify_info(
_('Order %s will be confirmed in background.') % order.name,
)
order.with_delay(
description=_(
'Confirmation of sales order %s'
) % order.name,
).confirm_in_background(notify=False)
22 changes: 22 additions & 0 deletions sale_confirm_background/views/sale_order_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_order_background_form" model="ir.ui.view">
<field name="name">sale.order.background.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="priority">900</field>
<field name="arch" type="xml">
<button name="action_cancel" position="after">
<button name="action_cancel" states="confirm_background" type="object" string="Cancel"/>
</button>
<button name="action_confirm" states="sent" position="attributes">
<attribute name="name">action_confirm_background</attribute>
</button>
<button name="action_confirm" states="draft" position="attributes">
<attribute name="name">action_confirm_background</attribute>
</button>
</field>
</record>

</odoo>

0 comments on commit 78beff6

Please sign in to comment.