Skip to content

Commit

Permalink
Merge 1470417 into 47ec750
Browse files Browse the repository at this point in the history
  • Loading branch information
achaussende committed Dec 9, 2014
2 parents 47ec750 + 1470417 commit 3407fef
Show file tree
Hide file tree
Showing 14 changed files with 564 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sale_cancel_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author Adrien CHAUSSENDE <adrien.chaussende@akretion.com>
#
##############################################################################

from . import sale
39 changes: 39 additions & 0 deletions sale_cancel_purchase/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author Adrien CHAUSSENDE <adrien.chaussende@akretion.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 Cancel Purchase',
'version': '1.0',
'category': 'Generic Modules',
'description': """
Allows direct Sale cancellation.
Cancels related Purchase Order by the same time.
Logs will be stocked in a field of the sale order.
""",
'author': 'Akretion',
'website': 'http://akretion.com',
'depends': ['purchase', 'sale_cancel_picking'],
'test': ['test/purchase_cancel_test.yml'],
'installable': True,
'auto_install': False,
'application': False,
}
36 changes: 36 additions & 0 deletions sale_cancel_purchase/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * sale_cancel_purchase
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-12-01 15:03+0000\n"
"PO-Revision-Date: 2014-12-01 15:03+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_cancel_purchase
#: code:addons/sale_cancel_purchase/sale.py:62
#, python-format
msgid "Number of purchase order lines deleted: %s"
msgstr "Nombre de lignes de commandes d'achat supprimé: %s"

#. module: sale_cancel_purchase
#: code:addons/sale_cancel_purchase/sale.py:38
#, python-format
msgid "Fail to cancel the line with the product %s in the purchase order %s as the state is %s"
msgstr "Echec lors de l'annulation de la ligne avec le produit %s dans la commande d'achat %s comme l'état est %s"

#. module: sale_cancel_purchase
#: code:_description:0
#: model:ir.model,name:sale_cancel_purchase.model_sale_order
#, python-format
msgid "Sales Order"
msgstr "Bon de commande"

36 changes: 36 additions & 0 deletions sale_cancel_purchase/i18n/sale_cancel_purchase.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * sale_cancel_purchase
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-12-01 15:03+0000\n"
"PO-Revision-Date: 2014-12-01 15:03+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_cancel_purchase
#: code:addons/sale_cancel_purchase/sale.py:62
#, python-format
msgid "Number of purchase order lines deleted: %s"
msgstr ""

#. module: sale_cancel_purchase
#: code:addons/sale_cancel_purchase/sale.py:38
#, python-format
msgid "Fail to cancel the line with the product %s in the purchase order %s as the state is %s"
msgstr ""

#. module: sale_cancel_purchase
#: code:_description:0
#: model:ir.model,name:sale_cancel_purchase.model_sale_order
#, python-format
msgid "Sales Order"
msgstr ""

64 changes: 64 additions & 0 deletions sale_cancel_purchase/sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author Adrien CHAUSSENDE <adrien.chaussende@akretion.com>
#
##############################################################################

from openerp.osv import orm
from openerp.tools.translate import _


class SaleOrder(orm.Model):
_inherit = 'sale.order'

def _can_unlink_purchase_line(self, cr, uid, po_line, context=None):
"""
Method that returns if it's possible or not to unlink the purchase line
:param order: Purchase Order Line
:type items: browse_record
:return: tuple that contains the following values
(able_to_cancel, message, important)
"""
able_to_unlink = False
important = False
message = ""

if po_line.state == 'cancel':
pass
if po_line.state == 'draft':
able_to_unlink = True
else:
able_to_unlink = False
important = True
message = _("Fail to cancel the line with the product %s "
"in the purchase order %s as the state is %s") \
% (po_line.product_id.name, po_line.order_id.name,
po_line.state)
return able_to_unlink, message, important

def _cancel_linked_record(self, cr, uid, order, context=None):
po_line_obj = self.pool['purchase.order.line']
po_line_ids = po_line_obj.search(cr, uid, [
('sale_order_id', '=', order.id),
], context=context)
count = 0
for po_line in po_line_obj.browse(cr, uid, po_line_ids,
context=context):
able_to_unlink, message, important = \
self._can_unlink_purchase_line(
cr, uid, po_line, context=context)
if able_to_unlink:
count += 1
po_line.unlink()

order.add_cancel_log(message, important)
if count:
order.add_cancel_log(
_("Number of purchase order lines deleted: %s") % count)
return super(SaleOrder, self)._cancel_linked_record(
cr, uid, order, context=context)
58 changes: 58 additions & 0 deletions sale_cancel_purchase/test/purchase_cancel_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-
In order to test the module sale_cancel_purchase, I will create a sale order,
confirm it, and then cancel it. I will check after cancelling, that the
related Purchase Order Lines are canceled too.

So, I create a product that will be bought.
-
!record {model: product.product, id: product_product_5}:
name: Bought Product
sale_ok: True
purchase_ok: True
type: product
procure_method: make_to_order
supply_method: buy
list_price: 25.0
-
I create a partner
-
!record {model: res.partner, id: test_seller}:
name: "Supplier"
-
I create supplier infos
-
!record {model: product.supplierinfo, id: suppinfo_2}:
name: test_seller
product_id: product_product_5_product_template
min_qty: 0
-
I create a sale order with one line with previous product
-
!record {model: sale.order, id: sale_order_5}:
partner_id: base.res_partner_2
note: Invoice after delivery
payment_term: account.account_payment_term
order_line:
- product_id: product_product_5
product_uom: 1
product_uom_qty: 5
price_unit: 50
-
I confirm the Sale Order
-
!function {model: sale.order, name: action_button_confirm}:
- eval: "[obj(ref('sale_order_5')).id]"
model: sale.order
-
Then, I cancel it
-
!function {model: sale.order, name: action_cancel}:
- eval: "[obj(ref('sale_order_5')).id]"
model: sale.order
-
I check that linked Purchase Order Lines have been deleted/unlinked.
-
!python {model: purchase.order.line}: |
po_line_ids = self.search(cr, uid, [('sale_order_id','=',ref('sale_order_5'))], context=context)
assert len(po_line_ids) == 0, "Found line ids that have not be deleted"

11 changes: 11 additions & 0 deletions sale_purchase_link/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author Adrien CHAUSSENDE <adrien.chaussende@akretion.com>
#
##############################################################################

from . import sale_purchase_link
41 changes: 41 additions & 0 deletions sale_purchase_link/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author Adrien CHAUSSENDE <adrien.chaussende@akretion.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-Purchase Link',
'version': '1.0',
'category': 'Generic Modules',
'description': """
Implements a link between a Sale Order and its generated Manufacturing
Orders.
""",
'author': 'Akretion',
'website': 'http://akretion.com',
'depends': ['procurement'],
'data': [
'purchase_view.xml',
'sale_view.xml',
],
'installable': True,
'auto_install': False,
'application': False,
}
53 changes: 53 additions & 0 deletions sale_purchase_link/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * sale_purchase_link
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-12-01 09:49+0000\n"
"PO-Revision-Date: 2014-12-01 09:49+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_purchase_link
#: code:_description:0
#: model:ir.model,name:sale_purchase_link.model_procurement_order
#, python-format
msgid "Procurement"
msgstr "Approvisionnement"

#. module: sale_purchase_link
#: code:_description:0
#: model:ir.model,name:sale_purchase_link.model_purchase_order_line
#, python-format
msgid "Purchase Order Line"
msgstr "Ligne de commande d'achat"

#. module: sale_purchase_link
#: model:ir.actions.act_window,name:sale_purchase_link.act_sale_order_purchase_order_open
msgid "Purchase Orders Lines"
msgstr "Lignes de commande d'achat"

#. module: sale_purchase_link
#: code:_description:0
#: model:ir.model,name:sale_purchase_link.model_sale_order
#, python-format
msgid "Sales Order"
msgstr "Bon de commande"

#. module: sale_purchase_link
#: field:purchase.order.line,sale_order_id:0
msgid "Source Sale Order"
msgstr "Bon de commande d'origine"

#. module: sale_purchase_link
#: view:sale.order:0
msgid "See Purchase Orders"
msgstr "Voir commande d'achats"

0 comments on commit 3407fef

Please sign in to comment.