Parcourir la source

commit inicial

Rodney Enciso Arias il y a 7 ans
commit
7cb0252eda

+ 54 - 0
README.rst

@@ -0,0 +1,54 @@
+.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
+   :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
+   :alt: License: AGPL-3
+
+======================
+Pickings back to draft
+======================
+
+This module allows to bring cancelled pickings back to draft
+
+Usage
+=====
+
+Just open a cancelled picking and click on 'back to draft' button
+
+.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
+   :alt: Try me on Runbot
+   :target: https://runbot.odoo-community.org/runbot/154/8.0
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues
+<https://github.com/OCA/stock-logistics-workflow/issues>`_. In case of trouble, please
+check there if your issue has already been reported. If you spotted it first,
+help us smashing it by providing a detailed and welcomed feedback.
+
+Credits
+=======
+
+Images
+------
+
+* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
+
+Contributors
+------------
+
+* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
+
+Maintainer
+----------
+
+.. image:: https://odoo-community.org/logo.png
+   :alt: Odoo Community Association
+   :target: https://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 https://odoo-community.org.

+ 5 - 0
__init__.py

@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# © 2016 Lorenzo Battistini - Agile Business Group
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from . import models

BIN
__init__.pyc


+ 21 - 0
__openerp__.py

@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# © 2016 Lorenzo Battistini - Agile Business Group
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+{
+    "name": "Pickings back to draft",
+    "summary": "Reopen cancelled pickings",
+    "version": "8.0.1.0.0",
+    "category": "Warehouse Management",
+    "website": "https://www.agilebg.com",
+    "author": "Agile Business Group, Odoo Community Association (OCA)",
+    "license": "AGPL-3",
+    "application": False,
+    "installable": True,
+    "depends": [
+        "stock",
+    ],
+    "data": [
+        'views/picking_view.xml',
+    ],
+    'images': ['images/picking.png'],
+}

BIN
images/picking.png


+ 5 - 0
models/__init__.py

@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# © 2016 Lorenzo Battistini - Agile Business Group
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from . import stock

BIN
models/__init__.pyc


+ 28 - 0
models/stock.py

@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+# © 2016 Lorenzo Battistini - Agile Business Group
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from openerp import models, api
+from openerp.exceptions import Warning as UserError
+from openerp.tools.translate import _
+
+
+class StockMove(models.Model):
+    _inherit = 'stock.move'
+
+    @api.multi
+    def action_back_to_draft(self):
+        if self.filtered(lambda m: m.state != 'cancel'):
+            raise UserError(_("You can set to draft cancelled moves only"))
+        self.write({'state': 'draft'})
+
+
+class StockPicking(models.Model):
+    _inherit = 'stock.picking'
+
+    @api.multi
+    def action_back_to_draft(self):
+        if self.filtered(lambda p: p.state != 'cancel'):
+            raise UserError(_("You can set to draft cancelled pickings only"))
+        moves = self.mapped('move_lines')
+        moves.action_back_to_draft()

BIN
models/stock.pyc


BIN
static/description/icon.png


+ 5 - 0
tests/__init__.py

@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# © 2016 Lorenzo Battistini - Agile Business Group
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from . import test_picking

+ 71 - 0
tests/test_picking.py

@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+# © 2016 Lorenzo Battistini - Agile Business Group
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from openerp.tests.common import TransactionCase
+from openerp.exceptions import Warning as UserError
+from openerp.osv import osv
+
+
+class TestPickingBackToDraft(TransactionCase):
+
+    def _create_picking(self):
+        return self.env['stock.picking'].create({
+            'partner_id': self.partner.id,
+            'picking_type_id': self.env.ref('stock.picking_type_out').id,
+        })
+
+    def _create_move(self, picking, product, quantity=5.0):
+        src_location = self.env.ref('stock.stock_location_stock')
+        dest_location = self.env.ref('stock.stock_location_customers')
+        return self.env['stock.move'].create({
+            'name': '/',
+            'picking_id': picking.id,
+            'product_id': product.id,
+            'product_uom_qty': quantity,
+            'product_uom': product.uom_id.id,
+            'location_id': src_location.id,
+            'location_dest_id': dest_location.id,
+        })
+
+    def setUp(self, *args, **kwargs):
+        super(TestPickingBackToDraft, self).setUp(*args, **kwargs)
+        self.partner = self.env.ref('base.res_partner_2')
+        self.product1 = self.env.ref('product.product_product_33')
+        self.product2 = self.env.ref('product.product_product_36')
+        self.picking_a = self._create_picking()
+        self.move_a_1 = self._create_move(
+            self.picking_a, self.product1, quantity=1)
+        self.move_a_2 = self._create_move(
+            self.picking_a, self.product2, quantity=2)
+
+    def test_back_to_draft(self):
+        self.assertEqual(self.picking_a.state, 'draft')
+        with self.assertRaises(UserError):
+            self.picking_a.action_back_to_draft()
+        self.picking_a.action_cancel()
+        self.assertEqual(self.picking_a.state, 'cancel')
+        self.picking_a.action_back_to_draft()
+        self.assertEqual(self.picking_a.state, 'draft')
+        self.picking_a.action_assign()
+        self.assertEqual(self.picking_a.state, 'confirmed')
+        with self.assertRaises(UserError):
+            self.picking_a.action_back_to_draft()
+        self.picking_a.action_cancel()
+        self.assertEqual(self.picking_a.state, 'cancel')
+        self.picking_a.action_back_to_draft()
+        self.assertEqual(self.picking_a.state, 'draft')
+        self.picking_a.action_confirm()
+        self.assertEqual(self.picking_a.state, 'confirmed')
+        self.picking_a.action_cancel()
+        self.assertEqual(self.picking_a.state, 'cancel')
+        self.picking_a.action_back_to_draft()
+        self.assertEqual(self.picking_a.state, 'draft')
+        self.picking_a.action_assign()
+        self.assertEqual(self.picking_a.state, 'confirmed')
+        self.picking_a.action_done()
+        self.assertEqual(self.picking_a.state, 'done')
+        with self.assertRaises(osv.except_osv):
+            self.picking_a.action_cancel()
+        with self.assertRaises(UserError):
+            self.picking_a.action_back_to_draft()

+ 15 - 0
views/picking_view.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="view_picking_form_reopen" model="ir.ui.view">
+            <field name="name">view_picking_form_reopen</field>
+            <field name="model">stock.picking</field>
+            <field name="inherit_id" ref="stock.view_picking_form"></field>
+            <field name="arch" type="xml">
+                <xpath expr="//button[@name='action_cancel']" position="after">
+                    <button name="action_back_to_draft" states="cancel" string="Back to draft" groups="base.group_user" type="object"/>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</openerp>