Skip to content

Commit

Permalink
Merge pull request #137 from gurneyalex/8.0-sale_order_revision
Browse files Browse the repository at this point in the history
8.0 sale order revision
  • Loading branch information
lepistone committed Jun 11, 2015
2 parents 3639077 + 2885278 commit 1c4dc2a
Show file tree
Hide file tree
Showing 9 changed files with 408 additions and 0 deletions.
41 changes: 41 additions & 0 deletions sale_order_revision/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License

Revisions for sale orders (and quotations)
==========================================

On cancelled orders, you can click on the "New copy of Quotation" button. This
will create a new revision of the quotation, with the same base number and a
'-revno' suffix appended. A message is added in the chatter saying that a new
revision was created.

In the form view, a new tab is added that lists the previous revisions, with
the date they were made obsolete and the user who performed the action.

The old revisions of a sale order are flagged as inactive, so they don't
clutter up searches.

Credits
=======

Contributors
------------

* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Raphael Valyi <rvalyi@akretion.com>
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit http://odoo-community.org.
9 changes: 9 additions & 0 deletions sale_order_revision/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

from . import model


def populate_unrevisioned_name(cr, registry):
cr.execute('UPDATE sale_order '
'SET unrevisioned_name = name '
'WHERE unrevisioned_name is NULL')
42 changes: 42 additions & 0 deletions sale_order_revision/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# @author Lorenzo Battistini <lorenzo.battistini@agilebg.com>
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

{
'name': "Sale order revisions",
'version': '0.1',
'category': 'Sale Management',
'author': 'Agile Business Group,'
'Camptocamp,'
'Akretion,'
'Odoo Community Association (OCA)',
'website': 'http://www.agilebg.com',
'license': 'AGPL-3',
"depends": ['sale'],
"data": [
'view/sale_order.xml',
],
"test": [
'test/sale_order.yml',
],
"active": False,
"installable": True,
"post_init_hook": 'populate_unrevisioned_name',
}
73 changes: 73 additions & 0 deletions sale_order_revision/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_revision
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-04-03 07:45+0000\n"
"PO-Revision-Date: 2015-04-03 07:45+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_revision
#: field:sale.order,active:0
msgid "Active"
msgstr "Actif"

#. module: sale_order_revision
#: field:sale.order,current_revision_id:0
msgid "Current revision"
msgstr "Dernière version"

#. module: sale_order_revision
#: code:addons/sale_order_revision/model/sale_order.py:64
#, python-format
msgid "New revision created: %s"
msgstr "Nouvelle version créée : %s"

#. module: sale_order_revision
#: field:sale.order,old_revision_ids:0
msgid "Old revisions"
msgstr "Précédentes versions"

#. module: sale_order_revision
#: field:sale.order,unrevisioned_name:0
msgid "Order Reference"
msgstr "Référence commande"

#. module: sale_order_revision
#: sql_constraint:sale.order:0
msgid "Order Reference and revision must be unique per Company."
msgstr "La référence de l'offre et son numéro de version doivent être uniques au sein d'une société."

#. module: sale_order_revision
#: field:sale.order,revision_number:0
msgid "Revision"
msgstr "Version"

#. module: sale_order_revision
#: view:sale.order:sale_order_revision.sale_order_form
msgid "Revisions"
msgstr "Versions"

#. module: sale_order_revision
#: model:ir.model,name:sale_order_revision.model_sale_order
msgid "Sales Order"
msgstr "Bon de commande"

#. module: sale_order_revision
#: view:sale.order:sale_order_revision.sale_order_form
msgid "Superseeded by"
msgstr "Remplacé par"

#. module: sale_order_revision
#: view:sale.order:sale_order_revision.sale_order_form
msgid "Superseeded on"
msgstr "Remplacé le"

73 changes: 73 additions & 0 deletions sale_order_revision/i18n/sale_order_revision.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_revision
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-04-03 07:44+0000\n"
"PO-Revision-Date: 2015-04-03 07:44+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_revision
#: field:sale.order,active:0
msgid "Active"
msgstr ""

#. module: sale_order_revision
#: field:sale.order,current_revision_id:0
msgid "Current revision"
msgstr ""

#. module: sale_order_revision
#: code:addons/sale_order_revision/model/sale_order.py:64
#, python-format
msgid "New revision created: %s"
msgstr ""

#. module: sale_order_revision
#: field:sale.order,old_revision_ids:0
msgid "Old revisions"
msgstr ""

#. module: sale_order_revision
#: field:sale.order,unrevisioned_name:0
msgid "Order Reference"
msgstr ""

#. module: sale_order_revision
#: sql_constraint:sale.order:0
msgid "Order Reference and revision must be unique per Company."
msgstr ""

#. module: sale_order_revision
#: field:sale.order,revision_number:0
msgid "Revision"
msgstr ""

#. module: sale_order_revision
#: view:sale.order:sale_order_revision.sale_order_form
msgid "Revisions"
msgstr ""

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

#. module: sale_order_revision
#: view:sale.order:sale_order_revision.sale_order_form
msgid "Superseeded by"
msgstr ""

#. module: sale_order_revision
#: view:sale.order:sale_order_revision.sale_order_form
msgid "Superseeded on"
msgstr ""

22 changes: 22 additions & 0 deletions sale_order_revision/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# @author Lorenzo Battistini <lorenzo.battistini@agilebg.com>
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import sale_order
96 changes: 96 additions & 0 deletions sale_order_revision/model/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# @author Lorenzo Battistini <lorenzo.battistini@agilebg.com>
# @author Raphaël Valyi <raphael.valyi@akretion.com> (ported to sale from
# original purchase_order_revision by Lorenzo Battistini)
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import fields, models, api
from openerp.tools.translate import _


class sale_order(models.Model):
_inherit = "sale.order"
current_revision_id = fields.Many2one('sale.order',
'Current revision',
readonly=True,
copy=True)
old_revision_ids = fields.One2many('sale.order',
'current_revision_id',
'Old revisions',
readonly=True,
context={'active_test': False})
revision_number = fields.Integer('Revision',
copy=False)
unrevisioned_name = fields.Char('Order Reference',
copy=True,
readonly=True)
active = fields.Boolean('Active',
default=True,
copy=True)

_sql_constraints = [
('revision_unique',
'unique(unrevisioned_name, revision_number, company_id)',
'Order Reference and revision must be unique per Company.'),
]

@api.multi
def copy_quotation(self):
self.ensure_one()
revision_self = self.with_context(new_sale_revision=True)
action = super(sale_order, revision_self).copy_quotation()
old_revision = self.browse(action['res_id'])
action['res_id'] = self.id
self.delete_workflow()
self.create_workflow()
self.write({'state': 'draft'})
msg = _('New revision created: %s') % self.name
self.message_post(body=msg)
old_revision.message_post(body=msg)
return action

@api.returns('self', lambda value: value.id)
@api.multi
def copy(self, defaults=None):
if not defaults:
defaults = {}
if self.env.context.get('new_sale_revision'):
prev_name = self.name
revno = self.revision_number
self.write({'revision_number': revno + 1,
'name': '%s-%02d' % (self.unrevisioned_name,
revno + 1)
})
defaults.update({'name': prev_name,
'revision_number': revno,
'active': False,
'state': 'cancel',
'current_revision_id': self.id,
})
return super(sale_order, self).copy(defaults)

@api.model
def create(self, values):
if 'unrevisioned_name' not in values:
if values.get('name', '/') == '/':
seq = self.env['ir.sequence']
values['name'] = seq.next_by_code('sale.order') or '/'
values['unrevisioned_name'] = values['name']
return super(sale_order, self).create(values)
24 changes: 24 additions & 0 deletions sale_order_revision/test/sale_order.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-
I create a SO
-
!record {model: sale.order, id: sale_order_1}:
partner_id: base.res_partner_2
order_line:
- product_id: product.product_product_15
product_uom_qty: 15.0
-
I cancel the SO
-
!python {model: sale.order}: |
self.action_cancel(cr, uid, [ref('sale_order_1')])
-
I create a new revision
-
!python {model: sale.order}: |
action = self.copy_quotation(cr, uid, [ref('sale_order_1')])
assert action['res_id'] == ref('sale_order_1')
new_so = self.browse(cr, uid, ref('sale_order_1'))
assert new_so.old_revision_ids, "Old revisions not set"
assert all(so.active == False for so in new_so.old_revision_ids)
assert new_so.revision_number == 1
assert new_so.name.endswith('-01')

0 comments on commit 1c4dc2a

Please sign in to comment.