Skip to content

Commit

Permalink
Merge adde83f into d4acb7a
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed May 23, 2016
2 parents d4acb7a + adde83f commit eb64362
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sale_order_manual_close/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

=======================
Sale order manual close
=======================

This module allows to force manually ending of sale orders.
The wizard will raise an error.
- If the order is in state 'draft', 'cancel' or 'done.
- If the order has some picking not finished.
- If the order has some invoice not finished.

Credits
=======

Contributors
------------
* Daniel Campos <danielcampos@avanzosc.es>
* Ainara Galdona <ainaragaldona@avanzosc.es>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Ana Juaristi <ajuaristio@gmail.com>
6 changes: 6 additions & 0 deletions sale_order_manual_close/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################

from . import wizard
34 changes: 34 additions & 0 deletions sale_order_manual_close/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
##############################################################################

{
"name": "Sale Order manual close",
"version": "8.0.1.0.0",
'author': 'OdooMRP team',
'website': "http://www.odoomrp.com",
'contributors': ["Daniel Campos <danielcampos@avanzosc.es>",
"Ainara Galdona <ainaragaldona@gmail.com>",
"Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>",
"Ana Juaristi <ajuaristio@gmail.com>"],
"depends": ['sale',
'sale_stock'
],
"category": "Custom Modules",
"data": ['wizard/saleorder_wiz_view.xml'],
"installable": True
}
95 changes: 95 additions & 0 deletions sale_order_manual_close/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_manual_close
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-01 13:04+0000\n"
"PO-Revision-Date: 2015-12-01 13:04+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_order_manual_close
#: view:wizard.saleorder.wf:sale_order_manual_close.view_saleorder_wf
msgid "Accept"
msgstr "Aceptar"

#. module: sale_order_manual_close
#: view:wizard.saleorder.wf:sale_order_manual_close.view_saleorder_wf
msgid "Cancel"
msgstr "Cancelar"

#. module: sale_order_manual_close
#: code:addons/sale_order_manual_close/wizard/saleorder_wf.py:19
#, python-format
msgid "Cannot process already processed or in 'draft' state order."
msgstr "No se puede procesar un pedido procesado o en estado 'borrador'."

#. module: sale_order_manual_close
#: field:wizard.saleorder.wf,create_uid:0
msgid "Created by"
msgstr "Creado por"

#. module: sale_order_manual_close
#: field:wizard.saleorder.wf,create_date:0
msgid "Created on"
msgstr "Creado el"

#. module: sale_order_manual_close
#: model:ir.actions.act_window,name:sale_order_manual_close.saleorder_wf
msgid "End Sale Order Workflow"
msgstr "Finalizar flujo de pedido de venta"

#. module: sale_order_manual_close
#: view:wizard.saleorder.wf:sale_order_manual_close.view_saleorder_wf
msgid "Finish selected Sale Orders?"
msgstr "¿Quieres finalizar los pedidos de venta seleccionados?"

#. module: sale_order_manual_close
#: field:wizard.saleorder.wf,id:0
msgid "ID"
msgstr "ID"

#. module: sale_order_manual_close
#: field:wizard.saleorder.wf,write_uid:0
msgid "Last Updated by"
msgstr "Última actualización por"

#. module: sale_order_manual_close
#: field:wizard.saleorder.wf,write_date:0
msgid "Last Updated on"
msgstr "Última actualización el"

#. module: sale_order_manual_close
#: view:wizard.saleorder.wf:sale_order_manual_close.view_saleorder_wf
msgid "Sale Order Process"
msgstr "Procesar pedidos de venta"

#. module: sale_order_manual_close
#: code:addons/sale_order_manual_close/wizard/saleorder_wf.py:26
#, python-format
msgid "The order has no processed invoices."
msgstr "El pedido tiene facturas no procesadas."

#. module: sale_order_manual_close
#: code:addons/sale_order_manual_close/wizard/saleorder_wf.py:23
#, python-format
msgid "The order has no processed picking."
msgstr "El pedido tiene albaranes no procesados."

#. module: sale_order_manual_close
#: model:ir.model,name:sale_order_manual_close.model_wizard_saleorder_wf
msgid "Wizard Sale Order Workflow Finish"
msgstr "Asistente para cerrar el flujo de pedido de venta"

#. module: sale_order_manual_close
#: view:wizard.saleorder.wf:sale_order_manual_close.view_saleorder_wf
msgid "or"
msgstr "o"

5 changes: 5 additions & 0 deletions sale_order_manual_close/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# (c) 2015 Ainara Galdona - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import test_sale_order_manual_close
135 changes: 135 additions & 0 deletions sale_order_manual_close/tests/test_sale_order_manual_close.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# -*- coding: utf-8 -*-
# (c) 2015 Ainara Galdona - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import openerp.tests.common as common
from openerp import exceptions, fields, _


class TestSaleOrderManualClose(common.TransactionCase):

def setUp(self):
super(TestSaleOrderManualClose, self).setUp()
self.sale_model = self.env['sale.order']
self.finish_wk_model = self.env['wizard.saleorder.wf']
uom_unit_id = self.ref('product.product_uom_unit')
line1 = {'name': 'Laptop E5023',
'product_id': self.ref('product.product_product_25'),
'product_uom_qty': 3,
'product_uos_qty': 3,
'product_uom': uom_unit_id,
'price_unit': 2950.00
}
line2 = {'name': 'Pen drive, 16GB',
'product_id': self.ref('product.product_product_30'),
'product_uom_qty': 5,
'product_uos_qty': 5,
'product_uom': uom_unit_id,
'price_unit': 145.00
}
line3 = {'name': 'Headset USB',
'product_id': self.ref('product.product_product_33'),
'product_uom_qty': 2,
'product_uos_qty': 2,
'product_uom': uom_unit_id,
'price_unit': 65.00
}
partner_id = self.ref('base.res_partner_2')
sale_vals = {
'partner_id': partner_id,
'partner_invoice_id': partner_id,
'partner_shipping_id': partner_id,
'user_id': self.ref('base.user_demo'),
'pricelist_id': self.ref('product.list0'),
'section_id': self.ref('sales_team.section_sales_department'),
'date_order': fields.Date.today(),
'order_line': [(0, 0, line1), (0, 0, line2), (0, 0, line3)],
'order_policy': 'manual'
}
self.order = self.sale_model.create(sale_vals)

def test_draft_order_finish(self):
try:
self.finish_wk_model.with_context(
active_model='sale.order', active_id=self.order.id,
active_ids=[self.order.id]).saleorder_finish_wf()
except exceptions.Warning as e:
self.assertEqual(e.message, _("Cannot process already processed or"
" in 'draft' state order."),
"The order is not in draft state.")

def test_cancel_order_finish(self):
self.order.signal_workflow('cancel')
try:
self.finish_wk_model.with_context(
active_model='sale.order', active_id=self.order.id,
active_ids=[self.order.id]).saleorder_finish_wf()
except exceptions.Warning as e:
self.assertEqual(e.message, _("Cannot process already processed or"
" in 'draft' state order."),
"The order is not in cancel state.")

def test_confirm_order_finish_error(self):
self.order.action_button_confirm()
try:
self.finish_wk_model.with_context(
active_model='sale.order', active_id=self.order.id,
active_ids=[self.order.id]).saleorder_finish_wf()
except exceptions.Warning as e:
self.assertEqual(e.message,
_("The order has no processed picking."),
"All pickings are canceled or processed.")

def test_confirm_order_picking_raise_finish(self):
self.order.action_button_confirm()
self.order.action_invoice_create()
self.order.invoice_ids.signal_workflow('invoice_cancel')
try:
self.finish_wk_model.with_context(
active_model='sale.order', active_id=self.order.id,
active_ids=[self.order.id]).saleorder_finish_wf()
except exceptions.Warning as e:
self.assertEqual(e.message,
_("The order has no processed picking."),
"All pickings are canceled or processed.")

def test_confirm_order_invoice_raise_finish(self):
self.order.action_button_confirm()
self.order.action_invoice_create()
self.order.picking_ids.action_cancel()
try:
self.finish_wk_model.with_context(
active_model='sale.order', active_id=self.order.id,
active_ids=[self.order.id]).saleorder_finish_wf()
except exceptions.Warning as e:
self.assertEqual(e.message,
_("The order has no processed invoices."),
"All invoices are canceled or processed.")

def test_confirm_order_ok_finish(self):
self.order.action_button_confirm()
self.order.action_invoice_create()
self.order.invoice_ids.signal_workflow('invoice_cancel')
self.order.picking_ids.action_cancel()
self.finish_wk_model.with_context(
active_model='sale.order', active_id=self.order.id,
active_ids=[self.order.id]).saleorder_finish_wf()
self.assertEqual(self.order.state, 'done',
"Orders workflow is not finished.")

def test_order_already_processed_finish(self):
self.order.action_button_confirm()
self.order.action_invoice_create()
self.order.invoice_ids.signal_workflow('invoice_cancel')
self.order.picking_ids.action_cancel()
self.finish_wk_model.with_context(
active_model='sale.order', active_id=self.order.id,
active_ids=[self.order.id]).saleorder_finish_wf()
try:
self.finish_wk_model.with_context(
active_model='sale.order', active_id=self.order.id,
active_ids=[self.order.id]).saleorder_finish_wf()
except exceptions.Warning as e:
self.assertEqual(e.message, _("Cannot process already processed or"
" in 'draft' state order."),
"The order is not already processed.")
6 changes: 6 additions & 0 deletions sale_order_manual_close/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################

from . import saleorder_wf
28 changes: 28 additions & 0 deletions sale_order_manual_close/wizard/saleorder_wf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
from openerp import models, api, exceptions, _


class WizardSaleorderWf(models.TransientModel):
_name = 'wizard.saleorder.wf'
_description = 'Wizard Sale Order Workflow Finish'

@api.multi
def saleorder_finish_wf(self):
active_id = self.env.context.get('active_id', False)
if not active_id:
return
order = self.env['sale.order'].browse(active_id)
if order.state in ('draft', 'done', 'cancel'):
raise exceptions.Warning(_("Cannot process already processed "
"or in 'draft' state order."))
elif order.picking_ids.filtered(lambda x:
x.state not in ('cancel', 'done')):
raise exceptions.Warning(_("The order has no processed picking."))
elif order.invoice_ids.filtered(lambda x:
x.state not in ('cancel', 'paid')):
raise exceptions.Warning(_("The order has no processed invoices."))
order.delete_workflow()
order.state = 'done'
28 changes: 28 additions & 0 deletions sale_order_manual_close/wizard/saleorder_wiz_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="view_saleorder_wf" model="ir.ui.view">
<field name="name">view.saleorder.wf</field>
<field name="model">wizard.saleorder.wf</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Sale Order Process">
<separator string="Finish selected Sale Orders?"
colspan="4" />
<footer>
<button class="oe_highlight" name="saleorder_finish_wf"
string="Accept" type="object" />
or
<button class="oe_link" special="cancel"
string="Cancel" />
</footer>
</form>
</field>
</record>
<act_window id="saleorder_wf" name="End Sale Order Workflow"
res_model="wizard.saleorder.wf" src_model="sale.order"
key2="client_action_relate" view_id="view_saleorder_wf"
target="new" />
</data>
</openerp>

0 comments on commit eb64362

Please sign in to comment.